### Eclipse Workspace Patch 1.0 #P org.eclipse.pde.ui Index: src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java,v retrieving revision 1.45 diff -u -r1.45 PluginImportWizard.java --- src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java 8 Jun 2007 16:43:37 -0000 1.45 +++ src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java 19 Nov 2007 15:19:49 -0000 @@ -10,21 +10,30 @@ *******************************************************************************/ package org.eclipse.pde.internal.ui.wizards.imports; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchManager; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.Wizard; +import org.eclipse.osgi.service.resolver.BundleDescription; import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.internal.ui.PDEPlugin; import org.eclipse.pde.internal.ui.PDEPluginImages; import org.eclipse.pde.internal.ui.PDEUIMessages; +import org.eclipse.pde.internal.ui.launcher.BundleLauncherHelper; import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation.IImportQuery; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -35,16 +44,17 @@ private static final String STORE_SECTION = "PluginImportWizard"; //$NON-NLS-1$ - private IStructuredSelection selection; + private IStructuredSelection selection; private PluginImportWizardFirstPage page1; private BaseImportWizardSecondPage page2; private BaseImportWizardSecondPage page3; public PluginImportWizard() { - IDialogSettings masterSettings = PDEPlugin.getDefault().getDialogSettings(); + IDialogSettings masterSettings = PDEPlugin.getDefault() + .getDialogSettings(); setDialogSettings(getSettingsSection(masterSettings)); setDefaultPageImageDescriptor(PDEPluginImages.DESC_PLUGIN_IMPORT_WIZ); - setWindowTitle(PDEUIMessages.ImportWizard_title); + setWindowTitle(PDEUIMessages.ImportWizard_title); } public void init(IWorkbench workbench, IStructuredSelection selection) { @@ -77,22 +87,69 @@ public boolean performFinish() { page1.storeSettings(); - ((BaseImportWizardSecondPage)page1.getNextPage()).storeSettings(); - + ((BaseImportWizardSecondPage) page1.getNextPage()).storeSettings(); + if (!doCheckLaunches()) { + MessageDialog.openInformation(getShell(), "Import problem", + "Some plugins cannot be imported due to workspace locking"); + return false; + } final IPluginModelBase[] models = getModelsToImport(); - doImportOperation(getShell(), page1.getImportType(), models, page2.forceAutoBuild()); + doImportOperation(getShell(), page1.getImportType(), models, page2 + .forceAutoBuild()); return true; } - public static void doImportOperation( - final Shell shell, - final int importType, - final IPluginModelBase[] models, + /** + * @return true if there is no problem with locked plugins + */ + private boolean doCheckLaunches() { + ILaunchManager launchManager = DebugPlugin.getDefault() + .getLaunchManager(); + ILaunch[] launches = launchManager.getLaunches(); + IPluginModelBase[] modelsToImport = getModelsToImport(); + HashMap imported = new HashMap(); + for (int j = 0; j < modelsToImport.length; ++j) { + BundleDescription bd = modelsToImport[j].getBundleDescription(); + if (bd != null) { + imported.put(bd.getSymbolicName(), modelsToImport[j]); + } + } + for (int i = 0; i < launches.length; ++i) { + if (!launches[i].isTerminated()) { + ILaunchConfiguration configuration = launches[i] + .getLaunchConfiguration(); + try { + Map workspaceBundleMap = BundleLauncherHelper + .getWorkspaceBundleMap(configuration, null); + for (Iterator iter = workspaceBundleMap.keySet().iterator(); iter + .hasNext();) { + IPluginModelBase bm = (IPluginModelBase) iter.next(); + BundleDescription description = bm + .getBundleDescription(); + if (description != null) { + imported.remove(description.getSymbolicName()); + } + if (imported.size() == 0) //there is no need to check next bundles + return false; + } + return imported.size() == modelsToImport.length; + } catch (CoreException e) { + PDEPlugin.logException(e); + return false; + } + } + } + return true; + } + + public static void doImportOperation(final Shell shell, + final int importType, final IPluginModelBase[] models, final boolean forceAutobuild) { PluginImportOperation.IImportQuery query = new ImportQuery(shell); - PluginImportOperation.IImportQuery executionQuery = new ImportQuery(shell); - final PluginImportOperation op = - new PluginImportOperation(models, importType, query, executionQuery, forceAutobuild); + PluginImportOperation.IImportQuery executionQuery = new ImportQuery( + shell); + final PluginImportOperation op = new PluginImportOperation(models, + importType, query, executionQuery, forceAutobuild); Job job = new Job(PDEUIMessages.ImportWizard_title) { protected IStatus run(IProgressMonitor monitor) { try { @@ -108,36 +165,25 @@ job.schedule(); } - private static class ReplaceDialog extends MessageDialog { public ReplaceDialog(Shell parentShell, String dialogMessage) { - super( - parentShell, - PDEUIMessages.ImportWizard_messages_title, - null, - dialogMessage, - MessageDialog.QUESTION, - new String[] { + super(parentShell, PDEUIMessages.ImportWizard_messages_title, null, + dialogMessage, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, - PDEUIMessages.ImportWizard_noToAll, - IDialogConstants.CANCEL_LABEL }, - 0); + PDEUIMessages.ImportWizard_noToAll, + IDialogConstants.CANCEL_LABEL }, 0); } } public static class ImportQuery implements IImportQuery { - public ImportQuery(Shell shell) {} + public ImportQuery(Shell shell) { + } private int yesToAll = 0; - private int[] RETURNCODES = - { - IImportQuery.YES, - IImportQuery.YES, - IImportQuery.NO, - IImportQuery.NO, - IImportQuery.CANCEL }; + private int[] RETURNCODES = { IImportQuery.YES, IImportQuery.YES, + IImportQuery.NO, IImportQuery.NO, IImportQuery.CANCEL }; public int doQuery(final String message) { if (yesToAll != 0) { @@ -147,7 +193,8 @@ final int[] result = { IImportQuery.CANCEL }; Display.getDefault().syncExec(new Runnable() { public void run() { - ReplaceDialog dialog = new ReplaceDialog(Display.getDefault().getActiveShell(), message); + ReplaceDialog dialog = new ReplaceDialog(Display + .getDefault().getActiveShell(), message); int retVal = dialog.open(); if (retVal >= 0) { result[0] = RETURNCODES[retVal]; @@ -168,7 +215,7 @@ if (page1.getScanAllPlugins()) { return page3; } - return page2; + return page2; } return null; } Index: src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java,v retrieving revision 1.109 diff -u -r1.109 PluginImportOperation.java --- src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java 8 Jun 2007 16:43:37 -0000 1.109 +++ src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java 19 Nov 2007 15:19:49 -0000 @@ -245,6 +245,7 @@ if (project.hasNature(JavaCore.NATURE_ID) && project.findMember(".classpath") == null) //$NON-NLS-1$ fProjectClasspaths .put(project, ClasspathComputer.getClasspath(project, model, true)); } catch (CoreException e) { + PDEPlugin.logException(e); } finally { monitor.done(); }