Search in sources :

Example 6 with RepositoryPlugin

use of aQute.bnd.service.RepositoryPlugin in project bnd by bndtools.

the class RepoCommand method _topom.

/**
	 * Read a repository and turn all bundles that have a pom into a dependency
	 * POM
	 * 
	 * @throws Exception
	 */
public void _topom(PomOptions opts) throws Exception {
    List<String> args = opts._arguments();
    String repoName = args.remove(0);
    String name = args.remove(0);
    RepositoryPlugin source = workspace.getRepository(repoName);
    if (source == null) {
        bnd.error("No such source repository: %s, available repos %s", repoName, workspace.getRepositories());
        return;
    }
    if (!(source instanceof ToDependencyPom)) {
        bnd.error("The repository %s cannot generate a dependency pom", source);
        return;
    }
    String sout = opts.output();
    if (sout == null)
        sout = "console";
    OutputStream out;
    if ("console".equals(sout))
        out = System.out;
    else {
        File f = bnd.getFile(sout);
        out = IO.outputStream(f);
    }
    try {
        ToDependencyPom r = (ToDependencyPom) source;
        aQute.bnd.service.maven.PomOptions po = new aQute.bnd.service.maven.PomOptions();
        po.dependencyManagement = opts.dependencyManagement();
        po.parent = opts.parent();
        po.gav = name;
        r.toPom(out, po);
    } finally {
        out.close();
    }
}
Also used : ToDependencyPom(aQute.bnd.service.maven.ToDependencyPom) OutputStream(java.io.OutputStream) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) File(java.io.File)

Example 7 with RepositoryPlugin

use of aQute.bnd.service.RepositoryPlugin in project bnd by bndtools.

the class ProjectTest method testCopyRepo.

public void testCopyRepo() throws Exception {
    Workspace ws = getWorkspace(IO.getFile("testresources/ws-repo-test"));
    Project project = ws.getProject("p1");
    assertNotNull(ws);
    assertNotNull(project);
    RepositoryPlugin repo = ws.getRepository("Repo");
    assertNotNull(repo);
    RepositoryPlugin release = ws.getRepository("Release");
    assertNotNull(release);
    project.copy(repo, (String) null, release);
    assertTrue(project.check());
    assertTrue(ws.check());
}
Also used : Project(aQute.bnd.build.Project) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Workspace(aQute.bnd.build.Workspace)

Example 8 with RepositoryPlugin

use of aQute.bnd.service.RepositoryPlugin in project bnd by bndtools.

the class Project method getBundle.

/**
	 * Get a bundle from one of the plugin repositories. If an exact version is
	 * required we just return the first repository found (in declaration order
	 * in the build.bnd file).
	 *
	 * @param bsn The bundle symbolic name
	 * @param range The version range
	 * @param strategy set to LOWEST or HIGHEST
	 * @return the file object that points to the bundle or null if not found
	 * @throws Exception when something goes wrong
	 */
