diff --git a/builder/src/main/java/org/jboss/builder/BuildChainBuilder.java b/builder/src/main/java/org/jboss/builder/BuildChainBuilder.java index 33810cf913070..cc6af15ead160 100644 --- a/builder/src/main/java/org/jboss/builder/BuildChainBuilder.java +++ b/builder/src/main/java/org/jboss/builder/BuildChainBuilder.java @@ -233,7 +233,7 @@ private void cycleCheck(Set builders, Set vi } private void cycleCheck(BuildStepBuilder builder, Set visited, Set checked, final Map> dependencies) throws ChainBuildException { - if (checked.add(builder)) { + if (! checked.contains(builder)) { if (! visited.add(builder)) { throw new ChainBuildException("Cycle detected: " + visited); } @@ -243,6 +243,7 @@ private void cycleCheck(BuildStepBuilder builder, Set visited, visited.remove(builder); } } + checked.add(builder); } private void addOne(final Map> allProduces, final Set included, final ArrayDeque toAdd, final ItemId idToAdd, Set dependencies) throws ChainBuildException { diff --git a/builder/src/test/java/org/jboss/builder/BasicTests.java b/builder/src/test/java/org/jboss/builder/BasicTests.java index f81ecb7b889c1..1d20885c9274f 100644 --- a/builder/src/test/java/org/jboss/builder/BasicTests.java +++ b/builder/src/test/java/org/jboss/builder/BasicTests.java @@ -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 + } + } + }