use of aQute.bnd.build.model.clauses.VersionedClause 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.clauses.VersionedClause 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.clauses.VersionedClause in project bnd by bndtools.
the class ResourceTest method testSnapshotResourceToVersionedClause.
public void testSnapshotResourceToVersionedClause() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addManifest(Domain.domain(IO.getFile("../demo-fragment/generated/demo-fragment.jar")));
Attrs attrs = new Attrs();
attrs.put("bnd.workspace.project", "demo-fragment");
rb.addCapability(CapabilityBuilder.createCapReqBuilder("bnd.workspace.project", attrs));
Resource resource = rb.build();
VersionedClause versionClause = ResourceUtils.toVersionClause(resource, "[===,==+)");
StringBuilder sb = new StringBuilder();
versionClause.formatTo(sb);
assertEquals("demo-fragment;version=snapshot", sb.toString());
}
use of aQute.bnd.build.model.clauses.VersionedClause 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);
}
use of aQute.bnd.build.model.clauses.VersionedClause in project liferay-ide by liferay.
the class PortletTemplate method modifyInitialBndModel.
@Override
public void modifyInitialBndModel(BndEditModel model, String projectName, ProjectPaths projectPaths) {
super.modifyInitialBndModel(model, projectName, projectPaths);
String buildpath = "${buildpath-rule}";
model.setBuildPath(Collections.singletonList(new VersionedClause(buildpath, Attrs.EMPTY_ATTRS)));
model.setIncludeResource(Collections.singletonList("${includeresource-rule}"));
ImportPattern[] patterns = { new ImportPattern("${imports-rule}", Attrs.EMPTY_ATTRS), new ImportPattern("*", new Attrs()) };
patterns[1].setOptional(true);
model.setImportPatterns(Arrays.asList(patterns));
model.setGenericString("Web-ContextPath", "/" + projectName);
String safePackageName = safePackageName(projectName);
String wholePackageName = "(osgi.identity=" + safePackageName + ")";
CapReqBuilder cap = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE);
cap.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, wholePackageName);
model.setRunRequires(Collections.singletonList(cap.buildSyntheticRequirement()));
}
Aggregations