Skip to content

Commit

Permalink
Merge pull request #97 from dmlloyd/circ
Browse files Browse the repository at this point in the history
Fix circularity detection and add a test
  • Loading branch information
stuartwdouglas authored Nov 15, 2018
2 parents b5aedde + 67b98cc commit fd43033
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private void cycleCheck(Set<BuildStepBuilder> builders, Set<BuildStepBuilder> vi
}

private void cycleCheck(BuildStepBuilder builder, Set<BuildStepBuilder> visited, Set<BuildStepBuilder> checked, final Map<BuildStepBuilder, Set<BuildStepBuilder>> dependencies) throws ChainBuildException {
if (checked.add(builder)) {
if (! checked.contains(builder)) {
if (! visited.add(builder)) {
throw new ChainBuildException("Cycle detected: " + visited);
}
Expand All @@ -243,6 +243,7 @@ private void cycleCheck(BuildStepBuilder builder, Set<BuildStepBuilder> visited,
visited.remove(builder);
}
}
checked.add(builder);
}

private void addOne(final Map<ItemId, List<Produce>> allProduces, final Set<BuildStepBuilder> included, final ArrayDeque<BuildStepBuilder> toAdd, final ItemId idToAdd, Set<BuildStepBuilder> dependencies) throws ChainBuildException {
Expand Down
31 changes: 31 additions & 0 deletions builder/src/test/java/org/jboss/builder/BasicTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,35 @@ public void execute(final BuildContext context) {
assertNotNull(result.consume(DummyItem.class));
assertFalse(ran.get());
}

@Test
public void testCircular() {
final BuildChainBuilder builder = BuildChain.builder();
builder.addFinal(DummyItem.class);
BuildStepBuilder stepBuilder = builder.addBuildStep(new BuildStep() {
public void execute(final BuildContext context) {
context.consume(DummyItem2.class);
context.produce(new DummyItem());
}
});
stepBuilder.produces(DummyItem.class);
stepBuilder.consumes(DummyItem2.class);
stepBuilder.build();
stepBuilder = builder.addBuildStep(new BuildStep() {
public void execute(final BuildContext context) {
context.consume(DummyItem.class);
context.produce(new DummyItem2());
}
});
stepBuilder.produces(DummyItem2.class);
stepBuilder.consumes(DummyItem.class);
stepBuilder.build();
try {
builder.build();
fail("Expected exception");
} catch (ChainBuildException expected) {
// ok
}
}

}

0 comments on commit fd43033

Please sign in to comment.