public Container getBundle(String bsn, String range, Strategy strategy, Map<String, String> attrs) throws Exception {
    if (range == null)
        range = "0";
    if (VERSION_ATTR_SNAPSHOT.equals(range) || VERSION_ATTR_PROJECT.equals(range)) {
        return getBundleFromProject(bsn, attrs);
    } else if (VERSION_ATTR_HASH.equals(range)) {
        return getBundleByHash(bsn, attrs);
    }
    Strategy useStrategy = strategy;
    if (VERSION_ATTR_LATEST.equals(range)) {
        Container c = getBundleFromProject(bsn, attrs);
        if (c != null)
            return c;
        useStrategy = Strategy.HIGHEST;
    }
    useStrategy = overrideStrategy(attrs, useStrategy);
    RepoFilter repoFilter = parseRepoFilter(attrs);
    List<RepositoryPlugin> plugins = workspace.getRepositories();
    if (useStrategy == Strategy.EXACT) {
        if (!Verifier.isVersion(range))
            return new Container(this, bsn, range, Container.TYPE.ERROR, null, bsn + ";version=" + range + " Invalid version", null, null);
        // For an exact range we just iterate over the repos
        // and return the first we find.
        Version version = new Version(range);
        for (RepositoryPlugin plugin : plugins) {
            DownloadBlocker blocker = new DownloadBlocker(this);
            File result = plugin.get(bsn, version, attrs, blocker);
            if (result != null)
                return toContainer(bsn, range, attrs, result, blocker);
        }
    } else {
        VersionRange versionRange = VERSION_ATTR_LATEST.equals(range) ? new VersionRange("0") : new VersionRange(range);
        // We have a range search. Gather all the versions in all the repos
        // and make a decision on that choice. If the same version is found
        // in
        // multiple repos we take the first
        SortedMap<Version, RepositoryPlugin> versions = new TreeMap<Version, RepositoryPlugin>();
        for (RepositoryPlugin plugin : plugins) {
            if (repoFilter != null && !repoFilter.match(plugin))
                continue;
            try {
                SortedSet<Version> vs = plugin.versions(bsn);
                if (vs != null) {
                    for (Version v : vs) {
                        if (!versions.containsKey(v) && versionRange.includes(v))
                            versions.put(v, plugin);
                    }
                }
            } catch (UnsupportedOperationException ose) {
                // To query, we must have a real version
                if (!versions.isEmpty() && Verifier.isVersion(range)) {
                    Version version = new Version(range);
                    DownloadBlocker blocker = new DownloadBlocker(this);
                    File file = plugin.get(bsn, version, attrs, blocker);
                    // if it does, return this as a result
                    if (file != null)
                        return toContainer(bsn, range, attrs, file, blocker);
                }
            }
        }
        //
        // We have to augment the list of returned versions
        // with info from the workspace. We use null as a marker
        // to indicate that it is a workspace project
        //
        SortedSet<Version> localVersions = getWorkspace().getWorkspaceRepository().versions(bsn);
        for (Version v : localVersions) {
            if (!versions.containsKey(v) && versionRange.includes(v))
                versions.put(v, null);
        }
        if (!versions.isEmpty()) {
            Version provider = null;
            switch(useStrategy) {
                case HIGHEST:
                    provider = versions.lastKey();
                    break;
                case LOWEST:
                    provider = versions.firstKey();
                    break;
                case EXACT:
                    // TODO need to handle exact better
                    break;
            }
            if (provider != null) {
                RepositoryPlugin repo = versions.get(provider);
                if (repo == null) {
                    // project
                    return getBundleFromProject(bsn, attrs);
                }
                String version = provider.toString();
                DownloadBlocker blocker = new DownloadBlocker(this);
                File result = repo.get(bsn, provider, attrs, blocker);
                if (result != null)
                    return toContainer(bsn, version, attrs, result, blocker);
            } else {
                msgs.FoundVersions_ForStrategy_ButNoProvider(versions, useStrategy);
            }
        }
    }
    return new Container(this, bsn, range, Container.TYPE.ERROR, null, bsn + ";version=" + range + " Not found in " + plugins, null, null);
}
Also used : RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) VersionRange(aQute.bnd.version.VersionRange) TreeMap(java.util.TreeMap) Version(aQute.bnd.version.Version) Strategy(aQute.bnd.service.Strategy) File(java.io.File)

Example 9 with RepositoryPlugin

use of aQute.bnd.service.RepositoryPlugin in project bnd by bndtools.

the class Project method getBundleByHash.

private Container getBundleByHash(String bsn, Map<String, String> attrs) throws Exception {
    String hashStr = attrs.get("hash");
    String algo = SHA_256;
    String hash = hashStr;
    int colonIndex = hashStr.indexOf(':');
    if (colonIndex > -1) {
        algo = hashStr.substring(0, colonIndex);
        int afterColon = colonIndex + 1;
        hash = (colonIndex < hashStr.length()) ? hashStr.substring(afterColon) : "";
    }
    for (RepositoryPlugin plugin : workspace.getRepositories()) {
        // The plugin *may* understand version=hash directly
        DownloadBlocker blocker = new DownloadBlocker(this);
        File result = plugin.get(bsn, Version.LOWEST, Collections.unmodifiableMap(attrs), blocker);
        // Service, use a capability search on the osgi.content namespace.
        if (result == null && plugin instanceof Repository) {
            Repository repo = (Repository) plugin;
            if (!SHA_256.equals(algo))
                // R5 repos only support SHA-256
                continue;
            Requirement contentReq = new CapReqBuilder(ContentNamespace.CONTENT_NAMESPACE).filter(String.format("(%s=%s)", ContentNamespace.CONTENT_NAMESPACE, hash)).buildSyntheticRequirement();
            Set<Requirement> reqs = Collections.singleton(contentReq);
            Map<Requirement, Collection<Capability>> providers = repo.findProviders(reqs);
            Collection<Capability> caps = providers != null ? providers.get(contentReq) : null;
            if (caps != null && !caps.isEmpty()) {
                Capability cap = caps.iterator().next();
                IdentityCapability idCap = ResourceUtils.getIdentityCapability(cap.getResource());
                Map<String, Object> idAttrs = idCap.getAttributes();
                String id = (String) idAttrs.get(IdentityNamespace.IDENTITY_NAMESPACE);
                Object version = idAttrs.get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
                Version bndVersion = version != null ? Version.parseVersion(version.toString()) : Version.LOWEST;
                if (!bsn.equals(id)) {
                    String error = String.format("Resource with requested hash does not match ID '%s' [hash: %s]", bsn, hashStr);
                    return new Container(this, bsn, "hash", Container.TYPE.ERROR, null, error, null, null);
                }
                result = plugin.get(id, bndVersion, null, blocker);
            }
        }
        if (result != null)
            return toContainer(bsn, "hash", attrs, result, blocker);
    }
    // If we reach this far, none of the repos found the resource.
    return new Container(this, bsn, "hash", Container.TYPE.ERROR, null, "Could not find resource by content hash " + hashStr, null, null);
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Capability(org.osgi.resource.Capability) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) Version(aQute.bnd.version.Version) Collection(java.util.Collection) File(java.io.File)

Example 10 with RepositoryPlugin

use of aQute.bnd.service.RepositoryPlugin in project bnd by bndtools.

the class ProjectBuilder method getBaselineRepo.

private RepositoryPlugin getBaselineRepo() {
    String repoName = getProperty(Constants.BASELINEREPO);
    if (repoName == null)
        return getReleaseRepo();
    List<RepositoryPlugin> repos = getPlugins(RepositoryPlugin.class);
    for (RepositoryPlugin r : repos) {
        if (r.getName().equals(repoName))
            return r;
    }
    error("Could not find -baselinerepo %s", repoName);
    return null;
}
Also used : RepositoryPlugin(aQute.bnd.service.RepositoryPlugin)

Aggregations

RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)62 Version (aQute.bnd.version.Version)25 File (java.io.File)24 Workspace (aQute.bnd.build.Workspace)12 IOException (java.io.IOException)10 Project (aQute.bnd.build.Project)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 Jar (aQute.bnd.osgi.Jar)7 CoreException (org.eclipse.core.runtime.CoreException)7 RemoteRepositoryPlugin (aQute.bnd.service.RemoteRepositoryPlugin)5 VersionRange (aQute.bnd.version.VersionRange)5 Description (aQute.lib.getopt.Description)5 Parameters (aQute.bnd.header.Parameters)4 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStatus (org.eclipse.core.runtime.IStatus)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 PartInitException (org.eclipse.ui.PartInitException)4 Attrs (aQute.bnd.header.Attrs)3