Skip to content

Commit

Permalink
[contract] bnd finds 2 contracts in bundle that provides only 1 if `-…
Browse files Browse the repository at this point in the history
…contract` instruction is parameterized

fixes #3726

Signed-off-by: Raymond Augé <[email protected]>

Signed-off-by: BJ Hargrave <[email protected]>
  • Loading branch information
rotty3000 authored and bjhargrave committed Mar 9, 2020
1 parent df73dea commit 1c7c049
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions biz.aQute.bndlib.tests/test/test/ContractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@

public class ContractTest extends TestCase {

public void testParameterized() throws Exception {
Jar bjara = getContractExporter("atest", "2.5", "${exports}");

Builder a = newBuilder();
a.setTrace(true);

a.addClasspath(bjara); // 1x
a.setProperty(Constants.CONTRACT, "atest;resolution:=optional,*");
a.setImportPackage("org.osgi.service.cm,*");
a.setProperty("Export-Package", "test.refer");
Jar ajar = a.build();
ajar.getManifest()
.write(System.out);
assertTrue(a.check());

Domain domain = Domain.domain(ajar.getManifest());
Parameters p = domain.getRequireCapability();
p.remove("osgi.ee");
assertNotNull(p);
assertEquals(1, p.size());
Attrs attrs = p.get("osgi.contract");
String optional = attrs.get("resolution:");
assertEquals("optional", optional);
assertEquals("(&(osgi.contract=atest)(version=2.5.0))", attrs.get("filter:"));
}

public void testDefinedContract() throws Exception {
Builder b = newBuilder();
b.setTrace(true);
Expand Down
1 change: 1 addition & 0 deletions biz.aQute.bndlib/src/aQute/bnd/osgi/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,7 @@ public boolean referred(PackageRef packageName) {
* @param contracted
*/
private void getManifestInfoFromClasspath(Jar jar, Packages classpathExports, Contracts contracts) {
logger.debug("get Manifest Info From Classpath for {}", jar);
try {
Manifest m = jar.getManifest();
if (m != null) {
Expand Down
5 changes: 4 additions & 1 deletion biz.aQute.bndlib/src/aQute/bnd/osgi/Contracts.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void clear() {
* compare the imports against.
*/
void collectContracts(String from, Parameters pcs) {
logger.debug("collecting Contracts {} from {}", pcs, from);

contract: for (Entry<String, Attrs> p : pcs.entrySet()) {
String namespace = p.getKey();
Expand All @@ -98,7 +99,7 @@ void collectContracts(String from, Parameters pcs) {
continue contract;
}

logger.debug("accepted {}", p);
logger.debug("accepted {} from {}", p, from);

Contract c = new Contract();
c.name = name;
Expand Down Expand Up @@ -144,6 +145,8 @@ void collectContracts(String from, Parameters pcs) {
for (String pname : c.uses) {
contracted.add(analyzer.getPackageRef(pname), c);
}

break;
}
}
}
Expand Down

0 comments on commit 1c7c049

Please sign in to comment.