use of aQute.bnd.version.Version in project bnd by bndtools.
the class Analyzer method augmentExports.
/**
* Provide any macro substitutions and versions for exported packages.
*
* @throws IOException
*/
void augmentExports(Packages exports) throws IOException {
for (PackageRef packageRef : exports.keySet()) {
String packageName = packageRef.getFQN();
setProperty(CURRENT_PACKAGE, packageName);
Attrs attributes = exports.get(packageRef);
try {
Attrs exporterAttributes = classpathExports.get(packageRef);
if (exporterAttributes == null) {
if (check(Check.EXPORTS)) {
Map<String, Resource> map = dot.getDirectories().get(packageRef.getBinary());
if ((map == null || map.isEmpty())) {
error("Exporting an empty package '%s'", packageRef.getFQN());
}
}
} else {
for (Map.Entry<String, String> entry : exporterAttributes.entrySet()) {
String key = entry.getKey();
// dont overwrite and no directives
if (!key.endsWith(":")) {
if (!attributes.containsKey(key))
attributes.put(key, entry.getValue());
else {
if (since(About._2_4)) {
// and we have set it.
if (key.equals(Constants.VERSION_ATTRIBUTE)) {
try {
Version fromExport = new Version(cleanupVersion(exporterAttributes.getVersion()));
Version fromSet = new Version(cleanupVersion(attributes.getVersion()));
if (!fromExport.equals(fromSet)) {
SetLocation location = warning("Version for package %s is set to different values in the source (%s) and in the manifest (%s). The version in the manifest is not " + "picked up by an other sibling bundles in this project or projects that directly depend on this project", packageName, attributes.get(key), exporterAttributes.get(key));
if (getPropertiesFile() != null)
location.file(getPropertiesFile().getAbsolutePath());
location.header(EXPORT_PACKAGE);
location.context(packageName);
}
} catch (Exception e) {
// Ignored here, is picked up in
// other places
}
}
}
}
}
}
}
} finally {
unsetProperty(CURRENT_PACKAGE);
}
fixupAttributes(packageRef, attributes);
removeAttributes(attributes);
}
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class MavenBndRepository method versions.
@Override
public SortedSet<Version> versions(String bsn) throws Exception {
init();
TreeSet<Version> versions = new TreeSet<Version>();
for (Version version : index.list(bsn)) {
versions.add(version);
}
return versions;
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class BridgeRepository method index.
private void index(Resource r) throws Exception {
IdentityCapability bc = ResourceUtils.getIdentityCapability(r);
String bsn = bc.osgi_identity();
Version version = bc.version();
Map<Version, ResourceInfo> map = index.get(bsn);
if (map == null) {
map = new HashMap<>();
index.put(bsn, map);
}
map.put(version, new ResourceInfo(r));
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class AetherRepository method versions.
@Override
public SortedSet<Version> versions(String bsn) throws Exception {
init();
// Use the index by preference
if (indexedRepo != null)
return indexedRepo.versions(ConversionUtils.maybeMavenCoordsToBsn(bsn));
Artifact artifact = null;
try {
artifact = new DefaultArtifact(bsn + ":[0,)");
} catch (Exception e) {
// ignore non-GAV style dependencies
}
if (artifact == null)
return null;
// Setup the Aether repo session and create the range request
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(Collections.singletonList(remoteRepo));
// Resolve the range
VersionRangeResult rangeResult = repoSystem.resolveVersionRange(session, rangeRequest);
// Add to the result
SortedSet<Version> versions = new TreeSet<Version>();
for (org.eclipse.aether.version.Version version : rangeResult.getVersions()) {
try {
versions.add(MavenVersion.parseString(version.toString()).getOSGiVersion());
} catch (IllegalArgumentException e) {
// ignore version
}
}
return versions;
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class ConversionUtils method fromBundleJar.
public static final Artifact fromBundleJar(Jar jar) throws Exception {
String groupId;
String artifactId;
String bsn = jar.getBsn();
groupId = jar.getManifest().getMainAttributes().getValue("Maven-GroupId");
if (groupId != null) {
String groupPrefix = groupId + ".";
if (bsn.startsWith(groupPrefix)) {
if (bsn.length() <= groupPrefix.length())
throw new IllegalArgumentException("Artifact ID appears to be empty");
artifactId = bsn.substring(groupPrefix.length());
} else {
artifactId = bsn;
}
} else {
int lastDot = bsn.lastIndexOf('.');
if (lastDot < 0)
throw new IllegalArgumentException(String.format("Cannot split symbolic name '%s' into group ID and artifact ID", bsn));
if (lastDot == 0)
throw new IllegalArgumentException("Group ID appears to be empty");
if (lastDot >= bsn.length() - 1)
throw new IllegalArgumentException("Artifact ID appear to be empty");
groupId = bsn.substring(0, lastDot);
artifactId = bsn.substring(lastDot + 1);
}
String versionString = jar.getVersion();
if (versionString == null)
versionString = "0";
else if (!Verifier.isVersion(versionString))
throw new IllegalArgumentException("Invalid version " + versionString);
Version version = Version.parseVersion(versionString);
return new DefaultArtifact(groupId, artifactId, JAR_EXTENSION, new MavenVersion(version).toString());
}
Aggregations