Search in sources :

Example 1 with BundleArtifact

use of org.apache.ivy.osgi.core.BundleArtifact in project ant-ivy by apache.

the class PluginAdapter method featureAsBundle.

public static BundleInfo featureAsBundle(URI baseUri, EclipseFeature feature) {
    BundleInfo b = new BundleInfo(feature.getId(), feature.getVersion());
    URI uri;
    if (feature.getUrl() == null) {
        uri = baseUri.resolve("features/" + feature.getId() + '_' + feature.getVersion() + ".jar");
    } else {
        uri = baseUri.resolve(feature.getUrl());
    }
    b.addArtifact(new BundleArtifact(false, uri, null));
    b.setDescription(feature.getDescription());
    b.setLicense(feature.getLicense());
    for (EclipsePlugin plugin : feature.getPlugins()) {
        BundleRequirement r = new BundleRequirement(BundleInfo.BUNDLE_TYPE, plugin.getId(), new VersionRange(plugin.getVersion()), null);
        b.addRequirement(r);
    }
    for (Require require : feature.getRequires()) {
        String id;
        if (require.getPlugin() != null) {
            id = require.getPlugin();
        } else {
            id = require.getFeature();
        }
        VersionRange range;
        if (require.getMatch().equals("greaterOrEqual")) {
            range = new VersionRange(require.getVersion());
        } else {
            throw new IllegalStateException("unsupported match " + require.getMatch());
        }
        BundleRequirement r = new BundleRequirement(BundleInfo.BUNDLE_TYPE, id, range, null);
        b.addRequirement(r);
    }
    return b;
}
Also used : Require(org.apache.ivy.osgi.updatesite.xml.Require) BundleInfo(org.apache.ivy.osgi.core.BundleInfo) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) VersionRange(org.apache.ivy.osgi.util.VersionRange) URI(java.net.URI) EclipsePlugin(org.apache.ivy.osgi.updatesite.xml.EclipsePlugin) BundleRequirement(org.apache.ivy.osgi.core.BundleRequirement)

Example 2 with BundleArtifact

use of org.apache.ivy.osgi.core.BundleArtifact in project ant-ivy by apache.

the class PluginAdapter method pluginAsBundle.

public static BundleInfo pluginAsBundle(URI baseUri, EclipsePlugin plugin) {
    BundleInfo b = new BundleInfo(plugin.getId(), plugin.getVersion());
    URI uri = baseUri.resolve("plugins/" + plugin.getId() + '_' + plugin.getVersion() + ".jar");
    b.addArtifact(new BundleArtifact(false, uri, null));
    return b;
}
Also used : BundleInfo(org.apache.ivy.osgi.core.BundleInfo) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) URI(java.net.URI)

Example 3 with BundleArtifact

use of org.apache.ivy.osgi.core.BundleArtifact in project ant-ivy by apache.

the class P2Descriptor method addArtifact.

private void addArtifact(BundleInfo bundle, BundleArtifact artifact) {
    // find an existing artifact that might be a duplicate
    BundleArtifact same = null;
    for (BundleArtifact a : bundle.getArtifacts()) {
        if (a.isSource() == artifact.isSource()) {
            same = a;
            break;
        }
    }
    if (same != null) {
        // we have two artifacts for the same bundle, let's choose a "packed" one
        if (artifact.getFormat() == null || same.getFormat() != null) {
            // the new one cannot be better
            return;
        }
        bundle.removeArtifact(same);
    }
    bundle.addArtifact(artifact);
}
Also used : BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact)

Example 4 with BundleArtifact

use of org.apache.ivy.osgi.core.BundleArtifact in project ant-ivy by apache.

the class OBRXMLWriter method saxBundleInfo.

