Search in sources :

Example 41 with Analyzer

use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.

the class AnalyzerTest method testSuperfluous.

/**
	 * We detect that there are instruction on im/export package headers that
	 * are never used. This usually indicates a misunderstanding or a change in
	 * the underlying classpath. These are reflected as warnings. If there is an
	 * extra import, and it contains no wildcards, then it is treated as a
	 * wildcard
	 * 
	 * @throws IOException
	 */
public static void testSuperfluous() throws Exception {
    Properties base = new Properties();
    base.put(Analyzer.IMPORT_PACKAGE, "*, =com.foo, com.foo.bar.*");
    base.put(Analyzer.EXPORT_PACKAGE, "*, com.bar, baz.*");
    File tmp = IO.getFile("jar/ds.jar");
    try (Analyzer h = new Analyzer()) {
        h.setJar(tmp);
        h.setProperties(base);
        Manifest m = h.calcManifest();
        m.write(System.err);
        assertTrue(//
        h.check(//
        "Unused Export-Package instructions: \\[baz.*\\]", "Unused Import-Package instructions: \\[com.foo.bar.*\\]"));
        assertTrue(h.getImports().getByFQN("com.foo") != null);
        assertTrue(h.getExports().getByFQN("com.bar") != null);
    }
}
Also used : Properties(java.util.Properties) Analyzer(aQute.bnd.osgi.Analyzer) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 42 with Analyzer

use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.

the class Target method testSimple.

public void testSimple() throws Exception {
    Analyzer analyzer = new Analyzer();
    Clazz clazz = new Clazz(analyzer, "", null);
    ClassDataCollector cd = new ClassDataCollector() {

        @Override
        public void addReference(TypeRef token) {
        }

        @Override
        public void annotation(Annotation annotation) {
            System.err.println("Annotation " + annotation);
        }

        @Override
        public void classBegin(int access, TypeRef name) {
            System.err.println("Class " + name);
        }

        @Override
        public void classEnd() {
            System.err.println("Class end ");
        }

        @Override
        public void extendsClass(TypeRef name) {
            System.err.println("extends " + name);
        }

        @Override
        public void implementsInterfaces(TypeRef[] name) {
            System.err.println("implements " + Arrays.toString(name));
        }

        @Override
        public void parameter(int p) {
            System.err.println("parameter " + p);
        }
    };
    clazz.parseClassFile(getClass().getResourceAsStream("Target.class"), cd);
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) Annotation(aQute.bnd.osgi.Annotation)

Example 43 with Analyzer

use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.

the class AnalyzerTest method testDs.

public static void testDs() throws Exception {
    Properties base = new Properties();
    base.put(Analyzer.IMPORT_PACKAGE, "*");
    base.put(Analyzer.EXPORT_PACKAGE, "*;-noimport:=true");
    File tmp = IO.getFile("jar/ds.jar");
    try (Analyzer analyzer = new Analyzer()) {
        analyzer.setJar(tmp);
        analyzer.setProperties(base);
        analyzer.calcManifest().write(System.err);
        assertTrue(analyzer.check());
        assertPresent(analyzer.getImports().keySet(), "org.osgi.service.packageadmin, " + "org.xml.sax, org.osgi.service.log," + " javax.xml.parsers," + " org.xml.sax.helpers," + " org.osgi.framework," + " org.eclipse.osgi.util," + " org.osgi.util.tracker, " + "org.osgi.service.component, " + "org.osgi.service.cm");
        assertPresent(analyzer.getExports().keySet(), "org.eclipse.equinox.ds.parser, " + "org.eclipse.equinox.ds.tracker, " + "org.eclipse.equinox.ds, " + "org.eclipse.equinox.ds.instance, " + "org.eclipse.equinox.ds.model, " + "org.eclipse.equinox.ds.resolver, " + "org.eclipse.equinox.ds.workqueue");
    }
}
Also used : Properties(java.util.Properties) Analyzer(aQute.bnd.osgi.Analyzer) File(java.io.File)

Example 44 with Analyzer

use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.

the class IncludeHeaderTest method testAbsentIncludes.

public static void testAbsentIncludes() throws IOException {
    Analyzer analyzer = new Analyzer();
    analyzer.setBase(IO.getFile("src/test"));
    Properties p = new Properties();
    p.put("-include", "-iamnotthere.txt");
    analyzer.setProperties(p);
    System.err.println(analyzer.getErrors());
    assertEquals(0, analyzer.getErrors().size());
}
Also used : Analyzer(aQute.bnd.osgi.Analyzer) Properties(java.util.Properties)

Example 45 with Analyzer

use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.

the class IncludeHeaderTest method testUrlIncludes2.

/**
	 * Test url includes
	 */
public static void testUrlIncludes2() throws IOException {
    Analyzer a = new Analyzer();
    Properties p = new Properties();
    p.setProperty("a", "1");
    p.setProperty("-include", "jar:file:jar/osgi.jar/!/META-INF/MANIFEST.MF");
    a.setProperties(p);
    assertEquals("1", a.getProperty("a"));
    assertEquals("osgi", a.getProperty("Bundle-SymbolicName"));
}
Also used : Analyzer(aQute.bnd.osgi.Analyzer) Properties(java.util.Properties)

Aggregations

Analyzer (aQute.bnd.osgi.Analyzer)55 File (java.io.File)21 Clazz (aQute.bnd.osgi.Clazz)14 Properties (java.util.Properties)14 Manifest (java.util.jar.Manifest)12 Jar (aQute.bnd.osgi.Jar)11 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)9 ClassDataCollector (aQute.bnd.osgi.ClassDataCollector)8 Parameters (aQute.bnd.header.Parameters)7 FileResource (aQute.bnd.osgi.FileResource)7 FileInputStream (java.io.FileInputStream)6 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)5 Description (aQute.lib.getopt.Description)5 Attrs (aQute.bnd.header.Attrs)4 Descriptors (aQute.bnd.osgi.Descriptors)4 Packages (aQute.bnd.osgi.Packages)4 Resource (aQute.bnd.osgi.Resource)4 Map (java.util.Map)4 PomFromManifest (aQute.bnd.maven.PomFromManifest)3 Domain (aQute.bnd.osgi.Domain)3