Search in sources :

Example 41 with Parameters

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

the class BndrunResolveContext method loadRepositories.

/**
	 * Load all the OSGi repositories from our registry
	 * <p>
	 * TODO Use Instruction ...
	 *
	 * @return
	 * @throws Exception
	 */
private Processor loadRepositories() throws Exception {
    //
    // Get all of the repositories from the plugin registry
    //
    List<Repository> allRepos = registry.getPlugins(Repository.class);
    Collection<Repository> orderedRepositories;
    String rn = properties.mergeProperties(Constants.RUNREPOS);
    if (rn == null) {
        //
        // No filter set, so we use all
        //
        orderedRepositories = allRepos;
    } else {
        Parameters repoNames = new Parameters(rn, project);
        // Map the repository names...
        Map<String, Repository> repoNameMap = new HashMap<String, Repository>(allRepos.size());
        for (Repository repo : allRepos) {
            String name;
            if (repo instanceof aQute.bnd.deployer.repository.wrapper.Plugin) {
                @SuppressWarnings("resource") aQute.bnd.deployer.repository.wrapper.Plugin wrapper = (aQute.bnd.deployer.repository.wrapper.Plugin) repo;
                wrapper.init();
                name = wrapper.toString();
            } else if (repo instanceof RepositoryPlugin) {
                name = ((RepositoryPlugin) repo).getName();
            } else {
                name = repo.toString();
            }
            repoNameMap.put(name, repo);
        }
        // Create the result list
        orderedRepositories = new ArrayList<>();
        for (String repoName : repoNames.keySet()) {
            Repository repo = repoNameMap.get(repoName);
            if (repo != null)
                orderedRepositories.add(repo);
        }
    }
    Processor repositoryAugments = findRepositoryAugments(orderedRepositories);
    Parameters augments = new Parameters(repositoryAugments.mergeProperties(Constants.AUGMENT), project);
    augments.putAll(new Parameters(properties.mergeProperties(Constants.AUGMENT), project));
    if (!augments.isEmpty()) {
        AggregateRepository aggregate = new AggregateRepository(orderedRepositories);
        AugmentRepository augment = new AugmentRepository(augments, aggregate);
        orderedRepositories = Collections.singleton((Repository) augment);
    }
    for (Repository repository : orderedRepositories) {
        super.addRepository(repository);
    }
    return repositoryAugments;
}
Also used : Parameters(aQute.bnd.header.Parameters) Processor(aQute.bnd.osgi.Processor) HashMap(java.util.HashMap) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) AggregateRepository(aQute.bnd.osgi.repository.AggregateRepository) AggregateRepository(aQute.bnd.osgi.repository.AggregateRepository) Repository(org.osgi.service.repository.Repository) AugmentRepository(aQute.bnd.osgi.repository.AugmentRepository) AugmentRepository(aQute.bnd.osgi.repository.AugmentRepository) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin)

Example 42 with Parameters

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

the class BndrunResolveContext method loadProvidedCapabilities.

private void loadProvidedCapabilities(ResourceBuilder system) throws Exception {
    //
    // Some capabilities are provided by the runtime, like native
    // code.
    // We need to add them here so the resolver is aware of them
    //
    Parameters providedCapabilities = new Parameters(properties.mergeProperties(Constants.RUNPROVIDEDCAPABILITIES), project);
    system.addProvideCapabilities(providedCapabilities);
}
Also used : Parameters(aQute.bnd.header.Parameters)

Example 43 with Parameters

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

the class BuilderTest method testMacroBasedExpansion.

/**
	 * This test checks if
	 * 
	 * @throws Exception
	 */
public static void testMacroBasedExpansion() throws Exception {
    Processor proc = new Processor();
    Builder builder = new Builder(proc);
    try {
        builder.setProperty("Export-Package", "${spec.packages}");
        proc.setProperty("spec.packages", "${core.packages}, ${cmpn.packages}, ${mobile.packages}");
        proc.setProperty("core.specs", "org.osgi.service.packageadmin, org.osgi.service.permissionadmin");
        proc.setProperty("core.packages", "${replace;${core.specs};.+;$0.*}");
        proc.setProperty("cmpn.specs", "org.osgi.service.event, org.osgi.service.cu");
        proc.setProperty("cmpn.packages", "${replace;${cmpn.specs};.+;$0.*}");
        proc.setProperty("mobile.specs", "org.osgi.service.wireadmin, org.osgi.service.log, org.osgi.service.cu");
        proc.setProperty("mobile.packages", "${replace;${mobile.specs};.+;$0.*}");
        builder.addClasspath(IO.getFile("jar/osgi.jar"));
        Jar jar = builder.build();
        // The total set is not uniqued so we're having an unused pattern
        // this could be solved with ${uniq;${spec.packages}} but this is
        // just
        // another test
        assertTrue(builder.check("Unused Export-Package instructions: \\[org.osgi.service.cu.\\*~\\]"));
        Domain domain = Domain.domain(jar.getManifest());
        Parameters h = domain.getExportPackage();
        assertTrue(h.containsKey("org.osgi.service.cu"));
        assertTrue(h.containsKey("org.osgi.service.cu.admin"));
    } finally {
        builder.close();
        proc.close();
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

Example 44 with Parameters

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

the class ContractTest method testUnused.

/**
	 * Make sure we do not add a contract if not used
	 * 
	 * @throws Exception
	 */
public void testUnused() throws Exception {
    Jar bjara = getContractExporter("atest", "2.5", "${exports}");
    Builder a = newBuilder();
    a.setTrace(true);
    a.addClasspath(bjara);
    a.setProperty(Constants.CONTRACT, "*");
    a.setImportPackage("test.packageinfo,*");
    a.setProperty("Export-Package", "test.refer");
    Jar ajar = a.build();
    assertTrue(a.check());
    Domain domain = Domain.domain(ajar.getManifest());
    Parameters p = domain.getRequireCapability();
    p.remove("osgi.ee");
    assertEquals(0, p.size());
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

Example 45 with Parameters

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

the class ContractTest method testSimple.

public void testSimple() throws Exception {
    Jar bjar = getContractExporter("test", "2.5", "${exports}");
    Builder a = newBuilder();
    a.setTrace(true);
    a.addClasspath(bjar);
    a.setProperty(Constants.CONTRACT, "*");
    a.setImportPackage("org.osgi.service.cm,*");
    a.setProperty("Export-Package", "test.refer");
    Jar ajar = a.build();
    assertTrue(a.check());
    Domain domain = Domain.domain(ajar.getManifest());
    Parameters rc = domain.getRequireCapability();
    rc.remove("osgi.ee");
    System.out.println(rc);
    assertEquals(1, rc.size());
    Packages ps = a.getImports();
    assertTrue(ps.containsFQN("org.osgi.service.cm"));
    Attrs attrs = ps.getByFQN("org.osgi.service.cm");
    assertNotNull(attrs);
    assertNull(attrs.getVersion());
}
Also used : Parameters(aQute.bnd.header.Parameters) Packages(aQute.bnd.osgi.Packages) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

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