use of aQute.bnd.build.model.BndEditModel in project bnd by bndtools.
the class BndModelTest method testSetBuildPath.
public void testSetBuildPath() throws Exception {
BndEditModel model = new BndEditModel();
File bndFile = getFile(BND_BUILDPATH);
model.loadFrom(bndFile);
List<VersionedClause> buildPath = model.getBuildPath();
// The remove causes the actual problem
buildPath.remove(0);
model.setBuildPath(buildPath);
Document document = new Document(IO.collect(bndFile));
model.saveChangesTo(document);
String data = document.get();
assertEquals(BND_BUILDPATH_EXPECTED, data);
}
use of aQute.bnd.build.model.BndEditModel in project bnd by bndtools.
the class BndModelTest method testEscapingBackslashes.
/**
* Test escaping of backslashes.
*
* @throws Exception
*/
public void testEscapingBackslashes() throws Exception {
String longstring = "abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890";
String formattedLongstring = "abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs \\\n" + " tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 \\\n" + " abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs \\\n" + " tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890";
BndEditModel model = new BndEditModel();
model.setBundleName("abc \\ def");
model.setBundleDescription(longstring);
model.setBundleActivator("ሴ \n");
assertEquals("abc \\ def", model.getBundleName());
assertEquals("abc \\\\ def", model.getDocumentChanges().get(Constants.BUNDLE_NAME));
assertEquals("abc \\ def", model.getProperties().get(Constants.BUNDLE_NAME));
assertEquals(longstring, model.getBundleDescription());
assertEquals(formattedLongstring, model.getDocumentChanges().get(Constants.BUNDLE_DESCRIPTION));
assertEquals(longstring, model.getProperties().get(Constants.BUNDLE_DESCRIPTION));
assertEquals("ሴ \n", model.getBundleActivator());
assertEquals("ሴ \\n\\\n\t", model.getDocumentChanges().get(Constants.BUNDLE_ACTIVATOR));
assertEquals("ሴ \n", model.getProperties().get(Constants.BUNDLE_ACTIVATOR));
}
use of aQute.bnd.build.model.BndEditModel in project bnd by bndtools.
the class Bndrun method resolve.
public <T> T resolve(boolean failOnChanges, boolean writeOnChanges, Converter<T, Collection<? extends HeaderClause>> runbundlesFormatter) throws Exception {
try (ProjectResolver projectResolver = new ProjectResolver(this)) {
try {
Map<Resource, List<Wire>> resolution = projectResolver.resolve();
if (!projectResolver.isOk()) {
return runbundlesFormatter.convert(Collections.<VersionedClause>emptyList());
}
Set<Resource> resources = resolution.keySet();
List<VersionedClause> runBundles = new ArrayList<>();
for (Resource resource : resources) {
VersionedClause runBundle = ResourceUtils.toVersionClause(resource, "[===,==+)");
if (!runBundles.contains(runBundle)) {
runBundles.add(runBundle);
}
}
Collections.sort(runBundles, new Comparator<VersionedClause>() {
@Override
public int compare(VersionedClause a, VersionedClause b) {
int diff = a.getName().compareTo(b.getName());
return (diff != 0) ? diff : a.getVersionRange().compareTo(b.getVersionRange());
}
});
File runFile = getPropertiesFile();
BndEditModel bem = new BndEditModel(getWorkspace());
Document doc = new Document(IO.collect(runFile));
bem.loadFrom(doc);
List<VersionedClause> bemRunBundles = bem.getRunBundles();
if (bemRunBundles == null)
bemRunBundles = new ArrayList<>();
String originalRunbundlesString = runbundlesWrappedFormatter.convert(bemRunBundles);
logger.debug("Original -runbundles was:\n\t {}", originalRunbundlesString);
String runbundlesString = runbundlesWrappedFormatter.convert(runBundles);
logger.debug("Resolved -runbundles is:\n\t {}", runbundlesString);
List<VersionedClause> deltaAdd = new ArrayList<>(runBundles);
deltaAdd.removeAll(bemRunBundles);
List<VersionedClause> deltaRemove = new ArrayList<>(bemRunBundles);
deltaRemove.removeAll(runBundles);
boolean added = bemRunBundles.addAll(deltaAdd);
boolean removed = bemRunBundles.removeAll(deltaRemove);
if (added || removed) {
if (failOnChanges && !bemRunBundles.isEmpty()) {
error("The runbundles have changed. Failing the build!\nWas: %s\nIs: %s", originalRunbundlesString, runbundlesString);
return runbundlesFormatter.convert(Collections.<VersionedClause>emptyList());
}
if (writeOnChanges) {
bem.setRunBundles(bemRunBundles);
String runBundlesProperty = bem.getDocumentChanges().get(Constants.RUNBUNDLES);
logger.debug("Writing changes to {}", runFile.getAbsolutePath());
logger.debug("{}:{}", Constants.RUNBUNDLES, runBundlesProperty);
bem.saveChangesTo(doc);
IO.store(doc.get(), runFile);
}
}
return runbundlesFormatter.convert(bemRunBundles);
} finally {
getInfo(projectResolver);
}
}
}
use of aQute.bnd.build.model.BndEditModel in project bnd by bndtools.
the class JpmRepoTest method testSimpleResolve.
// public void testResolveProviderWithRunpath() throws Exception {
// try {
// Project provider = ws.getProject("provider");
// provider.build();
// assertTrue(provider.check());
//
// Project requirer = ws.getProject("requirer");
// requirer.build();
// assertTrue(requirer.check());
//
// BndEditModel model = new BndEditModel();
// model.setProject(requirer);
// BndrunResolveContext context = new BndrunResolveContext(model, ws, log);
//
// Resolver resolver = new ResolverImpl(new
// org.apache.felix.resolver.Logger(4), null);
//
// Map<Resource,List<Wire>> resolved = resolver.resolve(context);
// Set<Resource> resources = resolved.keySet();
// Resource resource = getResource(resources, "requirer", "0");
// assertNotNull(resource);
// }
// catch (ResolutionException e) {
// fail("Resolve failed " + e);
// }
// }
public void testSimpleResolve() {
Repository repo = ws.getPlugin(Repository.class);
BndEditModel model = new BndEditModel();
model.setRunFw("org.apache.felix.framework");
List<Requirement> requires = new ArrayList<Requirement>();
CapReqBuilder capReq = CapReqBuilder.createBundleRequirement("org.apache.felix.gogo.shell", "[0,1)");
requires.add(capReq.buildSyntheticRequirement());
Map<Requirement, Collection<Capability>> shell = repo.findProviders(requires);
assertNotNull(shell);
assertEquals(1, shell.size());
model.setRunRequires(requires);
BndrunResolveContext context = new BndrunResolveContext(model, ws, log);
Resolver resolver = new BndResolver(new org.apache.felix.resolver.Logger(4));
try {
Map<Resource, List<Wire>> resolved = resolver.resolve(context);
Set<Resource> resources = resolved.keySet();
Resource resource = getResource(resources, "org.apache.felix.gogo.runtime", "0.12");
assertNotNull(resource);
} catch (ResolutionException e) {
fail("Resolve failed");
}
}
use of aQute.bnd.build.model.BndEditModel in project bnd by bndtools.
the class ResolveTest method testMultipleOptionsNotDuplicated.
/**
* Simple test that resolves a requirement
*
* @throws ResolutionException
*/
public void testMultipleOptionsNotDuplicated() throws ResolutionException {
// Resolve against repo 5
MockRegistry registry = new MockRegistry();
registry.addPlugin(createRepo(IO.getFile("testdata/repo5/index.xml"), "Test-5"));
// Set up a simple Java 7 Felix requirement as per Issue #971
BndEditModel runModel = new BndEditModel();
runModel.setRunFw("org.apache.felix.framework;version='4.2.1'");
runModel.setEE(EE.JavaSE_1_7);
runModel.setSystemPackages(Collections.singletonList(new ExportedPackage("org.w3c.dom.traversal", null)));
runModel.setGenericString("-resolve.effective", "active");
// Require the log service, GoGo shell and GoGo commands
List<Requirement> requirements = new ArrayList<Requirement>();
requirements.add(new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=org.apache.felix.log)").buildSyntheticRequirement());
requirements.add(new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=org.apache.felix.gogo.shell)").buildSyntheticRequirement());
requirements.add(new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=org.apache.felix.gogo.command)").buildSyntheticRequirement());
runModel.setRunRequires(requirements);
// Resolve the bndrun
BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
Resolver resolver = new BndResolver(new org.apache.felix.resolver.Logger(4));
Collection<Resource> resolvedResources = new ResolveProcess().resolveRequired(runModel, registry, resolver, Collections.<ResolutionCallback>emptyList(), log).keySet();
Map<String, Resource> mandatoryResourcesBySymbolicName = new HashMap<String, Resource>();
for (Resource r : resolvedResources) {
Capability cap = r.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).get(0);
// We shouldn't have more than one match for each symbolic name for
// this resolve
String symbolicName = (String) cap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
assertNull("Multiple results for " + symbolicName, mandatoryResourcesBySymbolicName.put(symbolicName, r));
}
assertEquals(4, resolvedResources.size());
}
Aggregations