Search in sources :

Example 1 with WorkspaceR5Repository

use of bndtools.central.WorkspaceR5Repository 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 2 with WorkspaceR5Repository

use of bndtools.central.WorkspaceR5Repository in project bndtools by bndtools.

the class BuiltBundleIndexer method builtBundles.

@Override
public void builtBundles(final IProject project, IPath[] paths) {
    IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
    final URI workspaceRootUri = wsroot.getLocationURI();
    Set<File> files = new HashSet<File>();
    for (IPath path : paths) {
        try {
            IFile ifile = wsroot.getFile(path);
            IPath location = ifile.getLocation();
            if (location != null)
                files.add(location.toFile());
        } catch (IllegalArgumentException e) {
            System.err.println("### Error processing path: " + path);
            e.printStackTrace();
        }
    }
    // Generate the index file
    File indexFile;
    try {
        Project model = Central.getProject(project);
        File target = model.getTarget();
        indexFile = new File(target, INDEX_FILENAME);
        IFile indexPath = wsroot.getFile(Central.toPath(indexFile));
        new SimpleIndexer().files(files).base(project.getLocation().toFile().toURI()).name(project.getName()).analyzer((f, rb) -> {
            Capability cap = new CapabilityBuilder("bndtools.workspace").addAttribute("bndtools.workspace", workspaceRootUri.toString()).addAttribute("project.path", project.getFullPath().toString()).buildSyntheticCapability();
            rb.addCapability(cap);
        }).index(indexFile);
        indexPath.refreshLocal(IResource.DEPTH_ZERO, null);
        if (indexPath.exists())
            indexPath.setDerived(true, null);
    } catch (Exception e) {
        logger.logError(MessageFormat.format("Failed to generate index file for bundles in project {0}.", project.getName()), e);
        return;
    }
    // Parse the index and add to the workspace repository
    try (InputStream input = IO.stream(indexFile)) {
        WorkspaceR5Repository workspaceRepo = Central.getWorkspaceR5Repository();
        workspaceRepo.loadProjectIndex(project, input, project.getLocation().toFile().toURI());
    } catch (Exception e) {
        logger.logError("Failed to update workspace index.", e);
    }
}
Also used : AbstractBuildListener(org.bndtools.build.api.AbstractBuildListener) SimpleIndexer(aQute.bnd.osgi.repository.SimpleIndexer) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Project(aQute.bnd.build.Project) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) Central(bndtools.central.Central) WorkspaceR5Repository(bndtools.central.WorkspaceR5Repository) Set(java.util.Set) File(java.io.File) MessageFormat(java.text.MessageFormat) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) HashSet(java.util.HashSet) Capability(org.osgi.resource.Capability) IProject(org.eclipse.core.resources.IProject) IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource) IFile(org.eclipse.core.resources.IFile) IO(aQute.lib.io.IO) URI(java.net.URI) Logger(org.bndtools.api.Logger) InputStream(java.io.InputStream) ILogger(org.bndtools.api.ILogger) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Capability(org.osgi.resource.Capability) InputStream(java.io.InputStream) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) URI(java.net.URI) WorkspaceR5Repository(bndtools.central.WorkspaceR5Repository) Project(aQute.bnd.build.Project) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) SimpleIndexer(aQute.bnd.osgi.repository.SimpleIndexer) File(java.io.File) IFile(org.eclipse.core.resources.IFile) HashSet(java.util.HashSet)

Aggregations

WorkspaceR5Repository (bndtools.central.WorkspaceR5Repository)2 Project (aQute.bnd.build.Project)1 WorkspaceRepository (aQute.bnd.build.WorkspaceRepository)1 SimpleIndexer (aQute.bnd.osgi.repository.SimpleIndexer)1 CapabilityBuilder (aQute.bnd.osgi.resource.CapabilityBuilder)1 IO (aQute.lib.io.IO)1 Central (bndtools.central.Central)1 File (java.io.File)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 MessageFormat (java.text.MessageFormat)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ILogger (org.bndtools.api.ILogger)1 Logger (org.bndtools.api.Logger)1 AbstractBuildListener (org.bndtools.build.api.AbstractBuildListener)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1