All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.p2.provider.ArtifactRepository Maven / Gradle / Ivy

The newest version!
package aQute.p2.provider;

import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.osgi.framework.Version;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import aQute.lib.converter.Converter;
import aQute.lib.converter.TypeReference;
import aQute.lib.filter.Filter;
import aQute.libg.sed.Domain;
import aQute.libg.sed.ReplacerAdapter;
import aQute.p2.api.Artifact;

/**
 * @formatter:off
 * 
 * 
 * 
 * 
 *   
 *     
 *     
 *   
 *   
 *     
 *     
 *     
 *   
 *   
 *     
 *       
 *         
 *         
 *         
 *       
 *     
 *   
 * 
* @formatter:on */ class ArtifactRepository extends XML { static class Rule { final Filter filter; String output; Rule(String filter, String output) { this.filter = new Filter(filter); this.output = output; } public boolean matches(Map map) throws Exception { return filter.matchMap(map); } } public static class XMLArtifact { public String classifier; public String id; public String version; public String format; } List rules; List artifacts = new ArrayList<>(); private URI base; ArtifactRepository(InputStream in, URI base) throws Exception { super(getDocument(in)); this.base = base; parse(); } private Rule createRule(Node ruleNode) { String filter = getAttribute(ruleNode, "filter"); String output = getAttribute(ruleNode, "output"); return new Rule(filter, output); } void parse() throws Exception { final Map properties = getProperties("repository/properties/property"); properties.put("repoUrl", base.resolve("") .toString()); final Domain parent = new Domain() { @Override public Map 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 map = Converter.cnv(new TypeReference>() {}, xmlArtifact); if ("osgi.bundle".equals(xmlArtifact.classifier)) { Domain domain = new Domain() { @Override public Map 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; } } } } } /** * * * * @param item * @return * @throws Exception * @throws IllegalAccessException * @throws IllegalArgumentException */ List getRules() throws Exception { List rules = new ArrayList<>(); NodeList ruleNodes = getNodes("repository/mappings/rule"); for (int i = 0; i < ruleNodes.getLength(); i++) { Node ruleNode = ruleNodes.item(i); Rule rule = createRule(ruleNode); rules.add(rule); } return rules; } public List getArtifacts() { return artifacts; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy