/** * Creates a Jackson object mapper based on a media type. It supports JSON, JSON Smile, XML, YAML * and CSV. * * @return The Jackson object mapper. */ protected ObjectMapper createObjectMapper() { ObjectMapper result = null; if (MediaType.APPLICATION_JSON.isCompatible(getMediaType())) { JsonFactory jsonFactory = new JsonFactory(); jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new ObjectMapper(jsonFactory); } else if (MediaType.APPLICATION_JSON_SMILE.isCompatible(getMediaType())) { SmileFactory smileFactory = new SmileFactory(); smileFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new ObjectMapper(smileFactory); } else if (MediaType.APPLICATION_XML.isCompatible(getMediaType()) || MediaType.TEXT_XML.isCompatible(getMediaType())) { XmlFactory xmlFactory = new XmlFactory(); xmlFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new XmlMapper(xmlFactory); } else if (MediaType.APPLICATION_YAML.isCompatible(getMediaType())) { YAMLFactory yamlFactory = new YAMLFactory(); yamlFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new ObjectMapper(yamlFactory); } else if (MediaType.TEXT_CSV.isCompatible(getMediaType())) { CsvFactory csvFactory = new CsvFactory(); csvFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new CsvMapper(csvFactory); } else { JsonFactory jsonFactory = new JsonFactory(); jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new ObjectMapper(jsonFactory); } return result; }
@Override public Set<Module> discover(GitInfo gitInfo) throws IOException { GHRepository repository = repositoryFor(gitInfo); GHTree tree = treeFor(repository, gitInfo); Set<String> poms = new HashSet<>(); for (GHTreeEntry entry : tree.getTree()) { if (isPom(entry.getPath())) { poms.add(entry.getPath()); } } Set<Module> modules = new HashSet<>(); for (String path : poms) { final ProjectObjectModel pom; try { JsonParser parser = xmlFactory.createParser(contentsFor(path, repository, gitInfo)); pom = objectMapper.readValue(parser, ProjectObjectModel.class); } catch (IOException e) { LOG.error( "Error parsing POM at path {} for repo {}@{}", path, gitInfo.getFullRepositoryName(), gitInfo.getBranch()); continue; } final String glob; if ("pom".equals(pom.getPackaging())) { glob = path; } else { glob = (path.contains("/") ? path.substring(0, path.lastIndexOf('/') + 1) : "") + "**"; } modules.add(new Module(pom.getArtifactId(), path, glob, BUILDPACK)); } return modules; }