Search in sources :

Example 6 with InfoRepository

use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.

the class TestWrapper method testRepo.

private void testRepo(int count, InfoRepository... repo) throws Exception, FileNotFoundException, IOException {
    List<InfoRepository> repos = Arrays.asList(repo);
    for (InfoRepository r : repos) {
        assertNotNull(r.get("biz.aQute.jpm.daemon", new Version("1.1.0"), null));
    }
    InfoRepositoryWrapper iw = new InfoRepositoryWrapper(tmp, repos);
    Requirement req = CapReqBuilder.createBundleRequirement("biz.aQute.jpm.daemon", null).buildSyntheticRequirement();
    Map<Requirement, Collection<Capability>> result = iw.findProviders(Arrays.asList(req));
    assertNotNull(result);
    assertEquals(count, result.size());
    iw.close();
    iw = new InfoRepositoryWrapper(tmp, repos);
    result = iw.findProviders(Arrays.asList(req));
    assertNotNull(result);
    assertEquals(count, result.size());
    iw.close();
    for (InfoRepository r : repos) {
        if (r instanceof Closeable)
            ((Closeable) r).close();
    }
}
Also used : Requirement(org.osgi.resource.Requirement) Version(aQute.bnd.version.Version) Closeable(java.io.Closeable) Collection(java.util.Collection) InfoRepository(aQute.bnd.service.repository.InfoRepository)

Example 7 with InfoRepository

use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.

the class ProjectBuilder method doBaseline.

/**
	 * Compare this builder's JAR with a baseline
	 * 
	 * @throws Exception
	 */
