use of aQute.bnd.osgi.Processor in project bnd by bndtools.
the class BndrunResolveContext method loadRepositories.
/**
* Load all the OSGi repositories from our registry
* <p>
* TODO Use Instruction ...
*
* @return
* @throws Exception
*/
private Processor loadRepositories() throws Exception {
//
// Get all of the repositories from the plugin registry
//
List<Repository> allRepos = registry.getPlugins(Repository.class);
Collection<Repository> orderedRepositories;
String rn = properties.mergeProperties(Constants.RUNREPOS);
if (rn == null) {
//
// No filter set, so we use all
//
orderedRepositories = allRepos;
} else {
Parameters repoNames = new Parameters(rn, project);
// Map the repository names...
Map<String, Repository> repoNameMap = new HashMap<String, Repository>(allRepos.size());
for (Repository repo : allRepos) {
String name;
if (repo instanceof aQute.bnd.deployer.repository.wrapper.Plugin) {
@SuppressWarnings("resource") aQute.bnd.deployer.repository.wrapper.Plugin wrapper = (aQute.bnd.deployer.repository.wrapper.Plugin) repo;
wrapper.init();
name = wrapper.toString();
} else if (repo instanceof RepositoryPlugin) {
name = ((RepositoryPlugin) repo).getName();
} else {
name = repo.toString();
}
repoNameMap.put(name, repo);
}
// Create the result list
orderedRepositories = new ArrayList<>();
for (String repoName : repoNames.keySet()) {
Repository repo = repoNameMap.get(repoName);
if (repo != null)
orderedRepositories.add(repo);
}
}
Processor repositoryAugments = findRepositoryAugments(orderedRepositories);
Parameters augments = new Parameters(repositoryAugments.mergeProperties(Constants.AUGMENT), project);
augments.putAll(new Parameters(properties.mergeProperties(Constants.AUGMENT), project));
if (!augments.isEmpty()) {
AggregateRepository aggregate = new AggregateRepository(orderedRepositories);
AugmentRepository augment = new AugmentRepository(augments, aggregate);
orderedRepositories = Collections.singleton((Repository) augment);
}
for (Repository repository : orderedRepositories) {
super.addRepository(repository);
}
return repositoryAugments;
}
use of aQute.bnd.osgi.Processor in project bnd by bndtools.
the class BndrunResolveContext method findRepositoryAugments.
private Processor findRepositoryAugments(Collection<Repository> orderedRepositories) {
Processor main = new Processor();
RequirementBuilder rb = new RequirementBuilder(BND_AUGMENT);
rb.filter("(path=*)");
Requirement req = rb.buildSyntheticRequirement();
for (Repository r : orderedRepositories) {
Map<Requirement, Collection<Capability>> found = r.findProviders(Collections.singleton(req));
Collection<Capability> capabilities = found.get(req);
if (capabilities != null) {
for (Capability capability : capabilities) {
findAdditionalAugmentsFromResource(main, capability);
}
}
}
return main;
}
use of aQute.bnd.osgi.Processor in project bnd by bndtools.
the class BuilderTest method testMacroBasedExpansion.
/**
* This test checks if
*
* @throws Exception
*/
public static void testMacroBasedExpansion() throws Exception {
Processor proc = new Processor();
Builder builder = new Builder(proc);
try {
builder.setProperty("Export-Package", "${spec.packages}");
proc.setProperty("spec.packages", "${core.packages}, ${cmpn.packages}, ${mobile.packages}");
proc.setProperty("core.specs", "org.osgi.service.packageadmin, org.osgi.service.permissionadmin");
proc.setProperty("core.packages", "${replace;${core.specs};.+;$0.*}");
proc.setProperty("cmpn.specs", "org.osgi.service.event, org.osgi.service.cu");
proc.setProperty("cmpn.packages", "${replace;${cmpn.specs};.+;$0.*}");
proc.setProperty("mobile.specs", "org.osgi.service.wireadmin, org.osgi.service.log, org.osgi.service.cu");
proc.setProperty("mobile.packages", "${replace;${mobile.specs};.+;$0.*}");
builder.addClasspath(IO.getFile("jar/osgi.jar"));
Jar jar = builder.build();
// The total set is not uniqued so we're having an unused pattern
// this could be solved with ${uniq;${spec.packages}} but this is
// just
// another test
assertTrue(builder.check("Unused Export-Package instructions: \\[org.osgi.service.cu.\\*~\\]"));
Domain domain = Domain.domain(jar.getManifest());
Parameters h = domain.getExportPackage();
assertTrue(h.containsKey("org.osgi.service.cu"));
assertTrue(h.containsKey("org.osgi.service.cu.admin"));
} finally {
builder.close();
proc.close();
}
}
use of aQute.bnd.osgi.Processor in project bnd by bndtools.
the class PropertiesTest method testFilter.
public static void testFilter() {
Processor p1 = new Processor();
p1.setProperty("dan", "bandera");
p1.setProperty("susan", "sarandon");
p1.setProperty("jon", "bostrom");
Processor p2 = new Processor(p1);
p2.setForceLocal(Arrays.asList("dan"));
p2.setProperty("susan", "schwarze");
assertNull(p2.getProperty("dan"));
assertEquals("schwarze", p2.getProperty("susan"));
assertEquals("bostrom", p2.getProperty("jon"));
}
use of aQute.bnd.osgi.Processor in project bnd by bndtools.
the class MavenBndRepository method put.
@Override
public PutResult put(InputStream stream, PutOptions options) throws Exception {
init();
File binaryFile = File.createTempFile("put", ".jar");
File pomFile = File.createTempFile("pom", ".xml");
LocalPutResult result = new LocalPutResult();
try {
if (options == null)
options = new PutOptions();
else {
result.options = options;
}
IO.copy(stream, binaryFile);
if (options.digest != null) {
byte[] digest = SHA1.digest(binaryFile).digest();
if (!Arrays.equals(options.digest, digest))
throw new IllegalArgumentException("The given sha-1 does not match the contents sha-1");
}
if (options.context == null) {
options.context = registry.getPlugin(Workspace.class);
if (options.context == null)
options.context = new Processor();
}
ReleaseDTO instructions = getReleaseDTO(options.context);
try (Jar binary = new Jar(binaryFile)) {
Resource pomResource;
if (instructions.pom.path != null) {
File f = options.context.getFile(instructions.pom.path);
if (!f.isFile())
throw new IllegalArgumentException("-maven-release specifies " + f + " as pom file but this file is not found");
pomResource = new FileResource(f);
} else {
pomResource = getPomResource(binary);
if (pomResource == null) {
pomResource = createPomResource(binary, options.context);
if (pomResource == null)
throw new IllegalArgumentException("No POM resource in META-INF/maven/... The Maven Bnd Repository requires this pom.");
}
}
IO.copy(pomResource.openInputStream(), pomFile);
IPom pom;
try (InputStream fin = IO.stream(pomFile)) {
pom = storage.getPom(fin);
}
Archive binaryArchive = pom.binaryArchive();
checkRemotePossible(instructions, binaryArchive.isSnapshot());
if (!binaryArchive.isSnapshot()) {
releasePlugin.add(options.context, pom);
if (storage.exists(binaryArchive)) {
logger.debug("Already released {} to {}", pom.getRevision(), this);
result.alreadyReleased = true;
return result;
}
}
logger.debug("Put release {}", pom.getRevision());
try (Release releaser = storage.release(pom.getRevision(), options.context.getProperties())) {
if (releaser == null) {
logger.debug("Already released {}", pom.getRevision());
return result;
}
if (instructions.snapshot >= 0)
releaser.setBuild(instructions.snapshot, null);
if (isLocal(instructions))
releaser.setLocalOnly();
releaser.add(pom.getRevision().pomArchive(), pomFile);
releaser.add(binaryArchive, binaryFile);
result.binaryArchive = binaryArchive;
result.pomArchive = pom.getRevision().pomArchive();
if (!isLocal(instructions)) {
try (Tool tool = new Tool(options.context, binary)) {
if (instructions.javadoc != null) {
if (!NONE.equals(instructions.javadoc.path)) {
try (Jar jar = getJavadoc(tool, options.context, instructions.javadoc.path, instructions.javadoc.options, instructions.javadoc.packages == JavadocPackages.EXPORT)) {
save(releaser, pom.getRevision(), jar, "javadoc");
}
}
}
if (instructions.sources != null) {
if (!NONE.equals(instructions.sources.path)) {
try (Jar jar = getSource(tool, options.context, instructions.sources.path)) {
save(releaser, pom.getRevision(), jar, "sources");
}
}
}
}
}
}
if (configuration.noupdateOnRelease() == false && !binaryArchive.isSnapshot())
index.add(binaryArchive);
}
return result;
} catch (Exception e) {
result.failed = e.getMessage();
throw e;
} finally {
IO.delete(binaryFile);
IO.delete(pomFile);
}
}
Aggregations