Search in sources :

Example 1 with RemoteRepositoryPlugin

use of aQute.bnd.service.RemoteRepositoryPlugin in project bndtools by bndtools.

the class RepositoryEntry method getFile.

public final File getFile(boolean forceDownload) {
    File result;
    try {
        if (repo instanceof RemoteRepositoryPlugin) {
            ResourceHandle handle = ((RemoteRepositoryPlugin) repo).getHandle(bsn, versionFinder.versionSpec, versionFinder.strategy, Collections.<String, String>emptyMap());
            switch(handle.getLocation()) {
                case local:
                case remote_cached:
                    result = handle.request();
                    break;
                default:
                    result = forceDownload ? handle.request() : null;
            }
        } else {
            Version version = versionFinder.findVersion();
            result = (version != null) ? repo.get(bsn, version, Collections.<String, String>emptyMap()) : null;
        }
        return result;
    } catch (Exception e) {
        logger.logError(MessageFormat.format("Failed to query repository {0} for bundle {1} version {2}.", repo.getName(), bsn, versionFinder), e);
        return null;
    }
}
Also used : Version(aQute.bnd.version.Version) ResourceHandle(aQute.bnd.service.ResourceHandle) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) File(java.io.File) IFile(org.eclipse.core.resources.IFile)

Example 2 with RemoteRepositoryPlugin

use of aQute.bnd.service.RemoteRepositoryPlugin in project bndtools by bndtools.

the class RepositoriesView method createActions.

