Search in sources :

Example 21 with Analyzer

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

the class IncludeHeaderTest method testPrecedence.

public static void testPrecedence() throws Exception {
    File base = IO.getFile("src/test");
    String a = "a=a.props\n";
    String b = "a=b.props\n";
    File aa = new File(base, "a.props");
    File bb = new File(base, "b.props");
    write(aa, a);
    write(bb, b);
    Analyzer analyzer = new Analyzer();
    analyzer.setBase(base);
    Properties x = new Properties();
    x.put("a", "x");
    x.put("-include", "a.props, b.props");
    analyzer.setProperties(x);
    // from org
    assertEquals("b.props", analyzer.getProperty("a"));
    analyzer = new Analyzer();
    analyzer.setBase(base);
    x = new Properties();
    x.put("a", "x");
    x.put("-include", "~a.props, b.props");
    analyzer.setProperties(x);
    // from org
    assertEquals("b.props", analyzer.getProperty("a"));
    analyzer = new Analyzer();
    analyzer.setBase(base);
    x = new Properties();
    x.put("a", "x");
    x.put("-include", "a.props, ~b.props");
    analyzer.setProperties(x);
    // from org
    assertEquals("a.props", analyzer.getProperty("a"));
    analyzer = new Analyzer();
    analyzer.setBase(base);
    x = new Properties();
    x.put("a", "x");
    x.put("-include", "~a.props, ~b.props");
    analyzer.setProperties(x);
    // from org
    assertEquals("x", analyzer.getProperty("a"));
    aa.delete();
    bb.delete();
}
Also used : Analyzer(aQute.bnd.osgi.Analyzer) Properties(java.util.Properties) File(java.io.File)

Example 22 with Analyzer

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

the class IncludeHeaderTest method testIncludeHeader.

public static void testIncludeHeader() throws IOException {
    Analyzer analyzer = new Analyzer();
    analyzer.setBase(IO.getFile("src/test"));
    Properties p = new Properties();
    p.put("a", "1");
    p.put("-include", "includeheadertest.mf, includeheadertest.prop");
    analyzer.setProperties(p);
    System.err.println(analyzer.getProperties());
    assertEquals("1", analyzer.getProperty("a"));
    assertEquals("end", analyzer.getProperty("last-props"));
    assertEquals("end", analyzer.getProperty("last-manifest"));
    assertEquals("abcd", analyzer.getProperty("manifest"));
    assertEquals("abcd", analyzer.getProperty("props"));
    assertEquals("1", analyzer.getProperty("test"));
}
Also used : Analyzer(aQute.bnd.osgi.Analyzer) Properties(java.util.Properties)

Example 23 with Analyzer

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

the class ClazzTest method test375.

/**
	 * {@code java.lang.IllegalArgumentException: Expected IDENTIFIER:
	 * <S:Z>()V;} This actually looks wrong since
	 */
public void test375() throws Exception {
    try (Analyzer a = new Analyzer()) {
        Clazz c = new Clazz(a, "", null);
        c.parseDescriptor("<S:[LFoo;>()V", Modifier.PUBLIC);
        c.parseDescriptor("<S:[Z>()V", Modifier.PUBLIC);
        c.parseDescriptor("<S:Z>()V", Modifier.PUBLIC);
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer)

Example 24 with Analyzer

use of aQute.bnd.osgi.Analyzer 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 25 with Analyzer

use of aQute.bnd.osgi.Analyzer 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)

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