Search in sources :

Example 1 with Artifact

use of aQute.p2.api.Artifact in project bnd by bndtools.

the class ArtifactRepository method parse.

void parse() throws Exception {
    final Map<String, String> properties = getProperties("repository/properties/property");
    properties.put("repoUrl", base.resolve("").toString());
    final Domain parent = new Domain() {

        @Override
        public Map<String, String> getMap() {
            return properties;
        }

        @Override
        public Domain getParent() {
            return null;
        }
    };
    rules = getRules();
    NodeList artifactNodes = getNodes("repository/artifacts/artifact");
    for (int i = 0; i < artifactNodes.getLength(); i++) {
        final Node artifactNode = artifactNodes.item(i).cloneNode(true);
        final XMLArtifact xmlArtifact = getFromType(artifactNode, XMLArtifact.class);
        final Map<String, String> map = Converter.cnv(new TypeReference<Map<String, String>>() {
        }, xmlArtifact);
        if ("osgi.bundle".equals(xmlArtifact.classifier)) {
            Domain domain = new Domain() {

                @Override
                public Map<String, String> getMap() {
                    return map;
                }

                @Override
                public Domain getParent() {
                    return parent;
                }
            };
            ReplacerAdapter ra = new ReplacerAdapter(domain);
            for (Rule r : rules) {
                if (r.matches(map)) {
                    String s = ra.process(r.output);
                    URI uri = new URI(s).normalize();
                    Artifact artifact = new Artifact();
                    artifact.uri = uri;
                    artifact.id = xmlArtifact.id;
                    artifact.version = new Version(xmlArtifact.version);
                    artifact.md5 = getProperties(artifactNode, "properties/property").get("download.md5");
                    artifacts.add(artifact);
                    break;
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) URI(java.net.URI) Artifact(aQute.p2.api.Artifact) Version(org.osgi.framework.Version) ReplacerAdapter(aQute.libg.sed.ReplacerAdapter) Domain(aQute.libg.sed.Domain) Map(java.util.Map)

Example 2 with Artifact

use of aQute.p2.api.Artifact in project bnd by bndtools.

the class P2Impl method parseIndexArtifacts.

private Promise<List<Artifact>> parseIndexArtifacts(Set<URI> cycles, URI uri, File file) throws Exception {
    P2Index index;
    if (file == null) {
        index = getDefaultIndex(uri);
    } else {
        index = parseIndex(file, uri);
    }
    canonicalize(index.artifacts);
    canonicalize(index.content);
    return getArtifacts(cycles, index.artifacts);
}
Also used : P2Index(aQute.p2.api.P2Index)

Example 3 with Artifact

use of aQute.p2.api.Artifact in project bnd by bndtools.

the class P2Indexer method readRepository.

private Repository readRepository() throws Exception {
    P2Impl p2 = new P2Impl(client, this.url, Processor.getExecutor());
    List<Artifact> artifacts = p2.getArtifacts();
    List<Promise<Resource>> fetched = new ArrayList<>(artifacts.size());
    Set<URI> visitedURIs = new HashSet<>(artifacts.size());
    Set<ArtifactID> visitedArtifacts = new HashSet<>(artifacts.size());
    Map<ArtifactID, Resource> knownResources = new HashMap<>();
    if (getBridge() != null) {
        for (Capability capability : getBridge().getRepository().findProviders(singleton(MD5_REQUIREMENT)).get(MD5_REQUIREMENT)) {
            Resource resource = capability.getResource();
            IdentityCapability identity = ResourceUtils.getIdentityCapability(resource);
            ArtifactID artifact = new ArtifactID(identity.osgi_identity(), identity.version(), (String) capability.getAttributes().get(MD5_ATTRIBUTE));
            knownResources.put(artifact, resource);
        }
    }
    for (final Artifact a : artifacts) {
        if (!visitedURIs.add(a.uri))
            continue;
        if (a.md5 != null) {
            ArtifactID id = new ArtifactID(a.id, toVersion(a.version), a.md5);
            if (!visitedArtifacts.add(id))
                continue;
            if (knownResources.containsKey(id)) {
                fetched.add(Promises.resolved(knownResources.get(id)));
                continue;
            }
        }
        Promise<Resource> promise = client.build().useCache(MAX_STALE).async(a.uri.toURL()).map(new Function<File, Resource>() {

            @Override
            public Resource apply(File file) {
                try {
                    ResourceBuilder rb = new ResourceBuilder();
                    rb.addFile(file, a.uri);
                    if (a.md5 != null)
                        rb.addCapability(new CapabilityBuilder(P2_CAPABILITY_NAMESPACE).addAttribute(MD5_ATTRIBUTE, a.md5));
                    return rb.build();
                } catch (Exception e) {
                    logger.debug("{}: Failed to create resource for %s from {}", name, a, file, e);
                    return RECOVERY;
                }
            }
        }).recover(new Function<Promise<?>, Resource>() {

            @Override
            public Resource apply(Promise<?> failed) {
                try {
                    logger.debug("{}: Failed to create resource for {}", name, a, failed.getFailure());
                } catch (InterruptedException e) {
                // impossible
                }
                return RECOVERY;
            }
        });
        fetched.add(promise);
    }
    Promise<List<Resource>> all = Promises.all(fetched);
    return all.map(new Function<List<Resource>, ResourcesRepository>() {

        @Override
        public ResourcesRepository apply(List<Resource> resources) {
            ResourcesRepository rr = new ResourcesRepository();
            for (Resource resource : resources) {
                if (resource != RECOVERY) {
                    rr.add(resource);
                }
            }
            return rr;
        }
    }).getValue();
}
Also used : P2Impl(aQute.p2.provider.P2Impl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) URI(java.net.URI) Function(org.osgi.util.function.Function) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Capability(org.osgi.resource.Capability) ContentCapability(aQute.bnd.osgi.resource.ResourceUtils.ContentCapability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Resource(org.osgi.resource.Resource) Artifact(aQute.p2.api.Artifact) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) IOException(java.io.IOException) DownloadListenerPromise(aQute.bnd.util.repository.DownloadListenerPromise) Promise(org.osgi.util.promise.Promise) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Aggregations

Artifact (aQute.p2.api.Artifact)2 URI (java.net.URI)2 ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)1 CapabilityBuilder (aQute.bnd.osgi.resource.CapabilityBuilder)1 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)1 ContentCapability (aQute.bnd.osgi.resource.ResourceUtils.ContentCapability)1 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)1 DownloadListenerPromise (aQute.bnd.util.repository.DownloadListenerPromise)1 Domain (aQute.libg.sed.Domain)1 ReplacerAdapter (aQute.libg.sed.ReplacerAdapter)1 P2Index (aQute.p2.api.P2Index)1 P2Impl (aQute.p2.provider.P2Impl)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Version (org.osgi.framework.Version)1