use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ResolveCommand method _validate.
public void _validate(ValidateOptions options) throws Exception {
ResourceBuilder system = new ResourceBuilder();
system.addEE(options.ee(EE.JavaSE_1_8));
if (options.core() != null)
system.addManifest(options.core().getManifest());
if (options.packages() != null)
system.addExportPackages(options.packages());
if (options.capabilities() != null)
system.addProvideCapabilities(options.capabilities());
if (options.system() != null) {
File f = IO.getFile(options.system());
if (!f.isFile()) {
error("Specified system file but not found: %s", f);
return;
}
Domain domain = Domain.domain(f);
system.addManifest(domain);
}
List<String> args = options._arguments();
File index = getFile(args.remove(0));
logger.debug("validating {}", index);
ResolverValidator validator = new ResolverValidator(bnd);
validator.use(bnd);
validator.addRepository(index.toURI());
validator.setSystem(system.build());
List<Resolution> result = validator.validate();
Set<Requirement> done = new HashSet<>();
for (Resolution res : result) {
if (options.all()) {
bnd.out.format("%s %-60s%n", res.succeeded ? "OK" : "**", res.resource, res.message == null ? "" : res.message);
}
if (!res.succeeded) {
for (Requirement req : res.missing) {
if (done.contains(req))
continue;
bnd.out.format(" missing %s%n", req);
done.add(req);
}
if (options.all()) {
for (Requirement req : res.repos) {
bnd.out.format(" repos %s%n", req);
}
for (Requirement req : res.system) {
bnd.out.format(" system %s%n", req);
}
for (Requirement req : res.optionals) {
bnd.out.format(" optional %s%n", req);
}
}
}
}
bnd.getInfo(validator);
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class Profiles method _create.
public void _create(CreateOptions options) throws Exception {
Builder b = new Builder();
bnd.addClose(b);
b.setBase(bnd.getBase());
if (options.properties() != null) {
for (String propertyFile : options.properties()) {
File pf = bnd.getFile(propertyFile);
b.addProperties(pf);
}
}
if (options.bsn() != null)
b.setProperty(Constants.BUNDLE_SYMBOLICNAME, options.bsn());
if (options.version() != null)
b.setProperty(Constants.BUNDLE_VERSION, options.version().toString());
Instructions match = options.match();
Parameters packages = new Parameters();
Parameters capabilities = new Parameters();
Collection<String> paths = new ArrayList<String>(new Parameters(b.getProperty("-paths"), bnd).keySet());
if (paths.isEmpty())
paths = options._arguments();
logger.debug("input {}", paths);
ResourceBuilder pb = new ResourceBuilder();
for (String root : paths) {
File f = bnd.getFile(root);
if (!f.exists()) {
error("could not find %s", f);
} else {
Glob g = options.extension();
if (g == null)
g = new Glob("*.jar");
Collection<File> files = IO.tree(f, "*.jar");
logger.debug("will profile {}", files);
for (File file : files) {
Domain domain = Domain.domain(file);
if (domain == null) {
error("Not a bundle because no manifest %s", file);
continue;
}
String bsn = domain.getBundleSymbolicName().getKey();
if (bsn == null) {
error("Not a bundle because no manifest %s", file);
continue;
}
if (match != null) {
Instruction instr = match.finder(bsn);
if (instr == null || instr.isNegated()) {
logger.debug("skipped {} because of non matching bsn {}", file, bsn);
continue;
}
}
Parameters eps = domain.getExportPackage();
Parameters pcs = domain.getProvideCapability();
logger.debug("parse {}:\ncaps: {}\npac: {}\n", file, pcs, eps);
packages.mergeWith(eps, false);
capabilities.mergeWith(pcs, false);
}
}
}
b.setProperty(Constants.PROVIDE_CAPABILITY, capabilities.toString());
b.setProperty(Constants.EXPORT_PACKAGE, packages.toString());
logger.debug("Found {} packages and {} capabilities", packages.size(), capabilities.size());
Jar jar = b.build();
File f = b.getOutputFile(options.output());
logger.debug("Saving as {}", f);
jar.write(f);
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class InfoRepositoryWrapper method init.
boolean init() {
try {
if (System.currentTimeMillis() < lastTime + 10000)
return true;
} finally {
lastTime = System.currentTimeMillis();
}
Set<String> errors = new LinkedHashSet<String>();
try {
//
// Get the current repo contents
//
Set<String> toBeDeleted = new HashSet<String>(persistent.keySet());
Map<String, DownloadBlocker> blockers = new HashMap<String, DownloadBlocker>();
for (InfoRepository repo : repos) {
Map<String, ResourceDescriptor> map = collectKeys(repo);
for (final Map.Entry<String, ResourceDescriptor> entry : map.entrySet()) {
final String id = entry.getKey();
toBeDeleted.remove(id);
if (persistent.containsKey(id))
continue;
final ResourceDescriptor rd = entry.getValue();
DownloadBlocker blocker = new DownloadBlocker(null) {
//
// We steal the thread of the downloader to index
//
@Override
public void success(File file) throws Exception {
IndexResult index = null;
try {
index = repoIndexer.indexFile(file);
ResourceBuilder rb = new ResourceBuilder();
for (org.osgi.service.indexer.Capability capability : index.capabilities) {
CapReqBuilder cb = new CapReqBuilder(capability.getNamespace());
cb.addAttributes(capability.getAttributes());
cb.addDirectives(capability.getDirectives());
rb.addCapability(cb.buildSyntheticCapability());
}
for (org.osgi.service.indexer.Requirement requirement : index.requirements) {
CapReqBuilder cb = new CapReqBuilder(requirement.getNamespace());
cb.addAttributes(requirement.getAttributes());
cb.addDirectives(requirement.getDirectives());
rb.addRequirement(cb.buildSyntheticRequirement());
}
Resource resource = rb.build();
PersistentResource pr = new PersistentResource(resource);
persistent.put(id, pr);
} finally {
super.success(file);
if (index != null) {
index.resource.close();
}
}
}
};
blockers.put(entry.getKey(), blocker);
repo.get(rd.bsn, rd.version, null, blocker);
}
}
for (Entry<String, DownloadBlocker> entry : blockers.entrySet()) {
String key = entry.getKey();
DownloadBlocker blocker = entry.getValue();
String reason = blocker.getReason();
if (reason != null) {
errors.add(key + ": " + reason);
}
}
persistent.keySet().removeAll(toBeDeleted);
} catch (Exception e) {
throw new RuntimeException(e);
}
if (!errors.isEmpty())
throw new IllegalStateException("Cannot index " + repos + " due to " + errors);
return true;
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ResolveTest method testenRouteGuard.
/**
* The enRoute base guard resolved but is missing bundles, the runbundles do
* not run
*/
public void testenRouteGuard() throws Exception {
MockRegistry registry = new MockRegistry();
Repository repo = createRepo(IO.getFile("testdata/enroute/index.xml"));
registry.addPlugin(repo);
List<Requirement> reqs = CapReqBuilder.getRequirementsFrom(new Parameters("osgi.wiring.package;filter:='(osgi.wiring.package=org.osgi.service.async)'"));
Collection<Capability> pack = repo.findProviders(reqs).get(reqs.get(0));
assertEquals(2, pack.size());
ResourceBuilder b = new ResourceBuilder();
File guard = IO.getFile("testdata/enroute/osgi.enroute.base.guard.jar");
Domain manifest = Domain.domain(guard);
b.addManifest(manifest);
Repository resourceRepository = new ResourcesRepository(b.build());
registry.addPlugin(resourceRepository);
Processor model = new Processor();
model.setRunfw("org.eclipse.osgi");
model.setRunblacklist("osgi.identity;filter:='(osgi.identity=osgi.enroute.base.api)',osgi.identity;filter:='(osgi.identity=osgi.cmpn)',osgi.identity;filter:='(osgi.identity=osgi.core)");
model.setRunRequires("osgi.identity;filter:='(osgi.identity=osgi.enroute.base.guard)'");
model.setRunee("JavaSE-1.8");
try {
BndrunResolveContext context = new BndrunResolveContext(model, null, registry, log);
Resolver resolver = new BndResolver(new ResolverLogger(4));
Map<Resource, List<Wire>> resolved = resolver.resolve(context);
Set<Resource> resources = resolved.keySet();
} catch (ResolutionException e) {
String msg = e.getMessage().replaceAll("\\[caused by:", "\n->");
System.out.println(msg);
fail(msg);
}
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ValidatorTest method testDelibarateFailWithSpecificResources.
public void testDelibarateFailWithSpecificResources() throws Exception {
try (ResolverValidator validator = new ResolverValidator()) {
ResourceBuilder system = new ResourceBuilder();
system.addEE(EE.JavaSE_1_8);
system.addManifest(OSGI_CORE.R6_0_0.getManifest());
validator.setSystem(system.build());
validator.setTrace(true);
List<Resource> resources = XMLResourceParser.getResources(IO.getFile("testdata/repo5-broken.index.xml").toURI());
List<Resolution> resolutions = validator.validate(resources);
assertFalse(validator.check());
assertEquals(1, resolutions.size());
String message = resolutions.get(0).message;
String expectedToContain = "missing requirement org.apache.felix.gogo.api";
assertTrue(String.format("expected to contain <%s> but was <%s>", expectedToContain, message), message.contains(expectedToContain));
}
}
Aggregations