Search in sources :

Example 6 with Clazz

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

the class ClazzTest method testDynamicInstr.

/**
	 * Complaint from Groovy that the dynamic instruction fails.
	 * 
	 * <pre>
	 *  [bndwrap]
	 * java.lang.ArrayIndexOutOfBoundsException: 15 [bndwrap] at
	 * aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:387) [bndwrap] at
	 * aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:308) [bndwrap] at
	 * aQute.bnd.osgi.Clazz.parseClassFileWithCollector(Clazz.java:297)
	 * [bndwrap] at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:286)
	 * [bndwrap] at aQute.bnd.osgi.Analyzer.analyzeJar(Analyzer.java:1489)
	 * [bndwrap] at
	 * aQute.bnd.osgi.Analyzer.analyzeBundleClasspath(Analyzer.java:1387)
	 * [bndwrap] Invalid class file:
	 * groovy/inspect/swingui/AstNodeToScriptVisitor.class [bndwrap] Exception:
	 * 15
	 * </pre>
	 */
public void testDynamicInstr() throws Exception {
    try (Analyzer a = new Analyzer()) {
        Clazz c = new Clazz(a, "", null);
        c.parseClassFile(new FileInputStream("jar/AstNodeToScriptVisitor.jclass"), new ClassDataCollector() {
        });
        Set<PackageRef> referred = c.getReferred();
        Descriptors d = new Descriptors();
        assertFalse(referred.contains(d.getPackageRef("")));
        System.out.println(referred);
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) Descriptors(aQute.bnd.osgi.Descriptors) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) FileInputStream(java.io.FileInputStream)

Example 7 with Clazz

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

the class CalltreeTest method testCalltree.

@SuppressWarnings("restriction")
public static void testCalltree() throws Exception {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Private-Package", "test");
    b.build();
    Collection<Clazz> clazzes = b.getClassspace().values();
    assertTrue(clazzes.size() > 10);
    CalltreeResource.writeCalltree(pw, clazzes);
    pw.close();
    System.err.println(sw.toString());
}
Also used : StringWriter(java.io.StringWriter) Builder(aQute.bnd.osgi.Builder) Clazz(aQute.bnd.osgi.Clazz) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 8 with Clazz

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

the class ClazzTest method testClassForNameFalsePickup.

/**
	 * Check if the class is not picking up false references when the
	 * CLass.forName name is constructed. The DeploymentAdminPermission.1.jclass
	 * turned out to use Class.forName with a name that was prefixed with a
	 * package from a property. bnd discovered the suffix
	 * (.DeploymentAdminPermission) but this ended up in the default package. So
	 * now the clazz parser tests that the name guessed for Class.forName must
	 * actually resemble a class name.
	 */
public void testClassForNameFalsePickup() throws Exception {
    try (Analyzer a = new Analyzer()) {
        Clazz c = new Clazz(a, "", null);
        c.parseClassFile(new FileInputStream("jar/DeploymentAdminPermission.1.jclass"), new ClassDataCollector() {
        });
        Set<PackageRef> referred = c.getReferred();
        Descriptors d = new Descriptors();
        assertFalse(referred.contains(d.getPackageRef("")));
        System.out.println(referred);
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) Descriptors(aQute.bnd.osgi.Descriptors) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) FileInputStream(java.io.FileInputStream)

Example 9 with Clazz

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

the class ClazzTest method testNoClassBound.

public void testNoClassBound() throws Exception {
    try (Analyzer a = new Analyzer()) {
        Clazz c = new Clazz(a, "", null);
        // From aQute.lib.collections.SortedList.fromIterator()
        c.parseDescriptor("<T::Ljava/lang/Comparable<*>;>(Ljava/util/Iterator<TT;>;)LaQute/lib/collections/SortedList<TT;>;", Modifier.PUBLIC);
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer)

Example 10 with Clazz

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

the class ClazzTest method testCaughtExceptions.

public void testCaughtExceptions() throws Exception {
    try (Analyzer a = new Analyzer()) {
        Clazz c = new Clazz(a, "", null);
        c.parseClassFile(new FileInputStream("bin/test/ClazzTest$Catching.class"), new ClassDataCollector() {
        });
        assertTrue(c.getReferred().toString().contains("org.xml.sax"));
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) FileInputStream(java.io.FileInputStream)

Aggregations

Clazz (aQute.bnd.osgi.Clazz)56 Analyzer (aQute.bnd.osgi.Analyzer)14 ClassDataCollector (aQute.bnd.osgi.ClassDataCollector)14 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)12 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)8 InputStream (java.io.InputStream)8 FileResource (aQute.bnd.osgi.FileResource)7 File (java.io.File)7 HashMap (java.util.HashMap)7 FileInputStream (java.io.FileInputStream)6 Resource (aQute.bnd.osgi.Resource)5 MethodDef (aQute.bnd.osgi.Clazz.MethodDef)4 Descriptors (aQute.bnd.osgi.Descriptors)4 Instruction (aQute.bnd.osgi.Instruction)4 Jar (aQute.bnd.osgi.Jar)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 Parameters (aQute.bnd.header.Parameters)3