Search in sources :

Example 1 with ProvisioningUI

use of org.eclipse.equinox.p2.ui.ProvisioningUI in project knime-core by knime.

the class InstallMissingNodesJob method startInstallJob.

private void startInstallJob(final Set<IInstallableUnit> featuresToInstall) {
    final ProvisioningUI provUI = ProvisioningUI.getDefaultUI();
    Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
    final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(provUI);
    loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
    loadJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(final IJobChangeEvent event) {
            if (PlatformUI.isWorkbenchRunning() && event.getResult().isOK()) {
                Display.getDefault().asyncExec(() -> {
                    if (Display.getDefault().isDisposed()) {
                        NodeLogger.getLogger("Display disposed, aborting install action");
                        // fixes AP-8376, AP-8380, AP-7184
                        return;
                    }
                    provUI.getPolicy().setRepositoriesVisible(false);
                    provUI.openInstallWizard(featuresToInstall, new InstallOperation(provUI.getSession(), featuresToInstall), loadJob);
                    provUI.getPolicy().setRepositoriesVisible(true);
                });
            }
        }
    });
    loadJob.setUser(true);
    loadJob.schedule();
}
Also used : ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) InstallOperation(org.eclipse.equinox.p2.operations.InstallOperation) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)

Example 2 with ProvisioningUI

use of org.eclipse.equinox.p2.ui.ProvisioningUI in project knime-core by knime.

the class BugfixMessageInjector method checkNewMinorVersion.

private List<String> checkNewMinorVersion() throws IOException, URISyntaxException {
    final ProvisioningUI provUI = ProvisioningUI.getDefaultUI();
    RepositoryTracker tracker = provUI.getRepositoryTracker();
    if (tracker == null) {
        // if run from the IDE there will be no tracker
        return Collections.emptyList();
    }
    UpdateOperation op = new UpdateOperation(provUI.getSession());
    op.resolveModal(new NullProgressMonitor());
    return Stream.of(op.getPossibleUpdates()).map(u -> u.toUpdate.getProperty("org.eclipse.equinox.p2.name")).sorted().distinct().collect(Collectors.toList());
}
Also used : RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ReentrantLock(java.util.concurrent.locks.ReentrantLock) TransformerException(javax.xml.transform.TransformerException) XPath(javax.xml.xpath.XPath) XPathConstants(javax.xml.xpath.XPathConstants) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) Collectors(java.util.stream.Collectors) File(java.io.File) XPathFactory(javax.xml.xpath.XPathFactory) List(java.util.List) Stream(java.util.stream.Stream) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Document(org.w3c.dom.Document) UpdateOperation(org.eclipse.equinox.p2.operations.UpdateOperation) SAXException(org.xml.sax.SAXException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Collections(java.util.Collections) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) UpdateOperation(org.eclipse.equinox.p2.operations.UpdateOperation) RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker)

Example 3 with ProvisioningUI

use of org.eclipse.equinox.p2.ui.ProvisioningUI in project knime-core by knime.

the class AbstractP2Action method checkSDKAndReadOnly.

/**
 * Checks whether the current instance is run from an SDK and if the configuration area is writable.
 *
 * @return <code>true</code> if the action should continue, <code>false</code> if it should be aborted
 */
protected final boolean checkSDKAndReadOnly() {
    final ProvisioningUI provUI = ProvisioningUI.getDefaultUI();
    if (provUI.getRepositoryTracker() == null) {
        MessageBox mbox = new MessageBox(ProvUI.getDefaultParentShell(), SWT.ICON_WARNING | SWT.OK);
        mbox.setText("Action impossible");
        mbox.setMessage("It seems you are running KNIME from an SDK. " + "Installing extension is not possible in this case.");
        mbox.open();
        return false;
    }
    String installLocation = Platform.getInstallLocation().getURL().toString();
    String configurationLocation = Platform.getConfigurationLocation().getURL().toString();
    if (!configurationLocation.contains(installLocation)) {
        MessageBox mbox = new MessageBox(ProvUI.getDefaultParentShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO);
        mbox.setText("Permission problem");
        mbox.setMessage("Your KNIME installation directory seems to be " + "read-only, maybe because KNIME was installed by a " + "different user. Installing extensions or updating KNIME " + "may cause problems. Do you really want to continue?");
        return (mbox.open() == SWT.YES);
    }
    return true;
}
Also used : ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 4 with ProvisioningUI

