use of aQute.bnd.osgi.Resource in project bnd by bndtools.
the class Make method process.
public Resource process(String source) {
Map<Instruction, Map<String, String>> make = getMakeHeader();
logger.debug("make {}", source);
for (Map.Entry<Instruction, Map<String, String>> entry : make.entrySet()) {
Instruction instr = entry.getKey();
Matcher m = instr.getMatcher(source);
if (m.matches() || instr.isNegated()) {
Map<String, String> arguments = replace(m, entry.getValue());
List<MakePlugin> plugins = builder.getPlugins(MakePlugin.class);
for (MakePlugin plugin : plugins) {
try {
Resource resource = plugin.make(builder, source, arguments);
if (resource != null) {
logger.debug("Made {} from args {} with {}", source, arguments, plugin);
return resource;
}
} catch (Exception e) {
builder.exception(e, "Plugin %s generates error when use in making %s with args %s", plugin, source, arguments);
}
}
}
}
return null;
}
use of aQute.bnd.osgi.Resource 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);
}
}
use of aQute.bnd.osgi.Resource in project bnd by bndtools.
the class PatchCommand method _create.
public void _create(createOptions opts) throws Exception {
List<String> arguments = opts._arguments();
Jar a = new Jar(bnd.getFile(arguments.remove(0)));
Manifest am = a.getManifest();
Jar b = new Jar(bnd.getFile(arguments.remove(0)));
Manifest bm = b.getManifest();
File patch = bnd.getFile(arguments.remove(0));
// TODO check arguments
Set<String> delete = Create.set();
for (String path : a.getResources().keySet()) {
Resource br = b.getResource(path);
if (br == null) {
logger.debug("DELETE {}", path);
delete.add(path);
} else {
Resource ar = a.getResource(path);
if (isEqual(ar, br)) {
logger.debug("UNCHANGED {}", path);
b.remove(path);
} else
logger.debug("UPDATE {}", path);
}
}
bm.getMainAttributes().putValue("Patch-Delete", Processor.join(delete, ", "));
bm.getMainAttributes().putValue("Patch-Version", am.getMainAttributes().getValue(Constants.BUNDLE_VERSION));
b.write(patch);
a.close();
b.close();
// TODO proper close
}
use of aQute.bnd.osgi.Resource in project bnd by bndtools.
the class MergeTest method testMerge.
static void testMerge(String type, String[] in, String[] out, String c, int errors, int warnings) throws Exception {
Builder b = new Builder();
try {
b.setClasspath(new File[] { IO.getFile("src/test/split/split-a.jar"), IO.getFile("src/test/split/split-b.jar") });
Properties p = new Properties();
if (type != null)
p.put("Export-Package", "test.split;-split-package:=" + type);
else
p.put("Export-Package", "test.split");
p.put("Import-Package", "");
b.setProperties(p);
Jar jar = b.build();
System.err.println("Errors :" + b.getErrors());
System.err.println("Warnings :" + b.getWarnings());
assertEquals(errors, b.getErrors().size());
assertEquals(warnings, b.getWarnings().size());
if (errors != 0)
return;
for (int i = 0; in != null && i < in.length; i++) assertNotNull("Contains " + in[i], jar.getResource("test/split/" + in[i]));
for (int i = 0; out != null && i < out.length; i++) assertNull("Does not contain " + out[i], jar.getResource("test/split/" + out[i]));
Resource r = jar.getResource("test/split/C");
InputStream is = r.openInputStream();
BufferedReader dis = new BufferedReader(new InputStreamReader(is));
String s = dis.readLine();
assertEquals(s, c);
} finally {
b.close();
}
}
use of aQute.bnd.osgi.Resource in project bnd by bndtools.
the class PreprocessTest method testPreProcessExcludeExtensionGlobal.
/**
* Check if we can override
*
* @throws Exception
*/
public static void testPreProcessExcludeExtensionGlobal() throws Exception {
Builder b = new Builder();
b.setProperty(Analyzer.PREPROCESSMATCHERS, "!*.TXT:i,*");
b.setProperty(Analyzer.INCLUDE_RESOURCE, "{src/test/builder-preprocess.txt},{src/test/builder-preprocess.txt2}");
b.setProperty("var", "Yes!");
;
b.build();
assertTrue(b.check());
System.out.println("testPreProcessExcludeExtensionsGlobal");
Jar jar = b.getJar();
Resource resource = jar.getResource("builder-preprocess.txt");
String s = IO.collect(resource.openInputStream());
System.out.println(s);
assertTrue(s.contains("${var}"));
assertFalse(s.contains("!Yes"));
resource = jar.getResource("builder-preprocess.txt2");
s = IO.collect(resource.openInputStream());
System.out.println(s);
assertTrue(s.contains("Yes!"));
assertFalse(s.contains("${var}"));
b.close();
}
Aggregations