Search in sources :

Example 6 with BundleInfo

use of org.apache.ivy.osgi.core.BundleInfo 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 7 with BundleInfo

use of org.apache.ivy.osgi.core.BundleInfo 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 8 with BundleInfo

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

the class P2Descriptor method addBundle.

public void addBundle(BundleInfo bundleInfo) {
    if (bundleInfo.isSource()) {
        if (bundleInfo.getSymbolicNameTarget() == null || bundleInfo.getVersionTarget() == null) {
            if (getLogLevel() <= Message.MSG_VERBOSE) {
                Message.verbose("The source bundle " + bundleInfo.getSymbolicName() + " did not declare its target. Ignoring it");
            }
            return;
        }
        Map<Version, BundleInfo> byVersion = sourceBundles.get(bundleInfo.getSymbolicName());
        if (byVersion == null) {
            byVersion = new HashMap<>();
            sourceBundles.put(bundleInfo.getSymbolicName(), byVersion);
        }
        byVersion.put(bundleInfo.getVersion(), bundleInfo);
        Map<Version, BundleInfo> byTargetVersion = sourceTargetBundles.get(bundleInfo.getSymbolicNameTarget());
        if (byTargetVersion == null) {
            byTargetVersion = new HashMap<>();
            sourceTargetBundles.put(bundleInfo.getSymbolicNameTarget(), byTargetVersion);
        }
        BundleInfo old = byTargetVersion.put(bundleInfo.getVersionTarget(), bundleInfo);
        if (old != null && !old.equals(bundleInfo)) {
            if (getLogLevel() <= Message.MSG_VERBOSE) {
                Message.verbose("Duplicate source for the bundle " + bundleInfo.getSymbolicNameTarget() + "@" + bundleInfo.getVersionTarget() + " : " + bundleInfo + " is replacing " + old);
            }
        }
        return;
    }
    super.addBundle(bundleInfo);
}
Also used : BundleInfo(org.apache.ivy.osgi.core.BundleInfo) Version(org.apache.ivy.osgi.util.Version)

Example 9 with BundleInfo

use of org.apache.ivy.osgi.core.BundleInfo 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)

Example 10 with BundleInfo

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

the class OBRXMLWriter method writeManifests.

public static void writeManifests(Iterable<ManifestAndLocation> manifestAndLocations, ContentHandler handler, boolean quiet) throws SAXException {
    int level = quiet ? Message.MSG_DEBUG : Message.MSG_WARN;
    handler.startDocument();
    AttributesImpl atts = new AttributesImpl();
    handler.startElement("", RepositoryHandler.REPOSITORY, RepositoryHandler.REPOSITORY, atts);
    int nbOk = 0;
    int nbRejected = 0;
    for (ManifestAndLocation manifestAndLocation : manifestAndLocations) {
        BundleInfo bundleInfo;
        try {
            bundleInfo = ManifestParser.parseManifest(manifestAndLocation.getManifest());
            bundleInfo.addArtifact(new BundleArtifact(false, manifestAndLocation.getUri(), null));
            if (manifestAndLocation.getSourceURI() != null) {
                bundleInfo.addArtifact(new BundleArtifact(true, manifestAndLocation.getSourceURI(), null));
            }
            nbOk++;
        } catch (ParseException e) {
            nbRejected++;
            IvyContext.getContext().getMessageLogger().log("Rejected " + manifestAndLocation.getUri() + ": " + e.getMessage(), level);
            continue;
        }
        saxBundleInfo(bundleInfo, handler);
    }
    handler.endElement("", RepositoryHandler.REPOSITORY, RepositoryHandler.REPOSITORY);
    handler.endDocument();
    Message.info(nbOk + " bundle" + (nbOk > 1 ? "s" : "") + " added, " + nbRejected + " bundle" + (nbRejected > 1 ? "s" : "") + " rejected.");
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) BundleInfo(org.apache.ivy.osgi.core.BundleInfo) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) ManifestAndLocation(org.apache.ivy.osgi.repo.ManifestAndLocation) ParseException(java.text.ParseException)

Aggregations

BundleInfo (org.apache.ivy.osgi.core.BundleInfo)13 BundleArtifact (org.apache.ivy.osgi.core.BundleArtifact)9 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 URI (java.net.URI)3 ParseException (java.text.ParseException)3 Manifest (java.util.jar.Manifest)3 ModuleDescriptorWrapper (org.apache.ivy.osgi.repo.ModuleDescriptorWrapper)3 Version (org.apache.ivy.osgi.util.Version)3 JarInputStream (java.util.jar.JarInputStream)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 AttributesImpl (org.xml.sax.helpers.AttributesImpl)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1