void createActions() {
    collapseAllAction = new Action() {

        @Override
        public void run() {
            viewer.collapseAll();
        }
    };
    collapseAllAction.setEnabled(false);
    collapseAllAction.setText("Collapse All");
    collapseAllAction.setToolTipText("Collapse All");
    collapseAllAction.setImageDescriptor(Icons.desc("collapse"));
    collapseAllAction.setDisabledImageDescriptor(Icons.desc("collapse.disabled"));
    refreshAction = new Action() {

        @Override
        public void run() {
            new WorkspaceJob("Refresh repositories") {

                @Override
                public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                    if (monitor == null)
                        monitor = new NullProgressMonitor();
                    monitor.subTask("Refresh all repositories");
                    try {
                        refreshAction.setEnabled(false);
                        Central.refreshPlugins();
                    } catch (Exception e) {
                        Throwable t = e;
                        while (t instanceof InvocationTargetException) t = ((InvocationTargetException) e).getTargetException();
                        logger.logError("Unexpected error in refreshing plugns", t);
                        return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Failed to refresh plugins", t);
                    } finally {
                        refreshAction.setEnabled(true);
                    }
                    return Status.OK_STATUS;
                }
            }.schedule();
        }
    };
    refreshAction.setEnabled(false);
    refreshAction.setText("Refresh");
    refreshAction.setToolTipText("Refresh Repositories Tree");
    refreshAction.setImageDescriptor(Icons.desc("refresh"));
    refreshAction.setDisabledImageDescriptor(Icons.desc("refresh.disabled"));
    addBundlesAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object element = selection.getFirstElement();
            if (element != null && element instanceof RepositoryPlugin) {
                RepositoryPlugin repo = (RepositoryPlugin) element;
                if (repo.canWrite()) {
                    AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(repo, new File[0]);
                    WizardDialog dialog = new WizardDialog(getViewSite().getShell(), wizard);
                    dialog.open();
                    viewer.refresh(repo);
                }
            }
        }
    };
    addBundlesAction.setEnabled(false);
    addBundlesAction.setText("Add");
    addBundlesAction.setToolTipText("Add Bundles to Repository");
    addBundlesAction.setImageDescriptor(Icons.desc("add"));
    addBundlesAction.setDisabledImageDescriptor(Icons.desc("add.disabled"));
    advancedSearchAction = new Action("Advanced Search", IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            if (advancedSearchAction.isChecked()) {
                AdvancedSearchDialog dialog = new AdvancedSearchDialog(getSite().getShell());
                if (advancedSearchState != null) {
                    try {
                        XMLMemento memento = XMLMemento.createReadRoot(new StringReader(advancedSearchState));
                        dialog.restoreState(memento);
                    } catch (Exception e) {
                        logger.logError("Failed to load dialog state", e);
                    }
                }
                if (Window.OK == dialog.open()) {
                    Requirement req = dialog.getRequirement();
                    contentProvider.setRequirementFilter(req);
                    SWTUtil.recurseEnable(false, filterPanel);
                    viewer.refresh();
                    viewer.expandToLevel(2);
                } else {
                    advancedSearchAction.setChecked(false);
                }
                try {
                    XMLMemento memento = XMLMemento.createWriteRoot("search");
                    dialog.saveState(memento);
                    StringWriter writer = new StringWriter();
                    memento.save(writer);
                    advancedSearchState = writer.toString();
                } catch (Exception e) {
                    logger.logError("Failed to save dialog state", e);
                }
            } else {
                contentProvider.setRequirementFilter(null);
                SWTUtil.recurseEnable(true, filterPanel);
                viewer.refresh();
            }
        }
    };
    advancedSearchAction.setEnabled(false);
    advancedSearchAction.setText("Advanced Search");
    advancedSearchAction.setToolTipText("Toggle Advanced Search");
    advancedSearchAction.setImageDescriptor(Icons.desc("search"));
    advancedSearchAction.setDisabledImageDescriptor(Icons.desc("search.disabled"));
    downloadAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            // The set of Repos included in the selection; they will be completely downloaded.
            Set<RemoteRepositoryPlugin> repos = Collections.newSetFromMap(new IdentityHashMap<>());
            repos.addAll(selectionByType(selection, RemoteRepositoryPlugin.class));
            // The set of Bundles included in the selection.
            Set<RepositoryBundle> bundles = Collections.newSetFromMap(new IdentityHashMap<>());
            for (RepositoryBundle bundle : selectionByType(selection, RepositoryBundle.class)) {
                // filter out bundles that come from already-selected repos.
                if (!repos.contains(bundle.getRepo()))
                    bundles.add(bundle);
            }
            // The set of Bundle Versions included in the selection
            Set<RepositoryBundleVersion> bundleVersions = Collections.newSetFromMap(new IdentityHashMap<>());
            for (RepositoryBundleVersion bundleVersion : selectionByType(selection, RepositoryBundleVersion.class)) {
                // filter out bundles that come from already-selected repos.
                if (!repos.contains(bundleVersion.getRepo()))
                    bundleVersions.add(bundleVersion);
            }
            RepoDownloadJob downloadJob = new RepoDownloadJob(repos, bundles, bundleVersions);
            downloadJob.schedule();
        }

        private <T> List<T> selectionByType(IStructuredSelection selection, Class<T> type) {
            List<T> result = new ArrayList<T>(selection.size());
            @SuppressWarnings("unchecked") Iterator<Object> iterator = selection.iterator();
            while (iterator.hasNext()) {
                Object item = iterator.next();
                if (type.isInstance(item)) {
                    @SuppressWarnings("unchecked") T cast = (T) item;
                    result.add(cast);
                }
            }
            return result;
        }
    };
    downloadAction.setEnabled(false);
    downloadAction.setText("Download Repository Content");
    downloadAction.setImageDescriptor(Icons.desc("download"));
    downloadAction.setDisabledImageDescriptor(Icons.desc("download.disabled"));
    offlineAction = new Action("Online/Offline Mode", IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            Workspace workspace = Central.getWorkspaceIfPresent();
            if (workspace != null) {
                prefs.setWorkspaceOffline(offlineAction.isChecked());
            }
        }
    };
    offlineAction.setEnabled(false);
    offlineAction.setToolTipText("Go Offline");
    offlineAction.setImageDescriptor(Icons.desc("connected"));
    offlineAction.setDisabledImageDescriptor(Icons.desc("connected.disabled"));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            boolean enable = false;
            @SuppressWarnings("unchecked") List<Object> list = selection.toList();
            for (Object item : list) {
                if (item instanceof RemoteRepositoryPlugin) {
                    enable = true;
                    break;
                } else if (item instanceof RepositoryEntry) {
                    if (!((RepositoryEntry) item).isLocal()) {
                        enable = true;
                        break;
                    }
                }
            }
            downloadAction.setEnabled(enable);
        }
    });
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) Set(java.util.Set) AddFilesToRepositoryWizard(bndtools.wizards.workspace.AddFilesToRepositoryWizard) IdentityHashMap(java.util.IdentityHashMap) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryEntry(bndtools.model.repo.RepositoryEntry) StringWriter(java.io.StringWriter) SWT(org.eclipse.swt.SWT) StringReader(java.io.StringReader) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Requirement(org.osgi.resource.Requirement) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) XMLMemento(org.eclipse.ui.XMLMemento) IFile(org.eclipse.core.resources.IFile) File(java.io.File) JarFile(java.util.jar.JarFile) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Workspace(aQute.bnd.build.Workspace)

