Search in sources :

Example 86 with Version

use of aQute.bnd.version.Version in project bndtools by bndtools.

the class BndContainerSourceManager method getSourceBundle.

private static File getSourceBundle(IPath path, Map<String, String> props) {
    Workspace bndWorkspace;
    try {
        bndWorkspace = Central.getWorkspace();
        if (bndWorkspace == null) {
            return null;
        }
    } catch (final Exception e) {
        return null;
    }
    IPath bundlePath = path;
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    IResource resource = root.findMember(path);
    if (resource != null) {
        bundlePath = resource.getLocation();
    }
    try (JarInputStream jarStream = new JarInputStream(IO.stream(bundlePath.toFile()), false)) {
        Manifest manifest = jarStream.getManifest();
        if (manifest == null) {
            return null;
        }
        Domain domain = Domain.domain(manifest);
        Entry<String, Attrs> bsnAttrs = domain.getBundleSymbolicName();
        if (bsnAttrs == null) {
            return null;
        }
        String bsn = bsnAttrs.getKey();
        String version = domain.getBundleVersion();
        if (version == null) {
            version = props.get("version");
        }
        for (RepositoryPlugin repo : RepositoryUtils.listRepositories(true)) {
            if (repo == null) {
                continue;
            }
            if (repo instanceof WorkspaceRepository) {
                continue;
            }
            File sourceBundle = repo.get(bsn + ".source", new Version(version), props);
            if (sourceBundle != null) {
                return sourceBundle;
            }
        }
    } catch (final Exception e) {
    // Ignore, something went wrong, or we could not find the source bundle
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) JarInputStream(java.util.jar.JarInputStream) Attrs(aQute.bnd.header.Attrs) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Manifest(java.util.jar.Manifest) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) Version(aQute.bnd.version.Version) WorkspaceRepository(aQute.bnd.build.WorkspaceRepository) IWorkspace(org.eclipse.core.resources.IWorkspace) Domain(aQute.bnd.osgi.Domain) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IWorkspace(org.eclipse.core.resources.IWorkspace) Workspace(aQute.bnd.build.Workspace)

Example 87 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class MavenRepository method versions.

public SortedSet<Version> versions(String bsn) throws Exception {
    File[] files = get(bsn, null);
    List<Version> versions = new ArrayList<Version>();
    for (File f : files) {
        String version = f.getParentFile().getName();
        version = Builder.cleanupVersion(version);
        Version v = new Version(version);
        versions.add(v);
    }
    if (versions.isEmpty())
        return SortedList.empty();
    return new SortedList<Version>(versions);
}
Also used : Version(aQute.bnd.version.Version) ArrayList(java.util.ArrayList) SortedList(aQute.lib.collections.SortedList) File(java.io.File)

Example 88 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class PomFromManifest method getVersion.

public Version getVersion() {
    if (xversion != null)
        return new Version(xversion);
    String version = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
    Version v = new Version(version);
    return new Version(v.getMajor(), v.getMinor(), v.getMicro());
}
Also used : Version(aQute.bnd.version.Version)

Example 89 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class JavaElement method getLocalAPI.

private Element getLocalAPI() throws Exception {
    Set<Element> result = new HashSet<Element>();
    for (Map.Entry<PackageRef, List<Element>> entry : packages.entrySet()) {
        List<Element> set = entry.getValue();
        for (Iterator<Element> i = set.iterator(); i.hasNext(); ) {
            if (notAccessible.contains(analyzer.getTypeRefFromFQN(i.next().getName())))
                i.remove();
        }
        String version = exports.get(entry.getKey()).get(Constants.VERSION_ATTRIBUTE);
        if (version != null) {
            Version v = new Version(version);
            set.add(new Element(VERSION, v.getWithoutQualifier().toString(), null, IGNORED, IGNORED, null));
        }
        Element pd = new Element(PACKAGE, entry.getKey().getFQN(), set, MINOR, MAJOR, null);
        result.add(pd);
    }
    for (JAVA java : javas) {
        result.add(new Element(CLASS_VERSION, java.toString(), null, CHANGED, CHANGED, null));
    }
    return new Element(API, "<api>", result, CHANGED, CHANGED, null);
}
Also used : JAVA(aQute.bnd.osgi.Clazz.JAVA) Version(aQute.bnd.version.Version) List(java.util.List) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 90 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class FileRepo method versions.

public List<Version> versions(String bsn) throws Exception {
    File dir = new File(root, bsn);
    final List<Version> versions = new ArrayList<Version>();
    dir.list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            Matcher m = REPO_FILE.matcher(name);
            if (m.matches()) {
                versions.add(new Version(m.group(2)));
                return true;
            }
            return false;
        }
    });
    return versions;
}
Also used : FilenameFilter(java.io.FilenameFilter) Version(aQute.bnd.version.Version) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) File(java.io.File)

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