BuildTypeDependenciesDecorator { public MavenDependenciesResult decorateWithBuildTypesAnalysis(MavenDependenciesResult mavenResult, SBuildType buildType) { RequestCache requestCache = new RequestCache(); requestCache.put(buildType, mavenResult); Map<ArtifactId, BuildTypeId> artifactBuildMapping = readArtifactModuleMapping(requestCache); return new MavenDependenciesResult(mavenResult.getResultType(), decorateDependenciesWithBuilds(mavenResult.getModule(), artifactBuildMapping), mavenResult.getFullTrace()); } BuildTypeDependenciesDecorator(MavenBuildTypeDependenciesAnalyzer mavenBuildAnalyzer, ProjectManager projectManager); MavenDependenciesResult decorateWithBuildTypesAnalysis(MavenDependenciesResult mavenResult, SBuildType buildType);  }
@Test public void decorateDependencies() { MModule build1Root = MModule("com.wixpress", "A", "1") .build(); MModule build2Root = MModule("com.wixpress", "B2", "2") .withDependency(build1Root) .build(); MModule build3moduleC3 = MModule("com.wixpress", "C3", "3") .withDependency(build2Root) .build(); MModule build3moduleC4 = MModule("com.wixpress", "C4", "4") .withDependency(build3moduleC3) .build(); MModule build3Root = MModule("com.wixpress", "C5", "5") .withModule(build3moduleC3) .withModule(build3moduleC4) .build(); when(projectManager.getActiveBuildTypes()).thenReturn(ImmutableList.of(build1, build2, build3)); when(mavenBuildAnalyzer.getBuildDependencies(eq(build1), anyBoolean())).thenReturn(new MavenDependenciesResult(build1Root)); when(mavenBuildAnalyzer.getBuildDependencies(eq(build2), anyBoolean())).thenReturn(new MavenDependenciesResult(build2Root)); MavenDependenciesResult mavenDependenciesResult = new MavenDependenciesResult(build3Root); when(mavenBuildAnalyzer.getBuildDependencies(eq(build3), anyBoolean())).thenReturn(mavenDependenciesResult); MavenDependenciesResult result = analyzer.decorateWithBuildTypesAnalysis(mavenDependenciesResult, build3); assertThat(result.getModule(), IsModule("com.wixpress", "C5", "5")); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .match(IsModule("com.wixpress", "C3", "3"))); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.wixpress", "C3", "3")) .match(IsMBuildTypeDependency("com.wixpress", "B2", "2", "proj2", "build2", "p2", "b2"))); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.wixpress", "C3", "3")) .get(IsArtifact("com.wixpress", "B2", "2")) .match(IsMBuildTypeDependency("com.wixpress", "A", "1", "proj1", "build1", "p1", "b1"))); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .match(IsModule("com.wixpress", "C4", "4"))); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.wixpress", "C4", "4")) .match(IsMDependency("com.wixpress", "C3", "3"))); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.wixpress", "C4", "4")) .get(IsArtifact("com.wixpress", "C3", "3")) .match(IsMBuildTypeDependency("com.wixpress", "B2", "2", "proj2", "build2", "p2", "b2"))); }
@Test public void decorateDependenciesWithMissingBuildType() { MModule build1Root = MModule("com.wixpress", "A", "1") .build(); MModule build2Root = MModule("com.wixpress", "B2", "2") .withDependency(build1Root) .build(); MModule build3moduleC3 = MModule("com.wixpress", "C3", "3") .withDependency(build2Root) .build(); MModule build3moduleC4 = MModule("com.wixpress", "C4", "4") .withDependency(build3moduleC3) .build(); MModule build3Root = MModule("com.wixpress", "C5", "5") .withModule(build3moduleC3) .withModule(build3moduleC4) .build(); when(projectManager.getActiveBuildTypes()).thenReturn(ImmutableList.of(build1, build2, build3)); when(mavenBuildAnalyzer.getBuildDependencies(eq(build1), anyBoolean())).thenReturn(new MavenDependenciesResult(build1Root)); when(mavenBuildAnalyzer.getBuildDependencies(eq(build2), anyBoolean())).thenReturn(new MavenDependenciesResult(ResultType.notRun)); MavenDependenciesResult mavenDependenciesResult = new MavenDependenciesResult(build3Root); when(mavenBuildAnalyzer.getBuildDependencies(eq(build3), anyBoolean())).thenReturn(mavenDependenciesResult); MavenDependenciesResult result = analyzer.decorateWithBuildTypesAnalysis(mavenDependenciesResult, build3); assertThat(result.getModule(), IsModule("com.wixpress", "C5", "5")); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .match(IsModule("com.wixpress", "C3", "3"))); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.wixpress", "C3", "3")) .match(IsMBuildTypeDependency("com.wixpress", "B2", "2", "unknown", "unknown", "B2", "com.wixpress"))); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.wixpress", "C3", "3")) .get(IsArtifact("com.wixpress", "B2", "2")) .match(IsMBuildTypeDependency("com.wixpress", "A", "1", "proj1", "build1", "p1", "b1"))); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .match(IsModule("com.wixpress", "C4", "4"))); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.wixpress", "C4", "4")) .match(IsMDependency("com.wixpress", "C3", "3"))); assertThat(result.getModule(), new ArtifactTreeMatcher<IArtifact>() .get(IsArtifact("com.wixpress", "C4", "4")) .get(IsArtifact("com.wixpress", "C3", "3")) .match(IsMBuildTypeDependency("com.wixpress", "B2", "2", "unknown", "unknown", "B2", "com.wixpress"))); }