Search in sources :

Example 31 with Processor

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

the class ResourceUtils method toVersionClause.

/**
	 * Create a VersionedClause by applying a version range mask to the
	 * resource! Masks are defined by
	 * {@link aQute.bnd.osgi.Macro#_range(String[])}. If the resource should
	 * represent a project in the bnd workspace, then instead the VersionClause
	 * will refer to it as a snapshot version: e.g. <bsn>;version=snapshot
	 */
public static VersionedClause toVersionClause(Resource resource, String mask) {
    Capability idCap = getIdentityCapability(resource);
    String identity = getIdentity(idCap);
    String versionString;
    if (resource.getCapabilities(WORKSPACE_NAMESPACE).isEmpty()) {
        Macro macro = new Macro(new Processor());
        Version version = getVersion(idCap);
        versionString = macro._range(new String[] { "range", mask, version.toString() });
    } else {
        versionString = "snapshot";
    }
    Attrs attribs = new Attrs();
    attribs.put(Constants.VERSION_ATTRIBUTE, versionString);
    return new VersionedClause(identity, attribs);
}
Also used : Processor(aQute.bnd.osgi.Processor) Capability(org.osgi.resource.Capability) Version(aQute.bnd.version.Version) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Macro(aQute.bnd.osgi.Macro) Attrs(aQute.bnd.header.Attrs)

Example 32 with Processor

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

the class Plugin method init.

/**
	 * This is called when all initialization is done for the plugins, now we
	 * can obtain a list of appropriate repos.
	 */
