Search in sources :

Example 16 with VersionedClause

use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.

the class ResolutionWizard method resourceToRunBundle.

private static VersionedClause resourceToRunBundle(Resource resource) {
    Capability idCap = ResourceUtils.getIdentityCapability(resource);
    String identity = ResourceUtils.getIdentity(idCap);
    // Map version range string, using "latest" for any workspace resources
    Attrs attribs = new Attrs();
    String versionRangeStr;
    if (isWorkspace(resource)) {
        versionRangeStr = VERSION_SNAPSHOT;
    } else {
        Version version = ResourceUtils.getVersion(idCap);
        VersionRange versionRange = createVersionRange(version);
        versionRangeStr = versionRange.toString();
    }
    attribs.put(Constants.VERSION_ATTRIBUTE, versionRangeStr);
    return new VersionedClause(identity, attribs);
}
Also used : Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Attrs(aQute.bnd.header.Attrs) VersionRange(aQute.bnd.version.VersionRange)

Example 17 with VersionedClause

use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.

the class EnrouteProjectTemplate method generateBndFile.

private Resource generateBndFile(String projectName, String pkg) {
    BndEditModel model = new BndEditModel();
    model.setPrivatePackages(Arrays.asList(new String[] { pkg + ".provider" }));
    model.setExportedPackages(Arrays.asList(new ExportedPackage(projectName + ".api", new Attrs())));
    model.setBundleDescription("${warning:please explain what this bundle does}");
    model.setBundleVersion("1.0.0.${tstamp}");
    List<VersionedClause> buildPath = new ArrayList<VersionedClause>();
    List<VersionedClause> tmp;
    tmp = model.getBuildPath();
    if (tmp != null)
        buildPath.addAll(tmp);
    Attrs attrs = new Attrs();
    attrs.put("version", "@1.0");
    buildPath.add(new VersionedClause("osgi.enroute.base.api", attrs));
    buildPath.add(new VersionedClause("osgi.enroute.base.junit", attrs));
    model.setBuildPath(buildPath);
    Document doc = new Document("");
    model.saveChangesTo(doc);
    StringResource bndBndResource = new StringResource(doc.get());
    return bndBndResource;
}
Also used : StringResource(org.bndtools.templating.StringResource) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) Attrs(aQute.bnd.header.Attrs) ArrayList(java.util.ArrayList) Document(aQute.bnd.properties.Document) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 18 with VersionedClause

use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.

the class RunRequirementsPart method doAddBundle.

private void doAddBundle() {
    try {
        RepoBundleSelectionWizard wizard = new RepoBundleSelectionWizard(new ArrayList<VersionedClause>(), DependencyPhase.Run);
        wizard.setSelectionPageTitle("Add Bundle Requirement");
        WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
        if (Window.OK == dialog.open()) {
            List<VersionedClause> result = wizard.getSelectedBundles();
            Set<Requirement> adding = new LinkedHashSet<Requirement>(result.size());
            for (VersionedClause bundle : result) {
                Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, bundle.getName());
                String versionRange = bundle.getVersionRange();
                if (versionRange != null && !"latest".equals(versionRange)) {
                    filter = new AndFilter().addChild(filter).addChild(new LiteralFilter(Filters.fromVersionRange(versionRange)));
                }
                Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
                adding.add(req);
            }
            updateViewerWithNewRequirements(adding);
        }
    } catch (Exception e) {
        ErrorDialog.openError(getSection().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error selecting bundles.", e));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) RepoBundleSelectionWizard(bndtools.wizards.repo.RepoBundleSelectionWizard) LiteralFilter(aQute.libg.filters.LiteralFilter) Requirement(org.osgi.resource.Requirement) AndFilter(aQute.libg.filters.AndFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) LiteralFilter(aQute.libg.filters.LiteralFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 19 with VersionedClause

use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.

the class RunBlacklistPart method doAddBundle.

private void doAddBundle() {
    try {
        RepoBundleSelectionWizard wizard = new RepoBundleSelectionWizard(new ArrayList<VersionedClause>(), DependencyPhase.Run);
        wizard.setSelectionPageTitle("Add Bundle Blacklist");
        WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
        if (Window.OK == dialog.open()) {
            List<VersionedClause> result = wizard.getSelectedBundles();
            Set<Requirement> adding = new LinkedHashSet<Requirement>(result.size());
            for (VersionedClause bundle : result) {
                Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, bundle.getName());
                String versionRange = bundle.getVersionRange();
                if (versionRange != null && !"latest".equals(versionRange)) {
                    filter = new AndFilter().addChild(filter).addChild(new LiteralFilter(Filters.fromVersionRange(versionRange)));
                }
                Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
                adding.add(req);
            }
            updateViewerWithNewBlacklist(adding);
        }
    } catch (Exception e) {
        ErrorDialog.openError(getSection().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error selecting bundles for blacklist.", e));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) RepoBundleSelectionWizard(bndtools.wizards.repo.RepoBundleSelectionWizard) LiteralFilter(aQute.libg.filters.LiteralFilter) Requirement(org.osgi.resource.Requirement) AndFilter(aQute.libg.filters.AndFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) LiteralFilter(aQute.libg.filters.LiteralFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 20 with VersionedClause

use of aQute.bnd.build.model.clauses.VersionedClause in project bnd by bndtools.

the class RunconfigToDistributionTask method execute.

@Override
public void execute() throws BuildException {
    try {
        createReleaseDir();
        BndEditModel model = new BndEditModel();
        model.loadFrom(bndFile);
        Project bndProject = new Project(new Workspace(rootDir), buildProject, bndFile);
        List<RepositoryPlugin> repositories = bndProject.getPlugins(RepositoryPlugin.class);
        if (allowSnapshots) {
            snapshots = indexBundleSnapshots();
        }
        for (VersionedClause runBundle : model.getRunBundles()) {
            String bsn = runBundle.getName();
            if (bsn.endsWith(".jar")) {
                bsn = bsn.substring(0, bsn.indexOf(".jar"));
            }
            if (allowSnapshots && snapshots.containsKey(bsn)) {
                Jar jar = snapshots.get(bsn);
                jar.write(new File(outputDir, jar.getName() + "-" + jar.getVersion() + ".jar"));
            } else {
                Version version = null;
                File foundJar = null;
                for (RepositoryPlugin repo : repositories) {
                    SortedSet<Version> versions = repo.versions(bsn);
                    for (Version availableVersion : versions) {
                        VersionRange range = null;
                        if (runBundle.getVersionRange() != null && !runBundle.getVersionRange().equals(Constants.VERSION_ATTR_LATEST)) {
                            range = new VersionRange(runBundle.getVersionRange());
                        }
                        boolean rangeMatches = range == null || range.includes(availableVersion);
                        boolean availableMatches = version == null || availableVersion.compareTo(version) > 0;
                        if (rangeMatches && availableMatches) {
                            version = availableVersion;
                            foundJar = repo.get(bsn, version, null);
                        }
                    }
                }
                if (foundJar != null) {
                    File outputFile = new File(outputDir, foundJar.getName());
                    Files.copy(foundJar.toPath(), outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                } else {
                    log(bsn + " could not be found in any repository");
                }
            }
        }
        bndProject.close();
    } catch (Exception e) {
        e.printStackTrace();
        throw new BuildException(e);
    }
}
Also used : VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) VersionRange(aQute.bnd.version.VersionRange) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) Project(aQute.bnd.build.Project) Version(aQute.bnd.version.Version) Jar(aQute.bnd.osgi.Jar) BuildException(org.apache.tools.ant.BuildException) BndEditModel(aQute.bnd.build.model.BndEditModel) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

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