Search in sources :

Example 16 with RevisionRef

use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.

the class Repository method getResources.

/**
	 * Answer the resource descriptors from a URL
	 */
// @Override
public Set<ResourceDescriptor> getResources(URI url, boolean includeDependencies) throws Exception {
    Matcher m = JPM_REVISION_URL_PATTERN.matcher(url.toString());
    if (!m.matches()) {
        return null;
    }
    Set<ResourceDescriptor> resources = new HashSet<ResourceDescriptor>();
    Revision revision = getRevision(new Coordinate(m.group(1), m.group(2), m.group(3), m.group(4)));
    if (revision != null) {
        ResourceDescriptor rd = createResourceDescriptor(new RevisionRef(revision));
        resources.add(rd);
        if (includeDependencies) {
            for (RevisionRef dependency : getLibrary().getClosure(revision._id, false)) {
                ResourceDescriptor dep = createResourceDescriptor(dependency);
                dep.dependency = true;
                resources.add(dep);
            }
        }
    }
    return resources;
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Revision(aQute.service.library.Library.Revision) Matcher(java.util.regex.Matcher) Coordinate(aQute.service.library.Coordinate) HashSet(java.util.HashSet)

Example 17 with RevisionRef

use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.

the class Repository method getRevisionRefs.

private List<RevisionRef> getRevisionRefs(String bsn) throws Exception {
    String classifier = null;
    String[] parts = bsn.split("__");
    if (parts.length == 3) {
        bsn = parts[0] + "__" + parts[1];
        classifier = parts[2];
    }
    Program program = getProgram(bsn, false);
    if (program != null) {
        List<RevisionRef> refs = new ArrayList<Library.RevisionRef>();
        for (RevisionRef r : program.revisions) {
            if (eq(classifier, r.classifier))
                refs.add(r);
        }
        return refs;
    }
    return Collections.emptyList();
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Program(aQute.service.library.Library.Program) ArrayList(java.util.ArrayList) Library(aQute.service.library.Library)

Example 18 with RevisionRef

use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.

the class Repository method revisionTooltip.

private String revisionTooltip(String bsn, Version version) throws Exception {
    RevisionRef r = getRevisionRef(bsn, version);
    if (r == null)
        return null;
    try (Formatter sb = new Formatter()) {
        sb.format("[%s:%s", r.groupId, r.artifactId);
        if (r.classifier != null) {
            sb.format(":%s", r.classifier);
        }
        sb.format("@%s] %s\n\n", r.version, r.phase);
        if (r.releaseSummary != null)
            sb.format("%s\n\n", r.releaseSummary);
        if (r.description != null)
            sb.format("%s\n\n", r.description.replaceAll("#\\s*", ""));
        sb.format("Size: %s\n", size(r.size, 0));
        sb.format("SHA-1: %s\n", Hex.toHexString(r.revision));
        sb.format("Age: %s\n", age(r.created));
        sb.format("URL: %s\n", r.urls);
        File f = getCache().getPath(bsn, version.toString(), r.revision);
        if (f.isFile() && f.length() == r.size)
            sb.format("Cached %s\n", f);
        else
            sb.format("Not downloaded\n");
        if (bsn.indexOf("__") >= 0) {
            sb.format("\nThis artifact has no OSGi metadata. Its coordinates are %s:%s@%s\n", r.groupId, r.artifactId, r.version);
        }
        Program p = getProgram(bsn, false);
        if (p != null) {
            Runnable update = getUpdateAction(p, r);
            if (update != null) {
                sb.format("%c This version can be updated to %s\n", DOWN_ARROW, update);
            }
        }
        File sources = getCache().getPath(bsn, version.toString(), r.revision, true);
        if (sources.isFile())
            sb.format("Has sources: %s\n", sources.getAbsolutePath());
        else
            sb.format("No sources\n");
        j.wrap((StringBuilder) sb.out());
        return sb.toString().trim();
    }
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Program(aQute.service.library.Library.Program) Formatter(java.util.Formatter) File(java.io.File)

Example 19 with RevisionRef

use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.

the class Repository method query.

// @Override
public Set<ResourceDescriptor> query(String query) throws Exception {
    Set<ResourceDescriptor> resources = new HashSet<ResourceDescriptor>();
    RevisionRef master = null;
    RevisionRef staging = null;
    for (Program p : getLibrary().getQueryPrograms(query, 0, 100)) {
        for (RevisionRef ref : p.revisions) {
            if (master == null && ref.phase == Library.Phase.MASTER) {
                master = ref;
            } else if (staging != null && ref.phase == Library.Phase.STAGING) {
                staging = ref;
            }
        }
        if (master != null)
            resources.add(createResourceDescriptor(master));
        if (staging != null)
            resources.add(createResourceDescriptor(staging));
    }
    return resources;
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Program(aQute.service.library.Library.Program) HashSet(java.util.HashSet)

Example 20 with RevisionRef

use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.

the class Repository method cleanUp.

/**
	 * Remove any unused entries in this repository
	 * 
	 * @throws Exception
	 */
void cleanUp() throws Exception {
    Workspace workspace = registry.getPlugin(Workspace.class);
    Set<Container> set = new HashSet<Container>();
    for (Project project : workspace.getAllProjects()) {
        set.addAll(project.getBuildpath());
        set.addAll(project.getRunbundles());
        set.addAll(project.getRunpath());
        set.addAll(project.getTestpath());
        set.addAll(project.getBootclasspath());
        set.addAll(project.getClasspath());
        //
        // This should be replaced with project.getRunfw()
        //
        String s = project.getProperty(Constants.RUNFW);
        List<Container> bundles = project.getBundles(Strategy.HIGHEST, s, Constants.RUNFW);
        set.addAll(bundles);
        File base = project.getBase();
        for (File sub : base.listFiles()) {
            if (sub.getName().endsWith(".bndrun")) {
                try (Project bndrun = new Project(workspace, base, sub)) {
                    set.addAll(bndrun.getRunbundles());
                    set.addAll(bndrun.getRunpath());
                    set.addAll(bndrun.getTestpath());
                    set.addAll(bndrun.getBootclasspath());
                    set.addAll(bndrun.getClasspath());
                }
            }
        }
    }
    Set<RevisionRef> refs = new HashSet<RevisionRef>(index.getRevisionRefs());
    Set<RevisionRef> keep = new HashSet<RevisionRef>();
    for (Container libOrRev : set) {
        for (Container c : libOrRev.getMembers()) {
            logger.debug("Dependency {}", c);
            if (!Verifier.isVersion(c.getVersion()))
                continue;
            RevisionRef ref = index.getRevisionRef(c.getBundleSymbolicName(), new Version(c.getVersion()));
            if (ref != null)
                refs.remove(ref);
            else {
                // missing!
                logger.debug("Missing {}", c.getBundleSymbolicName());
                Coordinate coord = new Coordinate(c.getBundleSymbolicName());
                Revision rev = getLibrary().getRevisionByCoordinate(coord);
                if (rev != null) {
                    index.addRevision(new RevisionRef(rev));
                } else
                    System.out.printf("not found %s\n", c);
            }
            keep.add(ref);
        }
    }
    for (RevisionRef ref : refs) {
        index.delete(ref.bsn, Index.toVersion(ref));
    }
    index.save();
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) RevisionRef(aQute.service.library.Library.RevisionRef) Revision(aQute.service.library.Library.Revision) Version(aQute.bnd.version.Version) Coordinate(aQute.service.library.Coordinate) File(java.io.File) Workspace(aQute.bnd.build.Workspace) HashSet(java.util.HashSet)

Aggregations

RevisionRef (aQute.service.library.Library.RevisionRef)22 Version (aQute.bnd.version.Version)11 Revision (aQute.service.library.Library.Revision)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 SocketException (java.net.SocketException)5 URISyntaxException (java.net.URISyntaxException)5 HashSet (java.util.HashSet)5 Matcher (java.util.regex.Matcher)5 Coordinate (aQute.service.library.Coordinate)4 Library (aQute.service.library.Library)4 ArrayList (java.util.ArrayList)4 Program (aQute.service.library.Library.Program)3 File (java.io.File)3 URI (java.net.URI)3 Formatter (java.util.Formatter)2 LinkedHashMap (java.util.LinkedHashMap)2 Container (aQute.bnd.build.Container)1 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1