From b24bd832e718ee11427895ff5822f618f5d772e2 Mon Sep 17 00:00:00 2001 From: Peter Kriens Date: Thu, 6 Oct 2022 15:24:52 +0200 Subject: [PATCH 1/5] #5336 Need -include loop detection 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 #5336 Signed-off-by: Peter Kriens --- .../test/test/ProcessorTest.java | 16 ++++++++++++++++ .../src/aQute/bnd/osgi/Processor.java | 1 + 2 files changed, 17 insertions(+) diff --git a/biz.aQute.bndlib.tests/test/test/ProcessorTest.java b/biz.aQute.bndlib.tests/test/test/ProcessorTest.java index 0095b91ccc..8e5f8b5c33 100644 --- a/biz.aQute.bndlib.tests/test/test/ProcessorTest.java +++ b/biz.aQute.bndlib.tests/test/test/ProcessorTest.java @@ -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; @@ -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; @@ -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")); + } + } + } diff --git a/biz.aQute.bndlib/src/aQute/bnd/osgi/Processor.java b/biz.aQute.bndlib/src/aQute/bnd/osgi/Processor.java index 44a3c47ba7..9c94895fd9 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/osgi/Processor.java +++ b/biz.aQute.bndlib/src/aQute/bnd/osgi/Processor.java @@ -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; From 03abc451a7682c424cd933f046c307bb79ed5cce Mon Sep 17 00:00:00 2001 From: Peter Kriens Date: Thu, 6 Oct 2022 16:21:36 +0200 Subject: [PATCH 2/5] ok, windows sucks as we know --- Signed-off-by: Peter Kriens Signed-off-by: Peter Kriens --- .../test/test/ProcessorTest.java | 8 ++------ test/.gitignore | 1 + test/.project | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 test/.gitignore create mode 100644 test/.project diff --git a/biz.aQute.bndlib.tests/test/test/ProcessorTest.java b/biz.aQute.bndlib.tests/test/test/ProcessorTest.java index 8e5f8b5c33..21dbaf5d73 100644 --- a/biz.aQute.bndlib.tests/test/test/ProcessorTest.java +++ b/biz.aQute.bndlib.tests/test/test/ProcessorTest.java @@ -15,7 +15,6 @@ 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; @@ -532,13 +531,10 @@ 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); + File foo = IO.getFile("generated/foo.bnd"); + IO.store("-include foo.bnd\nfoo=1\n", foo); try (Processor p = new Processor()) { p.setProperties(foo); assertTrue(p.check("Cyclic or multiple include of")); diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/test/.project b/test/.project new file mode 100644 index 0000000000..b0299dbe76 --- /dev/null +++ b/test/.project @@ -0,0 +1,17 @@ + + + test + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + From 1decc3fe30010b84fd6490f2f9642d8a884b81d6 Mon Sep 17 00:00:00 2001 From: Peter Kriens Date: Thu, 6 Oct 2022 16:32:12 +0200 Subject: [PATCH 3/5] oops --- Signed-off-by: Peter Kriens Signed-off-by: Peter Kriens --- test/.gitignore | 1 - test/.project | 17 ----------------- 2 files changed, 18 deletions(-) delete mode 100644 test/.gitignore delete mode 100644 test/.project diff --git a/test/.gitignore b/test/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/test/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/test/.project b/test/.project deleted file mode 100644 index b0299dbe76..0000000000 --- a/test/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - test - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - From a2d67aafed1f1a3220e4979a26010c994defce6e Mon Sep 17 00:00:00 2001 From: Peter Kriens Date: Thu, 6 Oct 2022 17:48:20 +0200 Subject: [PATCH 4/5] windows indeed is horrible Signed-off-by: Peter Kriens --- biz.aQute.bndlib.tests/test/test/ProcessorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biz.aQute.bndlib.tests/test/test/ProcessorTest.java b/biz.aQute.bndlib.tests/test/test/ProcessorTest.java index 21dbaf5d73..2f58fde7c1 100644 --- a/biz.aQute.bndlib.tests/test/test/ProcessorTest.java +++ b/biz.aQute.bndlib.tests/test/test/ProcessorTest.java @@ -534,7 +534,7 @@ public void testMergAndSuffixes() throws IOException { @Test public void testIncludeItself() throws IOException { File foo = IO.getFile("generated/foo.bnd"); - IO.store("-include foo.bnd\nfoo=1\n", foo); + IO.store("-include ./foo.bnd\nfoo=1\n", foo); try (Processor p = new Processor()) { p.setProperties(foo); assertTrue(p.check("Cyclic or multiple include of")); From d3427789a75d3d99cfc54fea68d62a72fa81dd7f Mon Sep 17 00:00:00 2001 From: Peter Kriens Date: Fri, 7 Oct 2022 10:23:38 +0200 Subject: [PATCH 5/5] something really weird. Tested it on windows and worked fine Signed-off-by: Peter Kriens --- biz.aQute.bndlib.tests/test/test/ProcessorTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/biz.aQute.bndlib.tests/test/test/ProcessorTest.java b/biz.aQute.bndlib.tests/test/test/ProcessorTest.java index 2f58fde7c1..88550374db 100644 --- a/biz.aQute.bndlib.tests/test/test/ProcessorTest.java +++ b/biz.aQute.bndlib.tests/test/test/ProcessorTest.java @@ -536,6 +536,7 @@ public void testIncludeItself() throws IOException { File foo = IO.getFile("generated/foo.bnd"); IO.store("-include ./foo.bnd\nfoo=1\n", foo); try (Processor p = new Processor()) { + p.setBase(foo.getParentFile()); p.setProperties(foo); assertTrue(p.check("Cyclic or multiple include of")); }