Search in sources :

Example 1 with ModuleDescriptorWrapper

use of org.apache.ivy.osgi.repo.ModuleDescriptorWrapper in project ant-ivy by apache.

the class OBRParserTest method testParseSource.

@Test
public void testParseSource() throws Exception {
    BundleRepoDescriptor repo = OBRXMLParser.parse(testObr.toURI(), new FileInputStream(new File(testObr, "sources.xml")));
    assertNotNull(repo);
    assertEquals(2, CollectionUtils.toList(repo.getModules()).size());
    Iterator<ModuleDescriptorWrapper> itModule = repo.getModules();
    while (itModule.hasNext()) {
        ModuleDescriptor md = itModule.next().getModuleDescriptor();
        if (md.getModuleRevisionId().getName().equals("org.apache.felix.eventadmin")) {
            assertEquals(1, md.getAllArtifacts().length);
        } else {
            assertEquals("org.apache.felix.bundlerepository", md.getModuleRevisionId().getName());
            assertEquals(2, md.getAllArtifacts().length);
            String type0 = md.getAllArtifacts()[0].getType();
            String url0 = md.getAllArtifacts()[0].getUrl().toExternalForm();
            String type1 = md.getAllArtifacts()[1].getType();
            String url1 = md.getAllArtifacts()[1].getUrl().toExternalForm();
            assertTrue("Default Maven URL must end with '/'", DEFAULT_M2_ROOT.endsWith("/"));
            String jarUrl = DEFAULT_M2_ROOT + "org/apache/felix/org.apache.felix." + "bundlerepository/1.0.3/org.apache.felix.bundlerepository-1.0.3.jar";
            String srcUrl = "http://oscar-osgi.sf.net/obr2/org.apache.felix." + "bundlerepository/org.apache.felix.bundlerepository-1.0.3-src.jar";
            if (type0.equals("jar")) {
                assertEquals(jarUrl, url0);
                assertEquals("source", type1);
                assertEquals(srcUrl, url1);
            } else {
                assertEquals("jar", type1);
                assertEquals(jarUrl, url1);
                assertEquals("source", type0);
                assertEquals(srcUrl, url0);
            }
        }
    }
    assertEquals("Felix-Releases", repo.getName());
    assertEquals("20120203022437.168", repo.getLastModified());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) BundleRepoDescriptor(org.apache.ivy.osgi.repo.BundleRepoDescriptor) ModuleDescriptorWrapper(org.apache.ivy.osgi.repo.ModuleDescriptorWrapper) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 2 with ModuleDescriptorWrapper

use of org.apache.ivy.osgi.repo.ModuleDescriptorWrapper in project ant-ivy by apache.

the class OBRXMLWriterTest method testWriteWithSource.

@Test
public void testWriteWithSource() throws Exception {
    List<BundleInfo> bundles = new ArrayList<>();
    BundleInfo bundle = new BundleInfo(BUNDLE_1, BUNDLE_VERSION);
    bundle.addArtifact(new BundleArtifact(false, new URI("file:///test.jar"), null));
    bundle.addArtifact(new BundleArtifact(true, new URI("file:///test-sources.jar"), null));
    bundles.add(bundle);
    bundle = new BundleInfo(BUNDLE_2, BUNDLE_VERSION);
    bundle.addArtifact(new BundleArtifact(false, new URI("file:///test2.jar"), null));
    bundles.add(bundle);
    new File("build/test-files").mkdirs();
    File obrFile = new File("build/test-files/obr-sources.xml");
    try (FileOutputStream out = new FileOutputStream(obrFile)) {
        ContentHandler handler = OBRXMLWriter.newHandler(out, "UTF-8", true);
        OBRXMLWriter.writeBundles(bundles, handler);
    }
    BundleRepoDescriptor repo;
    try (FileInputStream in = new FileInputStream(obrFile)) {
        repo = OBRXMLParser.parse(new URI("file:///test"), in);
    }
    assertEquals(2, CollectionUtils.toList(repo.getModules()).size());
    ModuleDescriptorWrapper bundle1 = repo.findModule(BUNDLE_1, BUNDLE_VERSION);
    assertNotNull(bundle1);
    Artifact[] artifacts = bundle1.getModuleDescriptor().getAllArtifacts();
    assertEquals(2, artifacts.length);
    if (artifacts[0].getType().equals("jar")) {
        assertEquals("source", artifacts[1].getType());
    } else {
        assertEquals("jar", artifacts[1].getType());
        assertEquals("source", artifacts[0].getType());
    }
    ModuleDescriptorWrapper bundle2 = repo.findModule(BUNDLE_2, BUNDLE_VERSION);
    assertNotNull(bundle2);
    assertEquals(1, bundle2.getModuleDescriptor().getAllArtifacts().length);
}
Also used : ModuleDescriptorWrapper(org.apache.ivy.osgi.repo.ModuleDescriptorWrapper) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) ArrayList(java.util.ArrayList) URI(java.net.URI) ContentHandler(org.xml.sax.ContentHandler) FileInputStream(java.io.FileInputStream) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) BundleRepoDescriptor(org.apache.ivy.osgi.repo.BundleRepoDescriptor) BundleInfo(org.apache.ivy.osgi.core.BundleInfo) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Test(org.junit.Test)

