Search in sources :

Example 1 with PomParser

use of aQute.bnd.maven.PomParser in project bnd by bndtools.

the class MavenTest method testPomParser.

/**
	 * Test the pom parser which will turn the pom into a set of properties,
	 * which will make it actually readable according to some.
	 * 
	 * @throws Exception
	 */
@SuppressWarnings("restriction")
public static void testPomParser() throws Exception {
    PomParser parser = new PomParser();
    Properties p = parser.getProperties(IO.getFile("testresources/ws/maven1/pom.xml"));
    p.store(System.err, "testing");
    assertEquals("Apache Felix Metatype Service", p.get("pom.name"));
    // is from
    assertEquals("org.apache.felix", p.get("pom.groupId"));
    // parent
    assertEquals("org.apache.felix.metatype", p.get("pom.artifactId"));
    assertEquals("bundle", p.get("pom.packaging"));
    Parameters map = parser.parseHeader(p.getProperty("pom.scope.test"));
    Map<String, String> junit = map.get("junit.junit");
    assertNotNull(junit);
    assertEquals("4.0", junit.get("version"));
    Map<String, String> easymock = map.get("org.easymock.easymock");
    assertNotNull(easymock);
    assertEquals("2.4", easymock.get("version"));
}
Also used : PomParser(aQute.bnd.maven.PomParser) Parameters(aQute.bnd.header.Parameters) Properties(java.util.Properties)

Example 2 with PomParser

use of aQute.bnd.maven.PomParser in project bnd by bndtools.

the class Domain method domain.

public static Domain domain(File file) throws IOException {
    if (file.getName().endsWith(".mf")) {
        try (InputStream in = IO.stream(file)) {
            Manifest m = new Manifest(in);
            return domain(m);
        }
    }
    if (file.getName().endsWith(".properties") || file.getName().endsWith(".bnd")) {
        Processor p = new Processor();
        p.setProperties(file);
        return domain(p);
    }
    if (file.getName().endsWith(".pom")) {
        try {
            PomParser p = new PomParser();
            p.setProperties(p.getProperties(file));
            return domain(p);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    // default & last. Assume JAR
    try (JarInputStream jin = new JarInputStream(IO.stream(file))) {
        Manifest m = jin.getManifest();
        if (m != null)
            return domain(m);
    }
    try (ZipFile zf = new ZipFile(file)) {
        ZipEntry entry = zf.getEntry("META-INF/MANIFEST.MF");
        if (entry == null)
            return null;
        Manifest m = new Manifest(zf.getInputStream(entry));
        return domain(m);
    } catch (ZipException e) {
        return null;
    }
}
Also used : PomParser(aQute.bnd.maven.PomParser) ZipFile(java.util.zip.ZipFile) JarInputStream(java.util.jar.JarInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) Manifest(java.util.jar.Manifest) ZipException(java.util.zip.ZipException) IOException(java.io.IOException)

Aggregations

PomParser (aQute.bnd.maven.PomParser)2 Parameters (aQute.bnd.header.Parameters)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 JarInputStream (java.util.jar.JarInputStream)1 Manifest (java.util.jar.Manifest)1 ZipEntry (java.util.zip.ZipEntry)1 ZipException (java.util.zip.ZipException)1 ZipFile (java.util.zip.ZipFile)1