Search in sources :

Example 6 with VersionRange

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

the class Verifier method verifyImports.

/**
	 * Verify that the imports properly use version ranges.
	 */
private void verifyImports() {
    if (isStrict()) {
        Parameters map = parseHeader(manifest.getMainAttributes().getValue(Constants.IMPORT_PACKAGE));
        Set<String> noimports = new HashSet<String>();
        Set<String> toobroadimports = new HashSet<String>();
        for (Entry<String, Attrs> e : map.entrySet()) {
            String version = e.getValue().get(Constants.VERSION_ATTRIBUTE);
            if (version == null) {
                if (!e.getKey().startsWith("javax.")) {
                    noimports.add(e.getKey());
                }
            } else {
                if (!VERSIONRANGE.matcher(version).matches()) {
                    Location location = error("Import Package %s has an invalid version range syntax %s", e.getKey(), version).location();
                    location.header = Constants.IMPORT_PACKAGE;
                    location.context = e.getKey();
                } else {
                    try {
                        VersionRange range = new VersionRange(version);
                        if (!range.isRange()) {
                            toobroadimports.add(e.getKey());
                        }
                        if (range.includeHigh() == false && range.includeLow() == false && range.getLow().equals(range.getHigh())) {
                            Location location = error("Import Package %s has an empty version range syntax %s, likely want to use [%s,%s]", e.getKey(), version, range.getLow(), range.getHigh()).location();
                            location.header = Constants.IMPORT_PACKAGE;
                            location.context = e.getKey();
                        }
                    // TODO check for exclude low, include high?
                    } catch (Exception ee) {
                        Location location = exception(ee, "Import Package %s has an invalid version range syntax %s: %s", e.getKey(), version, ee).location();
                        location.header = Constants.IMPORT_PACKAGE;
                        location.context = e.getKey();
                    }
                }
            }
        }
        if (!noimports.isEmpty()) {
            Location location = error("Import Package clauses without version range (excluding javax.*): %s", noimports).location();
            location.header = Constants.IMPORT_PACKAGE;
        }
        if (!toobroadimports.isEmpty()) {
            Location location = error("Import Package clauses which use a version instead of a version range. This imports EVERY later package and not as many expect until the next major number: %s", toobroadimports).location();
            location.header = Constants.IMPORT_PACKAGE;
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) VersionRange(aQute.bnd.version.VersionRange) HashSet(java.util.HashSet)

Example 7 with VersionRange

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

the class LocalIndexedRepo method actions.

public Map<String, Runnable> actions(Object... target) throws Exception {
    Map<String, Runnable> map = new HashMap<String, Runnable>();
    map.put("Refresh", new Runnable() {

        public void run() {
            regenerateAllIndexes();
        }
    });
    if (target.length == 3) {
        String bsn = (String) target[1];
        String version = (String) target[2];
        @SuppressWarnings("deprecation") aQute.bnd.filerepo.FileRepo storageRepo = new aQute.bnd.filerepo.FileRepo(storageDir);
        @SuppressWarnings("deprecation") final File f = storageRepo.get(bsn, new VersionRange(version, version), 0);
        if (f != null) {
            map.put("Delete", new Runnable() {

                public void run() {
                    deleteEntry(f);
                    regenerateAllIndexes();
                }

                private void deleteEntry(final File f) {
                    File parent = f.getParentFile();
                    IO.delete(f);
                    File[] listFiles = parent.listFiles();
                    if (listFiles.length == 1 && listFiles[0].getName().endsWith("-latest.jar"))
                        IO.delete(listFiles[0]);
                    listFiles = parent.listFiles();
                    if (listFiles.length == 0)
                        IO.delete(parent);
                }
            });
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) VersionRange(aQute.bnd.version.VersionRange) File(java.io.File)

Example 8 with VersionRange

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

the class AbstractIndexedRepo method findExactMatch.

ResourceHandle findExactMatch(String identity, String version) throws Exception {
    VersionRange range = new VersionRange(version);
    if (range.isRange())
        return null;
    Resource resource = identityMap.getExact(identity, range.getLow());
    if (resource == null)
        return null;
    return mapResourceToHandle(resource);
}
Also used : Resource(org.osgi.resource.Resource) VersionRange(aQute.bnd.version.VersionRange)

Example 9 with VersionRange

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

the class BndBuilderCapReqLoader method createVersionFilter.

private static final String createVersionFilter(String ns, String value, String rangeStr, String versionAttr) {
    SimpleFilter pkgNameFilter = new SimpleFilter(ns, value);
    Filter filter = pkgNameFilter;
    if (rangeStr != null) {
        VersionRange range = new VersionRange(rangeStr);
        Filter left;
        if (range.includeLow())
            left = new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, range.getLow().toString());
        else
            left = new NotFilter(new SimpleFilter(versionAttr, Operator.LessThanOrEqual, range.getLow().toString()));
        Filter right;
        if (!range.isRange())
            right = null;
        else if (range.includeHigh())
            right = new SimpleFilter(versionAttr, Operator.LessThanOrEqual, range.getHigh().toString());
        else
            right = new NotFilter(new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, range.getHigh().toString()));
        AndFilter combined = new AndFilter().addChild(pkgNameFilter).addChild(left);
        if (right != null)
            combined.addChild(right);
        filter = combined;
    }
    return filter.toString();
}
Also used : AndFilter(aQute.libg.filters.AndFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) NotFilter(aQute.libg.filters.NotFilter) AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) SimpleFilter(aQute.libg.filters.SimpleFilter) NotFilter(aQute.libg.filters.NotFilter) VersionRange(aQute.bnd.version.VersionRange)

Example 10 with VersionRange

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

the class RepoCommand method findMatchingVersion.

private DownloadBlocker findMatchingVersion(RepositoryPlugin dest, String bsn, Version version) throws Exception {
    Version floor = version.getWithoutQualifier();
    Version ceiling = new Version(floor.getMajor() + 1, 0, 0);
    VersionRange range = new VersionRange(true, floor, ceiling, false);
    SortedSet<Version> versions = dest.versions(bsn);
    if (versions == null || versions.isEmpty())
        return null;
    for (Version v : range.filter(versions)) {
    // First one is highest
    // TODO Diff
    }
    return null;
}
Also used : Version(aQute.bnd.version.Version) VersionRange(aQute.bnd.version.VersionRange)

Aggregations

VersionRange (aQute.bnd.version.VersionRange)31 Version (aQute.bnd.version.Version)11 File (java.io.File)6 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)5 Attrs (aQute.bnd.header.Attrs)4 Parameters (aQute.bnd.header.Parameters)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 Matcher (java.util.regex.Matcher)3 Resource (org.osgi.resource.Resource)3 Project (aQute.bnd.build.Project)2 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)2 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)2 SortedList (aQute.lib.collections.SortedList)2 AndFilter (aQute.libg.filters.AndFilter)2 Filter (aQute.libg.filters.Filter)2 NotFilter (aQute.libg.filters.NotFilter)2 SimpleFilter (aQute.libg.filters.SimpleFilter)2 TreeMap (java.util.TreeMap)2