use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor in project bnd by bndtools.
the class IndexedReposWithComms method testJpmRepoQuery.
public void testJpmRepoQuery() throws Exception {
try (HttpTestServer ht = http()) {
createSecureSocks5();
Workspace ws = Workspace.getWorkspace(aQute.lib.io.IO.getFile("workspaces/jpm"));
assertNotNull(ws);
ws.setProperty("repo", ht.getBaseURI().toASCIIString());
ws.setProperty("tmp", tmp.toURI().getPath());
ws.setProperty("-fixupmessages.jpmdeprecated", "aQute.bnd.jpm.Repository is deprecated");
Repository plugin = ws.getPlugin(Repository.class);
assertTrue(ws.check());
assertNotNull(plugin);
Set<ResourceDescriptor> query = plugin.query("bla");
assertTrue(ws.check());
assertTrue(query.size() > 0);
}
}
use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor in project bnd by bndtools.
the class IndexedReposWithComms method testJpmRepoDownload.
public void testJpmRepoDownload() throws Exception {
try (HttpTestServer ht = http()) {
createSecureSocks5();
Workspace ws = Workspace.getWorkspace(aQute.lib.io.IO.getFile("workspaces/jpm"));
assertNotNull(ws);
ws.setProperty("repo", ht.getBaseURI().toASCIIString());
ws.setProperty("tmp", tmp.toURI().getPath());
Repository plugin = ws.getPlugin(Repository.class);
ResourceDescriptor descriptor = plugin.getDescriptor("slf4j.simple", new Version("1.7.13"));
assertNotNull(descriptor);
File file = plugin.get("slf4j.simple", new Version("1.7.13"), null);
assertTrue(file.isFile());
byte[] digest = SHA256.digest(file).digest();
assertTrue(Arrays.equals(descriptor.sha256, digest));
}
}
use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor 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.SearchableRepository.ResourceDescriptor in project bnd by bndtools.
the class Workspace method addExtensions.
/**
* Add any extensions listed
*
* @param list
*/
@Override
protected void addExtensions(Set<Object> list) {
//
// <bsn>; version=<range>
//
Parameters extensions = getMergedParameters(EXTENSION);
Map<DownloadBlocker, Attrs> blockers = new HashMap<DownloadBlocker, Attrs>();
for (Entry<String, Attrs> i : extensions.entrySet()) {
String bsn = removeDuplicateMarker(i.getKey());
String stringRange = i.getValue().get(VERSION_ATTRIBUTE);
logger.debug("Adding extension {}-{}", bsn, stringRange);
if (stringRange == null)
stringRange = Version.LOWEST.toString();
else if (!VersionRange.isVersionRange(stringRange)) {
error("Invalid version range %s on extension %s", stringRange, bsn);
continue;
}
try {
SortedSet<ResourceDescriptor> matches = resourceRepositoryImpl.find(null, bsn, new VersionRange(stringRange));
if (matches.isEmpty()) {
error("Extension %s;version=%s not found in base repo", bsn, stringRange);
continue;
}
DownloadBlocker blocker = new DownloadBlocker(this);
blockers.put(blocker, i.getValue());
resourceRepositoryImpl.getResource(matches.last().id, blocker);
} catch (Exception e) {
error("Failed to load extension %s-%s, %s", bsn, stringRange, e);
}
}
logger.debug("Found extensions {}", blockers);
for (Entry<DownloadBlocker, Attrs> blocker : blockers.entrySet()) {
try {
String reason = blocker.getKey().getReason();
if (reason != null) {
error("Extension load failed: %s", reason);
continue;
}
@SuppressWarnings("resource") URLClassLoader cl = new URLClassLoader(new URL[] { blocker.getKey().getFile().toURI().toURL() }, getClass().getClassLoader());
Enumeration<URL> manifests = cl.getResources("META-INF/MANIFEST.MF");
while (manifests.hasMoreElements()) {
try (InputStream is = manifests.nextElement().openStream()) {
Manifest m = new Manifest(is);
Parameters activators = new Parameters(m.getMainAttributes().getValue("Extension-Activator"), this);
for (Entry<String, Attrs> e : activators.entrySet()) {
try {
Class<?> c = cl.loadClass(e.getKey());
ExtensionActivator extensionActivator = (ExtensionActivator) c.getConstructor().newInstance();
customize(extensionActivator, blocker.getValue());
List<?> plugins = extensionActivator.activate(this, blocker.getValue());
list.add(extensionActivator);
if (plugins != null)
for (Object plugin : plugins) {
list.add(plugin);
}
} catch (ClassNotFoundException cnfe) {
error("Loading extension %s, extension activator missing: %s (ignored)", blocker, e.getKey());
}
}
}
}
} catch (Exception e) {
error("failed to install extension %s due to %s", blocker, e);
}
}
}
Aggregations