Search in sources :

Example 26 with BndEditModel

use of aQute.bnd.build.model.BndEditModel in project bnd by bndtools.

the class BndrunResolveContextTest method testEffective.

public static void testEffective() {
    BndrunResolveContext context = new BndrunResolveContext(new BndEditModel(), new MockRegistry(), log);
    Requirement resolveReq = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_RESOLVE).buildSyntheticRequirement();
    Requirement activeReq = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_ACTIVE).buildSyntheticRequirement();
    Requirement noEffectiveDirectiveReq = new CapReqBuilder("dummy.ns").buildSyntheticRequirement();
    assertTrue(context.isEffective(resolveReq));
    assertFalse(context.isEffective(activeReq));
    assertTrue(context.isEffective(noEffectiveDirectiveReq));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 27 with BndEditModel

use of aQute.bnd.build.model.BndEditModel in project bnd by bndtools.

the class BndEditModelTest method testRunReposShared.

public static void testRunReposShared() throws Exception {
    Workspace ws = new Workspace(new File("testresources/ws"));
    BndEditModel model = new BndEditModel(ws);
    File f = new File("testresources/ws/p7/syspkg.bndrun");
    model.setBndResource(f);
    model.setBndResourceName("syspkg.bndrun");
    model.loadFrom(f);
    List<String> runrepos = model.getRunRepos();
    assertEquals(1, runrepos.size());
    assertEquals("testing", runrepos.get(0));
}
Also used : File(java.io.File) BndEditModel(aQute.bnd.build.model.BndEditModel) Workspace(aQute.bnd.build.Workspace)

Example 28 with BndEditModel

use of aQute.bnd.build.model.BndEditModel 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)

Example 29 with BndEditModel

use of aQute.bnd.build.model.BndEditModel in project bnd by bndtools.

the class BndEditModelTest method testVariableInSystemPackages.

public static void testVariableInSystemPackages() throws Exception {
    Workspace ws = new Workspace(new File("testresources/ws"));
    BndEditModel model = new BndEditModel(ws);
    File f = new File("testresources/ws/p7/syspkg.bndrun");
    model.setBndResource(f);
    model.setBndResourceName("syspkg.bndrun");
    model.loadFrom(f);
    List<ExportedPackage> ep = model.getSystemPackages();
    assertEquals("com.sun.xml.internal.bind", model.getProperties().mergeProperties(Constants.RUNSYSTEMPACKAGES));
    ExportedPackage e = new ExportedPackage("testing", null);
    ep = new LinkedList<ExportedPackage>();
    ep.add(e);
    model.setSystemPackages(ep);
    ep = model.getSystemPackages();
    assertEquals(1, ep.size());
    assertEquals("testing", ep.get(0).getName());
    e = new ExportedPackage("${var}", null);
    ep = new LinkedList<ExportedPackage>();
    ep.add(e);
    model.setSystemPackages(ep);
    ep = model.getSystemPackages();
    assertEquals(1, ep.size());
    assertEquals("com.sun.xml.internal.bind", model.getProperties().mergeProperties(Constants.RUNSYSTEMPACKAGES));
}
Also used : ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) File(java.io.File) BndEditModel(aQute.bnd.build.model.BndEditModel) Workspace(aQute.bnd.build.Workspace)

Example 30 with BndEditModel

use of aQute.bnd.build.model.BndEditModel in project bndtools by bndtools.

the class BlueprintXmlFileWizard method updateBundleBlueprintAndIncludeResource.

private void updateBundleBlueprintAndIncludeResource(IFile blueprintFile, IFile bndFile) throws Exception {
    BndEditModel editModel;
    IEditorPart editor = ResourceUtil.findEditor(workbench.getActiveWorkbenchWindow().getActivePage(), bndFile);
    IDocument doc = null;
    if (editor instanceof BndEditor) {
        editModel = ((BndEditor) editor).getEditModel();
    } else {
        editModel = new BndEditModel(Central.getWorkspace());
        doc = FileUtils.readFully(bndFile);
        editModel.loadFrom(new IDocumentWrapper(doc));
    }
    String blueprintrelativePath = blueprintFile.getProjectRelativePath().toString();
    updateBundleBlueprintIfNecessary(editModel, blueprintrelativePath);
    updateIncludeResourceIfNecessary(editModel, blueprintrelativePath, blueprintFile);
    if (editor == null) {
        editModel.saveChangesTo(new IDocumentWrapper(doc));
        FileUtils.writeFully(doc, bndFile, false);
    }
}
Also used : BndEditor(bndtools.editor.BndEditor) IEditorPart(org.eclipse.ui.IEditorPart) BndEditModel(aQute.bnd.build.model.BndEditModel) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

BndEditModel (aQute.bnd.build.model.BndEditModel)55 Requirement (org.osgi.resource.Requirement)35 MockRegistry (test.lib.MockRegistry)34 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)32 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)25 Capability (org.osgi.resource.Capability)25 File (java.io.File)15 Resource (org.osgi.resource.Resource)15 ArrayList (java.util.ArrayList)12 Document (aQute.bnd.properties.Document)8 List (java.util.List)7 Workspace (aQute.bnd.build.Workspace)6 Resolver (org.osgi.service.resolver.Resolver)6 ExportedPackage (aQute.bnd.build.model.clauses.ExportedPackage)5 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 IFile (org.eclipse.core.resources.IFile)4 CoreException (org.eclipse.core.runtime.CoreException)4 ResolutionException (org.osgi.service.resolver.ResolutionException)4