Search in sources :

Example 1 with Revision

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

the class Repository method getRevisionRef.

/**
	 * Find a revisionref for a bsn/version
	 * 
	 * @param bsn
	 * @param version
	 * @throws Exception
	 */
private RevisionRef getRevisionRef(String bsn, Version version) throws Exception {
    // Handle when we have a sha reference
    String id = bsn + "-" + version;
    if (notfoundref.contains(id))
        return null;
    if (isSha(bsn) && version.equals(Version.LOWEST)) {
        Revision r = getRevision(new Coordinate(bsn));
        if (r == null)
            return null;
        return new RevisionRef(r);
    }
    logger.debug("Looking for {}-{}", bsn, version);
    for (RevisionRef r : getRevisionRefs(bsn)) {
        Version v = toVersion(r.baseline, r.qualifier);
        if (v.equals(version))
            return r;
    }
    notfoundref.add(id);
    return null;
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Revision(aQute.service.library.Library.Revision) Coordinate(aQute.service.library.Coordinate) Version(aQute.bnd.version.Version)

Example 2 with Revision

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

the class JustAnotherPackageManager method latest.

public Map<String, Revision> latest(Collection<Revision> list) {
    Map<String, Revision> programs = new HashMap<String, Library.Revision>();
    for (Revision r : list) {
        String coordinates = r.groupId + ":" + r.artifactId;
        if (r.classifier != null)
            coordinates += ":" + r.classifier;
        if (r.groupId.equals(Library.SHA_GROUP))
            continue;
        Revision current = programs.get(coordinates);
        if (current == null)
            programs.put(coordinates, r);
        else {
            // who is better?
            if (compare(r, current) >= 0)
                programs.put(coordinates, r);
        }
    }
    return programs;
}
Also used : Revision(aQute.service.library.Library.Revision) HashMap(java.util.HashMap) Library(aQute.service.library.Library)

Example 3 with Revision

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

the class JustAnotherPackageManager method getCandidateAsync.

public ArtifactData getCandidateAsync(String arg) throws Exception {
    logger.debug("coordinate {}", arg);
    if (isUrl(arg))
        try {
            ArtifactData data = putAsync(new URI(arg));
            data.local = true;
            return data;
        } catch (Exception e) {
            logger.debug("hmm, not a valid url {}, will try the server", arg);
            return null;
        }
    File f = IO.getFile(arg);
    if (f.isFile())
        try {
            ArtifactData data = putAsync(f.toURI());
            data.local = true;
            return data;
        } catch (Exception e) {
            logger.debug("hmm, not a valid file {}, will try the server", arg);
            return null;
        }
    Coordinate c = new Coordinate(arg);
    if (c.isSha()) {
        ArtifactData r = get(c.getSha());
        if (r != null)
            return r;
    }
    Revision revision = library.getRevisionByCoordinate(c);
    if (revision == null)
        return null;
    logger.debug("revision {}", Hex.toHexString(revision._id));
    ArtifactData ad = get(revision._id);
    if (ad != null) {
        logger.debug("found in cache");
        return ad;
    }
    URI url = revision.urls.iterator().next();
    ArtifactData artifactData = putAsync(url);
    artifactData.coordinate = c;
    return artifactData;
}
Also used : Revision(aQute.service.library.Library.Revision) Coordinate(aQute.service.library.Coordinate) URI(java.net.URI) JarFile(java.util.jar.JarFile) IO.createTempFile(aQute.lib.io.IO.createTempFile) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 4 with Revision

use of aQute.service.library.Library.Revision 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 5 with Revision

use of aQute.service.library.Library.Revision 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

Revision (aQute.service.library.Library.Revision)8 Coordinate (aQute.service.library.Coordinate)6 RevisionRef (aQute.service.library.Library.RevisionRef)5 File (java.io.File)3 Matcher (java.util.regex.Matcher)3 Version (aQute.bnd.version.Version)2 IO.createTempFile (aQute.lib.io.IO.createTempFile)2 Justif (aQute.lib.justif.Justif)2 Library (aQute.service.library.Library)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 URI (java.net.URI)2 Date (java.util.Date)2 Formatter (java.util.Formatter)2 HashSet (java.util.HashSet)2 JarFile (java.util.jar.JarFile)2 Container (aQute.bnd.build.Container)1 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 Download (aQute.bnd.jpm.StoredRevisionCache.Download)1