Search in sources :

Example 46 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class ResourceUtils method toVersionClause.

/**
	 * Create a VersionedClause by applying a version range mask to the
	 * resource! Masks are defined by
	 * {@link aQute.bnd.osgi.Macro#_range(String[])}. If the resource should
	 * represent a project in the bnd workspace, then instead the VersionClause
	 * will refer to it as a snapshot version: e.g. <bsn>;version=snapshot
	 */
public static VersionedClause toVersionClause(Resource resource, String mask) {
    Capability idCap = getIdentityCapability(resource);
    String identity = getIdentity(idCap);
    String versionString;
    if (resource.getCapabilities(WORKSPACE_NAMESPACE).isEmpty()) {
        Macro macro = new Macro(new Processor());
        Version version = getVersion(idCap);
        versionString = macro._range(new String[] { "range", mask, version.toString() });
    } else {
        versionString = "snapshot";
    }
    Attrs attribs = new Attrs();
    attribs.put(Constants.VERSION_ATTRIBUTE, versionString);
    return new VersionedClause(identity, attribs);
}
Also used : Processor(aQute.bnd.osgi.Processor) Capability(org.osgi.resource.Capability) Version(aQute.bnd.version.Version) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Macro(aQute.bnd.osgi.Macro) Attrs(aQute.bnd.header.Attrs)

Example 47 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class ResourceUtils method toVersion.

public static Version toVersion(Object v) {
    if (v instanceof Version)
        return (Version) v;
    if (v instanceof org.osgi.framework.Version) {
        org.osgi.framework.Version o = (org.osgi.framework.Version) v;
        String q = o.getQualifier();
        return q.isEmpty() ? new Version(o.getMajor(), o.getMinor(), o.getMicro()) : new Version(o.getMajor(), o.getMinor(), o.getMicro(), q);
    }
    if (v instanceof String) {
        if (!Version.isVersion((String) v))
            return null;
        return new Version((String) v);
    }
    return null;
}
Also used : Version(aQute.bnd.version.Version)

Example 48 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class Index method delete.

public boolean delete(String bsn, Version v) throws Exception {
    init();
    Map<Version, Library.RevisionRef> map = cache.get(bsn);
    if (map != null) {
        try {
            Library.RevisionRef removed = map.remove(v);
            if (removed != null) {
                for (Iterator<RevisionRef> i = repo.revisionRefs.iterator(); i.hasNext(); ) {
                    RevisionRef other = i.next();
                    if (Arrays.equals(other.revision, removed.revision)) {
                        i.remove();
                    }
                }
                repo.revisionRefs.remove(removed);
                dirty = true;
                return true;
            }
        } finally {
            if (map.isEmpty())
                cache.remove(bsn);
        }
    }
    return false;
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) RevisionRef(aQute.service.library.Library.RevisionRef) Version(aQute.bnd.version.Version) Library(aQute.service.library.Library)

Example 49 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class Index method getRevisionRef.

@SuppressWarnings("deprecation")
public Library.RevisionRef getRevisionRef(String bsn, Version version) throws Exception {
    init();
    Map<Version, Library.RevisionRef> map = cache.get(bsn);
    if (map == null)
        return null;
    // Fixup the change from ref.url to ref.urls ...
    boolean save = false;
    RevisionRef ref = map.get(version);
    if (ref == null) {
        return null;
    }
    if (ref.urls.isEmpty() && ref.url != null) {
        ref.urls.add(ref.url);
        ref.url = null;
        save = true;
    }
    if (Boolean.getBoolean("jpm4j.in.test") == false) {
        for (Iterator<URI> i = ref.urls.iterator(); i.hasNext(); ) {
            URI uri = i.next();
            if (uri.getScheme().equalsIgnoreCase("file")) {
                i.remove();
                save = true;
            }
        }
    }
    if (save)
        save();
    return ref;
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Version(aQute.bnd.version.Version) URI(java.net.URI)

Example 50 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class Index method init.

private void init() throws Exception {
    if (repo == null) {
        cache = new TreeMap<String, TreeMap<Version, Library.RevisionRef>>();
        if (indexFile.isFile() && indexFile.length() > 100) {
            try (Decoder dec = codec.dec()) {
                repo = dec.from(indexFile).get(new TypeReference<Repo>() {
                });
                for (Library.RevisionRef r : repo.revisionRefs) {
                    TreeMap<Version, Library.RevisionRef> map = cache.get(r.bsn);
                    if (map == null) {
                        map = new TreeMap<Version, Library.RevisionRef>(Collections.reverseOrder());
                        cache.put(r.bsn, map);
                    }
                    Version v = toVersion(r.baseline, r.qualifier);
                    map.put(v, r);
                }
            }
        } else {
            repo = new Repo();
        }
    }
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) RevisionRef(aQute.service.library.Library.RevisionRef) Version(aQute.bnd.version.Version) Library(aQute.service.library.Library) TypeReference(aQute.lib.converter.TypeReference) TreeMap(java.util.TreeMap) Decoder(aQute.lib.json.Decoder)

Aggregations

Version (aQute.bnd.version.Version)171 File (java.io.File)67 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)29 ArrayList (java.util.ArrayList)21 Attrs (aQute.bnd.header.Attrs)19 MavenVersion (aQute.bnd.version.MavenVersion)19 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Jar (aQute.bnd.osgi.Jar)16 Workspace (aQute.bnd.build.Workspace)13 Project (aQute.bnd.build.Project)12 RevisionRef (aQute.service.library.Library.RevisionRef)12 Matcher (java.util.regex.Matcher)12 Parameters (aQute.bnd.header.Parameters)11 VersionRange (aQute.bnd.version.VersionRange)11 SortedList (aQute.lib.collections.SortedList)9 Processor (aQute.bnd.osgi.Processor)8 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)8 FileNotFoundException (java.io.FileNotFoundException)8 LinkedHashMap (java.util.LinkedHashMap)8