BuildPlanAnalyzer { public List<MBuildPlanItem> getBuildPlan(BuildTypeDependencies buildTypeDependencies) { Graph graph = buildGraph(buildTypeDependencies); markNodesPendingChangesAndLastBuild(graph); markNodesNeedingRebuild(graph); markNodesNeedingRebuildingByDependencies(graph); CycleSolvingTopologicalSorter<BuildTypeNode> topologicalSorter = new CycleSolvingTopologicalSorter<BuildTypeNode>(graph.values()); List<BuildTypeNode> sortedNodes = topologicalSorter.sort(); return transform(sortedNodes, new Transform()); } BuildPlanAnalyzer(ProjectManager projectManager, ConfigModel configModel, DependenciesDao dependenciesDao); List<MBuildPlanItem> getBuildPlan(BuildTypeDependencies buildTypeDependencies);  }
@Test public void testSortBuildTypes() { BuildTypeDependencies root = newBuildTypeDependencies("root", "a", "b"); BuildTypeDependencies a = newBuildTypeDependencies("a"); BuildTypeDependencies b = newBuildTypeDependencies("b"); mockBuild(root, false, d3); mockBuild(a, false, d2); mockBuild(b, false, d1); List<MBuildPlanItem> sorted = sorter.getBuildPlan(root); assertTrue(indexOf(sorted, buildPlanItem("root")) < indexOf(sorted, buildPlanItem("a"))); assertTrue(indexOf(sorted, buildPlanItem("a")) < indexOf(sorted, buildPlanItem("b"))); }
@Test public void testSortBuildTypesWithMultipleDependenciesOfSameBuildType() { BuildTypeDependencies root = newBuildTypeDependencies("root", "bt1", "bt2"); BuildTypeDependencies bt1 = newBuildTypeDependencies("bt1", "bt2"); BuildTypeDependencies bt2 = newBuildTypeDependencies("bt2"); mockBuild(root, false, d3); mockBuild(bt1, false, d2); mockBuild(bt2, false, d1); List<MBuildPlanItem> sorted = sorter.getBuildPlan(root); assertTrue(indexOf(sorted, buildPlanItem("root")) < indexOf(sorted, buildPlanItem("bt1"))); assertTrue(indexOf(sorted, buildPlanItem("bt1")) < indexOf(sorted, buildPlanItem("bt2"))); }
@Test public void dependentBuildNeverBuilt() { BuildTypeDependencies root = newBuildTypeDependencies("root", "bt1", "bt3"); BuildTypeDependencies bt1 = newBuildTypeDependencies("bt1", "bt2", "bt3"); BuildTypeDependencies bt2 = newBuildTypeDependencies("bt2"); BuildTypeDependencies bt3 = newBuildTypeDependencies("bt3"); mockBuild(root, false, d3); mockBuild(bt1, false, d2); mockBuild(bt2, false, null); mockBuild(bt3, false, d1); List<MBuildPlanItem> sorted = sorter.getBuildPlan(root); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("root")), true, containsString("[proj-bt1:name-bt1] require building")))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt1")), true, containsString("[proj-bt2:name-bt2] require building")))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt2")), true, containsString("No successful build found")))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt3")), false, any(String.class)))); }
@Test public void dependentBuildHasPendingChanges() { BuildTypeDependencies root = newBuildTypeDependencies("root", "bt1", "bt3"); BuildTypeDependencies bt1 = newBuildTypeDependencies("bt1", "bt2", "bt3"); BuildTypeDependencies bt2 = newBuildTypeDependencies("bt2"); BuildTypeDependencies bt3 = newBuildTypeDependencies("bt3"); mockBuild(root, false, d3); mockBuild(bt1, false, d2); mockBuild(bt2, true, d1); mockBuild(bt3, false, d1); List<MBuildPlanItem> sorted = sorter.getBuildPlan(root); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("root")), true, containsString("[proj-bt1:name-bt1] require building")))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt1")), true, containsString("[proj-bt2:name-bt2] require building")))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt2")), true, containsString("Has pending changes")))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt3")), false, any(String.class)))); }
@Test public void dependentBuildHasIgnoredPendingChanges() { when(config.getCommitsToIgnore()).thenReturn(ImmutableList.of("pending*")); BuildTypeDependencies root = newBuildTypeDependencies("root", "bt1", "bt3"); BuildTypeDependencies bt1 = newBuildTypeDependencies("bt1", "bt2", "bt3"); BuildTypeDependencies bt2 = newBuildTypeDependencies("bt2"); BuildTypeDependencies bt3 = newBuildTypeDependencies("bt3"); mockBuild(root, false, d3); mockBuild(bt1, false, d2); mockBuild(bt2, true, d1); mockBuild(bt3, false, d1); List<MBuildPlanItem> sorted = sorter.getBuildPlan(root); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("root")), false, any(String.class)))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt1")), false, any(String.class)))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt2")), false, any(String.class)))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt3")), false, any(String.class)))); }
@Test public void dependentBuildIsNewer() { BuildTypeDependencies root = newBuildTypeDependencies("root", "bt1", "bt3"); BuildTypeDependencies bt1 = newBuildTypeDependencies("bt1", "bt2", "bt3"); BuildTypeDependencies bt2 = newBuildTypeDependencies("bt2"); BuildTypeDependencies bt3 = newBuildTypeDependencies("bt3"); mockBuild(root, false, d4); mockBuild(bt1, false, d2); mockBuild(bt2, false, d3); mockBuild(bt3, false, d1); List<MBuildPlanItem> sorted = sorter.getBuildPlan(root); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("root")), true, containsString("[proj-bt1:name-bt1] require building")))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt1")), true, containsString("[proj-bt2:name-bt2] last build is newer")))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt2")), false, any(String.class)))); assertThat(sorted, hasItem(IsMBuildPlanItem(is(newBuildTypeId("bt3")), false, any(String.class)))); }
@Test public void cyclingDependency() { BuildTypeDependencies root = newBuildTypeDependencies("root", "bt1", "bt2"); BuildTypeDependencies bt1 = newBuildTypeDependencies("bt1", "bt2"); BuildTypeDependencies bt2 = newBuildTypeDependencies("bt2", "bt3"); BuildTypeDependencies bt3 = newBuildTypeDependencies("bt3", "bt1"); mockBuild(root, false, d4); mockBuild(bt1, false, d3); mockBuild(bt2, false, d2); mockBuild(bt3, false, d1); List<MBuildPlanItem> sorted = sorter.getBuildPlan(root); assertThat(sorted.size(), is(4)); }