Example 3 with RemoteRepositoryPlugin

use of aQute.bnd.service.RemoteRepositoryPlugin in project bndtools by bndtools.

the class RepositoryEntry method isLocal.

public final boolean isLocal() {
    boolean result = true;
    try {
        if (repo instanceof RemoteRepositoryPlugin) {
            ResourceHandle handle = ((RemoteRepositoryPlugin) repo).getHandle(bsn, versionFinder.versionSpec, versionFinder.strategy, Collections.<String, String>emptyMap());
            Location location = handle.getLocation();
            result = location == Location.local || location == Location.remote_cached;
        }
    } catch (Exception e) {
        logger.logError(MessageFormat.format("Failed to query repository {0} for bundle {1} version {2}.", repo.getName(), bsn, versionFinder), e);
    }
    return result;
}
Also used : ResourceHandle(aQute.bnd.service.ResourceHandle) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) InvocationTargetException(java.lang.reflect.InvocationTargetException) Location(aQute.bnd.service.ResourceHandle.Location)

Example 4 with RemoteRepositoryPlugin

use of aQute.bnd.service.RemoteRepositoryPlugin in project bndtools by bndtools.

the class RepoDownloadJob method run.

@Override
protected IStatus run(IProgressMonitor progress) {
    SubMonitor monitor = SubMonitor.convert(progress);
    boolean locked = LOCK.tryLock();
    try {
        while (!locked) {
            monitor.setBlocked(new Status(IStatus.INFO, Plugin.PLUGIN_ID, 0, "Waiting for other download jobs to complete.", null));
            if (progress.isCanceled())
                return Status.CANCEL_STATUS;
            try {
                locked = LOCK.tryLock(5, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
            }
        }
        monitor.clearBlocked();
        MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, "One or more repository files failed to download.", null);
        monitor.setTaskName("Expanding repository contents");
        List<RepositoryBundleVersion> rbvs = new LinkedList<RepositoryBundleVersion>();
        try {
            for (RemoteRepositoryPlugin repo : repos) {
                expandContentsInto(repo, rbvs);
            }
            for (RepositoryBundle bundle : bundles) {
                expandContentsInto(bundle, rbvs);
            }
            rbvs.addAll(bundleVersions);
        } catch (Exception e) {
            return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error listing repository contents", e);
        }
        monitor.setWorkRemaining(rbvs.size());
        for (RepositoryBundleVersion rbv : rbvs) {
            if (monitor.isCanceled())
                return Status.CANCEL_STATUS;
            String resourceName = "<<unknown>>";
            try {
                RemoteRepositoryPlugin repo = (RemoteRepositoryPlugin) rbv.getRepo();
                ResourceHandle handle = repo.getHandle(rbv.getBsn(), rbv.getVersion().toString(), Strategy.EXACT, Collections.<String, String>emptyMap());
                resourceName = handle.getName();
                Location location = handle.getLocation();
                if (location == Location.remote) {
                    monitor.setTaskName("Downloading " + handle.getName());
                    handle.request();
                }
            } catch (Exception e) {
                status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, String.format("Download of %s:%s with remote name %s failed", rbv.getBsn(), rbv.getVersion(), resourceName), e));
            } finally {
                monitor.worked(1);
            }
        }
        return status;
    } finally {
        if (locked)
            LOCK.unlock();
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RepositoryBundle(bndtools.model.repo.RepositoryBundle) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) LinkedList(java.util.LinkedList) ResourceHandle(aQute.bnd.service.ResourceHandle) Location(aQute.bnd.service.ResourceHandle.Location)

Aggregations

RemoteRepositoryPlugin (aQute.bnd.service.RemoteRepositoryPlugin)4 ResourceHandle (aQute.bnd.service.ResourceHandle)3 Location (aQute.bnd.service.ResourceHandle.Location)2 RepositoryBundle (bndtools.model.repo.RepositoryBundle)2 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)2 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IFile (org.eclipse.core.resources.IFile)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Workspace (aQute.bnd.build.Workspace)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 Version (aQute.bnd.version.Version)1 RepositoryEntry (bndtools.model.repo.RepositoryEntry)1 AddFilesToRepositoryWizard (bndtools.wizards.workspace.AddFilesToRepositoryWizard)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1