@Test public void testFindLocalArtifacts_absolutePath() { Path relativePath = Paths.get("src/test/resources/testproject"); Path absolutePath = relativePath.toAbsolutePath(); ImmutableMap<String, String> localArtifactsFromAbsolutePath = LinkageMonitor.findLocalArtifacts(system, session, absolutePath); ImmutableMap<String, String> localArtifactsFromRelativePath = LinkageMonitor.findLocalArtifacts(system, session, relativePath); assertEquals( "findLocalArtifacts should behave the same for relative and absolute paths", localArtifactsFromRelativePath, localArtifactsFromAbsolutePath); }
@VisibleForTesting static ImmutableMap<String, String> findLocalArtifacts( RepositorySystem repositorySystem, RepositorySystemSession session, Path projectDirectory) { ImmutableMap.Builder<String, String> artifactToVersion = ImmutableMap.builder(); Iterable<Path> paths = MoreFiles.fileTraverser().breadthFirst(projectDirectory); for (Path path : paths) { if (!path.getFileName().endsWith("pom.xml")) { continue; } Path relativePath = path.isAbsolute() ? projectDirectory.relativize(path) : path; ImmutableSet<Path> elements = ImmutableSet.copyOf(relativePath); if (elements.contains(Paths.get("build")) || elements.contains(Paths.get("target"))) { continue; } ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest(); modelRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); modelRequest.setProcessPlugins(false); modelRequest.setTwoPhaseBuilding(false); modelRequest.setPomFile(path.toFile()); modelRequest.setModelResolver( new ProjectModelResolver( session, null, repositorySystem, new DefaultRemoteRepositoryManager(), ImmutableList.of(CENTRAL), null, null)); modelRequest.setSystemProperties(System.getProperties()); try { ModelBuildingResult modelBuildingResult = modelBuilder.build(modelRequest); Model model = modelBuildingResult.getEffectiveModel(); artifactToVersion.put(model.getGroupId() + ":" + model.getArtifactId(), model.getVersion()); } catch (ModelBuildingException ex) { logger.info("Ignoring bad model: " + path + ": " + ex.getMessage()); } } return artifactToVersion.build(); }
LinkageMonitor { @VisibleForTesting static ImmutableMap<String, String> findLocalArtifacts( RepositorySystem repositorySystem, RepositorySystemSession session, Path projectDirectory) { ImmutableMap.Builder<String, String> artifactToVersion = ImmutableMap.builder(); Iterable<Path> paths = MoreFiles.fileTraverser().breadthFirst(projectDirectory); for (Path path : paths) { if (!path.getFileName().endsWith("pom.xml")) { continue; } Path relativePath = path.isAbsolute() ? projectDirectory.relativize(path) : path; ImmutableSet<Path> elements = ImmutableSet.copyOf(relativePath); if (elements.contains(Paths.get("build")) || elements.contains(Paths.get("target"))) { continue; } ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest(); modelRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); modelRequest.setProcessPlugins(false); modelRequest.setTwoPhaseBuilding(false); modelRequest.setPomFile(path.toFile()); modelRequest.setModelResolver( new ProjectModelResolver( session, null, repositorySystem, new DefaultRemoteRepositoryManager(), ImmutableList.of(CENTRAL), null, null)); modelRequest.setSystemProperties(System.getProperties()); try { ModelBuildingResult modelBuildingResult = modelBuilder.build(modelRequest); Model model = modelBuildingResult.getEffectiveModel(); artifactToVersion.put(model.getGroupId() + ":" + model.getArtifactId(), model.getVersion()); } catch (ModelBuildingException ex) { logger.info("Ignoring bad model: " + path + ": " + ex.getMessage()); } } return artifactToVersion.build(); } }
LinkageMonitor { @VisibleForTesting static ImmutableMap<String, String> findLocalArtifacts( RepositorySystem repositorySystem, RepositorySystemSession session, Path projectDirectory) { ImmutableMap.Builder<String, String> artifactToVersion = ImmutableMap.builder(); Iterable<Path> paths = MoreFiles.fileTraverser().breadthFirst(projectDirectory); for (Path path : paths) { if (!path.getFileName().endsWith("pom.xml")) { continue; } Path relativePath = path.isAbsolute() ? projectDirectory.relativize(path) : path; ImmutableSet<Path> elements = ImmutableSet.copyOf(relativePath); if (elements.contains(Paths.get("build")) || elements.contains(Paths.get("target"))) { continue; } ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest(); modelRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); modelRequest.setProcessPlugins(false); modelRequest.setTwoPhaseBuilding(false); modelRequest.setPomFile(path.toFile()); modelRequest.setModelResolver( new ProjectModelResolver( session, null, repositorySystem, new DefaultRemoteRepositoryManager(), ImmutableList.of(CENTRAL), null, null)); modelRequest.setSystemProperties(System.getProperties()); try { ModelBuildingResult modelBuildingResult = modelBuilder.build(modelRequest); Model model = modelBuildingResult.getEffectiveModel(); artifactToVersion.put(model.getGroupId() + ":" + model.getArtifactId(), model.getVersion()); } catch (ModelBuildingException ex) { logger.info("Ignoring bad model: " + path + ": " + ex.getMessage()); } } return artifactToVersion.build(); }  }
LinkageMonitor { @VisibleForTesting static ImmutableMap<String, String> findLocalArtifacts( RepositorySystem repositorySystem, RepositorySystemSession session, Path projectDirectory) { ImmutableMap.Builder<String, String> artifactToVersion = ImmutableMap.builder(); Iterable<Path> paths = MoreFiles.fileTraverser().breadthFirst(projectDirectory); for (Path path : paths) { if (!path.getFileName().endsWith("pom.xml")) { continue; } Path relativePath = path.isAbsolute() ? projectDirectory.relativize(path) : path; ImmutableSet<Path> elements = ImmutableSet.copyOf(relativePath); if (elements.contains(Paths.get("build")) || elements.contains(Paths.get("target"))) { continue; } ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest(); modelRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); modelRequest.setProcessPlugins(false); modelRequest.setTwoPhaseBuilding(false); modelRequest.setPomFile(path.toFile()); modelRequest.setModelResolver( new ProjectModelResolver( session, null, repositorySystem, new DefaultRemoteRepositoryManager(), ImmutableList.of(CENTRAL), null, null)); modelRequest.setSystemProperties(System.getProperties()); try { ModelBuildingResult modelBuildingResult = modelBuilder.build(modelRequest); Model model = modelBuildingResult.getEffectiveModel(); artifactToVersion.put(model.getGroupId() + ":" + model.getArtifactId(), model.getVersion()); } catch (ModelBuildingException ex) { logger.info("Ignoring bad model: " + path + ": " + ex.getMessage()); } } return artifactToVersion.build(); }  static void main(String[] arguments); }
LinkageMonitor { @VisibleForTesting static ImmutableMap<String, String> findLocalArtifacts( RepositorySystem repositorySystem, RepositorySystemSession session, Path projectDirectory) { ImmutableMap.Builder<String, String> artifactToVersion = ImmutableMap.builder(); Iterable<Path> paths = MoreFiles.fileTraverser().breadthFirst(projectDirectory); for (Path path : paths) { if (!path.getFileName().endsWith("pom.xml")) { continue; } Path relativePath = path.isAbsolute() ? projectDirectory.relativize(path) : path; ImmutableSet<Path> elements = ImmutableSet.copyOf(relativePath); if (elements.contains(Paths.get("build")) || elements.contains(Paths.get("target"))) { continue; } ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest(); modelRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); modelRequest.setProcessPlugins(false); modelRequest.setTwoPhaseBuilding(false); modelRequest.setPomFile(path.toFile()); modelRequest.setModelResolver( new ProjectModelResolver( session, null, repositorySystem, new DefaultRemoteRepositoryManager(), ImmutableList.of(CENTRAL), null, null)); modelRequest.setSystemProperties(System.getProperties()); try { ModelBuildingResult modelBuildingResult = modelBuilder.build(modelRequest); Model model = modelBuildingResult.getEffectiveModel(); artifactToVersion.put(model.getGroupId() + ":" + model.getArtifactId(), model.getVersion()); } catch (ModelBuildingException ex) { logger.info("Ignoring bad model: " + path + ": " + ex.getMessage()); } } return artifactToVersion.build(); }  static void main(String[] arguments);  }