Search in sources :

Example 6 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class BNDAnnotationTest method testBrokenName.

public void testBrokenName() throws Exception {
    Builder b = builder("*Broken*", 0, 2);
    Jar build = b.getJar();
    assertTrue(b.check("Invalid component name"));
    Domain m = Domain.domain(build.getManifest());
    Parameters parameters = m.getParameters("Service-Component");
    assertEquals(2, parameters.size());
    System.out.println(parameters);
    assertTrue(parameters.keySet().contains("OSGI-INF/Hello-World-Bnd---------$.xml"));
    assertTrue(parameters.keySet().contains("OSGI-INF/Hello-World.xml"));
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

Example 7 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class VersionPolicyTest method testDisableDefaultPackageVersion.

/**
	 * Test disable default package versions.
	 */
public static void testDisableDefaultPackageVersion() throws Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setProperty("Bundle-Version", "1.2.3");
    a.setProperty("Export-Package", "test.refer");
    a.setProperty("-nodefaultversion", "true");
    Jar jar = a.build();
    Manifest m = jar.getManifest();
    Parameters exports = Processor.parseHeader(m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE), null);
    Map<String, String> attrs = exports.get("test.refer");
    assertNotNull(attrs);
    assertNull(attrs.get("version"));
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 8 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class VersionPolicyTest method testConsumerType.

/**
	 * Tests if the implementation of the EventHandler (which is marked as a
	 * ConsumerType) causes the import of the api package to use the consumer
	 * version policy.
	 */
public static void testConsumerType() throws Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setPrivatePackage("test.versionpolicy.uses");
    a.setExportPackage("test.versionpolicy.api");
    a.setProperty("build", "123");
    Jar jar = a.build();
    assertTrue(a.check());
    Manifest m = jar.getManifest();
    m.write(System.err);
    Domain d = Domain.domain(m);
    Parameters parameters = d.getImportPackage();
    Attrs attrs = parameters.get("test.versionpolicy.api");
    assertNotNull(attrs);
    assertEquals("[1.2,2)", attrs.get("version"));
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 9 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class Analyzer method divideRegularAndDynamicImports.

Pair<Packages, Parameters> divideRegularAndDynamicImports() {
    Packages regularImports = new Packages(imports);
    Parameters dynamicImports = getDynamicImportPackage();
    Iterator<Entry<PackageRef, Attrs>> regularImportsIterator = regularImports.entrySet().iterator();
    while (regularImportsIterator.hasNext()) {
        Entry<PackageRef, Attrs> packageEntry = regularImportsIterator.next();
        PackageRef packageRef = packageEntry.getKey();
        Attrs attrs = packageEntry.getValue();
        String resolution = attrs.get(Constants.RESOLUTION_DIRECTIVE);
        if (Constants.RESOLUTION_DYNAMIC.equals(resolution)) {
            attrs.remove(Constants.RESOLUTION_DIRECTIVE);
            dynamicImports.put(packageRef.fqn, attrs);
            regularImportsIterator.remove();
        }
    }
    return new Pair<>(regularImports, dynamicImports);
}
Also used : Entry(java.util.Map.Entry) Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) Pair(aQute.libg.tuple.Pair)

Example 10 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class Analyzer method check.

/**
	 * Check if we have an a check option
	 */
public boolean check(Check key) {
    if (checks == null) {
        Parameters p = new Parameters(getProperty("-check"), this);
        checks = new HashSet<Check>();
        for (String k : p.keySet()) try {
            if (k.equalsIgnoreCase("all")) {
                checks = EnumSet.allOf(Check.class);
                break;
            }
            Check c = Enum.valueOf(Check.class, k.toUpperCase().replace('-', '_'));
            checks.add(c);
        } catch (Exception e) {
            error("Invalid -check constant, allowed values are %s", Arrays.toString(Check.values()));
        }
        if (!checks.isEmpty())
            checks = EnumSet.copyOf(checks);
    }
    return checks.contains(key) || checks.contains(Check.ALL);
}
Also used : Parameters(aQute.bnd.header.Parameters) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

Parameters (aQute.bnd.header.Parameters)167 Attrs (aQute.bnd.header.Attrs)80 File (java.io.File)45 Jar (aQute.bnd.osgi.Jar)44 Manifest (java.util.jar.Manifest)39 Builder (aQute.bnd.osgi.Builder)35 Domain (aQute.bnd.osgi.Domain)24 ArrayList (java.util.ArrayList)23 Map (java.util.Map)19 Attributes (java.util.jar.Attributes)17 IOException (java.io.IOException)15 HashMap (java.util.HashMap)15 Version (aQute.bnd.version.Version)11 HashSet (java.util.HashSet)10 Instructions (aQute.bnd.osgi.Instructions)9 FileNotFoundException (java.io.FileNotFoundException)8 Properties (java.util.Properties)8 Matcher (java.util.regex.Matcher)8 Analyzer (aQute.bnd.osgi.Analyzer)7 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)7