@Override
public void doBaseline(Jar dot) throws Exception {
    String diffignore = project.getProperty(Constants.DIFFIGNORE);
    logger.debug("ignore headers & paths {}", diffignore);
    differ.setIgnore(diffignore);
    Instructions diffpackages = new Instructions(new Parameters(project.getProperty(Constants.DIFFPACKAGES), this));
    logger.debug("diffpackages {}", diffpackages);
    try (Jar fromRepo = getBaselineJar()) {
        if (fromRepo == null) {
            logger.debug("No baseline jar {}", getProperty(Constants.BASELINE));
            return;
        }
        Version newer = new Version(getVersion());
        Version older = new Version(fromRepo.getVersion());
        if (!getBsn().equals(fromRepo.getBsn())) {
            error("The symbolic name of this project (%s) is not the same as the baseline: %s", getBsn(), fromRepo.getBsn());
            return;
        }
        if (newer.getWithoutQualifier().equals(older.getWithoutQualifier())) {
            RepositoryPlugin rr = getBaselineRepo();
            if (rr instanceof InfoRepository) {
                ResourceDescriptor descriptor = ((InfoRepository) rr).getDescriptor(getBsn(), older);
                if (descriptor != null && descriptor.phase != Phase.STAGING) {
                    error("Baselining %s against same version %s but the repository says the older repository version is not the required %s but is instead %s", getBsn(), getVersion(), Phase.STAGING, descriptor.phase);
                    return;
                }
            }
        }
        logger.debug("baseline {}-{} against: {}", getBsn(), getVersion(), fromRepo.getName());
        Baseline baseliner = new Baseline(this, differ);
        Set<Info> infos = baseliner.baseline(dot, fromRepo, diffpackages);
        if (infos.isEmpty())
            logger.debug("no deltas");
        StringBuffer sb = new StringBuffer();
        try (Formatter f = new Formatter(sb, Locale.US)) {
            for (Info info : infos) {
                if (!info.mismatch) {
                    continue;
                }
                sb.setLength(0);
                Diff packageDiff = info.packageDiff;
                f.format("Baseline mismatch for package %s, %s change. Current is %s, repo is %s, suggest %s or %s%n%#S", packageDiff.getName(), packageDiff.getDelta(), info.newerVersion, ((info.olderVersion != null) && info.olderVersion.equals(Version.LOWEST)) ? '-' : info.olderVersion, ((info.suggestedVersion != null) && info.suggestedVersion.compareTo(info.newerVersion) <= 0) ? "ok" : info.suggestedVersion, (info.suggestedIfProviders == null) ? "-" : info.suggestedIfProviders, packageDiff);
                SetLocation l = error("%s", f.toString());
                l.header(Constants.BASELINE);
                fillInLocationForPackageInfo(l.location(), packageDiff.getName());
                if (getPropertiesFile() != null)
                    l.file(getPropertiesFile().getAbsolutePath());
                l.details(info);
            }
            BundleInfo binfo = baseliner.getBundleInfo();
            if (binfo.mismatch) {
                sb.setLength(0);
                f.format("The bundle version (%s/%s) is too low, must be at least %s%n%#S", binfo.olderVersion, binfo.newerVersion, binfo.suggestedVersion, baseliner.getDiff());
                SetLocation error = error("%s", f.toString());
                error.context("Baselining");
                error.header(Constants.BUNDLE_VERSION);
                error.details(binfo);
                FileLine fl = getHeader(Pattern.compile("^" + Constants.BUNDLE_VERSION, Pattern.MULTILINE));
                if (fl != null) {
                    error.file(fl.file.getAbsolutePath());
                    error.line(fl.line);
                    error.length(fl.length);
                }
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Diff(aQute.bnd.service.diff.Diff) Formatter(java.util.Formatter) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Instructions(aQute.bnd.osgi.Instructions) Baseline(aQute.bnd.differ.Baseline) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Info(aQute.bnd.differ.Baseline.Info) InfoRepository(aQute.bnd.service.repository.InfoRepository) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Version(aQute.bnd.version.Version) Jar(aQute.bnd.osgi.Jar) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 8 with InfoRepository

use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.

the class ProjectBuilder method removeStagedAndFilter.

/**
	 * Remove any staging versions that have a variant with a higher qualifier.
	 * 
	 * @param versions
	 * @param repo
	 * @throws Exception
	 */
private SortedSet<Version> removeStagedAndFilter(SortedSet<Version> versions, RepositoryPlugin repo, String bsn) throws Exception {
    List<Version> filtered = new ArrayList<Version>(versions);
    Collections.reverse(filtered);
    InfoRepository ir = (repo instanceof InfoRepository) ? (InfoRepository) repo : null;
    //
    // Filter any versions that only differ in qualifier
    // The last variable is the last one added. Since we are
    // sorted from high to low, we skip any earlier base versions
    //
    Version last = null;
    for (Iterator<Version> i = filtered.iterator(); i.hasNext(); ) {
        Version v = i.next();
        // Check if same base version as last
        Version current = v.getWithoutQualifier();
        if (last != null && current.equals(last)) {
            i.remove();
            continue;
        }
        // /
        if (ir != null && !isMaster(ir, bsn, v))
            i.remove();
        last = current;
    }
    SortedList<Version> set = new SortedList<Version>(filtered);
    logger.debug("filtered for only latest staged: {} from {} in range ", set, versions);
    return set;
}
Also used : Version(aQute.bnd.version.Version) ArrayList(java.util.ArrayList) SortedList(aQute.lib.collections.SortedList) InfoRepository(aQute.bnd.service.repository.InfoRepository)

Aggregations

InfoRepository (aQute.bnd.service.repository.InfoRepository)8 Version (aQute.bnd.version.Version)5 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Parameters (aQute.bnd.header.Parameters)2 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 MultiMap (aQute.lib.collections.MultiMap)2 SortedList (aQute.lib.collections.SortedList)2 IOException (java.io.IOException)2 DownloadBlocker (aQute.bnd.build.DownloadBlocker)1 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 Baseline (aQute.bnd.differ.Baseline)1 BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)1 Info (aQute.bnd.differ.Baseline.Info)1 Instructions (aQute.bnd.osgi.Instructions)1 Jar (aQute.bnd.osgi.Jar)1 Processor (aQute.bnd.osgi.Processor)1 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)1