Search in sources :

Example 1 with VersionedClause

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);
}
Also used : VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Document(aQute.bnd.properties.Document) BndEditModel(aQute.bnd.build.model.BndEditModel) File(java.io.File)

Example 2 with VersionedClause

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);
        }
    }
}
Also used : VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) Document(aQute.bnd.properties.Document) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 3 with VersionedClause

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());
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Attrs(aQute.bnd.header.Attrs) Resource(org.osgi.resource.Resource)

Example 4 with VersionedClause

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);
}
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 5 with VersionedClause

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()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) ImportPattern(aQute.bnd.build.model.clauses.ImportPattern) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Attrs(aQute.bnd.header.Attrs)

Aggregations

VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)26 Attrs (aQute.bnd.header.Attrs)16 Resource (org.osgi.resource.Resource)7 File (java.io.File)6 BndEditModel (aQute.bnd.build.model.BndEditModel)5 ArrayList (java.util.ArrayList)5 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)4 WizardDialog (org.eclipse.jface.wizard.WizardDialog)4 Test (org.junit.Test)4 Workspace (aQute.bnd.build.Workspace)3 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)3 Document (aQute.bnd.properties.Document)3 AndFilter (aQute.libg.filters.AndFilter)3 Filter (aQute.libg.filters.Filter)3 SimpleFilter (aQute.libg.filters.SimpleFilter)3 ProjectBundle (bndtools.model.repo.ProjectBundle)3 RepositoryBundle (bndtools.model.repo.RepositoryBundle)3 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)3 RepoBundleSelectionWizard (bndtools.wizards.repo.RepoBundleSelectionWizard)3 LinkedHashSet (java.util.LinkedHashSet)3