Search in sources :

Example 81 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class PomRepositoryTest method testDependenciesWithVersionRanges.

public void testDependenciesWithVersionRanges() throws Exception {
    BndPomRepository bpr = new BndPomRepository();
    Workspace w = Workspace.createStandaloneWorkspace(new Processor(), tmp.toURI());
    w.setBase(tmp);
    bpr.setRegistry(w);
    Map<String, String> config = new HashMap<>();
    config.put("revision", "com.mchange:mchange-commons-java:0.2.10");
    config.put("snapshotUrls", "https://repo1.maven.org/maven2/");
    config.put("releaseUrls", "https://repo1.maven.org/maven2/");
    config.put("name", "test");
    bpr.setProperties(config);
    List<String> list = bpr.list(null);
    for (String bsn : list) {
        SortedSet<Version> versions = bpr.versions(bsn);
        assertEquals(1, versions.size());
        Version v = versions.first();
        switch(bsn) {
            case "log4j:log4j":
                assertEquals("1.2.14", v.toString());
                break;
            case "com.typesafe.config":
                assertEquals("1.2.1", v.toString());
                break;
            case "com.mchange:mchange-commons-java":
                assertEquals("0.2.10", v.toString());
                break;
            case "slf4j.api":
                assertEquals("1.7.5", v.toString());
                break;
            default:
                fail(bsn);
        }
    }
    assertNotNull(list);
    assertEquals(4, list.size());
}
Also used : Processor(aQute.bnd.osgi.Processor) HashMap(java.util.HashMap) Version(aQute.bnd.version.Version) Workspace(aQute.bnd.build.Workspace)

Example 82 with Version

use of aQute.bnd.version.Version in project bndtools by bndtools.

the class Auxiliary method doImport.

/*
     * Parse the exports and see
     */
private boolean doImport(String exports) {
    if (closed.get() || exports == null || exports.isEmpty())
        return false;
    Parameters out = new Parameters();
    Parameters p = new Parameters(exports);
    for (Entry<String, Attrs> e : p.entrySet()) {
        Attrs attrs = e.getValue();
        if (attrs == null)
            continue;
        String plugins = attrs.get("bnd-plugins");
        if (plugins == null)
            continue;
        if (!(plugins.isEmpty() || "true".equalsIgnoreCase(plugins))) {
            if (Verifier.isVersionRange(plugins)) {
                VersionRange range = new VersionRange(plugins);
                if (// TODO
                !range.includes(About._3_0))
                    continue;
            }
        }
        // 
        // Ok, matched
        // 
        String v = attrs.getVersion();
        if (v == null)
            v = "0";
        for (Iterator<String> i = attrs.keySet().iterator(); i.hasNext(); ) {
            String key = i.next();
            if (key.endsWith(":"))
                i.remove();
        }
        if (Verifier.isVersion(v)) {
            Version version = new Version(v);
            attrs.put("version", new VersionRange(true, version, version, true).toString());
        }
        out.put(e.getKey(), attrs);
    }
    if (out.isEmpty())
        return false;
    String imports = out.toString();
    synchronized (this) {
        if (delta == null)
            delta = new ArrayList<>();
        delta.add(imports);
    }
    return true;
}
Also used : Parameters(aQute.bnd.header.Parameters) Version(aQute.bnd.version.Version) Attrs(aQute.bnd.header.Attrs) ArrayList(java.util.ArrayList) VersionRange(aQute.bnd.version.VersionRange)

Example 83 with Version

use of aQute.bnd.version.Version in project bndtools by bndtools.

the class RepositoryTargetLocation method resolveBundles.

@Override
protected TargetBundle[] resolveBundles(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
    resolveRepository();
    try {
        List<TargetBundle> bundles = new ArrayList<>();
        List<String> bsns = repository.list("*");
        monitor.beginTask("Resolving Bundles", bsns.size());
        int i = 0;
        for (String bsn : bsns) {
            Version version = repository.versions(bsn).last();
            File download = repository.get(bsn, version, new HashMap<String, String>(), new RepositoryPlugin.DownloadListener[] {});
            try {
                bundles.add(new TargetBundle(download));
            } catch (Exception e) {
                throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, "Invalid plugin in repository: " + bsn + " @ " + getLocation(false), e));
            }
            if (monitor.isCanceled())
                return null;
            monitor.worked(++i);
        }
        monitor.done();
        return bundles.toArray(new TargetBundle[0]);
    } catch (CoreException e) {
        throw e;
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, MESSAGE_UNABLE_TO_RESOLVE_BUNDLES, e));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) CoreException(org.eclipse.core.runtime.CoreException) TargetBundle(org.eclipse.pde.core.target.TargetBundle) CoreException(org.eclipse.core.runtime.CoreException) Version(aQute.bnd.version.Version) File(java.io.File)

