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();
}
}
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);
}
}
}
}
}
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;
}
Aggregations