Skip to content

Commit

Permalink
show warning on duplicate properties
Browse files Browse the repository at this point in the history
within the same .bnd file
warn only when pedantic==true
includes testcase

Signed-off-by: Christoph Rueger <[email protected]>
  • Loading branch information
chrisrueger committed Mar 9, 2025
1 parent fb95115 commit ad94c49
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions aQute.libg/src/aQute/lib/utf8properties/PropertiesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ void parse() {
error("Invalid property key: `%s`", key);
}

if (reporter != null && reporter.isPedantic() && this.properties.containsKey(key)) {
error("Duplicate property key: `%s`", key);
}

skipWhitespace();

if (current == ':' || current == '=') {
Expand Down
36 changes: 36 additions & 0 deletions biz.aQute.bndlib.tests/test/test/ProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
import java.util.jar.Manifest;
import java.util.regex.Pattern;

import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import aQute.bnd.build.Container;
import aQute.bnd.build.Project;
Expand All @@ -44,10 +48,14 @@
@SuppressWarnings({
"resource", "restriction"
})
@ExtendWith(SoftAssertionsExtension.class)
public class ProjectTest {
@InjectTemporaryDirectory
File tmp;

@InjectSoftAssertions
SoftAssertions softly;

@Test
public void testAliasbuild() throws Exception {
Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
Expand Down Expand Up @@ -1198,4 +1206,32 @@ public void testCopyRepo() throws Exception {
assertTrue(project.check());
assertTrue(ws.check());
}


@Test
public void testWarnOnDuplicateProperties() throws Exception {
File base = IO.getFile("generated/test-testWarnOnDuplicateProperties");
base.mkdirs();
File bnd = new File(base, "bnd.bnd");
IO.store("""
Header-1: a\n
Header-1: b
""", bnd);

try (Processor a = new Processor()) {
a.setPedantic(true);
a.loadProperties(bnd);

softly.assertThat(a.getWarnings()
.size())
.isEqualTo(1);
softly.assertThat(a.getErrors()
.size())
.isEqualTo(0);
softly.assertThat(a.getWarnings()
.get(0))
.isEqualTo("Duplicate property key: `Header-1`: <<Header-1: b>>");

}
}
}

0 comments on commit ad94c49

Please sign in to comment.