Search in sources :

Example 6 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 7 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)

Example 8 with Revision

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

the class Repository method dropTarget.

public boolean dropTarget(URI uri) throws Exception {
    try {
        init();
        //
        // On Linux we seem to get some spurious text. One case it added the
        // text of the version after the URI. So we remove anything after
        // the new line
        //
        String t = uri.toString().trim();
        int n = t.indexOf('\n');
        if (n > 0) {
            uri = new URI(t.substring(0, n));
            logger.debug("dropTarget cleaned up from {} to {}", t, uri);
        }
        RevisionRef ref;
        logger.debug("dropTarget {}", uri);
        String uriString = uri.toString();
        Matcher m = JPM_REVISION_URL_PATTERN.matcher(uriString);
        if (!m.matches()) {
            if (depositoryGroup != null || depositoryName != null)
                return false;
            if (!Boolean.getBoolean("jpm4j.in.test") && uri.getScheme().equalsIgnoreCase("file"))
                return false;
            //
            // See if it is a bundle
            //
            Download d = getCache().doDownload(uri);
            if (d == null) {
                return false;
            }
            ref = analyze(d.tmp, uri);
            if (ref == null) {
                logger.debug("not a proper url to drop {}", uri);
                IO.delete(d.tmp);
                return false;
            }
            getCache().makePermanent(ref, d);
        } else {
            Revision revision = getRevision(new Coordinate(m.group(1), m.group(2), m.group(3), m.group(4)));
            if (revision == null) {
                reporter.error("no revision found for %s", uri);
                return false;
            }
            ref = new RevisionRef(revision);
        }
        Library.RevisionRef resource = index.getRevisionRef(ref.revision);
        if (resource != null) {
            resource.urls.add(uri);
            // we know that we modified a resource so the index is dirty
            index.save(true);
            logger.debug("resource already loaded {}", uri);
            return true;
        }
        logger.debug("adding revision {}", ref);
        add(ref);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Revision(aQute.service.library.Library.Revision) RevisionRef(aQute.service.library.Library.RevisionRef) Matcher(java.util.regex.Matcher) Coordinate(aQute.service.library.Coordinate) Library(aQute.service.library.Library) URI(java.net.URI) Download(aQute.bnd.jpm.StoredRevisionCache.Download) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) SocketException(java.net.SocketException) IOException(java.io.IOException)

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