Search in sources :

Example 1 with MavenRemoteRepository

use of aQute.bnd.maven.support.MavenRemoteRepository 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 2 with MavenRemoteRepository

use of aQute.bnd.maven.support.MavenRemoteRepository in project bnd by bndtools.

the class MavenTest method testMavenRepo1.

/**
	 * Test the maven remote repository
	 */
public static void testMavenRepo1() throws Exception {
    Maven maven = new Maven(null);
    MavenRemoteRepository mr = new MavenRemoteRepository();
    mr.setMaven(maven);
    MavenEntry me = maven.getEntry("org.apache.commons", "com.springsource.org.apache.commons.beanutils", "1.6.1");
    me.remove();
    me = maven.getEntry("org.apache.commons", "com.springsource.org.apache.commons.collections", "2.1.1");
    me.remove();
    me = maven.getEntry("org.apache.commons", "com.springsource.org.apache.commons.logging", "1.0.4");
    me.remove();
    mr.setRepositories(new URI[] { IO.getFile(new File("").getAbsoluteFile(), "testresources/ws/maven1/m2").toURI() });
    Map<String, String> map = new HashMap<String, String>();
    map.put("scope", "compile");
    File file = mr.get("org.apache.commons+com.springsource.org.apache.commons.beanutils", "1.6.1", Strategy.LOWEST, map);
    assertNotNull(file);
    assertTrue(file.isFile());
    assertEquals("org.apache.commons+com.springsource.org.apache.commons.beanutils;version=\"1.6.1\"\n" + "org.apache.commons+com.springsource.org.apache.commons.collections;version=\"2.1.1\"\n" + "org.apache.commons+com.springsource.org.apache.commons.logging;version=\"1.0.4\"\n", IO.collect(file));
    file = mr.get("org.apache.commons+com.springsource.org.apache.commons.beanutils", "1.6.1", Strategy.LOWEST, null);
    assertEquals("com.springsource.org.apache.commons.beanutils-1.6.1.jar", file.getName());
}
Also used : Maven(aQute.bnd.maven.support.Maven) HashMap(java.util.HashMap) MavenRemoteRepository(aQute.bnd.maven.support.MavenRemoteRepository) MavenEntry(aQute.bnd.maven.support.MavenEntry) File(java.io.File)

Aggregations

Maven (aQute.bnd.maven.support.Maven)2 MavenEntry (aQute.bnd.maven.support.MavenEntry)2 MavenRemoteRepository (aQute.bnd.maven.support.MavenRemoteRepository)2 File (java.io.File)2 Workspace (aQute.bnd.build.Workspace)1 Processor (aQute.bnd.osgi.Processor)1 HashMap (java.util.HashMap)1