Search in sources :

Example 26 with RepositoryPlugin

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

the class ProjectBuilder method getReleaseRepo.

private RepositoryPlugin getReleaseRepo() {
    String repoName = getProperty(Constants.RELEASEREPO);
    List<RepositoryPlugin> repos = getPlugins(RepositoryPlugin.class);
    for (RepositoryPlugin r : repos) {
        if (r.canWrite()) {
            if (repoName == null || r.getName().equals(repoName)) {
                return r;
            }
        }
    }
    if (repoName == null)
        error("Could not find a writable repo for the release repo (-releaserepo is not set)");
    else
        error("No such -releaserepo %s found", repoName);
    return null;
}
Also used : RepositoryPlugin(aQute.bnd.service.RepositoryPlugin)

Example 27 with RepositoryPlugin

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

the class Project method deploy.

/**
	 * Deploy the file (which must be a bundle) into the repository.
	 *
	 * @param name The repository name
	 * @param file bundle
	 */
public void deploy(String name, File file) throws Exception {
    List<RepositoryPlugin> plugins = getPlugins(RepositoryPlugin.class);
    RepositoryPlugin rp = null;
    for (RepositoryPlugin plugin : plugins) {
        if (!plugin.canWrite()) {
            continue;
        }
        if (name == null) {
            rp = plugin;
            break;
        } else if (name.equals(plugin.getName())) {
            rp = plugin;
            break;
        }
    }
    if (rp != null) {
        try {
            rp.put(new BufferedInputStream(IO.stream(file)), new RepositoryPlugin.PutOptions());
            return;
        } catch (Exception e) {
            msgs.DeployingFile_On_Exception_(file, rp.getName(), e);
        }
        return;
    }
    logger.debug("No repo found {}", file);
    throw new IllegalArgumentException("No repository found for " + file);
}
Also used : PutOptions(aQute.bnd.service.RepositoryPlugin.PutOptions) BufferedInputStream(java.io.BufferedInputStream) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) IOException(java.io.IOException)

Example 28 with RepositoryPlugin

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

the class Project method getBundlesWildcard.

/**
	 * Get all bundles matching a wildcard expression.
	 *
	 * @param bsnPattern A bsn wildcard, e.g. "osgi*" or just "*".
	 * @param range A range to narrow the versions of bundles found, or null to
	 *            return any version.
	 * @param strategyx The version selection strategy, which may be 'HIGHEST'
	 *            or 'LOWEST' only -- 'EXACT' is not permitted.
	 * @param attrs Additional search attributes.
	 * @throws Exception
	 */
public List<Container> getBundlesWildcard(String bsnPattern, String range, Strategy strategyx, Map<String, String> attrs) throws Exception {
    if (VERSION_ATTR_SNAPSHOT.equals(range) || VERSION_ATTR_PROJECT.equals(range))
        return Collections.singletonList(new Container(this, bsnPattern, range, TYPE.ERROR, null, "Cannot use snapshot or project version with wildcard matches", null, null));
    if (strategyx == Strategy.EXACT)
        return Collections.singletonList(new Container(this, bsnPattern, range, TYPE.ERROR, null, "Cannot use exact version strategy with wildcard matches", null, null));
    VersionRange versionRange;
    if (range == null || VERSION_ATTR_LATEST.equals(range))
        versionRange = new VersionRange("0");
    else
        versionRange = new VersionRange(range);
    RepoFilter repoFilter = parseRepoFilter(attrs);
    if (bsnPattern != null) {
        bsnPattern = bsnPattern.trim();
        if (bsnPattern.length() == 0 || bsnPattern.equals("*"))
            bsnPattern = null;
    }
    SortedMap<String, Pair<Version, RepositoryPlugin>> providerMap = new TreeMap<String, Pair<Version, RepositoryPlugin>>();
    List<RepositoryPlugin> plugins = workspace.getRepositories();
    for (RepositoryPlugin plugin : plugins) {
        if (repoFilter != null && !repoFilter.match(plugin))
            continue;
        List<String> bsns = plugin.list(bsnPattern);
        if (bsns != null)
            for (String bsn : bsns) {
                SortedSet<Version> versions = plugin.versions(bsn);
                if (versions != null && !versions.isEmpty()) {
                    Pair<Version, RepositoryPlugin> currentProvider = providerMap.get(bsn);
                    Version candidate;
                    switch(strategyx) {
                        case HIGHEST:
                            candidate = versions.last();
                            if (currentProvider == null || candidate.compareTo(currentProvider.getFirst()) > 0) {
                                providerMap.put(bsn, new Pair<Version, RepositoryPlugin>(candidate, plugin));
                            }
                            break;
                        case LOWEST:
                            candidate = versions.first();
                            if (currentProvider == null || candidate.compareTo(currentProvider.getFirst()) < 0) {
                                providerMap.put(bsn, new Pair<Version, RepositoryPlugin>(candidate, plugin));
                            }
                            break;
                        default:
                            // we shouldn't have reached this point!
                            throw new IllegalStateException("Cannot use exact version strategy with wildcard matches");
                    }
                }
            }
    }
    List<Container> containers = new ArrayList<Container>(providerMap.size());
    for (Entry<String, Pair<Version, RepositoryPlugin>> entry : providerMap.entrySet()) {
        String bsn = entry.getKey();
        Version version = entry.getValue().getFirst();
        RepositoryPlugin repo = entry.getValue().getSecond();
        DownloadBlocker downloadBlocker = new DownloadBlocker(this);
        File bundle = repo.get(bsn, version, attrs, downloadBlocker);
        if (bundle != null && !bundle.getName().endsWith(".lib")) {
            containers.add(new Container(this, bsn, range, Container.TYPE.REPO, bundle, null, attrs, downloadBlocker));
        }
    }
    return containers;
}
Also used : ArrayList(java.util.ArrayList) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) VersionRange(aQute.bnd.version.VersionRange) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) Version(aQute.bnd.version.Version) File(java.io.File) Pair(aQute.libg.tuple.Pair)

