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));
}
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));
}
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));
}
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));
}
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);
}
}
Aggregations