use of org.eclipse.equinox.p2.ui.ProvisioningUI in project gemoc-studio by eclipse.

the class PrepareInstallProfileJob method run.

public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException {
    try {
        SubMonitor monitor = SubMonitor.convert(progressMonitor, Messages.InstallConnectorsJob_task_configuring, 100);
        try {
            final Collection<IInstallableUnit> ius = computeInstallableUnits(monitor.newChild(50));
            checkCancelled(monitor);
            final InstallOperation installOperation = resolve(monitor.newChild(50), ius, repositoryLocations.toArray(new URI[0]));
            checkCancelled(monitor);
            if (!headless) {
                Display.getDefault().asyncExec(new Runnable() {

                    public void run() {
                        openInstallWizard(provisioningUI, ius, installOperation);
                    }
                });
            }
        } finally {
            monitor.done();
        }
    } catch (OperationCanceledException e) {
        throw new InterruptedException();
    } catch (Exception e) {
        throw new InvocationTargetException(e);
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) InstallOperation(org.eclipse.equinox.p2.operations.InstallOperation) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) MalformedURLException(java.net.MalformedURLException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with ProvisioningUI

use of org.eclipse.equinox.p2.ui.ProvisioningUI in project azure-tools-for-java by Microsoft.

the class PluginUtil method forceInstallPluginUsingP2.

private static void forceInstallPluginUsingP2(String pluginGroupID) {
    URI repoURI = getEclipseP2Repository();
    ProvisioningUI provisioningUI = ProvisioningUI.getDefaultUI();
    if (provisioningUI != null && repoURI != null) {
        ProvisioningSession provisioningSession = provisioningUI.getSession();
        IProvisioningAgent provisioningAgent = null;
        if (provisioningSession != null && (provisioningAgent = provisioningSession.getProvisioningAgent()) != null) {
            IMetadataRepositoryManager manager = (IMetadataRepositoryManager) provisioningAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);
            if (manager != null) {
                try {
                    IMetadataRepository repository = manager.loadRepository(repoURI, null);
                    if (repository != null) {
                        IQueryResult<IInstallableUnit> iqr = repository.query(QueryUtil.createIUQuery(pluginGroupID), null);
                        if (iqr != null) {
                            Collection<IInstallableUnit> iuList = StreamSupport.stream(iqr.spliterator(), false).collect(Collectors.toList());
                            if (iuList.size() > 0) {
                                InstallOperation io = new InstallOperation(provisioningSession, iuList);
                                provisioningUI.openInstallWizard(iuList, io, null);
                                return;
                            }
                        }
                    }
                } catch (Exception e) {
                    String errorMsg = "Error installing " + pluginGroupID + "! Please manually install using Eclipse P2 repository from: Help -> Install New Software.... Click OK to continue.";
                    PluginUtil.displayErrorDialogAndLog(getParentShell(), "Fail to install", errorMsg, e);
                }
            }
        }
    }
    String errorMsg = "Error installing " + pluginGroupID + "! In the following installation wizard, please select the right repository and then filter by " + pluginGroupID + "! Click OK to continue.";
    PluginUtil.displayErrorDialogAndLog(getParentShell(), "Fail to install", errorMsg, null);
    provisioningUI.openInstallWizard(null, null, null);
}
Also used : ProvisioningSession(org.eclipse.equinox.p2.operations.ProvisioningSession) IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) InstallOperation(org.eclipse.equinox.p2.operations.InstallOperation) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) URI(java.net.URI) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Aggregations

ProvisioningUI (org.eclipse.equinox.p2.ui.ProvisioningUI)10 URI (java.net.URI)5 RepositoryTracker (org.eclipse.equinox.p2.operations.RepositoryTracker)4 IOException (java.io.IOException)3 CoreException (org.eclipse.core.runtime.CoreException)3 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)3 InstallOperation (org.eclipse.equinox.p2.operations.InstallOperation)3 ProvisioningSession (org.eclipse.equinox.p2.operations.ProvisioningSession)3 UpdateOperation (org.eclipse.equinox.p2.operations.UpdateOperation)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URISyntaxException (java.net.URISyntaxException)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2 IProvisioningAgent (org.eclipse.equinox.p2.core.IProvisioningAgent)2 LoadMetadataRepositoryJob (org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1