Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions biz.aQute.bndlib.tests/test/test/BndEditModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,65 @@ private String getPortablePath(File base) {
return path;
}

@Test
void testGetLocalMergePropertyKey_baseKey() throws Exception {
BndEditModel model = new BndEditModel();
model.loadFrom("-runrequires: osgi.identity;filter:='(osgi.identity=foo)'");
assertThat(model.getLocalMergePropertyKey(Constants.RUNREQUIRES))
.contains(Constants.RUNREQUIRES);
}

@Test
void testGetLocalMergePropertyKey_variantKey() throws Exception {
BndEditModel model = new BndEditModel();
model.loadFrom("-runrequires.shared: osgi.identity;filter:='(osgi.identity=foo)'");
assertThat(model.getLocalMergePropertyKey(Constants.RUNREQUIRES))
.contains("-runrequires.shared");
}

@Test
void testGetLocalMergePropertyKey_noKey() throws Exception {
BndEditModel model = new BndEditModel();
model.loadFrom("# empty bndrun");
assertThat(model.getLocalMergePropertyKey(Constants.RUNREQUIRES))
.isEmpty();
}

@Test
void testGetLocalMergePropertyKey_exactKeyTakesPrecedence() throws Exception {
BndEditModel model = new BndEditModel();
model.loadFrom("-runrequires.shared: foo\n-runrequires: bar");
assertThat(model.getLocalMergePropertyKey(Constants.RUNREQUIRES))
.contains(Constants.RUNREQUIRES);
}

@Test
void testSetRunRequiresAtKey_baseKey_writesToRunrequires() throws Exception {
BndEditModel model = new BndEditModel();
model.loadFrom("-runrequires: osgi.identity;filter:='(osgi.identity=foo)'");
Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE)
.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.identity=bar)")
.buildSyntheticRequirement();

model.setRunRequiresAtKey(Constants.RUNREQUIRES, List.of(req));

assertThat(model.getDocumentChanges()).containsKey(Constants.RUNREQUIRES);
assertThat(model.getDocumentChanges()).doesNotContainKey("-runrequires.shared");
}

@Test
void testSetRunRequiresAtKey_variantKey_writesToVariant() throws Exception {
BndEditModel model = new BndEditModel();
model.loadFrom("-runrequires.shared: osgi.identity;filter:='(osgi.identity=foo)'");
Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE)
.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.identity=bar)")
.buildSyntheticRequirement();

model.setRunRequiresAtKey("-runrequires.shared", List.of(req));

assertThat(model.getDocumentChanges()).containsKey("-runrequires.shared");
assertThat(model.getDocumentChanges()).doesNotContainKey(Constants.RUNREQUIRES);
}

}

2 changes: 1 addition & 1 deletion biz.aQute.bndlib/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Bundle-Description: bndlib: A Swiss Army Knife for OSGi
Export-Package: \
aQute.bnd.build;-noimport:=true,\
aQute.bnd.build.api;-noimport:=true,\
aQute.bnd.build.model;-noimport:=true,\
aQute.bnd.build.model;version='4.6.0';-noimport:=true,\
aQute.bnd.build.model.clauses;-noimport:=true,\
aQute.bnd.build.model.conversions;-noimport:=true,\
aQute.bnd.buildtool;-noimport:=true,\
Expand Down
25 changes: 25 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/build/model/BndEditModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,31 @@ public void setRunRequires(List<Requirement> requires) {
doSetObject(Constants.RUNREQUIRES, oldValue, requires, requirementListFormatter);
}

/** Returns the local document property key matching the stem or a stem.* variant, or empty if none. */
public Optional<String> getLocalMergePropertyKey(String stem) {
if (documentProperties.containsKey(stem))
return Optional.of(stem);
String prefix = stem + ".";
return documentProperties.stringPropertyNames()
.stream()
.filter(k -> k.startsWith(prefix))
.findFirst();
}

/**
* Sets run requirements at the given key, which may be a stem.* variant (e.g. {@code -runrequires.shared}).
* Also fires a property change for the base {@link Constants#RUNREQUIRES} key so all subscribers are notified.
*/
public void setRunRequiresAtKey(String key, List<Requirement> requires) {
if (Constants.RUNREQUIRES.equals(key)) {
setRunRequires(requires);
return;
}
List<Requirement> oldValue = doGetObject(key, requirementListConverter);
doSetObject(key, oldValue, requires, requirementListFormatter);
propChangeSupport.firePropertyChange(Constants.RUNREQUIRES, oldValue, requires);
}

public List<Requirement> getRunBlacklist() {
return doGetObject(Constants.RUNBLACKLIST, requirementListConverter, true);
}
Expand Down
Loading
Loading