use of aQute.bnd.osgi.Packages in project bnd by bndtools.
the class VerifierPluginTest method testNoVerifierPluginExecution.
public static void testNoVerifierPluginExecution() throws Exception {
final AtomicBoolean executedCheck = new AtomicBoolean(false);
AnalyzerPlugin analyzerPlugin = new AnalyzerPlugin() {
@Override
public boolean analyzeJar(Analyzer analyzer) throws Exception {
// The following is null when AnalyzerPlugins execute
Packages exports = analyzer.getExports();
if (exports == null) {
executedCheck.set(true);
}
return false;
}
};
try (Builder b = new Builder()) {
b.setProperty("Bundle-SymbolicName", "p1");
b.setProperty("Bundle-Version", "1.2.3");
b.setExportPackage("test.activator");
b.addClasspath(new File("bin"));
b.getPlugins().add(analyzerPlugin);
Jar jar = b.build();
}
assertTrue(executedCheck.get());
}
use of aQute.bnd.osgi.Packages in project bnd by bndtools.
the class VerifierPluginTest method testVerifierPluginExecution.
public static void testVerifierPluginExecution() throws Exception {
final AtomicBoolean executedCheck = new AtomicBoolean(false);
VerifierPlugin verifier = new VerifierPlugin() {
@Override
public void verify(Analyzer analyzer) throws Exception {
// the following is true only after the jar and manifest have
// been analyzed
Packages exports = analyzer.getExports();
PackageRef packageRef = analyzer.getPackageRef("test/activator");
if (exports.containsKey(packageRef)) {
executedCheck.set(true);
}
}
};
try (Builder b = new Builder()) {
b.setProperty("Bundle-SymbolicName", "p1");
b.setProperty("Bundle-Version", "1.2.3");
b.setExportPackage("test.activator");
b.addClasspath(new File("bin"));
b.getPlugins().add(verifier);
Jar jar = b.build();
}
assertTrue(executedCheck.get());
}
use of aQute.bnd.osgi.Packages in project bnd by bndtools.
the class AnalyzerTest method testAsm2.
/**
* See if we set attributes on export
*
* @throws IOException
*/
public static void testAsm2() throws Exception {
Properties base = new Properties();
base.put(Analyzer.IMPORT_PACKAGE, "*");
base.put(Analyzer.EXPORT_PACKAGE, "org.objectweb.asm;name=short, org.objectweb.asm.signature;name=long");
try (Analyzer h = new Analyzer()) {
h.setJar(IO.getFile("jar/asm.jar"));
h.setProperties(base);
h.calcManifest().write(System.err);
assertTrue(h.check());
Packages exports = h.getExports();
assertTrue(exports.getByFQN("org.objectweb.asm.signature") != null);
assertTrue(exports.getByFQN("org.objectweb.asm") != null);
assertTrue(Arrays.asList("org.objectweb.asm", "org.objectweb.asm.signature").removeAll(h.getImports().keySet()) == false);
assertEquals("Expected size", 2, h.getExports().size());
assertEquals("short", get(h.getExports(), h.getPackageRef("org.objectweb.asm"), "name"));
assertEquals("long", get(h.getExports(), h.getPackageRef("org.objectweb.asm.signature"), "name"));
}
}
use of aQute.bnd.osgi.Packages in project bnd by bndtools.
the class AnalyzerTest method testBundleClasspathWithVersionedExports.
public static void testBundleClasspathWithVersionedExports() throws Exception {
Builder b = new Builder();
try {
b.setBundleClasspath("foo");
b.setIncludeResource("foo/test/refer_versioned=bin/test/refer_versioned");
b.setProperty(Constants.EXPORT_CONTENTS, "${packages;ANNOTATED;org.osgi.annotation.versioning.Version}");
Jar jar = b.build();
Manifest m = jar.getManifest();
assertTrue(b.check());
Packages exports = b.getExports();
String version = exports.getByFQN("test.refer_versioned").getVersion();
assertEquals("3.5.7", version);
m.write(System.err);
} finally {
b.close();
}
}
use of aQute.bnd.osgi.Packages in project bnd by bndtools.
the class BuilderTest method testImportRangeCalculatedFromClasspath_3.
/**
* Check if we imported the package with the correct version range when
* there's an empty package in front of it in the classpath. First form
* calling builds().
*/
public static void testImportRangeCalculatedFromClasspath_3() throws Exception {
Properties base = new Properties();
base.put(Analyzer.IMPORT_PACKAGE, "javax.servlet,javax.servlet.http");
Builder analyzer = new Builder();
try {
analyzer.addClasspath(new File("bin"));
analyzer.setPrivatePackage("test");
analyzer.setClasspath(new File[] { IO.getFile("jar/jsp-api.jar"), IO.getFile("jar/servlet-api.jar") });
analyzer.setProperties(base);
analyzer.builds();
assertTrue(analyzer.check());
Packages imports = analyzer.getImports();
Attrs attrs = imports.getByFQN("javax.servlet.http");
assertEquals("[3.0,4)", attrs.getVersion());
attrs = imports.getByFQN("javax.servlet");
assertEquals("[3.0,4)", attrs.getVersion());
} finally {
analyzer.close();
}
}
Aggregations