aQute.p2.provider.ArtifactRepository Maven / Gradle / Ivy
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;
import aQute.p2.api.Classifier;
/**
* @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
© 2015 - 2024 Weber Informatics LLC | Privacy Policy