Example 29 with RepositoryPlugin

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

the class Project method getReleaseRepos.

private List<RepositoryPlugin> getReleaseRepos(String names) {
    Parameters repoNames = parseReleaseRepos(names);
    List<RepositoryPlugin> plugins = getPlugins(RepositoryPlugin.class);
    List<RepositoryPlugin> result = new ArrayList<>();
    if (repoNames == null) {
        // -releaserepo unspecified
        for (RepositoryPlugin plugin : plugins) {
            if (plugin.canWrite()) {
                result.add(plugin);
                break;
            }
        }
        if (result.isEmpty()) {
            msgs.NoNameForReleaseRepository();
        }
        return result;
    }
    repoNames: for (String repoName : repoNames.keySet()) {
        for (RepositoryPlugin plugin : plugins) {
            if (plugin.canWrite() && repoName.equals(plugin.getName())) {
                result.add(plugin);
                continue repoNames;
            }
        }
        msgs.ReleaseRepository_NotFoundIn_(repoName, plugins);
    }
    return result;
}
Also used : Parameters(aQute.bnd.header.Parameters) ArrayList(java.util.ArrayList) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin)

Example 30 with RepositoryPlugin

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

the class ProjectBuilder method getBaselineJar.

/**
	 * This method attempts to find the baseline jar for the current project. It
	 * reads the -baseline property and treats it as instructions. These
	 * instructions are matched against the bsns of the jars (think sub
	 * builders!). If they match, the sub builder is selected.
	 * <p>
	 * The instruction can then specify the following options:
	 * 
	 * <pre>
	 *  version :
	 * baseline version from repository file : a file path
	 * </pre>
	 * 
	 * If neither is specified, the current version is used to find the highest
	 * version (without qualifier) that is below the current version. If a
	 * version is specified, we take the highest version with the same base
	 * version.
	 * <p>
	 * Since baselining is expensive and easily generates errors you must enable
	 * it. The easiest solution is to {@code -baseline: *}. This will match all
	 * sub builders and will calculate the version.
	 * 
	 * @return a Jar or null
	 */
public Jar getBaselineJar() throws Exception {
    String bl = getProperty(Constants.BASELINE);
    if (bl == null || Constants.NONE.equals(bl))
        return null;
    Instructions baselines = new Instructions(getProperty(Constants.BASELINE));
    if (baselines.isEmpty())
        // no baselining
        return null;
    RepositoryPlugin repo = getBaselineRepo();
    if (repo == null)
        // errors reported already
        return null;
    String bsn = getBsn();
    Version version = new Version(getVersion());
    SortedSet<Version> versions = removeStagedAndFilter(repo.versions(bsn), repo, bsn);
    if (versions.isEmpty()) {
        // We have a repo
        Version v = Version.parseVersion(getVersion()).getWithoutQualifier();
        if (v.compareTo(Version.ONE) > 0) {
            warning("There is no baseline for %s in the baseline repo %s. The build is for version %s, which is higher than 1.0.0 which suggests that there should be a prior version.", getBsn(), repo, v);
        }
        return null;
    }
    for (Entry<Instruction, Attrs> e : baselines.entrySet()) {
        if (e.getKey().matches(bsn)) {
            Attrs attrs = e.getValue();
            Version target;
            if (attrs.containsKey("version")) {
                // Specified version!
                String v = attrs.get("version");
                if (!Verifier.isVersion(v)) {
                    error("Not a valid version in %s %s", Constants.BASELINE, v);
                    return null;
                }
                Version base = new Version(v);
                SortedSet<Version> later = versions.tailSet(base);
                if (later.isEmpty()) {
                    error("For baselineing %s-%s, specified version %s not found", bsn, version, base);
                    return null;
                }
                // First element is equal or next to the base we desire
                target = later.first();
            // Now, we could end up with a higher version than our
            // current
            // project
            } else if (attrs.containsKey("file")) {
                // Can be useful to specify a file
                // for example when copying a bundle with a public api
                File f = getProject().getFile(attrs.get("file"));
                if (f != null && f.isFile()) {
                    Jar jar = new Jar(f);
                    addClose(jar);
                    return jar;
                }
                error("Specified file for baseline but could not find it %s", f);
                return null;
            } else {
                target = versions.last();
            }
            if (target.getWithoutQualifier().compareTo(version.getWithoutQualifier()) > 0) {
                error("The baseline version %s is higher than the current version %s for %s in %s", target, version, bsn, repo);
                return null;
            }
            if (target.getWithoutQualifier().compareTo(version.getWithoutQualifier()) == 0) {
                if (isPedantic()) {
                    warning("Baselining against jar");
                }
            }
            File file = repo.get(bsn, target, attrs);
            if (file == null || !file.isFile()) {
                error("Decided on version %s-%s but cannot get file from repo %s", bsn, version, repo);
                return null;
            }
            Jar jar = new Jar(file);
            addClose(jar);
            return jar;
        }
    }
    // Ignore, nothing matched
    return null;
}
Also used : Version(aQute.bnd.version.Version) Attrs(aQute.bnd.header.Attrs) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Instructions(aQute.bnd.osgi.Instructions) Jar(aQute.bnd.osgi.Jar) Instruction(aQute.bnd.osgi.Instruction) File(java.io.File)

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