diff options
author | Sarika Sinha | 2020-11-05 06:00:57 +0000 |
---|---|---|
committer | Sarika Sinha | 2020-11-05 06:00:57 +0000 |
commit | 5bb7e72122e0bb02d75efe535220e8ee71e01372 (patch) | |
tree | 5327b95d58e23580bea34b8221d22195d56d59d2 | |
parent | 96ed04c64d542a0c16496b03ae57c716bc140434 (diff) | |
download | eclipse.platform.debug-5bb7e72122e0bb02d75efe535220e8ee71e01372.tar.gz eclipse.platform.debug-5bb7e72122e0bb02d75efe535220e8ee71e01372.tar.xz eclipse.platform.debug-5bb7e72122e0bb02d75efe535220e8ee71e01372.zip |
Revert "Bug 567432 - Remove external tools migration code from 2004"Y20201109-0220Y20201108-1200Y20201107-1200Y20201106-1200Y20201105-1200I20201108-1800I20201107-1800I20201107-0750I20201106-1800I20201106-0710I20201105-1800I20201105-0230
This reverts commit 96ed04c64d542a0c16496b03ae57c716bc140434.
Reason for revert: Build failed as Ant test depends on the removed method.
Change-Id: Iaf1df8740db51d441ffdd484025088838cd980c8
8 files changed, 339 insertions, 5 deletions
diff --git a/org.eclipse.core.externaltools/src/org/eclipse/core/externaltools/internal/model/BuilderCoreUtils.java b/org.eclipse.core.externaltools/src/org/eclipse/core/externaltools/internal/model/BuilderCoreUtils.java index c87bac400..aed44a3a8 100644 --- a/org.eclipse.core.externaltools/src/org/eclipse/core/externaltools/internal/model/BuilderCoreUtils.java +++ b/org.eclipse.core.externaltools/src/org/eclipse/core/externaltools/internal/model/BuilderCoreUtils.java @@ -23,9 +23,12 @@ import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.DebugPlugin; @@ -243,6 +246,44 @@ public class BuilderCoreUtils { return folder; } + /** + * Migrates the launch configuration working copy, which is based on an old- + * style external tool builder, to a new, saved launch configuration. The + * returned launch configuration will contain the same attributes as the + * given working copy with the exception of the configuration name, which + * may be changed during the migration. The name of the configuration will + * only be changed if the current name is not a valid name for a saved + * config. + * + * @param workingCopy + * the launch configuration containing attributes from an + * old-style project builder. + * @return ILaunchConfiguration a new, saved launch configuration whose + * attributes match those of the given working copy as well as + * possible + * @throws CoreException + * if an exception occurs while attempting to save the new + * launch configuration + */ + public static ILaunchConfiguration migrateBuilderConfiguration( + IProject project, ILaunchConfigurationWorkingCopy workingCopy) + throws CoreException { + workingCopy.setContainer(getBuilderFolder(project, true)); + // Before saving, make sure the name is valid + String name = workingCopy.getName(); + name = name.replace('/', '.'); + if (name.charAt(0) == ('.')) { + name = name.substring(1); + } + IStatus status = ResourcesPlugin.getWorkspace().validateName(name, + IResource.FILE); + if (!status.isOK()) { + name = "ExternalTool"; //$NON-NLS-1$ + } + name = DebugPlugin.getDefault().getLaunchManager().generateLaunchConfigurationName(name); + workingCopy.rename(name); + return workingCopy.doSave(); + } /** * Converts the build types string into an array of build kinds. diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/BuilderUtils.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/BuilderUtils.java index 039cd0a7e..e0f4d21c8 100644 --- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/BuilderUtils.java +++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/BuilderUtils.java @@ -82,6 +82,20 @@ public class BuilderUtils { } /** + * Returns whether the given configuration is an "unmigrated" builder. + * Unmigrated builders are external tools that are stored in an old format + * but have not been migrated by the user. Old format builders are always + * translated into launch config working copies in memory, but they're not + * considered "migrated" until the config has been saved and the project spec + * updated. + * @param config the config to examine + * @return whether the given config represents an unmigrated builder + */ + public static boolean isUnmigratedConfig(ILaunchConfiguration config) { + return BuilderCoreUtils.isUnmigratedConfig(config); + } + + /** * Converts the given config to a build command which is stored in the * given command. * @@ -140,6 +154,25 @@ public class BuilderUtils { return newWorkingCopy.doSave(); } + /** + * Migrates the launch configuration working copy, which is based on an old- + * style external tool builder, to a new, saved launch configuration. The + * returned launch configuration will contain the same attributes as the + * given working copy with the exception of the configuration name, which + * may be changed during the migration. The name of the configuration will + * only be changed if the current name is not a valid name for a saved + * config. + * + * @param workingCopy the launch configuration containing attributes from an + * old-style project builder. + * @return ILaunchConfiguration a new, saved launch configuration whose + * attributes match those of the given working copy as well as possible + * @throws CoreException if an exception occurs while attempting to save the + * new launch configuration + */ + public static ILaunchConfiguration migrateBuilderConfiguration(IProject project, ILaunchConfigurationWorkingCopy workingCopy) throws CoreException { + return BuilderCoreUtils.migrateBuilderConfiguration(project, workingCopy); + } /** * Converts the build types string into an array of diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolsPreferenceInitializer.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolsPreferenceInitializer.java new file mode 100644 index 000000000..1c8043a5b --- /dev/null +++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolsPreferenceInitializer.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2004, 2013 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.externaltools.internal.model; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; + +public class ExternalToolsPreferenceInitializer extends AbstractPreferenceInitializer { + + public ExternalToolsPreferenceInitializer() { + super(); + } + + @Override + public void initializeDefaultPreferences() { + IPreferenceStore prefs = ExternalToolsPlugin.getDefault().getPreferenceStore(); + prefs.setDefault(IPreferenceConstants.PROMPT_FOR_TOOL_MIGRATION, true); + prefs.setDefault(IPreferenceConstants.PROMPT_FOR_PROJECT_MIGRATION, true); + } +} diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/IPreferenceConstants.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/IPreferenceConstants.java new file mode 100644 index 000000000..c63cd7e74 --- /dev/null +++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/IPreferenceConstants.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.externaltools.internal.model; + + +/** + * Constants used to identify user preferences. + */ +public interface IPreferenceConstants { + + /** + * Boolean preference key which indicates whether or not the user should be prompted + * before an external tool project builder is migrated to the new builder format. + * This is used before an old-style (Eclipse 1.0 or 2.0) builder is migrated to + * the new format (launch configurations). + */ + String PROMPT_FOR_TOOL_MIGRATION = "externaltools.builders.promptForMigration"; //$NON-NLS-1$ + /** + * Boolean preference key which indicates whether or not the user should be prompted + * before a project is migrated tot he new builder handle format. + * This is used before an old-style (Eclipse 2.1) project handle is migrated + * from the old format (launch config handles) to the new format (path to the launch). + */ + String PROMPT_FOR_PROJECT_MIGRATION = "externaltools.builders.promptForProjectMigration"; //$NON-NLS-1$ +} diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/BuilderPropertyPage.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/BuilderPropertyPage.java index e07eab8a3..2bee78fc2 100644 --- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/BuilderPropertyPage.java +++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/BuilderPropertyPage.java @@ -50,7 +50,9 @@ import org.eclipse.debug.ui.DebugUITools; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ICheckStateListener; @@ -82,6 +84,7 @@ import org.eclipse.ui.externaltools.internal.launchConfigurations.IgnoreWhiteSpa import org.eclipse.ui.externaltools.internal.model.BuilderUtils; import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin; import org.eclipse.ui.externaltools.internal.model.IExternalToolsHelpContextIds; +import org.eclipse.ui.externaltools.internal.model.IPreferenceConstants; import org.eclipse.ui.progress.IProgressService; /** @@ -211,9 +214,15 @@ public final class BuilderPropertyPage extends PropertyPage implements ICheckSta return; } + boolean projectNeedsMigration= false; for (ICommand command : commands) { String[] version= new String[] {IExternalToolConstants.EMPTY_STRING}; ILaunchConfiguration config = BuilderUtils.configFromBuildCommandArgs(project, command.getArguments(), version); + if (BuilderCoreUtils.VERSION_2_1.equals(version[0])) { + // Storing the .project file of a project with 2.1 configs, will + // edit the file in a way that isn't backwards compatible. + projectNeedsMigration= true; + } Object element= null; if (config != null) { if (!config.isWorkingCopy() && !config.exists()) { @@ -243,6 +252,29 @@ public final class BuilderPropertyPage extends PropertyPage implements ICheckSta viewer.setChecked(element, isEnabled(element)); } } + if (projectNeedsMigration) { + IPreferenceStore store= ExternalToolsPlugin.getDefault().getPreferenceStore(); + boolean prompt= store.getBoolean(IPreferenceConstants.PROMPT_FOR_PROJECT_MIGRATION); + boolean proceed= true; + if (prompt) { + Shell shell= getShell(); + if (shell == null) { + return; + } + MessageDialogWithToggle dialog= MessageDialogWithToggle.openYesNoQuestion(shell, ExternalToolsUIMessages.BuilderPropertyPage_0, ExternalToolsUIMessages.BuilderPropertyPage_1, ExternalToolsUIMessages.BuilderPropertyPage_2, false, null, null); + proceed= dialog.getReturnCode() == IDialogConstants.YES_ID; + store.setValue(IPreferenceConstants.PROMPT_FOR_PROJECT_MIGRATION, !dialog.getToggleState()); + } + if (!proceed) { + // Open the page read-only + viewer.getTable().setEnabled(false); + downButton.setEnabled(false); + editButton.setEnabled(false); + importButton.setEnabled(false); + newButton.setEnabled(false); + removeButton.setEnabled(false); + } + } } /** @@ -661,6 +693,19 @@ public final class BuilderPropertyPage extends PropertyPage implements ICheckSta Object data = selection.getData(); if (data instanceof ILaunchConfiguration) { ILaunchConfiguration config= (ILaunchConfiguration) data; + if (BuilderUtils.isUnmigratedConfig(config)) { + if (!shouldProceedWithMigration()) { + return; + } + try { + config= BuilderUtils.migrateBuilderConfiguration(getInputProject(), (ILaunchConfigurationWorkingCopy) config); + } catch (CoreException e) { + handleException(e); + return; + } + // Replace the working copy in the table with the migrated configuration + selection.setData(config); + } userHasMadeChanges= true; boolean wasAutobuilding= ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding(); try { @@ -691,6 +736,32 @@ public final class BuilderPropertyPage extends PropertyPage implements ICheckSta return Window.OK == dialog.open(); } + /** + * Prompts the user to proceed with the migration of a project builder from + * the old format to the new, launch configuration-based, format and returns + * whether or not the user wishes to proceed with the migration. + * + * @return boolean whether or not the user wishes to proceed with migration + */ + private boolean shouldProceedWithMigration() { + if (!ExternalToolsPlugin.getDefault().getPreferenceStore().getBoolean(IPreferenceConstants.PROMPT_FOR_TOOL_MIGRATION)) { + // User has asked not to be prompted + return true; + } + Shell shell= getShell(); + if (shell == null) { + return false; + } + // Warn the user that editing an old config will cause storage migration. + MessageDialogWithToggle dialog= MessageDialogWithToggle.openYesNoQuestion(getShell(), + ExternalToolsUIMessages.BuilderPropertyPage_Migrate_project_builder_10, + ExternalToolsUIMessages.BuilderPropertyPage_Not_Support, + ExternalToolsUIMessages.BuilderPropertyPage_Prompt, + false, + ExternalToolsPlugin.getDefault().getPreferenceStore(), + IPreferenceConstants.PROMPT_FOR_TOOL_MIGRATION); + return dialog.getReturnCode() == IDialogConstants.YES_ID; + } /** * Handles unexpected internal exceptions @@ -917,17 +988,17 @@ public final class BuilderPropertyPage extends PropertyPage implements ICheckSta } } catch (CoreException e1) { } - if (config instanceof ILaunchConfigurationWorkingCopy) { - ILaunchConfigurationWorkingCopy workingCopy = ((ILaunchConfigurationWorkingCopy) config); + + if (!BuilderUtils.isUnmigratedConfig(config) && (config instanceof ILaunchConfigurationWorkingCopy)) { + ILaunchConfigurationWorkingCopy workingCopy= ((ILaunchConfigurationWorkingCopy) config); // Save any changes to the config (such as enable/disable) if (workingCopy.isDirty()) { try { workingCopy.doSave(); } catch (CoreException e) { - Shell shell = getShell(); + Shell shell= getShell(); if (shell != null) { - MessageDialog.openError(shell, ExternalToolsUIMessages.BuilderPropertyPage_39, NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_40, new String[] { - workingCopy.getName() })); + MessageDialog.openError(shell, ExternalToolsUIMessages.BuilderPropertyPage_39, NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_40, new String[] {workingCopy.getName()})); } } } diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/ExternalToolsPreferencePage.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/ExternalToolsPreferencePage.java new file mode 100644 index 000000000..b3728dfbe --- /dev/null +++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/ExternalToolsPreferencePage.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2000, 2013 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Frederic Gurr - Fixed restore default behavior (bug 346082) + *******************************************************************************/ +package org.eclipse.ui.externaltools.internal.ui; + + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin; +import org.eclipse.ui.externaltools.internal.model.IExternalToolsHelpContextIds; +import org.eclipse.ui.externaltools.internal.model.IPreferenceConstants; + +/** + * Preference page that allows the user to customize external tools + */ +public class ExternalToolsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + + private Button promptForToolMigrationButton; + private Button promptForProjectMigrationButton; + + public ExternalToolsPreferencePage() { + setPreferenceStore(ExternalToolsPlugin.getDefault().getPreferenceStore()); + setDescription(ExternalToolsUIMessages.ExternalToolsPreferencePage_External_tool_project_builders_migration_2); + } + + /** + * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createContents(Composite parent) { + PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IExternalToolsHelpContextIds.EXTERNAL_TOOLS_PREFERENCE_PAGE); + //The main composite + Composite composite = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + layout.marginHeight=0; + layout.marginWidth=0; + composite.setLayout(layout); + composite.setFont(parent.getFont()); + + promptForToolMigrationButton= createCheckButton(composite, ExternalToolsUIMessages.ExternalToolsPreferencePage_Prompt_before_migrating_3, IPreferenceConstants.PROMPT_FOR_TOOL_MIGRATION); + promptForProjectMigrationButton= createCheckButton(composite, ExternalToolsUIMessages.ExternalToolsPreferencePage_1, IPreferenceConstants.PROMPT_FOR_PROJECT_MIGRATION); + + applyDialogFont(composite); + + return composite; + } + + /** + * Returns a new check button with the given label for the given preference. + */ + private Button createCheckButton(Composite parent, String label, String preferenceKey) { + Button button= new Button(parent, SWT.CHECK | SWT.LEFT); + button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); + button.setFont(parent.getFont()); + button.setText(label); + button.setSelection(getPreferenceStore().getBoolean(preferenceKey)); + return button; + } + + /** + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + */ + @Override + public void init(IWorkbench workbench) { + } + + /** + * @see org.eclipse.jface.preference.PreferencePage#performOk() + */ + @Override + public boolean performOk() { + getPreferenceStore().setValue(IPreferenceConstants.PROMPT_FOR_TOOL_MIGRATION, promptForToolMigrationButton.getSelection()); + getPreferenceStore().setValue(IPreferenceConstants.PROMPT_FOR_PROJECT_MIGRATION, promptForProjectMigrationButton.getSelection()); + return super.performOk(); + } + + /** + * @see org.eclipse.jface.preference.PreferencePage#performDefaults() + */ + @Override + protected void performDefaults() { + promptForToolMigrationButton.setSelection(getPreferenceStore().getDefaultBoolean(IPreferenceConstants.PROMPT_FOR_TOOL_MIGRATION)); + promptForProjectMigrationButton.setSelection(getPreferenceStore().getDefaultBoolean(IPreferenceConstants.PROMPT_FOR_PROJECT_MIGRATION)); + super.performDefaults(); + } +} diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/ExternalToolsUIMessages.properties b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/ExternalToolsUIMessages.properties index e28068367..6c8b79ce6 100644 --- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/ExternalToolsUIMessages.properties +++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/ExternalToolsUIMessages.properties @@ -49,6 +49,10 @@ FileSelectionDialog_Choose_Location_1=Choose Location FileSelectionDialog_Ok_2=OK FileSelectionDialog_Cancel_3=Cancel +ExternalToolsPreferencePage_External_tool_project_builders_migration_2=External tool project builders stored in an old format will be migrated to a new format when edited. Projects which store builders using an old format will be migrated whenever a change is made. Once migrated, project builders will not be understood by installations using these older formats. +ExternalToolsPreferencePage_Prompt_before_migrating_3=&Confirm before migrating external tool project builders for edit +ExternalToolsPreferencePage_1=C&onfirm before migrating projects to the new format + EditCommandDialog_0=Configure Builder EditCommandDialog_1=Run this builder: EditCommandDialog_2=After a "&Clean" diff --git a/org.eclipse.ui.externaltools/plugin.xml b/org.eclipse.ui.externaltools/plugin.xml index 1809465e3..3800d0d63 100644 --- a/org.eclipse.ui.externaltools/plugin.xml +++ b/org.eclipse.ui.externaltools/plugin.xml @@ -78,6 +78,15 @@ </command> </extension> <extension + point="org.eclipse.ui.preferencePages"> + <page + name="%PreferencePage.externalToolsPreferences" + category="org.eclipse.debug.ui.DebugPreferencePage" + class="org.eclipse.ui.externaltools.internal.ui.ExternalToolsPreferencePage" + id="org.eclipse.ui.externaltools.ExternalToolsPreferencePage"> + </page> + </extension> + <extension point="org.eclipse.ui.propertyPages"> <page name="%PropertyPage.externalToolsBuilders" @@ -189,5 +198,9 @@ id="org.eclipse.ui.externaltools.workingSetComparator"> </launchConfigurationComparator> </extension> + + <extension point="org.eclipse.core.runtime.preferences"> + <initializer class="org.eclipse.ui.externaltools.internal.model.ExternalToolsPreferenceInitializer"/> + </extension> </plugin> |