Search in sources :

Example 26 with Processor

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();
}
Also used : Processor(aQute.bnd.osgi.Processor)

Example 27 with Processor

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());
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) File(java.io.File)

Example 28 with Processor

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());
}
Also used : Processor(aQute.bnd.osgi.Processor) Parameters(aQute.bnd.header.Parameters)

Example 29 with Processor

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);
        }
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) PutOptions(aQute.bnd.service.RepositoryPlugin.PutOptions) IOException(java.io.IOException)

Example 30 with Processor

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);
    }
}
Also used : Processor(aQute.bnd.osgi.Processor)

Aggregations

Processor (aQute.bnd.osgi.Processor)185 HashMap (java.util.HashMap)43 File (java.io.File)37 Macro (aQute.bnd.osgi.Macro)29 Workspace (aQute.bnd.build.Workspace)27 Jar (aQute.bnd.osgi.Jar)17 HttpClient (aQute.bnd.http.HttpClient)14 Baseline (aQute.bnd.differ.Baseline)12 DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)12 BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)10 IOException (java.io.IOException)10 Resource (org.osgi.resource.Resource)10 Info (aQute.bnd.differ.Baseline.Info)8 Version (aQute.bnd.version.Version)8 ArrayList (java.util.ArrayList)8 List (java.util.List)7 ProgressPlugin (aQute.bnd.service.progress.ProgressPlugin)6 Collection (java.util.Collection)6 Properties (java.util.Properties)6 Parameters (aQute.bnd.header.Parameters)5