Search in sources :

Example 6 with Packages

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Packages(aQute.bnd.osgi.Packages) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Analyzer(aQute.bnd.osgi.Analyzer) AnalyzerPlugin(aQute.bnd.service.AnalyzerPlugin) File(java.io.File)

Example 7 with Packages

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VerifierPlugin(aQute.bnd.service.verifier.VerifierPlugin) Packages(aQute.bnd.osgi.Packages) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Analyzer(aQute.bnd.osgi.Analyzer) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) File(java.io.File)

Example 8 with Packages

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"));
    }
}
Also used : Packages(aQute.bnd.osgi.Packages) Properties(java.util.Properties) Analyzer(aQute.bnd.osgi.Analyzer)

Example 9 with Packages

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();
    }
}
Also used : Packages(aQute.bnd.osgi.Packages) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest)

Example 10 with Packages

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();
    }
}
Also used : Packages(aQute.bnd.osgi.Packages) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Properties(java.util.Properties) File(java.io.File)

Aggregations

Packages (aQute.bnd.osgi.Packages)12 Builder (aQute.bnd.osgi.Builder)9 Attrs (aQute.bnd.header.Attrs)7 File (java.io.File)7 Properties (java.util.Properties)7 Analyzer (aQute.bnd.osgi.Analyzer)4 Jar (aQute.bnd.osgi.Jar)4 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)3 Parameters (aQute.bnd.header.Parameters)2 Domain (aQute.bnd.osgi.Domain)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Manifest (java.util.jar.Manifest)2 PomFromManifest (aQute.bnd.maven.PomFromManifest)1 Def (aQute.bnd.osgi.Clazz.Def)1 Descriptors (aQute.bnd.osgi.Descriptors)1 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)1 FileResource (aQute.bnd.osgi.FileResource)1 Resource (aQute.bnd.osgi.Resource)1 Verifier (aQute.bnd.osgi.Verifier)1 AnalyzerPlugin (aQute.bnd.service.AnalyzerPlugin)1