Search in sources :

Example 16 with Processor

use of aQute.bnd.osgi.Processor 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 17 with Processor

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

the class BndrunResolveContext method findRepositoryAugments.

private Processor findRepositoryAugments(Collection<Repository> orderedRepositories) {
    Processor main = new Processor();
    RequirementBuilder rb = new RequirementBuilder(BND_AUGMENT);
    rb.filter("(path=*)");
    Requirement req = rb.buildSyntheticRequirement();
    for (Repository r : orderedRepositories) {
        Map<Requirement, Collection<Capability>> found = r.findProviders(Collections.singleton(req));
        Collection<Capability> capabilities = found.get(req);
        if (capabilities != null) {
            for (Capability capability : capabilities) {
                findAdditionalAugmentsFromResource(main, capability);
            }
        }
    }
    return main;
}
Also used : Requirement(org.osgi.resource.Requirement) AggregateRepository(aQute.bnd.osgi.repository.AggregateRepository) Repository(org.osgi.service.repository.Repository) AugmentRepository(aQute.bnd.osgi.repository.AugmentRepository) Processor(aQute.bnd.osgi.Processor) Capability(org.osgi.resource.Capability) Collection(java.util.Collection) RequirementBuilder(aQute.bnd.osgi.resource.RequirementBuilder)

Example 18 with Processor

use of aQute.bnd.osgi.Processor 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 19 with Processor

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

the class PropertiesTest method testFilter.

public static void testFilter() {
    Processor p1 = new Processor();
    p1.setProperty("dan", "bandera");
    p1.setProperty("susan", "sarandon");
    p1.setProperty("jon", "bostrom");
    Processor p2 = new Processor(p1);
    p2.setForceLocal(Arrays.asList("dan"));
    p2.setProperty("susan", "schwarze");
    assertNull(p2.getProperty("dan"));
    assertEquals("schwarze", p2.getProperty("susan"));
    assertEquals("bostrom", p2.getProperty("jon"));
}
Also used : Processor(aQute.bnd.osgi.Processor)

Example 20 with Processor

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

the class MavenBndRepository method put.

@Override
public PutResult put(InputStream stream, PutOptions options) throws Exception {
    init();
    File binaryFile = File.createTempFile("put", ".jar");
    File pomFile = File.createTempFile("pom", ".xml");
    LocalPutResult result = new LocalPutResult();
    try {
        if (options == null)
            options = new PutOptions();
        else {
            result.options = options;
        }
        IO.copy(stream, binaryFile);
        if (options.digest != null) {
            byte[] digest = SHA1.digest(binaryFile).digest();
            if (!Arrays.equals(options.digest, digest))
                throw new IllegalArgumentException("The given sha-1 does not match the contents sha-1");
        }
        if (options.context == null) {
            options.context = registry.getPlugin(Workspace.class);
            if (options.context == null)
                options.context = new Processor();
        }
        ReleaseDTO instructions = getReleaseDTO(options.context);
        try (Jar binary = new Jar(binaryFile)) {
            Resource pomResource;
            if (instructions.pom.path != null) {
                File f = options.context.getFile(instructions.pom.path);
                if (!f.isFile())
                    throw new IllegalArgumentException("-maven-release specifies " + f + " as pom file but this file is not found");
                pomResource = new FileResource(f);
            } else {
                pomResource = getPomResource(binary);
                if (pomResource == null) {
                    pomResource = createPomResource(binary, options.context);
                    if (pomResource == null)
                        throw new IllegalArgumentException("No POM resource in META-INF/maven/... The Maven Bnd Repository requires this pom.");
                }
            }
            IO.copy(pomResource.openInputStream(), pomFile);
            IPom pom;
            try (InputStream fin = IO.stream(pomFile)) {
                pom = storage.getPom(fin);
            }
            Archive binaryArchive = pom.binaryArchive();
            checkRemotePossible(instructions, binaryArchive.isSnapshot());
            if (!binaryArchive.isSnapshot()) {
                releasePlugin.add(options.context, pom);
                if (storage.exists(binaryArchive)) {
                    logger.debug("Already released {} to {}", pom.getRevision(), this);
                    result.alreadyReleased = true;
                    return result;
                }
            }
            logger.debug("Put release {}", pom.getRevision());
            try (Release releaser = storage.release(pom.getRevision(), options.context.getProperties())) {
                if (releaser == null) {
                    logger.debug("Already released {}", pom.getRevision());
                    return result;
                }
                if (instructions.snapshot >= 0)
                    releaser.setBuild(instructions.snapshot, null);
                if (isLocal(instructions))
                    releaser.setLocalOnly();
                releaser.add(pom.getRevision().pomArchive(), pomFile);
                releaser.add(binaryArchive, binaryFile);
                result.binaryArchive = binaryArchive;
                result.pomArchive = pom.getRevision().pomArchive();
                if (!isLocal(instructions)) {
                    try (Tool tool = new Tool(options.context, binary)) {
                        if (instructions.javadoc != null) {
                            if (!NONE.equals(instructions.javadoc.path)) {
                                try (Jar jar = getJavadoc(tool, options.context, instructions.javadoc.path, instructions.javadoc.options, instructions.javadoc.packages == JavadocPackages.EXPORT)) {
                                    save(releaser, pom.getRevision(), jar, "javadoc");
                                }
                            }
                        }
                        if (instructions.sources != null) {
                            if (!NONE.equals(instructions.sources.path)) {
                                try (Jar jar = getSource(tool, options.context, instructions.sources.path)) {
                                    save(releaser, pom.getRevision(), jar, "sources");
                                }
                            }
                        }
                    }
                }
            }
            if (configuration.noupdateOnRelease() == false && !binaryArchive.isSnapshot())
                index.add(binaryArchive);
        }
        return result;
    } catch (Exception e) {
        result.failed = e.getMessage();
        throw e;
    } finally {
        IO.delete(binaryFile);
        IO.delete(pomFile);
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) Archive(aQute.maven.api.Archive) InputStream(java.io.InputStream) IPom(aQute.maven.api.IPom) Resource(aQute.bnd.osgi.Resource) FileResource(aQute.bnd.osgi.FileResource) PomResource(aQute.bnd.maven.PomResource) FileResource(aQute.bnd.osgi.FileResource) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Jar(aQute.bnd.osgi.Jar) File(java.io.File) Release(aQute.maven.api.Release) Workspace(aQute.bnd.build.Workspace)

Aggregations

Processor (aQute.bnd.osgi.Processor)185 HashMap (java.util.HashMap)43 File (java.io.File)37 Macro (aQute.bnd.osgi.Macro)29 Workspace (aQute.bnd.build.Workspace)27 Jar (aQute.bnd.osgi.Jar)17 HttpClient (aQute.bnd.http.HttpClient)14 Baseline (aQute.bnd.differ.Baseline)12 DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)12 BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)10 IOException (java.io.IOException)10 Resource (org.osgi.resource.Resource)10 Info (aQute.bnd.differ.Baseline.Info)8 Version (aQute.bnd.version.Version)8 ArrayList (java.util.ArrayList)8 List (java.util.List)7 ProgressPlugin (aQute.bnd.service.progress.ProgressPlugin)6 Collection (java.util.Collection)6 Properties (java.util.Properties)6 Parameters (aQute.bnd.header.Parameters)5