Search in sources :

Example 11 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 12 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 13 with VersionedClause

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

the class MapValuesContentProvider method doAdd.

void doAdd() {
    IStructuredSelection selection = (IStructuredSelection) availableViewer.getSelection();
    List<VersionedClause> adding = new ArrayList<VersionedClause>(selection.size());
    for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
        Object item = iter.next();
        if (item instanceof RepositoryBundle) {
            adding.add(RepositoryBundleUtils.convertRepoBundle((RepositoryBundle) item));
        } else if (item instanceof RepositoryBundleVersion) {
            adding.add(RepositoryBundleUtils.convertRepoBundleVersion((RepositoryBundleVersion) item, phase));
        } else if (item instanceof ProjectBundle) {
            String bsn = ((ProjectBundle) item).getBsn();
            Attrs attribs = new Attrs();
            attribs.put(Constants.VERSION_ATTRIBUTE, "latest");
            adding.add(new VersionedClause(bsn, attribs));
        }
    }
    if (!adding.isEmpty()) {
        for (VersionedClause clause : adding) {
            selectedBundles.put(clause.getName(), clause);
        }
        selectedViewer.add(adding.toArray());
        availableViewer.refresh();
        propSupport.firePropertyChange(PROP_SELECTION, null, selectedBundles);
    }
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) ProjectBundle(bndtools.model.repo.ProjectBundle) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 14 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)

Example 15 with VersionedClause

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

the class ResourceTest method testResourceToVersionedClause.

public void testResourceToVersionedClause() throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    rb.addManifest(Domain.domain(IO.getFile("../demo-fragment/generated/demo-fragment.jar")));
    Resource resource = rb.build();
    VersionedClause versionClause = ResourceUtils.toVersionClause(resource, "[===,==+)");
    StringBuilder sb = new StringBuilder();
    versionClause.formatTo(sb);
    assertEquals("demo-fragment;version='[1.0.0,1.0.1)'", sb.toString());
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Resource(org.osgi.resource.Resource)

Aggregations

VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)15 Attrs (aQute.bnd.header.Attrs)8 File (java.io.File)6 BndEditModel (aQute.bnd.build.model.BndEditModel)5 ArrayList (java.util.ArrayList)5 Resource (org.osgi.resource.Resource)5 Document (aQute.bnd.properties.Document)3 WizardDialog (org.eclipse.jface.wizard.WizardDialog)3 Project (aQute.bnd.build.Project)2 Workspace (aQute.bnd.build.Workspace)2 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)2 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)2 Version (aQute.bnd.version.Version)2 VersionRange (aQute.bnd.version.VersionRange)2 AndFilter (aQute.libg.filters.AndFilter)2 Filter (aQute.libg.filters.Filter)2 LiteralFilter (aQute.libg.filters.LiteralFilter)2 SimpleFilter (aQute.libg.filters.SimpleFilter)2 ProjectBundle (bndtools.model.repo.ProjectBundle)2 RepositoryBundle (bndtools.model.repo.RepositoryBundle)2