Search in sources :

Example 51 with RepositoryPlugin

use of aQute.bnd.service.RepositoryPlugin 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 52 with RepositoryPlugin

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

the class RepoCommand method _list.

@Description("List all artifacts from the current repositories with their versions")
public void _list(listOptions opts) throws Exception {
    logger.debug("list");
    Set<String> bsns = new HashSet<String>();
    Instruction from = opts.from();
    if (from == null)
        from = new Instruction("*");
    for (RepositoryPlugin repo : repos) {
        if (from.matches(repo.getName()))
            bsns.addAll(repo.list(opts.query()));
    }
    logger.debug("list {}", bsns);
    for (String bsn : new SortedList<String>(bsns)) {
        if (!opts.noversions()) {
            Set<Version> versions = new TreeSet<Version>();
            for (RepositoryPlugin repo : repos) {
                logger.debug("get {} from {}", bsn, repo);
                if (from.matches(repo.getName())) {
                    SortedSet<Version> result = repo.versions(bsn);
                    if (result != null)
                        versions.addAll(result);
                }
            }
            bnd.out.printf("%-40s %s%n", bsn, versions);
        } else {
            bnd.out.printf("%s%n", bsn);
        }
    }
}
Also used : Version(aQute.bnd.version.Version) TreeSet(java.util.TreeSet) SortedList(aQute.lib.collections.SortedList) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Instruction(aQute.bnd.osgi.Instruction) HashSet(java.util.HashSet) Description(aQute.lib.getopt.Description)

Example 53 with RepositoryPlugin

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

the class RepoCommand method _get.

/**
	 * get a file from the repo
	 * 
	 * @param opts
	 */
@Description("Get an artifact from a repository.")
public void _get(getOptions opts) throws Exception {
    Instruction from = opts.from();
    if (from == null)
        from = new Instruction("*");
    List<String> args = opts._arguments();
    if (args.isEmpty()) {
        bnd.error("Get needs at least a bsn");
        return;
    }
    String bsn = args.remove(0);
    String range = null;
    if (!args.isEmpty()) {
        range = args.remove(0);
        if (!args.isEmpty()) {
            bnd.error("Extra args %s", args);
        }
    }
    VersionRange r = new VersionRange(range == null ? "0" : range);
    Map<Version, RepositoryPlugin> index = new HashMap<Version, RepositoryPlugin>();
    for (RepositoryPlugin repo : repos) {
        if (from.matches(repo.getName())) {
            SortedSet<Version> versions = repo.versions(bsn);
            if (versions != null)
                for (Version v : versions) {
                    if (r.includes(v))
                        index.put(v, repo);
                }
        }
    }
    SortedList<Version> l = new SortedList<Version>(index.keySet());
    if (l.isEmpty()) {
        bnd.out.printf("No versions found for %s%n", bsn);
        return;
    }
    Version v;
    if (opts.lowest())
        v = l.first();
    else
        v = l.last();
    RepositoryPlugin repo = index.get(v);
    File file = repo.get(bsn, v, null);
    File dir = bnd.getBase();
    String name = file.getName();
    if (opts.output() != null) {
        File f = bnd.getFile(opts.output());
        if (f.isDirectory())
            dir = f;
        else {
            dir = f.getParentFile();
            name = f.getName();
        }
    }
    IO.mkdirs(dir);
    IO.copy(file, new File(dir, name));
}
Also used : HashMap(java.util.HashMap) Version(aQute.bnd.version.Version) SortedList(aQute.lib.collections.SortedList) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) VersionRange(aQute.bnd.version.VersionRange) Instruction(aQute.bnd.osgi.Instruction) File(java.io.File) Description(aQute.lib.getopt.Description)

Example 54 with RepositoryPlugin

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

the class RepoCommand method _diff.

@Description("Diff jars (or show tree)")
public void _diff(diffOptions options) throws UnsupportedEncodingException, IOException, Exception {
    List<String> args = options._arguments();
    String newer = args.remove(0);
    String older = args.size() > 0 ? args.remove(0) : null;
    RepositoryPlugin rnewer = findRepo(newer);
    RepositoryPlugin rolder = older == null ? null : findRepo(older);
    if (rnewer == null) {
        bnd.messages.NoSuchRepository_(newer);
        return;
    }
    if (older != null && rolder == null) {
        bnd.messages.NoSuchRepository_(newer);
        return;
    }
    PrintWriter pw = IO.writer(bnd.out, UTF_8);
    Tree tNewer = RepositoryElement.getTree(rnewer);
    if (rolder == null) {
        if (options.json())
            codec.enc().to(pw).put(tNewer.serialize()).flush();
        else
            DiffCommand.show(pw, tNewer, 0);
    } else {
        Tree tOlder = RepositoryElement.getTree(rolder);
        Diff diff = new DiffImpl(tNewer, tOlder);
        MultiMap<String, String> map = new MultiMap<String, String>();
        for (Diff bsn : diff.getChildren()) {
            for (Diff version : bsn.getChildren()) {
                if (version.getDelta() == Delta.UNCHANGED)
                    continue;
                if (options.remove() == false && options.added() == false || (//
                options.remove() && version.getDelta() == Delta.REMOVED) || (options.added() && version.getDelta() == Delta.ADDED)) {
                    map.add(bsn.getName(), version.getName());
                }
            }
        }
        if (options.json())
            codec.enc().to(pw).put(map).flush();
        else if (!options.diff())
            bnd.printMultiMap(map);
        else
            DiffCommand.show(pw, diff, 0, !options.full());
    }
    pw.flush();
}
Also used : MultiMap(aQute.lib.collections.MultiMap) Diff(aQute.bnd.service.diff.Diff) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Tree(aQute.bnd.service.diff.Tree) DiffImpl(aQute.bnd.differ.DiffImpl) PrintWriter(java.io.PrintWriter) Description(aQute.lib.getopt.Description)

Example 55 with RepositoryPlugin

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

the class RepoCommand method _repos.

@Description("List the current repositories")
public void _repos(@SuppressWarnings("unused") reposOptions opts) {
    int n = 1;
    for (RepositoryPlugin repo : repos) {
        String location = "";
        try {
            location = repo.getLocation();
        } catch (Throwable e) {
        // Ignore
        }
        bnd.out.printf("%03d: %-20s %4s %-20s %s%n", n++, repo.getName(), repo.canWrite() ? "r/w" : "r/o", Descriptors.getShortName(repo.getClass().getName()), location);
    }
}
Also used : RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Description(aQute.lib.getopt.Description)

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