Search in sources :

Example 91 with Version

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);
    }
}
Also used : Version(aQute.bnd.version.Version) Attrs(aQute.bnd.header.Attrs) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) HashMap(java.util.HashMap) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 92 with Version

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;
}
Also used : Version(aQute.bnd.version.Version) TreeSet(java.util.TreeSet)

Example 93 with Version

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));
}
Also used : Version(aQute.bnd.version.Version) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)

Example 94 with Version

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;
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) URISyntaxException(java.net.URISyntaxException) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion) TreeSet(java.util.TreeSet) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 95 with Version

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());
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion) Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

Version (aQute.bnd.version.Version)171 File (java.io.File)67 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)29 ArrayList (java.util.ArrayList)21 Attrs (aQute.bnd.header.Attrs)19 MavenVersion (aQute.bnd.version.MavenVersion)19 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Jar (aQute.bnd.osgi.Jar)16 Workspace (aQute.bnd.build.Workspace)13 Project (aQute.bnd.build.Project)12 RevisionRef (aQute.service.library.Library.RevisionRef)12 Matcher (java.util.regex.Matcher)12 Parameters (aQute.bnd.header.Parameters)11 VersionRange (aQute.bnd.version.VersionRange)11 SortedList (aQute.lib.collections.SortedList)9 Processor (aQute.bnd.osgi.Processor)8 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)8 FileNotFoundException (java.io.FileNotFoundException)8 LinkedHashMap (java.util.LinkedHashMap)8