Skip to content

Commit 7ee23e2

Browse files
committed
#22 fix cycle check, fix parallel build tests
1 parent c21aec9 commit 7ee23e2

File tree

7 files changed

+35
-94
lines changed

7 files changed

+35
-94
lines changed

src/main/groovy/repo/build/ComponentDependencyGraph.groovy

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import repo.build.maven.MavenComponent
1717
class ComponentDependencyGraph {
1818
private final Map<MavenArtifactRef, MavenComponent> componentsMap
1919
private final DirectedGraph<MavenComponent, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class)
20-
private final Map<MavenComponent, Set<MavenComponent>> cycleRefs = new HashMap<>()
20+
private final CycleDetector<MavenComponent, DefaultEdge> cycleDetector = new CycleDetector<>(graph)
2121

2222
ComponentDependencyGraph(Map<MavenArtifactRef, MavenComponent> componentsMap) {
2323
this.componentsMap = componentsMap
@@ -55,24 +55,24 @@ class ComponentDependencyGraph {
5555

5656
private void addComponentRef(MavenComponent component, MavenArtifactRef ref) {
5757
MavenComponent refComponent = componentsMap.get(ref)
58-
if (refComponent) {
58+
if (refComponent && !component.equals(refComponent)) {
5959
add(refComponent)
60-
DefaultEdge e = graph.addEdge(component, refComponent)
61-
if (hasCycles()) {
62-
graph.removeEdge(e)
63-
if (!cycleRefs.containsKey(component)) {
64-
cycleRefs.put(component, new HashSet<MavenComponent>())
65-
}
66-
cycleRefs.get(component).add(refComponent)
67-
}
60+
graph.addEdge(component, refComponent)
6861
}
6962
}
7063

7164
boolean hasCycles() {
72-
CycleDetector<MavenComponent, DefaultEdge> cycleDetector = new CycleDetector<>(graph)
7365
return cycleDetector.detectCycles()
7466
}
7567

68+
Set<MavenComponent> findCycles() {
69+
return cycleDetector.findCycles()
70+
}
71+
72+
Set<MavenComponent> findCycles(MavenComponent v) {
73+
return cycleDetector.findCyclesContainingVertex(v)
74+
}
75+
7676
List<MavenComponent> sort() {
7777
TopologicalOrderIterator<MavenComponent, DefaultEdge> i = new TopologicalOrderIterator<>(graph)
7878
List<MavenComponent> items = new ArrayList<>()
@@ -83,10 +83,6 @@ class ComponentDependencyGraph {
8383
return items
8484
}
8585

86-
Map<MavenComponent, Set<MavenComponent>> getCycleRefs() {
87-
return cycleRefs
88-
}
89-
9086
List<MavenComponent> getIncoming(MavenComponent component) {
9187
return graph.incomingEdgesOf(component)
9288
.collect { graph.getEdgeSource(it) }

src/main/groovy/repo/build/ExecuteProcess.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ExecuteProcess {
4242

4343
def exitValue = process.waitFor()
4444
// for read process output
45-
Thread.sleep(100)
45+
Thread.sleep(100L)
4646

4747
def outStream = new AnsiOutputStream(System.out)
4848
if (bufferStream.size() > 0) {
@@ -83,7 +83,7 @@ class ExecuteProcess {
8383

8484
def exitValue = process.waitFor()
8585
// for read process output
86-
Thread.sleep(100)
86+
Thread.sleep(100L)
8787

8888
if (checkErrorCode && exitValue != 0) {
8989
throw new RepoBuildException("name '$cmd' has exit code $exitValue");

src/main/groovy/repo/build/maven/Build.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class Build {
2727
// check circular dependencies
2828
def graph = ComponentDependencyGraph.build(components)
2929
if (graph.hasCycles()) {
30-
for (def entry : graph.cycleRefs) {
31-
def component = entry.getKey()
32-
def error = new RepoBuildException("Project ${component.@path} has circular ref to ${entry.getValue()}")
30+
for (def component : graph.findCycles()) {
31+
def componentCycle = graph.findCycles(component).collect { it.path }
32+
def error = new RepoBuildException("Component ${component.@path} has circular refs in cycle ${componentCycle}")
3333
context.addError(error)
3434
}
3535
throw new RepoBuildException("project has circular dependencies")

src/test/groovy/repo/build/MavenFeatureTest.groovy

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -397,31 +397,32 @@ class MavenFeatureTest extends BaseTestCase {
397397
}
398398

399399
@Test
400-
@Ignore
401400
void testBuildParallelCircularDepsFail() {
402401
def url = new File(sandbox.env.basedir, 'manifest')
403-
GitFeature.cloneManifest(context, url.getAbsolutePath(), 'master')
404-
GitFeature.sync(context)
405-
GitFeature.switch(context, 'feature/1')
406402

407-
sandbox.component('parent',
403+
sandbox.component('c1',
408404
{ Sandbox sandbox, File dir ->
409-
Maven.execute(sandbox.context, new File(dir, 'pom.xml'),
410-
{ InvocationRequest req ->
411-
req.setGoals(Arrays.asList("versions:set"))
412-
req.setInteractive(false)
413-
Properties properties = new Properties()
414-
properties.put("newVersion", version)
415-
properties.put('generateBackupPoms', 'false')
416-
req.setProperties(properties)
417-
}
418-
)
419-
Git.add(sandbox.context, dir, 'pom.xml')
420-
Git.commit(sandbox.context, dir, 'vup')
405+
Git.checkout(sandbox.context,dir, "feature/1")
406+
def ant = new AntBuilder()
407+
ant.copy(todir: dir, overwrite: true) {
408+
fileset(dir: 'src/test/resources/circular/c1') {
409+
include(name: '**/**')
410+
}
411+
}
412+
Git.add(sandbox.context, dir, '*.*')
413+
Git.commit(sandbox.context, dir, 'add')
421414
})
422415

416+
GitFeature.cloneManifest(context, url.getAbsolutePath(), 'master')
417+
GitFeature.sync(context)
418+
GitFeature.switch(context, 'feature/1')
423419

424-
assertTrue(MavenFeature.buildParallel(context))
420+
try {
421+
MavenFeature.buildParallel(context)
422+
fail()
423+
} catch (RepoBuildException e) {
424+
425+
}
425426
}
426427

427428
}

src/test/resources/circular/c2/api/pom.xml

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/test/resources/circular/c2/api/src/main/java/Test.java

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/test/resources/circular/c2/pom.xml

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)