Example 3 with ModuleDescriptorWrapper

use of org.apache.ivy.osgi.repo.ModuleDescriptorWrapper in project ant-ivy by apache.

the class UpdateSiteLoaderTest method testIvyDE.

@Test
public void testIvyDE() throws IOException, ParseException, SAXException, URISyntaxException {
    RepoDescriptor site = loader.load(new URI("http://www.apache.org/dist/ant/ivyde/updatesite/"));
    assertTrue(site.getModules().hasNext());
    Iterator<ModuleDescriptorWrapper> it = site.getModules();
    while (it.hasNext()) {
        String name = it.next().getModuleDescriptor().getModuleRevisionId().getName();
        assertTrue(name, name.startsWith("org.apache.ivy"));
    }
}
Also used : RepoDescriptor(org.apache.ivy.osgi.repo.RepoDescriptor) ModuleDescriptorWrapper(org.apache.ivy.osgi.repo.ModuleDescriptorWrapper) URI(java.net.URI) Test(org.junit.Test)

Example 4 with ModuleDescriptorWrapper

use of org.apache.ivy.osgi.repo.ModuleDescriptorWrapper in project ant-ivy by apache.

the class P2Descriptor method finish.

public void finish() {
    sourceBundles = null;
    Set<String> bundleIds = getCapabilityValues(BundleInfo.BUNDLE_TYPE);
    if (bundleIds == null) {
        return;
    }
    for (String bundleId : bundleIds) {
        for (ModuleDescriptorWrapper mdw : findModules(BundleInfo.BUNDLE_TYPE, bundleId)) {
            String symbolicName = mdw.getBundleInfo().getSymbolicName();
            Map<Version, BundleInfo> byVersion = sourceTargetBundles.get(symbolicName);
            if (byVersion == null) {
                continue;
            }
            BundleInfo source = byVersion.get(mdw.getBundleInfo().getVersion());
            if (source == null) {
                continue;
            }
            for (BundleArtifact artifact : source.getArtifacts()) {
                mdw.getBundleInfo().addArtifact(artifact);
            }
        }
    }
    sourceTargetBundles = null;
}
Also used : BundleInfo(org.apache.ivy.osgi.core.BundleInfo) ModuleDescriptorWrapper(org.apache.ivy.osgi.repo.ModuleDescriptorWrapper) Version(org.apache.ivy.osgi.util.Version) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact)

Example 5 with ModuleDescriptorWrapper

use of org.apache.ivy.osgi.repo.ModuleDescriptorWrapper in project ant-ivy by apache.

the class P2Descriptor method addArtifactUrl.

public void addArtifactUrl(String classifier, String id, Version version, URI uri, String format) {
    if (!classifier.equals("osgi.bundle")) {
        // we only support OSGi bundle, no Eclipse feature or anything else
        return;
    }
    ModuleDescriptorWrapper module = findModule(id, version);
    if (module != null) {
        addArtifact(module.getBundleInfo(), new BundleArtifact(false, uri, format));
        return;
    }
    // not found in the regular bundle. Let's look up in the source ones
    Map<Version, BundleInfo> byVersion = sourceBundles.get(id);
    if (byVersion == null) {
        return;
    }
    BundleInfo source = byVersion.get(version);
    if (source == null) {
        return;
    }
    addArtifact(source, new BundleArtifact(true, uri, format));
}
Also used : BundleInfo(org.apache.ivy.osgi.core.BundleInfo) ModuleDescriptorWrapper(org.apache.ivy.osgi.repo.ModuleDescriptorWrapper) Version(org.apache.ivy.osgi.util.Version) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact)

Aggregations

ModuleDescriptorWrapper (org.apache.ivy.osgi.repo.ModuleDescriptorWrapper)5 BundleArtifact (org.apache.ivy.osgi.core.BundleArtifact)3 BundleInfo (org.apache.ivy.osgi.core.BundleInfo)3 Test (org.junit.Test)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 URI (java.net.URI)2 BundleRepoDescriptor (org.apache.ivy.osgi.repo.BundleRepoDescriptor)2 Version (org.apache.ivy.osgi.util.Version)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Artifact (org.apache.ivy.core.module.descriptor.Artifact)1 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)1 RepoDescriptor (org.apache.ivy.osgi.repo.RepoDescriptor)1 ContentHandler (org.xml.sax.ContentHandler)1