Skip to content
Merged
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
80 changes: 80 additions & 0 deletions biz.aQute.bndlib.tests/test/test/BuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3187,6 +3187,86 @@ public void testFindActivator() throws Exception {
}
}

/**
* Check that the defined activator is found, and not concatenated by the
* Bundle-Activator annotation in TypeInVersionedPackage
*
* @throws Exception
*/
@Test
public void testBundleActivatorShouldNotBeConcatenated() throws Exception {
Builder bmaker = new Builder();
try {
bmaker.setProperty("Bundle-Activator", "test.activator.Activator");
bmaker.setProperty("build", "xyz"); // for @Version annotation
bmaker.setProperty("Private-Package", "test.*");
bmaker.setProperty("-bundleannotations",
"test.annotationheaders.attrs.std.activator.TypeInVersionedPackage");
// bmaker.setProperty("-dsannotations", "!*");
// bmaker.setProperty("-metatypeannotations", "!*");
bmaker.setClasspath(new File[] {
new File("bin_test")
});
bmaker.setProperty("-fixupmessages.export",
"The annotation aQute.bnd.annotation.Export applied to package test.versionpolicy.api is deprecated and will be removed in a future release. The org.osgi.annotation.bundle.Export should be used instead");
bmaker.setProperty("-fixupmessages.directive",
"Unknown directive foobar: in Export-Package, allowed directives are uses:,mandatory:,include:,exclude:,-import:, and 'x-*'");

Jar jar = bmaker.build();
report("testBundleActivatorShouldNotBeConcatenated", bmaker, jar);

Attributes main = jar.getManifest()
.getMainAttributes();
assertEquals("test.activator.Activator", main.getValue(Constants.BUNDLE_ACTIVATOR));
assertFalse(
bmaker
.check(
"The Bundle-Activator header only supports a single type. The following types were found: test.activator.Activator,test.annotationheaders.attrs.std.activator.TypeInVersionedPackage. This usually happens when a macro resolves to multiple types"));
} finally {
bmaker.close();
}
}

/**
* Check that the Bundle-Activator annotation in TypeInVersionedPackage
* defines the Bundle-Activator of our bundle.
*
* @throws Exception
*/
@Test
public void testBundleActivatorFromAnnotation() throws Exception {
Builder bmaker = new Builder();
try {
// bmaker.setProperty("Bundle-Activator",
// "test.activator.Activator");
bmaker.setProperty("build", "xyz"); // for @Version annotation
bmaker.setProperty("Private-Package", "test.*");
bmaker.setProperty("-bundleannotations",
"test.annotationheaders.attrs.std.activator.TypeInVersionedPackage,*");
bmaker.setClasspath(new File[] {
new File("bin_test")
});
bmaker.setProperty("-fixupmessages.export",
"The annotation aQute.bnd.annotation.Export applied to package test.versionpolicy.api is deprecated and will be removed in a future release. The org.osgi.annotation.bundle.Export should be used instead");
bmaker.setProperty("-fixupmessages.directive",
"Unknown directive foobar: in Export-Package, allowed directives are uses:,mandatory:,include:,exclude:,-import:, and 'x-*'");

Jar jar = bmaker.build();
// assertTrue(bmaker.check());
report("testBundleActivatorFromAnnotation", bmaker, jar);

Attributes main = jar.getManifest()
.getMainAttributes();
assertEquals("test.annotationheaders.attrs.std.activator.TypeInVersionedPackage",
main.getValue(Constants.BUNDLE_ACTIVATOR));

assertFalse(bmaker.check(
"The Bundle-Activator header only supports a single type*"));
} finally {
bmaker.close();
}
}

@Test
public void testImportVersionRange() throws Exception {
assertVersionEquals("[1.1,2.0)", "[1.1,2.0)");
Expand Down
24 changes: 23 additions & 1 deletion biz.aQute.bndlib/src/aQute/bnd/osgi/AnnotationHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ class AnnotationHeaders extends ClassDataCollector implements Closeable {
PROVIDE_CAPABILITY, BUNDLE_CATEGORY, BUNDLE_DOC_URL, BUNDLE_DEVELOPERS, BUNDLE_CONTRIBUTORS, BUNDLE_COPYRIGHT,
STD_REQUIREMENT, STD_CAPABILITY, STD_HEADER);

/**
* OSGi Bundle headers, which should not be touched (concatenated by
* additional headers from annotations) if their value already defined in
* analyzer .bnd file , because these headers allow only a single value
* (i.e. not multiple values concatenated by comma). Thus concatenating
* would create invalid / broken header values. For example if
* Bundle-Activator is already specified in analyzer .bnd then this should
* win.
*/
private static final Set<String> BUNDLE_HEADERS_ANALYZER_WINS = Sets.of(Constants.BUNDLE_ACTIVATOR,
Constants.BUNDLE_ACTIVATIONPOLICY, Constants.BUNDLE_NAME, Constants.BUNDLE_SYMBOLICNAME,
Constants.BUNDLE_VERSION, Constants.BUNDLE_MANIFESTVERSION, Constants.MAIN_CLASS);

// Used to detect attributes and directives on Require-Capability and
// Provide-Capability
static final String STD_ATTRIBUTE = "org.osgi.annotation.bundle.Attribute";
Expand Down Expand Up @@ -1030,11 +1043,20 @@ private void add(Annotation annotation, String name, String value) throws IOExce
/*
* This method is a pass thru for the properties of the analyzer. If we have
* such a header, we get the analyzer header and concatenate our values
* after removing dups.
* after removing dups. But there are exceptions: Some headers (e.g.
* Bundle-Activator) only allow a single value and for them concatenating to
* the analyzer header does not make sense.
*/

public String getHeader(String name) {
String value = analyzer.getProperty(name);

// for some OSGi headers we do not want to concatenate to existing
// analyzer value (analyzer value wins)
if (value != null && BUNDLE_HEADERS_ANALYZER_WINS.contains(name)) {
return value;
}

if (headers.containsKey(name)) {
//
// Remove duplicates and sort
Expand Down