Search in sources :

Example 1 with Coordinate

use of aQute.service.library.Coordinate 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 2 with Coordinate

use of aQute.service.library.Coordinate 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 3 with Coordinate

use of aQute.service.library.Coordinate in project bnd by bndtools.

the class Main method printRevisions.

void printRevisions(Iterable<? extends Revision> revisions, RevisionPrintOptions po) {
    if (po.coordinate()) {
        for (Revision r : revisions) {
            out.println(new Coordinate(r));
        }
        return;
    }
    Justif j = new Justif(140, 40, 70, 82, 100, 120);
    try (Formatter f = j.formatter()) {
        for (Revision r : revisions) {
            f.format("[%s] ", r.phase.getIdentifier());
            if (r.groupId.equals(Library.OSGI_GROUP) || r.groupId.equals(Library.SHA_GROUP))
                f.format("%s ", r.artifactId);
            else
                f.format("%s:%s ", r.groupId, r.artifactId);
            f.format("\t0%s\t1%tF\t2%s", r.version, new Date(r.modified), Hex.toHexString(r._id));
            if (po.description() && r.description != null) {
                f.format("\n \t1%s", r.description);
            }
            f.format("\n");
        }
        out.println(j.wrap());
    }
}
Also used : Revision(aQute.service.library.Library.Revision) Justif(aQute.lib.justif.Justif) Coordinate(aQute.service.library.Coordinate) Formatter(java.util.Formatter) Date(java.util.Date)

Example 4 with Coordinate

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

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

Coordinate (aQute.service.library.Coordinate)6 Revision (aQute.service.library.Library.Revision)6 RevisionRef (aQute.service.library.Library.RevisionRef)4 Version (aQute.bnd.version.Version)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 URI (java.net.URI)2 HashSet (java.util.HashSet)2 Matcher (java.util.regex.Matcher)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 IO.createTempFile (aQute.lib.io.IO.createTempFile)1 Justif (aQute.lib.justif.Justif)1 Library (aQute.service.library.Library)1 SocketException (java.net.SocketException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1