Example 84 with Version

use of aQute.bnd.version.Version in project bndtools by bndtools.

the class OSGiFrameworkContentProvider method refreshProviders.

private IStatus refreshProviders() {
    List<IStatus> statuses = new ArrayList<>();
    IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(Plugin.PLUGIN_ID, "osgiFrameworks");
    for (IConfigurationElement element : configElements) {
        String frameworkName = element.getAttribute("name");
        String bsn = element.getAttribute("bsn");
        URL iconUrl = null;
        String iconPath = element.getAttribute("icon");
        if (iconPath != null) {
            Bundle contributorBundle = BundleUtils.findBundle(Plugin.getDefault().getBundleContext(), element.getContributor().getName(), null);
            if (contributorBundle != null)
                iconUrl = contributorBundle.getEntry(iconPath);
        }
        List<RepositoryPlugin> repositories;
        try {
            repositories = (workspace != null) ? workspace.getRepositories() : Collections.<RepositoryPlugin>emptyList();
        } catch (Exception e) {
            return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, e.getMessage(), e);
        }
        for (RepositoryPlugin repo : repositories) {
            try {
                SortedSet<Version> versions = repo.versions(bsn);
                if (versions != null)
                    for (Version version : versions) {
                        try {
                            File framework = repo.get(bsn, version, null);
                            if (framework != null)
                                frameworks.add(new OSGiFramework(frameworkName, bsn, version, iconUrl));
                        } catch (Exception e) {
                            String msg = String.format("Error finding repository entry for OSGi framework %s, version %s.", bsn, version.toString());
                            logger.logError(msg, e);
                            statuses.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, msg, e));
                        }
                    }
            } catch (Exception e) {
                String msg = String.format("Error searching repository for OSGi framework %s.", bsn);
                logger.logError(msg, e);
                statuses.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, msg, e));
            }
        }
    }
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            structuredViewer.refresh(true);
        }
    });
    if (statuses.size() > 0) {
        return new MultiStatus(Plugin.PLUGIN_ID, IStatus.ERROR, statuses.toArray(new IStatus[0]), "Errors while refreshing OSGi framework providers.", null);
    }
    return Status.OK_STATUS;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) MultiStatus(org.eclipse.core.runtime.MultiStatus) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) URL(java.net.URL) Version(aQute.bnd.version.Version) File(java.io.File)

Example 85 with Version

use of aQute.bnd.version.Version in project bndtools by bndtools.

the class RepoDownloadJob method expandContentsInto.

private void expandContentsInto(RepositoryBundle bundle, List<RepositoryBundleVersion> rbvs) throws Exception {
    RepositoryPlugin repo = bundle.getRepo();
    SortedSet<Version> versions = repo.versions(bundle.getBsn());
    if (versions != null) {
        for (Version version : versions) {
            RepositoryBundleVersion rbv = new RepositoryBundleVersion(bundle, version);
            rbvs.add(rbv);
        }
    }
}
Also used : RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) Version(aQute.bnd.version.Version) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin)

Aggregations

Version (aQute.bnd.version.Version)171 File (java.io.File)67 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)29 ArrayList (java.util.ArrayList)21 Attrs (aQute.bnd.header.Attrs)19 MavenVersion (aQute.bnd.version.MavenVersion)19 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Jar (aQute.bnd.osgi.Jar)16 Workspace (aQute.bnd.build.Workspace)13 Project (aQute.bnd.build.Project)12 RevisionRef (aQute.service.library.Library.RevisionRef)12 Matcher (java.util.regex.Matcher)12 Parameters (aQute.bnd.header.Parameters)11 VersionRange (aQute.bnd.version.VersionRange)11 SortedList (aQute.lib.collections.SortedList)9 Processor (aQute.bnd.osgi.Processor)8 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)8 FileNotFoundException (java.io.FileNotFoundException)8 LinkedHashMap (java.util.LinkedHashMap)8