public void init() {
    if (init)
        return;
    init = true;
    try {
        //
        // Get the list if repos registered, repos that we can handle
        //
        List<InfoRepository> irs = new ArrayList<InfoRepository>();
        for (InfoRepository ir : registry.getPlugins(InfoRepository.class)) {
            irs.add(ir);
        }
        this.wrapper = new InfoRepositoryWrapper(dir, irs);
        if (config.reindex())
            this.wrapper.clear();
        if (config.augments() != null) {
            Workspace workspace = registry.getPlugin(Workspace.class);
            try (Processor p = new Processor(workspace)) {
                if (!config.augments().equals("WORKSPACE")) {
                    File f = IO.getFile(workspace.getBuildDir(), config.augments());
                    if (!f.isFile()) {
                        if (reporter != null)
                            reporter.error("No augment file found at %s", f.getAbsolutePath());
                        return;
                    }
                    //
                    // We read this in a processor that extends the
                    // workspace so
                    // we
                    // can use workspace properties
                    //
                    p.setProperties(f);
                    this.wrapper.clear(f.lastModified());
                }
                //
                // And then add it to the indexer to use.
                //
                this.wrapper.addAugment(p.getFlattenedProperties());
                this.wrapper.clear(workspace.getPropertiesFile().lastModified());
            }
        }
    } catch (Exception e) {
        throw Exceptions.duck(e);
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) ArrayList(java.util.ArrayList) InfoRepository(aQute.bnd.service.repository.InfoRepository) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Example 33 with Processor

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

the class ResolveTest method testenRouteGuard.

/**
	 * The enRoute base guard resolved but is missing bundles, the runbundles do
	 * not run
	 */
public void testenRouteGuard() throws Exception {
    MockRegistry registry = new MockRegistry();
    Repository repo = createRepo(IO.getFile("testdata/enroute/index.xml"));
    registry.addPlugin(repo);
    List<Requirement> reqs = CapReqBuilder.getRequirementsFrom(new Parameters("osgi.wiring.package;filter:='(osgi.wiring.package=org.osgi.service.async)'"));
    Collection<Capability> pack = repo.findProviders(reqs).get(reqs.get(0));
    assertEquals(2, pack.size());
    ResourceBuilder b = new ResourceBuilder();
    File guard = IO.getFile("testdata/enroute/osgi.enroute.base.guard.jar");
    Domain manifest = Domain.domain(guard);
    b.addManifest(manifest);
    Repository resourceRepository = new ResourcesRepository(b.build());
    registry.addPlugin(resourceRepository);
    Processor model = new Processor();
    model.setRunfw("org.eclipse.osgi");
    model.setRunblacklist("osgi.identity;filter:='(osgi.identity=osgi.enroute.base.api)',osgi.identity;filter:='(osgi.identity=osgi.cmpn)',osgi.identity;filter:='(osgi.identity=osgi.core)");
    model.setRunRequires("osgi.identity;filter:='(osgi.identity=osgi.enroute.base.guard)'");
    model.setRunee("JavaSE-1.8");
    try {
        BndrunResolveContext context = new BndrunResolveContext(model, null, registry, log);
        Resolver resolver = new BndResolver(new ResolverLogger(4));
        Map<Resource, List<Wire>> resolved = resolver.resolve(context);
        Set<Resource> resources = resolved.keySet();
    } catch (ResolutionException e) {
        String msg = e.getMessage().replaceAll("\\[caused by:", "\n->");
        System.out.println(msg);
        fail(msg);
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Parameters(aQute.bnd.header.Parameters) Processor(aQute.bnd.osgi.Processor) Capability(org.osgi.resource.Capability) Resolver(org.osgi.service.resolver.Resolver) MockRegistry(test.lib.MockRegistry) Resource(org.osgi.resource.Resource) ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) ArrayList(java.util.ArrayList) List(java.util.List) Domain(aQute.bnd.osgi.Domain) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 34 with Processor

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

the class ResolveProcessTest method testBigNastyResolveRequired.

public void testBigNastyResolveRequired() throws ResolutionException, MalformedURLException, URISyntaxException {
    ResolveProcess process = new ResolveProcess();
    ResolverLogger logger = new ResolverLogger();
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(getIndex("testdata/repo7/index.xml"));
    registry.addPlugin(getIndex("testdata/repo7/index-aries.xml"));
    registry.addPlugin(getIndex("testdata/repo7/index-gemini.xml"));
    registry.addPlugin(getIndex("testdata/repo7/index-local.xml"));
    Processor model = new Processor();
    model.setProperty("-runfw", "org.apache.felix.framework");
    model.setProperty("-runrequires", "osgi.extender;filter:='(osgi.extender=osgi.component)'");
    Map<Resource, List<Wire>> requiredResources = process.resolveRequired(model, null, registry, new BndResolver(logger), Collections.<ResolutionCallback>emptyList(), logger);
    Collection<Resource> optionalResources = process.getOptionalResources();
    assertEquals(1, requiredResources.size());
    assertEquals(13, optionalResources.size());
    SortedSet<Resource> set = new TreeSet<Resource>(new ResourceComparator());
    set.addAll(optionalResources);
    Iterator<Resource> it = set.iterator();
    checkOptionalResource(process, it.next(), "org.apache.felix.configadmin", parseVersion("1.8.2"), "org.osgi.service.cm");
    checkOptionalResource(process, it.next(), "org.apache.felix.configadmin", parseVersion("1.8.8"), "org.osgi.service.cm");
    checkOptionalResource(process, it.next(), "org.apache.felix.gogo.command", parseVersion("0.12.0"), "org.osgi.service.log");
    checkOptionalResource(process, it.next(), "org.apache.felix.gogo.runtime", parseVersion("0.10.0"), "org.apache.felix.service.command");
    checkOptionalResource(process, it.next(), "org.apache.felix.log", parseVersion("1.0.1"), "org.osgi.service.log");
    checkOptionalResource(process, it.next(), "org.apache.felix.metatype", parseVersion("1.0.4"), "org.osgi.service.metatype");
    checkOptionalResource(process, it.next(), "org.apache.felix.metatype", parseVersion("1.1.0"), "org.osgi.service.metatype");
    checkOptionalResource(process, it.next(), "org.apache.felix.shell", parseVersion("1.4.2"), "org.osgi.service.log", "org.apache.felix.shell");
    checkOptionalResource(process, it.next(), "org.eclipse.osgi.services", parseVersion("3.1.200.v20070605"), "org.osgi.service.cm", "org.osgi.service.log", "org.osgi.service.metatype");
    checkOptionalResource(process, it.next(), "org.ops4j.pax.logging.pax-logging-api", parseVersion("1.4.0"), "org.osgi.service.log");
    checkOptionalResource(process, it.next(), "osgi.cmpn", parseVersion("4.3.1.201210102024"), "org.osgi.service.cm", "org.osgi.service.log", "org.osgi.service.metatype");
    checkOptionalResource(process, it.next(), "osgi.cmpn", parseVersion("5.0.0.201305092017"), "org.osgi.service.cm", "org.osgi.service.log", "org.osgi.service.metatype");
    checkOptionalResource(process, it.next(), "osgi.enterprise", parseVersion("4.2.0.201003190513"), "org.osgi.service.cm", "org.osgi.service.log", "org.osgi.service.metatype");
}
Also used : Processor(aQute.bnd.osgi.Processor) MockRegistry(test.lib.MockRegistry) Resource(org.osgi.resource.Resource) TreeSet(java.util.TreeSet) List(java.util.List)

Example 35 with Processor

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

the class BndEditModelTest method testVariableInRunRequirements.

public static void testVariableInRunRequirements() throws Exception {
    Workspace ws = new Workspace(new File("testresources/ws"));
    BndEditModel model = new BndEditModel(ws);
    File f = new File("testresources/ws/p7/reuse.bndrun");
    model.setBndResource(f);
    model.setBndResourceName("reuse.bndrun");
    model.loadFrom(f);
    // VERIFY
    Processor processor = model.getProperties();
    String runrequirements = processor.mergeProperties(Constants.RUNREQUIRES);
    String[] rrr = runrequirements.split(",");
    assertEquals(4, rrr.length);
    assertEquals("osgi.identity;filter:='(osgi.identity=variable)'", rrr[0]);
    assertEquals("osgi.identity;filter:='(osgi.identity=variable2)'", rrr[1]);
    assertEquals("osgi.identity;filter:='(osgi.identity=b)'", rrr[2]);
    assertEquals("osgi.identity;filter:='(osgi.identity=c)'", rrr[3]);
    // [cs] don't know how to update this.
    List<Requirement> r = model.getRunRequires();
    assertEquals(3, r.size());
    assertEquals(new CapReqBuilder("${var}").buildSyntheticRequirement(), r.get(0));
    assertEquals(new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.identity=b)").buildSyntheticRequirement(), r.get(1));
    assertEquals(new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.identity=c)").buildSyntheticRequirement(), r.get(2));
    // Test Set with variables
    List<Requirement> rr = new LinkedList<Requirement>();
    rr.add(new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.identity=b)").buildSyntheticRequirement());
    rr.add(new CapReqBuilder("${var}").buildSyntheticRequirement());
    model.setRunRequires(rr);
    // VERIFY
    processor = model.getProperties();
    runrequirements = processor.mergeProperties(Constants.RUNREQUIRES);
    rrr = runrequirements.split(",");
    assertEquals(3, rrr.length);
    assertEquals("osgi.identity;filter:='(osgi.identity=b)'", rrr[0]);
    assertEquals("osgi.identity;filter:='(osgi.identity=variable)'", rrr[1]);
    assertEquals("osgi.identity;filter:='(osgi.identity=variable2)'", rrr[2]);
    // Test SET
    rr = new LinkedList<Requirement>();
    rr.add(getReq("(osgi.identity=b)"));
    rr.add(getReq("(osgi.identity=c)"));
    model.setRunRequires(rr);
    // VERIFY
    processor = model.getProperties();
    runrequirements = processor.mergeProperties(Constants.RUNREQUIRES);
    rrr = runrequirements.split(",");
    assertEquals(2, rrr.length);
    assertEquals("osgi.identity;filter:='(osgi.identity=b)'", rrr[0]);
    assertEquals("osgi.identity;filter:='(osgi.identity=c)'", rrr[1]);
    r = model.getRunRequires();
    assertEquals(getReq("(osgi.identity=b)"), r.get(0));
    assertEquals(getReq("(osgi.identity=c)"), r.get(1));
    // TEST Saving changes and those changes persist...
    Document d = new Document("");
    model.saveChangesTo(d);
    processor = model.getProperties();
    runrequirements = processor.mergeProperties(Constants.RUNREQUIRES);
    rrr = runrequirements.split(",");
    assertEquals(2, rrr.length);
    assertEquals("	osgi.identity;filter:='(osgi.identity=b)'", rrr[0]);
    assertEquals("	osgi.identity;filter:='(osgi.identity=c)'", rrr[1]);
    assertEquals(getReq("(osgi.identity=b)"), r.get(0));
    assertEquals(getReq("(osgi.identity=c)"), r.get(1));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Processor(aQute.bnd.osgi.Processor) Document(aQute.bnd.properties.Document) File(java.io.File) BndEditModel(aQute.bnd.build.model.BndEditModel) LinkedList(java.util.LinkedList) 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