Search in sources :

Example 1 with Parser

use of org.apache.karaf.util.maven.Parser in project karaf by apache.

the class KarServiceImpl method copyResourceToJar.

private void copyResourceToJar(JarOutputStream jos, URI location, Map<URI, Integer> locationMap) {
    if (locationMap.containsKey(location)) {
        return;
    }
    try {
        String noPrefixLocation = location.toString().substring(location.toString().lastIndexOf(":") + 1);
        Parser parser = new Parser(noPrefixLocation);
        String path = "repository/" + parser.getArtifactPath();
        jos.putNextEntry(new JarEntry(path));
        try (InputStream is = location.toURL().openStream()) {
            StreamUtils.copy(is, jos);
        }
        locationMap.put(location, 1);
    } catch (Exception e) {
        LOGGER.error("Error adding " + location, e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JarEntry(java.util.jar.JarEntry) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Parser(org.apache.karaf.util.maven.Parser)

Example 2 with Parser

use of org.apache.karaf.util.maven.Parser in project karaf by apache.

the class ParserTest method unparserTest.

@Test
public void unparserTest() throws MalformedURLException {
    Parser p1 = new Parser("org.apache/karaf/1/xml/features");
    assertThat(p1.toMvnURI(), equalTo("org.apache/karaf/1/xml/features"));
    Parser p2 = new Parser("org.apache/karaf/1/xml");
    assertThat(p2.toMvnURI(), equalTo("org.apache/karaf/1/xml"));
    Parser p3 = new Parser("org.apache/karaf/1/jar/uber");
    assertThat(p3.toMvnURI(), equalTo("org.apache/karaf/1/jar/uber"));
    Parser p4 = new Parser("org.apache/karaf/1//uber");
    assertThat(p4.toMvnURI(), equalTo("org.apache/karaf/1/jar/uber"));
    Parser p5 = new Parser("org.apache/karaf/1/jar");
    assertThat(p5.toMvnURI(), equalTo("org.apache/karaf/1"));
    Parser p6 = new Parser("org.apache/karaf/1");
    assertThat(p6.toMvnURI(), equalTo("org.apache/karaf/1"));
}
Also used : Parser(org.apache.karaf.util.maven.Parser) Test(org.junit.Test)

Example 3 with Parser

use of org.apache.karaf.util.maven.Parser in project karaf by apache.

the class FeaturesProcessorTest method mavenURIs.

@Test
public void mavenURIs() throws Exception {
    Parser p = new Parser("group/artifact/[1,2)/xml/features*");
    assertThat(p.getVersion(), equalTo("[1,2)"));
    assertThat(p.getClassifier(), equalTo("features*"));
    p = new Parser("org.springframework*/*cloud*/*");
    assertThat(p.getVersion(), equalTo("*"));
    assertThat(p.getArtifact(), equalTo("*cloud*"));
    assertThat(p.getGroup(), equalTo("org.springframework*"));
    assertThat(p.getType(), equalTo("jar"));
    assertThat(p.getClassifier(), nullValue());
    p = new Parser("org.ops4j/org.ops4j*/*//uber");
    assertThat(p.getVersion(), equalTo("*"));
    assertThat(p.getArtifact(), equalTo("org.ops4j*"));
    assertThat(p.getGroup(), equalTo("org.ops4j"));
    assertThat(p.getType(), equalTo("jar"));
    assertThat(p.getClassifier(), equalTo("uber"));
}
Also used : Parser(org.apache.karaf.util.maven.Parser) Test(org.junit.Test)

Aggregations

Parser (org.apache.karaf.util.maven.Parser)3 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 JarEntry (java.util.jar.JarEntry)1