Skip to content

Commit

Permalink
bndtools#5336 Need -include loop detection
Browse files Browse the repository at this point in the history
The problem was that there was no test cases. There
actually was a loop detection. I already was incredibly
surprised because I am pretty sure I wrote this code
and forgetting to check cycles is even beneath me.However,
I'd forgotten to add a return after the error message ...

So the code continued forever to include the same
file anyway although dutifully reporting it.

Fixes bndtools#5336

Signed-off-by: Peter Kriens <Peter.Kriens@aqute.biz>
  • Loading branch information
pkriens committed Oct 6, 2022
1 parent 61bf8a6 commit b24bd83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions biz.aQute.bndlib.tests/test/test/ProcessorTest.java
Expand Up @@ -15,6 +15,7 @@
import java.util.function.Predicate;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.osgi.resource.Capability;

import aQute.bnd.header.Attrs;
Expand All @@ -26,6 +27,7 @@
import aQute.bnd.osgi.resource.ResourceBuilder;
import aQute.bnd.osgi.resource.ResourceUtils;
import aQute.lib.collections.ExtList;
import aQute.lib.io.IO;
import aQute.lib.strings.Strings;
import aQute.service.reporter.Reporter.SetLocation;

Expand Down Expand Up @@ -529,4 +531,18 @@ public void testMergAndSuffixes() throws IOException {
}

}

@TempDir
File tmpdir;

@Test
public void testIncludeItself() throws IOException {
File foo = new File(tmpdir, "foo.bnd");
IO.store("-include " + foo.getAbsolutePath() + "\nfoo=1\n", foo);
try (Processor p = new Processor()) {
p.setProperties(foo);
assertTrue(p.check("Cyclic or multiple include of"));
}
}

}
1 change: 1 addition & 0 deletions biz.aQute.bndlib/src/aQute/bnd/osgi/Processor.java
Expand Up @@ -868,6 +868,7 @@ public void doIncludeFile(File file, boolean overwrite, Properties target) throw
public void doIncludeFile(File file, boolean overwrite, Properties target, String extensionName) throws Exception {
if (!addIncludedIfAbsent(file)) {
error("Cyclic or multiple include of %s", file);
return;
}
updateModified(file.lastModified(), file.toString());
Properties sub;
Expand Down

0 comments on commit b24bd83

Please sign in to comment.