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);
}
}
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);
}
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");
}
}
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());
}
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"));
}
Aggregations