private static void saxBundleInfo(BundleInfo bundleInfo, ContentHandler handler) throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    addAttr(atts, ResourceHandler.SYMBOLIC_NAME, bundleInfo.getSymbolicName());
    addAttr(atts, ResourceHandler.VERSION, bundleInfo.getRawVersion());
    for (BundleArtifact artifact : bundleInfo.getArtifacts()) {
        if (!artifact.isSource()) {
            addAttr(atts, ResourceHandler.URI, bundleInfo.getArtifacts().get(0).getUri().toString());
            break;
        }
    }
    handler.startElement("", ResourceHandler.RESOURCE, ResourceHandler.RESOURCE, atts);
    for (BundleArtifact artifact : bundleInfo.getArtifacts()) {
        if (artifact.isSource()) {
            startElement(handler, ResourceSourceHandler.SOURCE);
            characters(handler, artifact.getUri().toString());
            endElement(handler, ResourceSourceHandler.SOURCE);
            break;
        }
    }
    for (BundleCapability capability : bundleInfo.getCapabilities()) {
        saxCapability(capability, handler);
    }
    for (BundleRequirement requirement : bundleInfo.getRequirements()) {
        saxRequirement(requirement, handler);
    }
    handler.endElement("", ResourceHandler.RESOURCE, ResourceHandler.RESOURCE);
    handler.characters("\n".toCharArray(), 0, 1);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) BundleCapability(org.apache.ivy.osgi.core.BundleCapability) BundleRequirement(org.apache.ivy.osgi.core.BundleRequirement)

Example 5 with BundleArtifact

use of org.apache.ivy.osgi.core.BundleArtifact in project ant-ivy by apache.

the class OBRResolverTest method genericTestResolve.

private void genericTestResolve(String jarName, String conf, ModuleRevisionId[] expectedMrids, ModuleRevisionId[] expected2Mrids) throws Exception {
    JarInputStream jis = new JarInputStream(new FileInputStream("test/test-repo/bundlerepo/" + jarName));
    Manifest manifest = jis.getManifest();
    jis.close();
    BundleInfo bundleInfo = ManifestParser.parseManifest(manifest);
    bundleInfo.addArtifact(new BundleArtifact(false, new File("test/test-repo/bundlerepo/" + jarName).toURI(), null));
    DefaultModuleDescriptor md = BundleInfoAdapter.toModuleDescriptor(OSGiManifestParser.getInstance(), null, bundleInfo, profileProvider);
    ResolveReport resolveReport = ivy.resolve(md, new ResolveOptions().setConfs(new String[] { conf }).setOutputReport(false));
    assertFalse("resolve failed " + resolveReport.getAllProblemMessages(), resolveReport.hasError());
    Set<ModuleRevisionId> actual = new HashSet<>();
    for (Artifact artifact : resolveReport.getArtifacts()) {
        actual.add(artifact.getModuleRevisionId());
    }
    Set<ModuleRevisionId> expected = new HashSet<>(Arrays.asList(expectedMrids));
    if (expected2Mrids != null) {
        // in this use case, we have two choices, let's try the second one
        try {
            Set<ModuleRevisionId> expected2 = new HashSet<>(Arrays.asList(expected2Mrids));
            assertEquals(expected2, actual);
            // test passed
            return;
        } catch (AssertionError e) {
        // too bad, let's continue
        }
    }
    assertEquals(expected, actual);
}
Also used : JarInputStream(java.util.jar.JarInputStream) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Manifest(java.util.jar.Manifest) FileInputStream(java.io.FileInputStream) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) ResolveReport(org.apache.ivy.core.report.ResolveReport) BundleInfo(org.apache.ivy.osgi.core.BundleInfo) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) File(java.io.File) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) HashSet(java.util.HashSet)

Aggregations

BundleArtifact (org.apache.ivy.osgi.core.BundleArtifact)11 BundleInfo (org.apache.ivy.osgi.core.BundleInfo)9 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 URI (java.net.URI)3 ModuleDescriptorWrapper (org.apache.ivy.osgi.repo.ModuleDescriptorWrapper)3 ParseException (java.text.ParseException)2 JarInputStream (java.util.jar.JarInputStream)2 Manifest (java.util.jar.Manifest)2 Artifact (org.apache.ivy.core.module.descriptor.Artifact)2 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)2 ResolveReport (org.apache.ivy.core.report.ResolveReport)2 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)2 BundleRequirement (org.apache.ivy.osgi.core.BundleRequirement)2 Version (org.apache.ivy.osgi.util.Version)2 AttributesImpl (org.xml.sax.helpers.AttributesImpl)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1