use of aQute.bnd.osgi.Processor in project bnd by bndtools.
the class ProcessorTest method testFixupMessages.
public void testFixupMessages() throws IOException {
Processor p = new Processor();
p.setTrace(true);
p.error("abc");
assertFalse(p.isOk());
p.error("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc;restrict:=warning");
assertEquals(1, p.getErrors().size());
assertEquals(0, p.getWarnings().size());
p.error("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc");
assertEquals(0, p.getErrors().size());
assertEquals(0, p.getWarnings().size());
p.error("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc;is:=error");
assertEquals(1, p.getErrors().size());
assertEquals(0, p.getWarnings().size());
p.clear();
p.error("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc;is:=warning");
assertEquals(0, p.getErrors().size());
assertEquals(1, p.getWarnings().size());
p.clear();
p.error("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc;replace:=def");
assertEquals("def", p.getErrors().get(0));
assertEquals(0, p.getWarnings().size());
p.clear();
p.setProperty(Constants.FIXUPMESSAGES, "'abc def\\s*ghi';is:=warning");
p.error("abc def \t\t ghi");
assertEquals(0, p.getErrors().size());
assertEquals(1, p.getWarnings().size());
p.error("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc;replace:=def;is:=warning");
assertEquals("def", p.getWarnings().get(0));
assertEquals(0, p.getErrors().size());
p.clear();
p.warning("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc;restrict:=error");
assertEquals(0, p.getErrors().size());
assertEquals(1, p.getWarnings().size());
p.clear();
p.warning("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc");
assertEquals(0, p.getErrors().size());
assertEquals(0, p.getWarnings().size());
p.clear();
p.warning("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc;is:=warning");
assertEquals(0, p.getErrors().size());
assertEquals(1, p.getWarnings().size());
p.clear();
p.warning("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc;is:=error");
assertEquals(1, p.getErrors().size());
assertEquals(0, p.getWarnings().size());
p.clear();
p.warning("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc;replace:=def");
assertEquals("def", p.getWarnings().get(0));
assertEquals(0, p.getErrors().size());
p.clear();
p.warning("abc");
p.setProperty(Constants.FIXUPMESSAGES, "abc;replace:=def;is:=error");
assertEquals("def", p.getErrors().get(0));
assertEquals(0, p.getWarnings().size());
p.close();
}
use of aQute.bnd.osgi.Processor in project bnd by bndtools.
the class ProcessorTest method testFileUriMacro.
public void testFileUriMacro() throws Exception {
try (Processor p = new Processor()) {
String baseURI = p.getBaseURI().toString();
File some = new File("generated");
p.setProperty("uri1", "${fileuri;dist/bundles}");
p.setProperty("uri2", "${fileuri;" + some.getCanonicalPath() + "/dist/bundles}");
p.setProperty("uri3", "${fileuri;.}");
String uri1 = p.getProperty("uri1");
String uri2 = p.getProperty("uri2");
String uri3 = p.getProperty("uri3");
assertEquals(baseURI + "dist/bundles", uri1);
assertEquals(some.toURI() + "dist/bundles", uri2);
assertEquals(baseURI, uri3);
assertTrue(p.check());
}
}
use of aQute.bnd.osgi.Processor in project bnd by bndtools.
the class ParseHeaderTest method assertNames.
static void assertNames(String header, String[] keys, String expectedError, String expectedWarning) {
Processor p = new Processor();
p.setPedantic(true);
Parameters map = Processor.parseHeader(header, p);
for (String key : keys) assertTrue(map.containsKey(key));
assertEquals(keys.length, map.size());
if (expectedError != null) {
System.err.println(p.getErrors());
assertTrue(p.getErrors().size() > 0);
assertTrue(p.getErrors().get(0).indexOf(expectedError) >= 0);
} else
assertEquals(0, p.getErrors().size());
if (expectedWarning != null) {
System.err.println(p.getWarnings());
assertTrue(p.getWarnings().size() > 0);
String w = p.getWarnings().get(0);
assertTrue(w.contains(expectedWarning));
} else
assertEquals(0, p.getWarnings().size());
}
use of aQute.bnd.osgi.Processor in project bnd by bndtools.
the class Project method install.
private void install(File f, RepositoryPlugin repo, Attrs value) throws Exception {
try (Processor p = new Processor()) {
p.getProperties().putAll(value);
PutOptions options = new PutOptions();
options.context = p;
try (InputStream in = IO.stream(f)) {
repo.put(in, options);
} catch (Exception e) {
exception(e, "Cannot install %s into %s because %s", f, repo.getName(), e);
}
}
}
use of aQute.bnd.osgi.Processor in project bnd by bndtools.
the class Project method getOutputFile.
/**
* Calculate the file for a JAR. The default name is bsn.jar, but this can
* be overridden with an
*
* @throws Exception
*/
public File getOutputFile(String bsn, String version) throws Exception {
if (version == null)
version = "0";
try (Processor scoped = new Processor(this)) {
scoped.setProperty("@bsn", bsn);
scoped.setProperty("@version", version);
String path = scoped.getProperty(OUTPUTMASK, bsn + ".jar");
return IO.getFile(getTarget(), path);
}
}
Aggregations