Search in sources :

Example 1 with WorkspaceRepository

use of aQute.bnd.build.WorkspaceRepository in project bnd by bndtools.

the class WorkspaceRepositoryTest method setUp.

public void setUp() throws Exception {
    workspace = new Workspace(IO.getFile("testresources/ws-repo-test"));
    repo = new WorkspaceRepository(workspace);
}
Also used : WorkspaceRepository(aQute.bnd.build.WorkspaceRepository) Workspace(aQute.bnd.build.Workspace)

Example 2 with WorkspaceRepository

use of aQute.bnd.build.WorkspaceRepository 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 3 with WorkspaceRepository

use of aQute.bnd.build.WorkspaceRepository in project bndtools by bndtools.

the class RepositoryTreeContentProvider method getRepositoryBundles.

Object[] getRepositoryBundles(final RepositoryPlugin repoPlugin) {
    Object[] result = null;
    if (requirementFilter != null) {
        if (repoPlugin instanceof Repository) {
            result = searchR5Repository(repoPlugin, (Repository) repoPlugin);
        } else if (repoPlugin instanceof WorkspaceRepository) {
            try {
                WorkspaceR5Repository workspaceRepo = Central.getWorkspaceR5Repository();
                result = searchR5Repository(repoPlugin, workspaceRepo);
            } catch (Exception e) {
                logger.logError("Error querying workspace repository", e);
            }
        }
        return result;
    }
    /*
         * We can't directly call repoPlugin.list() since we are on the UI thread so the plan is to first check to see
         * if we have cached the list results already from a previous job, if so, return those results directly If not,
         * then we need to create a background job that will call list() and once it is finished, we tell the Viewer to
         * refresh this node and the next time this method gets called the 'results' will be available in the cache
         */
    Map<String, Object[]> listResults = repoPluginListResults.get(repoPlugin);
    if (listResults == null) {
        listResults = new HashMap<>();
        repoPluginListResults.put(repoPlugin, listResults);
    }
    result = listResults.get(wildcardFilter);
    if (result == null) {
        Job job = new Job("Loading " + repoPlugin.getName() + " content...") {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                IStatus status = Status.OK_STATUS;
                Object[] jobresult;
                List<String> bsns = null;
                try {
                    bsns = repoPlugin.list(wildcardFilter);
                } catch (Exception e) {
                    String message = MessageFormat.format("Error querying repository {0}.", repoPlugin.getName());
                    logger.logError(message, e);
                    status = new Status(IStatus.ERROR, Plugin.PLUGIN_ID, message, e);
                }
                if (bsns != null) {
                    Collections.sort(bsns);
                    jobresult = new RepositoryBundle[bsns.size()];
                    int i = 0;
                    for (String bsn : bsns) {
                        jobresult[i++] = new RepositoryBundle(repoPlugin, bsn);
                    }
                    Map<String, Object[]> listResults = repoPluginListResults.get(repoPlugin);
                    listResults.put(wildcardFilter, jobresult);
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (!structuredViewer.getControl().isDisposed())
                                structuredViewer.refresh(repoPlugin, true);
                        }
                    });
                }
                return status;
            }
        };
        job.schedule();
        // wait 100 ms and see if the job will complete fast (likely already cached)
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        IStatus status = job.getResult();
        if (status != null && status.isOK()) {
            Map<String, Object[]> fastResults = repoPluginListResults.get(repoPlugin);
            result = fastResults.get(wildcardFilter);
        } else {
            Object[] loading = new Object[] { new LoadingContentElement() };
            listResults.put(wildcardFilter, loading);
            result = loading;
        }
    }
    return result;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) WorkspaceR5Repository(bndtools.central.WorkspaceR5Repository) WorkspaceRepository(aQute.bnd.build.WorkspaceRepository) Repository(org.osgi.service.repository.Repository) WorkspaceR5Repository(bndtools.central.WorkspaceR5Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceRepository(aQute.bnd.build.WorkspaceRepository) Job(org.eclipse.core.runtime.jobs.Job)

Example 4 with WorkspaceRepository

use of aQute.bnd.build.WorkspaceRepository in project bndtools by bndtools.

the class ImportPackageQuickFixProcessor method getSuggestions.

IJavaCompletionProposal[] getSuggestions(Set<String> pkgs, IInvocationContext context) throws CoreException {
    List<RepositoryPlugin> ps = listRepositories();
    final BndBuildPathHandler handler = getBuildPathHandler(context);
    MultiMap<String, String> bundles = new MultiMap<>();
    String wsName = null;
    boolean loggedWorkspaceError = false;
    for (String pkg : pkgs) {
        for (RepositoryPlugin p : ps) {
            Collection<Capability> caps = null;
            if (p instanceof Repository) {
                caps = searchRepository((Repository) p, pkg);
            } else if (p instanceof WorkspaceRepository) {
                try {
                    caps = searchRepository(getWorkspaceRepo(), pkg);
                    wsName = p.getName();
                } catch (Exception e) {
                    if (!loggedWorkspaceError) {
                        logger.logError("Error trying to fetch the repository for the current workspace", e);
                        loggedWorkspaceError = true;
                    }
                }
            }
            if (caps == null) {
                continue;
            }
            for (Capability cap : caps) {
                final String bsn = capabilityToBSN(cap);
                if (bsn != null && !handler.containsBundle(bsn)) {
                    bundles.add(bsn, p.getName());
                }
            }
        }
    }
    if (bundles.isEmpty()) {
        return null;
    }
    IJavaCompletionProposal[] retval = new IJavaCompletionProposal[bundles.size()];
    int i = 0;
    for (Map.Entry<String, List<String>> bundle : bundles.entrySet()) {
        // NOTE: The call to contains() here, based on the current MultiMap implementation, will
        // do a linear search. Because a single bundle is unlikely to be found in more than a few
        // repos in any given workspace this probably won't make a difference, but if any performance issues show up
        // in the future this would be a place to look.
        final int relevance = bundle.getValue().contains(wsName) ? ADD_BUNDLE_WORKSPACE : ADD_BUNDLE;
        retval[i++] = new AddBundleCompletionProposal(bundle.getKey(), bundle.getValue(), relevance, context);
    }
    return retval;
}
Also used : Capability(org.osgi.resource.Capability) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal) CoreException(org.eclipse.core.runtime.CoreException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Point(org.eclipse.swt.graphics.Point) MultiMap(aQute.lib.collections.MultiMap) WorkspaceRepository(aQute.bnd.build.WorkspaceRepository) Repository(org.osgi.service.repository.Repository) WorkspaceRepository(aQute.bnd.build.WorkspaceRepository) List(java.util.List) ArrayList(java.util.ArrayList) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map)

Aggregations

WorkspaceRepository (aQute.bnd.build.WorkspaceRepository)4 Workspace (aQute.bnd.build.Workspace)2 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 IOException (java.io.IOException)2 CoreException (org.eclipse.core.runtime.CoreException)2 Repository (org.osgi.service.repository.Repository)2 Attrs (aQute.bnd.header.Attrs)1 Domain (aQute.bnd.osgi.Domain)1 Version (aQute.bnd.version.Version)1 MultiMap (aQute.lib.collections.MultiMap)1 WorkspaceR5Repository (bndtools.central.WorkspaceR5Repository)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 JarInputStream (java.util.jar.JarInputStream)1 Manifest (java.util.jar.Manifest)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1