use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.
the class Repository method getRevisionRef.
/**
* Find a revisionref for a bsn/version
*
* @param bsn
* @param version
* @throws Exception
*/
private RevisionRef getRevisionRef(String bsn, Version version) throws Exception {
// Handle when we have a sha reference
String id = bsn + "-" + version;
if (notfoundref.contains(id))
return null;
if (isSha(bsn) && version.equals(Version.LOWEST)) {
Revision r = getRevision(new Coordinate(bsn));
if (r == null)
return null;
return new RevisionRef(r);
}
logger.debug("Looking for {}-{}", bsn, version);
for (RevisionRef r : getRevisionRefs(bsn)) {
Version v = toVersion(r.baseline, r.qualifier);
if (v.equals(version))
return r;
}
notfoundref.add(id);
return null;
}
use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.
the class JustAnotherPackageManager method what.
public String what(String key, boolean oneliner) throws Exception {
byte[] sha;
Matcher m = SHA_P.matcher(key);
if (m.matches()) {
sha = Hex.toByteArray(key);
} else {
m = URL_P.matcher(key);
if (m.matches()) {
URL url = new URL(key);
sha = SHA1.digest(url.openStream()).digest();
} else {
File jarfile = new File(key);
if (!jarfile.exists()) {
reporter.error("File does not exist: %s", jarfile.getCanonicalPath());
}
sha = SHA1.digest(jarfile).digest();
}
}
logger.debug("sha {}", Hex.toHexString(sha));
Revision revision = library.getRevision(sha);
if (revision == null) {
return null;
}
Justif justif = new Justif(120, 20, 70, 20, 75);
DateFormat dateFormat = DateFormat.getDateInstance();
StringBuilder sb = new StringBuilder();
try (Formatter f = new Formatter(sb)) {
if (oneliner) {
f.format("%20s %s%n", Hex.toHexString(revision._id), createCoord(revision));
} else {
f.format("Artifact: %s%n", revision.artifactId);
if (revision.organization != null && revision.organization.name != null) {
f.format(" (%s)", revision.organization.name);
}
f.format("%n");
f.format("Coordinates\t0: %s%n", createCoord(revision));
f.format("Created\t0: %s%n", dateFormat.format(new Date(revision.created)));
f.format("Size\t0: %d%n", revision.size);
f.format("Sha\t0: %s%n", Hex.toHexString(revision._id));
f.format("URL\t0: %s%n", createJpmLink(revision));
f.format("%n");
f.format("%s%n", revision.description);
f.format("%n");
f.format("Dependencies\t0:%n");
boolean flag = false;
Iterable<RevisionRef> closure = library.getClosure(revision._id, true);
for (RevisionRef dep : closure) {
f.format(" - %s \t2- %s \t3- %s%n", dep.name, createCoord(dep), dateFormat.format(new Date(dep.created)));
flag = true;
}
if (!flag) {
f.format(" None%n");
}
f.format("%n");
}
f.flush();
justif.wrap(sb);
return sb.toString();
}
}
use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.
the class JPMTest method testAddMirrorURL.
public void testAddMirrorURL() throws Exception {
// Drop two URIs for an identical resource
URI uri1 = IO.getFile("testdata/ws/cnf/jar/biz.aQute.bnd.annotation-2.3.0.jar").toURI();
repo.dropTarget(uri1);
URI uri2 = IO.getFile("testdata/ws/cnf/jar/biz.aQute.bnd.annotation-2.3.0-duplicate.jar").toURI();
repo.dropTarget(uri2);
// Read the index, there should be one resource but two mirror URLs
List<RevisionRef> refs = new Index(IO.getFile(tmp, "index")).getRevisionRefs();
assertEquals(1, refs.size());
assertEquals(2, refs.get(0).urls.size());
assertTrue(refs.get(0).urls.contains(uri1));
assertTrue(refs.get(0).urls.contains(uri2));
}
use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.
the class Repository method get.
/**
* Get a revision.
*/
@Override
public File get(String bsn, Version version, Map<String, String> attrs, final DownloadListener... listeners) throws Exception {
init();
// Check if we're supposed to have this
RevisionRef resource = index.getRevisionRef(bsn, version);
if (resource == null)
return null;
else
return getLocal(resource, attrs, listeners);
}
use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.
the class Repository method analyze.
/**
* We have a URI that potentially could be a JAR. We download it and analyze
* it. If it looks like a bndle or JAR, we try to guess the different parts
* from it and return a ReveisionRef.
*
* @param uri the potential URI to a bundle/jar
* @return null or a RevisionRef describing the bundle/jar
* @throws IOException
* @throws IllegalArgumentException
*/
private RevisionRef analyze(File file, URI uri) throws IllegalArgumentException, IOException {
try {
try (Jar jar = new Jar(file)) {
Manifest manifest = jar.getManifest();
if (manifest == null) {
logger.debug("Jar {} has no manifest", uri);
return null;
}
Domain domain = Domain.domain(manifest);
RevisionRef ref = new RevisionRef();
ref.created = System.currentTimeMillis();
ref.md5 = MD5.digest(file).digest();
ref.revision = SHA1.digest(file).digest();
ref.phase = Library.Phase.MASTER;
ref.size = file.length();
ref.urls.add(uri);
Entry<String, Attrs> bsn = domain.getBundleSymbolicName();
if (bsn != null) {
ref.bsn = bsn.getKey();
ref.name = domain.get(Constants.BUNDLE_SYMBOLICNAME);
ref.version = domain.getBundleVersion();
ref.description = domain.get(Constants.BUNDLE_DESCRIPTION);
ref.groupId = "osgi";
ref.artifactId = ref.bsn;
}
try {
Map<String, Resource> map = jar.getDirectories().get("META-INF/maven");
if (map.size() != 1) {
return ref;
}
ref.groupId = map.keySet().iterator().next();
map = jar.getDirectories().get("META-INF/maven/" + ref.groupId);
if (map.size() != 1) {
return ref;
}
ref.artifactId = map.keySet().iterator().next();
if (ref.bsn == null) {
ref.bsn = ref.groupId + "__" + ref.artifactId;
}
Resource r = jar.getResource("META-INF/maven/" + ref.groupId + "/" + ref.artifactId + "/pom.xml");
if (r != null) {
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(r.openInputStream());
XPath xp = xpf.newXPath();
if (ref.description == null) {
ref.description = xp.evaluate("//description", doc);
}
if (ref.version == null) {
ref.version = xp.evaluate("//version", doc);
}
if (ref.name == null) {
ref.name = xp.evaluate("//name", doc);
}
ref.packaging = xp.evaluate("//packaging", doc);
ref.classifier = xp.evaluate("//classifier", doc);
}
} catch (Exception e) {
logger.debug("parsing maven failed for {}: {}", uri, e);
}
if (ref.version == null)
ref.version = "0";
if (Verifier.isVersion(ref.version)) {
Version version = new Version(ref.version);
ref.baseline = version.getWithoutQualifier().toString();
ref.qualifier = version.getQualifier();
}
if (ref.bsn == null) {
Pattern JAR_URI_P = Pattern.compile(".*/([^/]+)(?:\\.jar)?", Pattern.CASE_INSENSITIVE);
Matcher m = JAR_URI_P.matcher(uri.toString());
if (m.matches()) {
ref.bsn = m.group(1);
} else
ref.bsn = "unknown";
}
return ref;
}
} catch (Exception e) {
logger.debug("Could not parse JAR {}: {}", uri, e);
}
return null;
}
Aggregations