MavenProjectDependenciesAnalyzer { public MModule getModuleDependencies(MavenModule mavenModule, RepositorySystemSession session, DependenciesAnalyzerListener listener) throws ArtifactDescriptorException, IOException, DependencyCollectionException, ModelBuildingException { ModuleDependencies moduleDependencies = doGetModuleDependencies(mavenModule, session, listener); return toMModule(moduleDependencies); } MavenProjectDependenciesAnalyzer(List<RemoteRepository> remoteRepositories, RepositorySystem repositorySystem); MModule getModuleDependencies(MavenModule mavenModule, RepositorySystemSession session, DependenciesAnalyzerListener listener);  }
@Test public void getDependenciesOfProjA() throws MavenWorkspaceReaderException, ArtifactDescriptorException, IOException, DependencyCollectionException, ModelBuildingException { File repositoryRoot = new File("src/test/resources/projA"); WorkspaceFilesystem workspaceFilesystem = new FSWorkspaceFilesystem(repositoryRoot); MavenWorkspaceReader workspaceReader = mavenBooter.newWorkspaceReader(workspaceFilesystem, new LoggingMavenWorkspaceListener(listenerLogger)); MavenRepositorySystemSession session = mavenBooter.newRepositorySystemSession(new LoggingTransferListener(listenerLogger), new LoggingRepositoryListener(listenerLogger)); session.setWorkspaceReader(workspaceReader); MModule mModule = mavenProjectDependenciesAnalyzer.getModuleDependencies(workspaceReader.getRootModule(), session, new LoggingDependenciesAnalyzerListener(listenerLogger)); assertThat(mModule, IsArtifact("com.sonatype.example", "projA", "1.0.0-SNAPSHOT")); assertThat(mModule.getDependencyTree(), IsArtifact("com.sonatype.example", "projA", "1.0.0-SNAPSHOT")); assertThat(mModule.getDependencyTree().getDependencies(), hasItem(Matchers.<MDependency>IsArtifact("org.apache.maven", "maven-model", "3.0.4"))); mModule.accept(new LoggingModuleVisitor(listenerLogger)); }
@Test public void getDependenciesOfProjB() throws MavenWorkspaceReaderException, ArtifactDescriptorException, IOException, DependencyCollectionException, ModelBuildingException { File repositoryRoot = new File("src/test/resources/projB"); WorkspaceFilesystem workspaceFilesystem = new FSWorkspaceFilesystem(repositoryRoot); MavenWorkspaceReader workspaceReader = mavenBooter.newWorkspaceReader(workspaceFilesystem, new LoggingMavenWorkspaceListener(listenerLogger)); MavenRepositorySystemSession session = mavenBooter.newRepositorySystemSession(new LoggingTransferListener(listenerLogger), new LoggingRepositoryListener(listenerLogger)); session.setWorkspaceReader(workspaceReader); MModule mModule = mavenProjectDependenciesAnalyzer.getModuleDependencies(workspaceReader.getRootModule(), session, new LoggingDependenciesAnalyzerListener(listenerLogger)); mModule.accept(new LoggingModuleVisitor(listenerLogger)); assertThat(mModule, IsModule("com.sonatype.example", "projB", "1.0.0-SNAPSHOT")); assertThat(mModule, new ArtifactTreeMatcher<IArtifact>() .match(IsModule("com.sonatype.example", "moduleA", "1.0.0-SNAPSHOT"))); assertThat(mModule, new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.sonatype.example", "moduleA", "1.0.0-SNAPSHOT")) .match(IsMDependency("commons-io", "commons-io", "1.3.2"))); assertThat(mModule, new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.sonatype.example", "moduleA", "1.0.0-SNAPSHOT")) .get(IsArtifact("commons-io", "commons-io", "1.3.2")) .notMatch(IsMDependency("junit", "junit", "3.8.1"))); assertThat(mModule, new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.sonatype.example", "moduleB", "1.0.0-SNAPSHOT")) .match(IsMDependency("org.apache.commons", "commons-skin", "3"))); assertThat(mModule, new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.sonatype.example", "moduleB", "1.0.0-SNAPSHOT")) .get(IsArtifact("com.sonatype.example", "moduleA", "1.0.0-SNAPSHOT")) .get(IsArtifact("commons-io", "commons-io", "1.3.2")) .notMatch(IsMDependency("junit", "junit", "3.8.1"))); assertThat(mModule, new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.sonatype.example", "moduleB", "1.0.0-SNAPSHOT")) .get(IsArtifact("junit", "junit", "4.10")) .notMatch(IsMDependency("org.hamcrest", "hamcrest-core", "1.1"))); }
@Ignore @Test public void test() throws MavenWorkspaceReaderException, ArtifactDescriptorException, IOException, DependencyCollectionException, ModelBuildingException { File repositoryRoot = new File("c:/work/wix/git/wix-public"); WorkspaceFilesystem workspaceFilesystem = new FSWorkspaceFilesystem(repositoryRoot); MavenWorkspaceReader workspaceReader = mavenBooter.newWorkspaceReader(workspaceFilesystem, new LoggingMavenWorkspaceListener(listenerLogger)); MavenRepositorySystemSession session = mavenBooter.newRepositorySystemSession(new LoggingTransferListener(listenerLogger), new LoggingRepositoryListener(listenerLogger)); session.setWorkspaceReader(workspaceReader); MModule mModule = mavenProjectDependenciesAnalyzer.getModuleDependencies(workspaceReader.getRootModule(), session, new LoggingDependenciesAnalyzerListener(listenerLogger)); mModule.accept(new LoggingModuleVisitor(listenerLogger)); }