Search in sources :

Example 51 with Processor

use of aQute.bnd.osgi.Processor in project bnd by bndtools.

the class HttpClientTest method testMultipleProgressPlugins.

public void testMultipleProgressPlugins() throws Exception {
    final long deadline = System.currentTimeMillis() + 1000L;
    try (HttpClient hc = new HttpClient()) {
        Processor p = new Processor();
        final int[] counts = new int[2];
        counts[0] = counts[1] = 0;
        p.addBasicPlugin(new ProgressPlugin() {

            @Override
            public Task startTask(String name, int size) {
                return new Task() {

                    @Override
                    public void worked(int units) {
                        counts[0]++;
                    }

                    @Override
                    public void done(String message, Throwable e) {
                        counts[0]++;
                    }

                    @Override
                    public boolean isCanceled() {
                        return false;
                    }
                };
            }
        });
        p.addBasicPlugin(new ProgressPlugin() {

            @Override
            public Task startTask(String name, int size) {
                return new Task() {

                    @Override
                    public void worked(int units) {
                        counts[1]++;
                    }

                    @Override
                    public void done(String message, Throwable e) {
                        counts[1]++;
                    }

                    @Override
                    public boolean isCanceled() {
                        return false;
                    }
                };
            }
        });
        hc.setRegistry(p);
        String text = hc.build().get(String.class).go(httpServer.getBaseURI("get"));
        assertNotNull(text);
        assertTrue(counts[0] > 0);
        assertEquals(counts[0], counts[1]);
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) ProgressPlugin(aQute.bnd.service.progress.ProgressPlugin) HttpClient(aQute.bnd.http.HttpClient)

Example 52 with Processor

use of aQute.bnd.osgi.Processor in project bnd by bndtools.

the class MavenTest method testMavenRepo.

/**
	 * See if we can create a maven repostory as a plugin
	 * 
	 * @throws Exception
	 */
public static void testMavenRepo() throws Exception {
    Workspace ws = Workspace.getWorkspace(cwd.getParentFile());
    Maven maven = ws.getMaven();
    Processor processor = new Processor(ws);
    processor.setProperty(Constants.PLUGIN, "aQute.bnd.maven.support.MavenRemoteRepository;repositories=testresources/ws/maven1/m2");
    MavenRemoteRepository mr = processor.getPlugin(MavenRemoteRepository.class);
    assertNotNull(mr);
    assertEquals(maven, mr.getMaven());
    // Cleanup the maven cache so we do not get random results
    MavenEntry me = maven.getEntry("org.apache.commons", "com.springsource.org.apache.commons.beanutils", "1.6.1");
    assertNotNull(me);
    me.remove();
    Map<String, String> map = MAP.$("groupId", "org.apache.commons");
    File file = mr.get("com.springsource.org.apache.commons.beanutils", "1.6.1", Strategy.LOWEST, map);
    assertNotNull(file);
    assertEquals("com.springsource.org.apache.commons.beanutils-1.6.1.jar", file.getName());
    assertTrue(file.isFile());
    Map<String, String> map2 = MAP.$("groupId", "org.apache.commons").$("scope", "compile");
    file = mr.get("com.springsource.org.apache.commons.beanutils", "1.6.1", Strategy.LOWEST, map2);
    assertNotNull(file);
    assertTrue(file.isFile());
    assertEquals("compile.lib", file.getName());
    String lib = IO.collect(file);
    System.err.println(lib);
    lib = lib.replaceAll("org.apache.commons\\+com.springsource.org.apache.commons.beanutils;version=\"1.6.1\"", "1");
    lib = lib.replaceAll("org.apache.commons\\+com.springsource.org.apache.commons.collections;version=\"2.1.1\"", "2");
    lib = lib.replaceAll("org.apache.commons\\+com.springsource.org.apache.commons.logging;version=\"1.0.4\"", "3");
    assertEquals("1\n2\n3\n", lib);
}
Also used : Maven(aQute.bnd.maven.support.Maven) Processor(aQute.bnd.osgi.Processor) MavenRemoteRepository(aQute.bnd.maven.support.MavenRemoteRepository) MavenEntry(aQute.bnd.maven.support.MavenEntry) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Example 53 with Processor

use of aQute.bnd.osgi.Processor in project bnd by bndtools.

the class MacroTest method testNames.

public static void testNames() {
    Processor p = new Processor();
    p.setProperty("a", "a");
    p.setProperty("aa", "aa");
    Macro macro = new Macro(p);
    assertEquals("aa", macro.process("${${a}${a}}"));
}
Also used : Processor(aQute.bnd.osgi.Processor) Macro(aQute.bnd.osgi.Macro)

Example 54 with Processor

use of aQute.bnd.osgi.Processor in project bnd by bndtools.

the class MacroTest method testMacroStrings.

/**
	 * String functions
	 */
public void testMacroStrings() throws Exception {
    Processor processor = new Processor();
    processor.setProperty("empty", "");
    assertEquals("6", processor.getReplacer().process("${length;abcdef}"));
    assertEquals("true", processor.getReplacer().process("${is;1.3;1.3;1.3}"));
    assertEquals("false", processor.getReplacer().process("${is;abc;1.3}"));
    assertEquals("true", processor.getReplacer().process("${isnumber;1.3}"));
    assertEquals("false", processor.getReplacer().process("${isnumber;abc}"));
    assertEquals("true", processor.getReplacer().process("${isempty;${empty}}"));
    assertEquals("true", processor.getReplacer().process("${isempty;${empty};${empty};${empty};${empty};}"));
    assertEquals("false", processor.getReplacer().process("${isempty;abc}"));
    assertEquals("\n000010", processor.getReplacer().process("${format;\n%06d;10}"));
    assertEquals("000010", processor.getReplacer().process("${format;%1$06d;10}"));
    assertEquals("2e C8 300 620", processor.getReplacer().process("${format;%x %X %d %o;46;200;300;400;500}"));
    assertEquals("+00010", processor.getReplacer().process("${format;%+06d;10}"));
    assertEquals(String.format("%,6d", 100000), processor.getReplacer().process("${format;%,6d;100000}"));
    assertEquals("xyz", processor.getReplacer().process("${trim; \txyz\t  }"));
    assertEquals("DEFbDEFcdDEFef", processor.getReplacer().process("${subst;abacdaef;a;DEF}"));
    assertEquals("DEFbacdaef", processor.getReplacer().process("${subst;abacdaef;a;DEF;1}"));
    assertEquals("DEFbDEFcdaef", processor.getReplacer().process("${subst;abacdaef;a;DEF;2}"));
    assertEquals("DEFbDEFcdDEFef", processor.getReplacer().process("${subst;abacdaef;a;DEF;3}"));
    assertEquals("DEFbDEFcdDEFef", processor.getReplacer().process("${subst;abacdaef;a;DEF;300}"));
    assertEquals("true", processor.getReplacer().process("${matches;aaaabcdef;[a]+bcdef}"));
    assertEquals("false", processor.getReplacer().process("${matches;bcdef;[a]+bcdef}"));
    assertEquals("-1", processor.getReplacer().process("${ncompare;2;200}"));
    assertEquals("1", processor.getReplacer().process("${ncompare;200;1}"));
    assertEquals("0", processor.getReplacer().process("${ncompare;200;200}"));
    assertEquals("-1", processor.getReplacer().process("${compare;abc;def}"));
    assertEquals("1", processor.getReplacer().process("${compare;def;abc}"));
    assertEquals("0", processor.getReplacer().process("${compare;abc;abc}"));
    assertEquals("ABCDEF", processor.getReplacer().process("${toupper;abcdef}"));
    assertEquals("abcdef", processor.getReplacer().process("${tolower;ABCDEF}"));
    assertEquals("ab,efab,ef", processor.getReplacer().process("${split;cd;abcdefabcdef}"));
    assertEquals("ab,d,fab,d,f", processor.getReplacer().process("${split;[ce];abcdefabcdef}"));
    assertEquals("3", processor.getReplacer().process("${find;abcdef;def}"));
    assertEquals("-1", processor.getReplacer().process("${find;abc;defxyz}"));
    assertEquals("9", processor.getReplacer().process("${findlast;def;abcdefabcdef}"));
    assertEquals("abcdef", processor.getReplacer().process("${startswith;abcdef;abc}"));
    assertEquals("", processor.getReplacer().process("${startswith;abcdef;xyz}"));
    assertEquals("abcdef", processor.getReplacer().process("${endswith;abcdef;def}"));
    assertEquals("", processor.getReplacer().process("${endswith;abcdef;xyz}"));
    assertEquals("abcdef", processor.getReplacer().process("${endswith;abcdef;def}"));
    assertEquals("", processor.getReplacer().process("${endswith;abcdef;xyz}"));
    assertEquals("def", processor.getReplacer().process("${extension;abcdef.def}"));
    assertEquals("", processor.getReplacer().process("${extension;abcdefxyz}"));
    assertEquals("abc", processor.getReplacer().process("${substring;abcdef;0;3}"));
    assertEquals("abc", processor.getReplacer().process("${substring;abcdef;;3}"));
    assertEquals("def", processor.getReplacer().process("${substring;abcdef;-3}"));
    assertEquals("de", processor.getReplacer().process("${substring;abcdef;-3;-1}"));
    assertEquals("def", processor.getReplacer().process("${substring;abcdef;3}"));
    assertEquals("6", processor.getReplacer().process("${length;abcdef}"));
    assertEquals("0", processor.getReplacer().process("${length;}"));
}
Also used : Processor(aQute.bnd.osgi.Processor)

Example 55 with Processor

use of aQute.bnd.osgi.Processor in project bnd by bndtools.

the class MacroTest method testSystem.

/**
	 * Verify system command
	 */
public static void testSystem() throws Exception {
    // disable this test on windows
    if (!"/".equals(File.separator))
        return;
    Processor p = new Processor();
    Macro macro = new Macro(p);
    assertEquals("Hello World", macro.process("${system;echo Hello World}"));
    assertTrue(macro.process("${system;wc;Hello World}").matches("\\s*[0-9]+\\s+[0-9]+\\s+[0-9]+\\s*"));
}
Also used : Processor(aQute.bnd.osgi.Processor) Macro(aQute.bnd.osgi.Macro)

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