Remove old legacy project and project conversion code

This commit is contained in:
aboyko
2023-10-12 10:19:15 -04:00
parent 4fe5be7711
commit 2b85fb3d1f
14 changed files with 2 additions and 1216 deletions

View File

@@ -25,7 +25,6 @@ Export-Package: org.springsource.ide.eclipse.commons.frameworks.core,
org.springsource.ide.eclipse.commons.frameworks.core.internal.commands,
org.springsource.ide.eclipse.commons.frameworks.core.internal.java,
org.springsource.ide.eclipse.commons.frameworks.core.internal.plugins,
org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion,
org.springsource.ide.eclipse.commons.frameworks.core.maintype,
org.springsource.ide.eclipse.commons.frameworks.core.util,
org.springsource.ide.eclipse.commons.frameworks.core.workspace

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* Copyright (c) 2012, 2023 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,13 +10,10 @@
*******************************************************************************/
package org.springsource.ide.eclipse.commons.frameworks.core;
import java.net.URISyntaxException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.IConversionConstants;
/**
* @author Nieraj Singh
@@ -91,26 +88,5 @@ public class FrameworkCoreActivator extends AbstractUIPlugin {
}
return new Status(IStatus.WARNING, PLUGIN_ID, 0, message, exception);
}
/**
* Returns true if the plugin id has not yet run legacy conversion for this workspace yet
* @param pluginid plugin id to check
* @return true iff legacy conversion has not taken place for this plugin, but it has for the workspace as a whole
*/
public boolean shouldMigratePlugin(String pluginid) {
if (getPreferenceStore().getBoolean(IConversionConstants.LEGACY_MIGRATION_ALREADY_DONE)) {
String plugins = getPreferenceStore().getString(IConversionConstants.LEGACY_MIGRATION_PLUGINS);
return plugins.contains("," + pluginid + ","); //$NON-NLS-1$ //$NON-NLS-2$
} else {
// workspace legacy migration has not yet been successfully performed
return false;
}
}
public void registerPluginMigrationComplete(String pluginid) {
String plugins = getPreferenceStore().getString(IConversionConstants.LEGACY_MIGRATION_PLUGINS);
plugins += "," + pluginid + ","; //$NON-NLS-1$ //$NON-NLS-2$
getPreferenceStore().putValue(IConversionConstants.LEGACY_MIGRATION_PLUGINS, plugins);
}
}

View File

@@ -1,122 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.Properties;
import java.util.Map.Entry;
import org.eclipse.core.internal.utils.FileUtil;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.springsource.ide.eclipse.commons.frameworks.core.FrameworkCoreActivator;
/**
* Shared methods between the two converter classes
* @author Andrew Eisenberg
* @since 3.0.0
*/
public abstract class AbstractLegacyConverter implements IConversionConstants {
public abstract IStatus convert(IProgressMonitor monitor);
protected void copyPluginStateLocation(String from,
String to) throws IOException {
File oldPreferencesFolder = FrameworkCoreActivator.getDefault().getStateLocation().removeLastSegments(1).append(from).toFile();
if (oldPreferencesFolder.exists() && oldPreferencesFolder.isDirectory()) {
File newPreferencesFolder = FrameworkCoreActivator.getDefault().getStateLocation().removeLastSegments(1).append(to).toFile();
copyDirectory(oldPreferencesFolder, newPreferencesFolder);
}
}
/**
* @param oldFolder
* @param newFolder
* @throws IOException
*/
private void copyDirectory(File oldFolder, File newFolder)
throws IOException {
if (!newFolder.exists()) {
newFolder.mkdir();
}
// copy everything and delete old so we never have to do this again
for (File oldFile : oldFolder.listFiles()) {
String oldName = oldFile.getName();
String newName = oldName.replace(GRAILS_OLD_PLUGIN_NAME, GRAILS_NEW_PLUGIN_NAME);
newName = newName.replace(ROO_OLD_PLUGIN_NAME, ROO_NEW_PLUGIN_NAME);
File newFile = new File(newFolder, newName);
if (oldFile.isDirectory()) {
copyDirectory(new File(oldFolder, oldName), new File(newFolder, newName));
} else {
copyFile(oldFile, newFile);
}
}
}
/**
* Copies a preference file from the old location to the new one, replacing prefixes of the appropriate settings
*
* @param settingsFile the original settings file to copy
* @param newSettingsFile the new settings file to create
* @param oldPrefix old prefix of keys to migrate set to null if not using prefixes
* @param newPrefix new key prefix
*/
protected void copyPreferencesFile(File settingsFile, File newSettingsFile, String oldPrefix, String newPrefix) throws IOException,
CoreException, FileNotFoundException {
if (settingsFile.exists()) {
Properties oldProps = new Properties();
oldProps.load(new FileInputStream(settingsFile));
Properties newProps = new Properties();
for (Entry<Object, Object> prop : oldProps.entrySet()) {
String oldKey = prop.getKey().toString();
String newKey;
if (oldPrefix != null && oldKey.startsWith(oldPrefix)) {
newKey = oldKey.replace(oldPrefix, newPrefix);
} else {
newKey = oldKey;
}
newProps.put(newKey, prop.getValue());
}
newProps.store(new FileOutputStream(newSettingsFile), ""); //$NON-NLS-1$
}
}
public static void copyFile(File sourceFile, File destFile)
throws IOException {
if (!sourceFile.exists()) {
return;
}
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
} finally {
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
}
}

View File

@@ -1,107 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012, 2020 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion;
/**
* Set of constants to be used to
* convert legacy (pre-3.0) STS projects to 3.0 projects.
* @author Andrew Eisenberg
* @since 3.0.0
*/
public interface IConversionConstants {
String AUTO_CHECK_FOR_LEGACY_STS_PROJECTS = "org.springsource.ide.eclipse.commons.frameworks.ui.legacyconversion.autocheck"; //$NON-NLS-1$
String LEGACY_MIGRATION_ALREADY_DONE = "org.springsource.ide.eclipse.commons.frameworks.ui.legacyconversion.done"; //$NON-NLS-1$
// comma separated list of plugins that already have run plugin-specific legacy conversion code
String LEGACY_MIGRATION_PLUGINS = "org.springsource.ide.eclipse.commons.frameworks.ui.legacyconversion.plugins"; //$NON-NLS-1$
// GRAILS
String GRAILS_OLD_PREFERENCE_PREFIX = "com.springsource.sts.grails"; //$NON-NLS-1$
String GRAILS_NEW_PREFERENCE_PREFIX = "org.grails.ide.eclipse"; //$NON-NLS-1$
String GRAILS_OLD_PLUGIN_NAME = GRAILS_OLD_PREFERENCE_PREFIX + ".core"; //$NON-NLS-1$
String GRAILS_NEW_PLUGIN_NAME = GRAILS_NEW_PREFERENCE_PREFIX + ".core"; //$NON-NLS-1$
String GRAILS_OLD_NATURE = GRAILS_OLD_PLUGIN_NAME + ".nature"; //$NON-NLS-1$
String GRAILS_NEW_NATURE = GRAILS_NEW_PLUGIN_NAME + ".nature"; //$NON-NLS-1$
String GRAILS_OLD_CONTAINER = GRAILS_OLD_PLUGIN_NAME + ".CLASSPATH_CONTAINER"; //$NON-NLS-1$
String GRAILS_NEW_CONTAINER = GRAILS_NEW_PLUGIN_NAME + ".CLASSPATH_CONTAINER"; //$NON-NLS-1$
String GRAILS_OLD_ATTRIBUTE = GRAILS_OLD_PLUGIN_NAME + ".SOURCE_FOLDER"; //$NON-NLS-1$
String GRAILS_NEW_ATTRIBUTE = GRAILS_NEW_PLUGIN_NAME + ".SOURCE_FOLDER"; //$NON-NLS-1$
String GRAILS_OLD_PERSPECTIVE_ID = "com.springsource.sts.grails.perspective"; //$NON-NLS-1$
String GRAILS_NEW_PERSPECTIVE_ID = "org.grails.ide.eclipse.perspective"; //$NON-NLS-1$
// GRADLE
String GRADLE_OLD_PREFIX = "com.springsource.sts.gradle"; //$NON-NLS-1$
String GRADLE_NEW_PREFIX = "org.springsource.ide.eclipse.gradle"; //$NON-NLS-1$
String GRADLE_OLD_PLUGIN_NAME = "com.springsource.sts.gradle.core"; //$NON-NLS-1$
String GRADLE_NEW_PLUGIN_NAME = "org.springsource.ide.eclipse.gradle.core"; //$NON-NLS-1$
String GRADLE_OLD_NATURE = GRADLE_OLD_PLUGIN_NAME + ".nature"; //$NON-NLS-1$
String GRADLE_NEW_NATURE = GRADLE_NEW_PLUGIN_NAME + ".nature"; //$NON-NLS-1$
// ROO
String ROO_OLD_NATURE = "com.springsource.sts.roo.core.nature"; //$NON-NLS-1$
String ROO_NEW_NATURE = "com.springsource.sts.roo.core.nature"; //$NON-NLS-1$
String ROO_OLD_PLUGIN_NAME = "com.springsource.sts.roo.core"; //$NON-NLS-1$
String ROO_NEW_PLUGIN_NAME = "org.springframework.ide.eclipse.roo.core"; //$NON-NLS-1$
String ROO_OLD_UI_NAME = "com.springsource.sts.roo.ui"; //$NON-NLS-1$
String ROO_NEW_UI_NAME = "org.springframework.ide.eclipse.roo.ui"; //$NON-NLS-1$
// OTHER
String STS_OLD_CONTENT_CORE = "com.springsource.sts.content.core"; //$NON-NLS-1$
String STS_NEW_CONTENT_CORE = "org.springsource.ide.eclipse.commons.content.core"; //$NON-NLS-1$
String STS_OLD_CORE = "com.springsource.sts.core"; //$NON-NLS-1$
String STS_NEW_CORE = "org.springsource.ide.eclipse.commons.core"; //$NON-NLS-1$
String STS_OLD_IDE_UI = "com.springsource.sts.ide.ui"; //$NON-NLS-1$
String STS_NEW_IDE_UI = "org.springsource.ide.eclipse.dashboard.ui"; //$NON-NLS-1$
String[] STS_OLD_WORKSPACE_PREFS = new String[] {
"com.springsource.sts.grails.core", //$NON-NLS-1$
"com.springsource.sts.grails.ui", //$NON-NLS-1$
"com.springsource.sts.grails.editor.gsp", //$NON-NLS-1$
"com.springsource.sts.grails.explorer", //$NON-NLS-1$
"com.springsource.sts.grails.refactoring", //$NON-NLS-1$
"com.springsource.sts.grails.groovy.debug.core", //$NON-NLS-1$
"com.springsource.sts.config.ui", //$NON-NLS-1$
"com.springsource.sts.core", //$NON-NLS-1$
// "com.springsource.sts.gradle.core", Gradle does its own thing.
"com.springsource.sts.groovy.debug.core", //$NON-NLS-1$
"com.springsource.sts.ide.metadata", //$NON-NLS-1$
"com.springsource.sts.maven", //$NON-NLS-1$
"com.springsource.sts.ide.osgi", //$NON-NLS-1$
"com.springsource.sts.ide.ui", //$NON-NLS-1$
//"com.springsource.sts.config.flow", //$NON-NLS-1$
};
String[] STS_NEW_WORKSPACE_PREFS = new String[] {
"org.grails.ide.eclipse.core", //$NON-NLS-1$
"org.grails.ide.eclipse.ui", //$NON-NLS-1$
"org.grails.ide.eclipse.editor.gsp", //$NON-NLS-1$
"org.grails.ide.eclipse.explorer", //$NON-NLS-1$
"org.grails.ide.eclipse.refactoring", //$NON-NLS-1$
"org.grails.ide.eclipse.groovy.debug.core", //$NON-NLS-1$
"org.springframework.ide.eclipse.config.ui", //$NON-NLS-1$
"org.springsource.ide.eclipse.commons.core", //$NON-NLS-1$
// "org.springsource.ide.eclipse.gradle.core", //$NON-NLS-1$
"org.grails.ide.eclipse.groovy.debug.core", //$NON-NLS-1$
"org.springframework.ide.eclipse.metadata", //$NON-NLS-1$
"org.springframework.ide.eclipse.maven", //$NON-NLS-1$
"org.springframework.ide.eclipse.osgi.runtime", //$NON-NLS-1$
"org.springsource.ide.eclipse.dashboard.ui", //$NON-NLS-1$
//"org.springframework.ide.eclipse.config.graph" //$NON-NLS-1$
};
}

View File

@@ -1,222 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.springsource.ide.eclipse.commons.frameworks.core.FrameworkCoreActivator;
/**
* Converts legacy maven projects to the new m2e
* @author Andrew Eisenberg
* @since 3.0.0
*/
public class LegacyProjectConverter extends AbstractLegacyConverter implements IConversionConstants {
private final List<IProject> allLegacyProjects;
private IProject[] selectedLegacyProjects;
/**
* Converts a single project
*/
public LegacyProjectConverter(IProject legacyProject) {
allLegacyProjects = Collections.singletonList(legacyProject);
selectedLegacyProjects = new IProject[] { legacyProject };
}
public LegacyProjectConverter(List<IProject> legacyProjects) {
this.allLegacyProjects = legacyProjects;
}
public List<IProject> getAllLegacyProjects() {
return allLegacyProjects;
}
public IProject[] getSelectedLegacyProjects() {
return selectedLegacyProjects;
}
public void setSelectedLegacyProjects(IProject[] selectedLegacyProjects) {
this.selectedLegacyProjects = selectedLegacyProjects;
}
public IStatus convert(IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
SubMonitor sub = SubMonitor.convert(monitor, selectedLegacyProjects.length);
IStatus[] statuses = new IStatus[selectedLegacyProjects.length];
int i = 0;
for (IProject project : selectedLegacyProjects) {
if (project.isAccessible()) {
sub.subTask("Converting " + project.getName()); //$NON-NLS-1$
if (sub.isCanceled()) {
throw new OperationCanceledException();
}
statuses[i++] = convert(project, monitor);
} else {
// project was closed before job started.
statuses[i++] = Status.OK_STATUS;
}
sub.worked(1);
}
return new MultiStatus(FrameworkCoreActivator.PLUGIN_ID, 0, statuses, "Result of converting legacy maven projects", null); //$NON-NLS-1$
}
private IStatus convert(IProject project, IProgressMonitor monitor) {
SubMonitor sub = SubMonitor.convert(monitor, 1);
// grab project rule
Job.getJobManager().beginRule(ResourcesPlugin.getWorkspace().getRoot(), sub);
try {
if (project.hasNature(GRAILS_OLD_NATURE)) {
convertGrailsProject(project, sub);
} else if (project.hasNature(ROO_OLD_NATURE)) {
convertRooProject(project, sub);
} else if (project.hasNature(GRADLE_OLD_NATURE)) {
convertGradleProject(project, sub);
}
} catch (Exception e) {
return new Status(IStatus.ERROR, FrameworkCoreActivator.PLUGIN_ID, "Failed to convert " + project.getName(), e); //$NON-NLS-1$
} finally {
// release rule
Job.getJobManager().endRule(ResourcesPlugin.getWorkspace().getRoot());
}
sub.worked(1);
return new Status(IStatus.OK, FrameworkCoreActivator.PLUGIN_ID, "Converted " + project.getName()); //$NON-NLS-1$
}
private static void convertGradleProject(IProject project, SubMonitor sub) throws Exception {
// nature
IProjectDescription description = project.getDescription();
String[] ids = description.getNatureIds();
List<String> newIds = new ArrayList<String>(ids.length);
for (int i = 0; i < ids.length; i++) {
if (!ids[i].equals(GRADLE_OLD_NATURE) && !ids[i].equals(GRADLE_NEW_NATURE)) {
newIds.add(ids[i]);
} else {
newIds.add(GRADLE_NEW_NATURE);
}
}
description.setNatureIds(newIds.toArray(new String[0]));
project.setDescription(description, sub);
// project preferences
// DO NOTHING: gradle tooling handles these itself by reading in both old and new locations.
// classpath container
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] classpath = javaProject.getRawClasspath();
List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>();
for (int i = 0; i < classpath.length; i++) {
IClasspathEntry entry = classpath[i];
if (entry.getEntryKind()==IClasspathEntry.CPE_CONTAINER) {
String path = entry.getPath().toString();
if (path.contains(GRADLE_OLD_PREFIX)) {
entry = JavaCore.newContainerEntry(new Path(path.replace(GRADLE_OLD_PREFIX, GRADLE_NEW_PREFIX)),
entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
}
}
newClasspath.add(entry);
}
javaProject.setRawClasspath(newClasspath.toArray(new IClasspathEntry[0]), sub);
}
private void convertGrailsProject(IProject project, SubMonitor sub) throws Exception {
// nature
IProjectDescription description = project.getDescription();
String[] ids = description.getNatureIds();
List<String> newIds = new ArrayList<String>(ids.length);
for (int i = 0; i < ids.length; i++) {
if (!ids[i].equals(GRAILS_OLD_NATURE) && !ids[i].equals(GRAILS_NEW_NATURE)) {
newIds.add(ids[i]);
} else {
newIds.add(GRAILS_NEW_NATURE);
}
}
description.setNatureIds(newIds.toArray(new String[0]));
project.setDescription(description, sub);
// project preferences
IFolder preferencesFolder = project.getFolder(".settings/"); //$NON-NLS-1$
File settingsFile = preferencesFolder.getFile(GRAILS_OLD_PLUGIN_NAME + ".prefs").getLocation().toFile(); //$NON-NLS-1$ //$NON-NLS-2$
File newSettingsFile = preferencesFolder.getFile(GRAILS_NEW_PLUGIN_NAME + ".prefs").getLocation().toFile(); //$NON-NLS-1$ //$NON-NLS-2$
copyPreferencesFile(settingsFile, newSettingsFile, GRAILS_OLD_PREFERENCE_PREFIX, GRAILS_NEW_PREFERENCE_PREFIX);
InstanceScope.INSTANCE.getNode(GRAILS_OLD_PLUGIN_NAME).sync();
preferencesFolder.refreshLocal(IResource.DEPTH_ONE, sub);
// classpath container
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] classpath = javaProject.getRawClasspath();
List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>();
for (int i = 0; i < classpath.length; i++) {
if (classpath[i].getPath().toString().equals(GRAILS_OLD_CONTAINER)) {
newClasspath.add(JavaCore.newContainerEntry(new Path(GRAILS_NEW_CONTAINER), classpath[i].getAccessRules(), convertGrailsClasspathAttributes(classpath[i]), classpath[i].isExported()));
} else if (classpath[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
newClasspath.add(JavaCore.newSourceEntry(classpath[i].getPath(), classpath[i].getInclusionPatterns(),
classpath[i].getExclusionPatterns(), classpath[i].getOutputLocation(), convertGrailsClasspathAttributes(classpath[i])));
} else {
newClasspath.add(classpath[i]);
}
}
javaProject.setRawClasspath(newClasspath.toArray(new IClasspathEntry[0]), sub);
}
private IClasspathAttribute[] convertGrailsClasspathAttributes(
IClasspathEntry entry) {
IClasspathAttribute[] oldAttributes = entry.getExtraAttributes();
if (oldAttributes == null || oldAttributes.length == 0) {
return new IClasspathAttribute[0];
}
IClasspathAttribute[] newAttributes = new IClasspathAttribute[oldAttributes.length];
for (int i = 0; i < oldAttributes.length; i++) {
if (oldAttributes[i].getName().equals(GRAILS_OLD_ATTRIBUTE)) {
newAttributes[i] = JavaCore.newClasspathAttribute(GRAILS_NEW_ATTRIBUTE, oldAttributes[i].getValue());
} else {
newAttributes[i] = oldAttributes[i];
}
}
return newAttributes;
}
private void convertRooProject(IProject project, SubMonitor sub) throws Exception {
IFolder preferencesFolder = project.getFolder(".settings/"); //$NON-NLS-1$
File settingsFile = preferencesFolder.getFile(ROO_OLD_PLUGIN_NAME + ".prefs").getLocation().toFile(); //$NON-NLS-1$ //$NON-NLS-2$
File newSettingsFile = preferencesFolder.getFile(ROO_NEW_PLUGIN_NAME + ".prefs").getLocation().toFile(); //$NON-NLS-1$ //$NON-NLS-2$
copyPreferencesFile(settingsFile, newSettingsFile, ROO_OLD_PLUGIN_NAME, ROO_NEW_PLUGIN_NAME);
InstanceScope.INSTANCE.getNode(ROO_OLD_PLUGIN_NAME).sync();
preferencesFolder.refreshLocal(IResource.DEPTH_ONE, sub);
}
}

View File

@@ -1,127 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.internal.runtime.InternalPlatform;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.preference.IPreferenceStore;
import org.springsource.ide.eclipse.commons.frameworks.core.FrameworkCoreActivator;
/**
* Converts legacy 2.x workspace preferences into 3.x preferences
* @author Andrew Eisenberg
* @since 3.0.0
*/
public class LegacyWorkspaceConverter extends AbstractLegacyConverter implements IConversionConstants {
private static final IPreferenceStore PREFERENCE_STORE = FrameworkCoreActivator.getDefault().getPreferenceStore();
public boolean shouldAutoConvert() {
return ! PREFERENCE_STORE.getBoolean(LEGACY_MIGRATION_ALREADY_DONE);
}
public IStatus convert(IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
SubMonitor sub = SubMonitor.convert(monitor, 4);
IStatus[] statuses = new IStatus[4];
statuses[0] = copyPluginPreferences(sub);
// nothing to do for grails any more
// statuses[1] = convertGrailsWorkspacePreferences(sub);
statuses[1] = Status.OK_STATUS;
statuses[2] = convertRooWorkspacePreferences(sub);
statuses[3] = convertSTSPreferences(sub);
IStatus result = new MultiStatus(FrameworkCoreActivator.PLUGIN_ID, 0, statuses,
"Result of converting legacy STS 2.x workspace preferences to 3.x", null); //$NON-NLS-1$
// FrameworkCoreActivator.getDefault().getLog().log(result);
if (result.isOK()) {
PREFERENCE_STORE.setValue(LEGACY_MIGRATION_ALREADY_DONE, true);
}
return result;
}
/**
* Copies preferences inside of the
* @param sub
* @return
*/
private IStatus copyPluginPreferences(SubMonitor sub) {
sub.subTask("Copying plugin preferences for legacy STS workspace"); //$NON-NLS-1$
try {
File prefsFolder = InternalPlatform.getDefault().getRuntimeInstance().getStateLocation().toFile();
prefsFolder = new File(prefsFolder, ".settings");
for (int i = 0; i < STS_OLD_WORKSPACE_PREFS.length; i++) {
if (STS_NEW_WORKSPACE_PREFS[i].equals("???")) { //$NON-NLS-1$
continue;
}
copyPreferencesFile(new File(prefsFolder, STS_OLD_WORKSPACE_PREFS[i] + ".prefs"), new File(prefsFolder, STS_NEW_WORKSPACE_PREFS[i] + ".prefs"), STS_OLD_WORKSPACE_PREFS[i], STS_NEW_WORKSPACE_PREFS[i]); //$NON-NLS-1$ //$NON-NLS-2$
InstanceScope.INSTANCE.getNode(STS_NEW_WORKSPACE_PREFS[i]).sync();
}
} catch (Exception e) {
return new Status(IStatus.ERROR, FrameworkCoreActivator.PLUGIN_ID, "Failed to convert legacy STS workspace preferences", e); //$NON-NLS-1$
}
return new Status(IStatus.OK, FrameworkCoreActivator.PLUGIN_ID, "Converted legacy STS plugin preferences"); //$NON-NLS-1$
}
private IStatus convertSTSPreferences(SubMonitor sub) {
sub.subTask("Converting STS plugin state locations"); //$NON-NLS-1$
try {
copyPluginStateLocation(STS_OLD_CONTENT_CORE, STS_NEW_CONTENT_CORE);
copyPluginStateLocation(STS_OLD_CORE, STS_NEW_CORE);
copyPluginStateLocation(STS_OLD_IDE_UI, STS_NEW_IDE_UI);
return new Status(IStatus.OK, FrameworkCoreActivator.PLUGIN_ID, "Converted legacy STS plugin state locations"); //$NON-NLS-1$
} catch (IOException e) {
return new Status(IStatus.ERROR, FrameworkCoreActivator.PLUGIN_ID, "Failed to convert legacy STS plugin state locations", e); //$NON-NLS-1$
} finally {
sub.worked(1);
}
}
// TODO FIXADE Probably safe to delete
// private IStatus convertGrailsWorkspacePreferences(SubMonitor sub) {
// sub.subTask("Converting Grails plugin state locations"); //$NON-NLS-1$
// try {
// copyPluginStateLocation(GRAILS_OLD_PREFERENCE_PREFIX, GRAILS_NEW_PREFERENCE_PREFIX);
// return new Status(IStatus.OK, FrameworkCoreActivator.PLUGIN_ID, "Converted legacy Grails plugin state locations"); //$NON-NLS-1$
// } catch (IOException e) {
// return new Status(IStatus.ERROR, FrameworkCoreActivator.PLUGIN_ID, "Failed to convert legacy Grails plugin state locations", e); //$NON-NLS-1$
// } finally {
// sub.worked(1);
// }
// }
private IStatus convertRooWorkspacePreferences(SubMonitor sub) {
sub.subTask("Converting Roo plugin state locations"); //$NON-NLS-1$
try {
// Let RooInstallManager migrate the roo.installs content
// copyPluginStateLocation(ROO_OLD_PLUGIN_NAME, ROO_NEW_PLUGIN_NAME);
copyPluginStateLocation(ROO_OLD_UI_NAME, ROO_NEW_UI_NAME);
return new Status(IStatus.OK, FrameworkCoreActivator.PLUGIN_ID, "Converted legacy Roo plugin state locations"); //$NON-NLS-1$
} catch (IOException e) {
return new Status(IStatus.ERROR, FrameworkCoreActivator.PLUGIN_ID, "Failed to convert legacy Roo plugin state locations", e); //$NON-NLS-1$
} finally {
sub.worked(1);
}
}
}

View File

@@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.startup">
<startup
class="org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion.LegacySTSChecker">
</startup>
</extension>
<extension
point="org.eclipse.ui.popupMenus">
<!-- Deal with legacy projects -->
<objectContribution
objectClass="org.eclipse.core.resources.IProject"
adaptable="true"
id="iprojectcontributions">
<visibility>
<or>
<objectState name="nature" value="com.springsource.sts.grails.core.nature"/>
<objectState name="nature" value="com.springsource.sts.gradle.core.nature"/>
</or>
</visibility>
<action
label="Migrate legacy STS projects..."
class="org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion.ConvertLegacyProjectAction"
menubarPath="org.eclipse.ui.projectConfigure/additions"
id="convertLegacy">
</action>
</objectContribution>
</extension>
</plugin>

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* Copyright (c) 2012, 2023 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,7 +14,6 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion.LegacyProjectListener;
/**
* @author Nieraj Singh
@@ -50,7 +49,6 @@ public class FrameworkUIActivator extends AbstractUIPlugin {
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
LegacyProjectListener.LISTENER.dispose();
super.stop(context);
}

View File

@@ -1,38 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
/**
* Convert all legacy maven projects in the workspace
*
* @author Andrew Eisenberg
* @since 2.8.0
*/
public class ConvertLegacyProjectAction implements IObjectActionDelegate {
public void run(IAction action) {
LegacyProjectsJob job = new LegacyProjectsJob(true);
job.schedule();
}
public void selectionChanged(IAction action, ISelection selection) {
// we don't care about the actual selection
}
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}
}

View File

@@ -1,75 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.springsource.ide.eclipse.commons.frameworks.core.FrameworkCoreActivator;
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.IConversionConstants;
/**
* Listens for legacy STS projects appearing in the workspace
*
* @author Andrew Eisenberg
* @since 3.0.0
*/
public class LegacyProjectListener implements IResourceChangeListener, IConversionConstants {
public static final LegacyProjectListener LISTENER = new LegacyProjectListener();
private boolean shouldPerformCheck() {
return FrameworkCoreActivator.getDefault().getPreferenceStore().getBoolean(AUTO_CHECK_FOR_LEGACY_STS_PROJECTS);
}
public void resourceChanged(IResourceChangeEvent event) {
if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
List<IProject> projects = getProjects(event.getDelta());
if (!projects.isEmpty() && shouldPerformCheck()) {
LegacyProjectsJob job = new LegacyProjectsJob(projects, false);
job.schedule();
}
}
}
private List<IProject> getProjects(IResourceDelta delta) {
final List<IProject> projects = new ArrayList<IProject>();
try {
delta.accept(new IResourceDeltaVisitor() {
public boolean visit(IResourceDelta innerDelta) throws CoreException {
if (innerDelta.getKind() == IResourceDelta.ADDED && innerDelta.getResource().getType() == IResource.PROJECT) {
IProject project = (IProject) innerDelta.getResource();
if (LegacyProjectsJob.isLegacyProject(project, false)) {
projects.add(project);
}
}
// only continue for the workspace root
return innerDelta.getResource().getType() == IResource.ROOT;
}
});
} catch (CoreException e) {
FrameworkCoreActivator.getDefault().getLog().log(e.getStatus());
}
return projects;
}
public void dispose() {
ResourcesPlugin.getWorkspace().removeResourceChangeListener(LegacyProjectListener.LISTENER);
}
}

View File

@@ -1,127 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.progress.UIJob;
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.IConversionConstants;
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.LegacyProjectConverter;
/**
* Checks entire workspace for legacy projects
*
* @author Andrew Eisenberg
* @author Leo Dos Santos
* @since 3.0.0
*/
public class LegacyProjectsJob extends UIJob implements IConversionConstants {
private final boolean warnIfNone;
private List<IProject> legacyProjects;
public LegacyProjectsJob(boolean warnIfNone) {
super("Legacy STS Project Checker"); //$NON-NLS-1$
this.warnIfNone = warnIfNone;
}
public LegacyProjectsJob(List<IProject> legacyProjects, boolean warnIfNone) {
this(warnIfNone);
this.legacyProjects = legacyProjects;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
monitor.beginTask("Checking for legacy STS projects", 100); //$NON-NLS-1$
IStatus status = doCheck(monitor, getDisplay().getActiveShell());
monitor.done();
return status;
}
private IStatus doCheck(IProgressMonitor monitor, Shell shell) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
SubMonitor sub = SubMonitor.convert(monitor, 100);
if (legacyProjects == null) {
legacyProjects = findLegacyProjects();
}
sub.worked(30);
if (legacyProjects.size() > 0) {
LegacyProjectConverter converter = new LegacyProjectConverter(legacyProjects);
if (askToConvert(shell, converter)) {
return converter.convert(sub.newChild(70));
}
} else if (warnIfNone && !LegacySTSChecker.NON_BLOCKING) {
MessageDialog.openInformation(shell, "No legacy projects found", "No legacy projects found."); //$NON-NLS-1$ //$NON-NLS-2$
}
return Status.OK_STATUS;
}
private List<IProject> findLegacyProjects() {
List<IProject> legacyProjectsList = new ArrayList<IProject>();
IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : allProjects) {
try {
if (isLegacyProject(project, true)) {
legacyProjectsList.add(project);
}
} catch (CoreException e) {
// shouldn't happen since we already know project is accessible
// don't want to use the regular logging mechanism since that may
// load the bundle.
e.printStackTrace();
}
}
return legacyProjectsList;
}
public boolean askToConvert(Shell shell, LegacyProjectConverter converter) {
if (LegacySTSChecker.NON_BLOCKING) {
return false;
}
converter.setSelectedLegacyProjects(ListMessageDialog.openViewer(shell, converter.getAllLegacyProjects().toArray(new IProject[0])));
return converter.getSelectedLegacyProjects() != null;
}
public static boolean isLegacyProject(IProject project, boolean isWorkspaceMigration) throws CoreException{
return project.isAccessible() &&
(
// only migrate grails projects at workspace migration time.
// imported grails projects are handled by the GrailsProjectVersionFixer
(project.hasNature(GRAILS_OLD_NATURE) && isWorkspaceMigration) ||
(project.hasNature(ROO_OLD_NATURE) && needsRooPrefMigration(project)) ||
//only migrate gradle projects at workspace migration time, GradleImportOperation deals with old natures etc. during project import.
(project.hasNature(GRADLE_OLD_NATURE) && isWorkspaceMigration)
);
}
private static boolean needsRooPrefMigration(IProject project) {
IFolder preferencesFolder = project.getFolder(".settings/"); //$NON-NLS-1$
File settingsFile = preferencesFolder.getFile(ROO_NEW_PLUGIN_NAME + ".prefs").getLocation().toFile(); //$NON-NLS-1$ //$NON-NLS-2$
return !settingsFile.exists();
}
}

View File

@@ -1,80 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.UIJob;
import org.springsource.ide.eclipse.commons.frameworks.core.FrameworkCoreActivator;
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.IConversionConstants;
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.LegacyWorkspaceConverter;
import org.springsource.ide.eclipse.commons.frameworks.ui.FrameworkUIActivator;
/**
* Checks for legacy STS projects in the workspace at startup.
* Must be very careful not to accidentally load the rest of STS if
* no legacy projects are found
*
* @author Andrew Eisenberg
* @since 3.0.0
*/
public class LegacySTSChecker implements IStartup, IConversionConstants {
// set to true during testing mode
public static boolean NON_BLOCKING = false;
private static final IPreferenceStore PREFERENCE_STORE = FrameworkCoreActivator.getDefault().getPreferenceStore();
/**
* This entry to the checker comes at the startup of the workbench
*/
public void earlyStartup() {
PREFERENCE_STORE.setDefault(AUTO_CHECK_FOR_LEGACY_STS_PROJECTS, true);
if (shouldPerformProjectCheck()) {
Job job = new LegacyProjectsJob(false);
job.schedule();
ResourcesPlugin.getWorkspace().addResourceChangeListener(LegacyProjectListener.LISTENER, IResourceChangeEvent.POST_CHANGE);
}
if (shouldPerformWorkspaceMigration()) {
new UIJob("Convert legacy STS 2.x preferences") { //$NON-NLS-1$
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IStatus status = new LegacyWorkspaceConverter().convert(monitor);
IStatus status2 = new PerspectiveMigrator().migratePerspective(GRAILS_OLD_PERSPECTIVE_ID, GRAILS_NEW_PERSPECTIVE_ID, monitor);
MultiStatus statuses = new MultiStatus(FrameworkUIActivator.PLUGIN_ID, 0, new IStatus[] { status, status2 }, "Legacy workspace migration", null);
return statuses;
}
}.schedule();
}
}
private boolean shouldPerformProjectCheck() {
return FrameworkCoreActivator.getDefault().getPreferenceStore().getBoolean(AUTO_CHECK_FOR_LEGACY_STS_PROJECTS);
}
private boolean shouldPerformWorkspaceMigration() {
return ! PREFERENCE_STORE.getBoolean(LEGACY_MIGRATION_ALREADY_DONE);
}
}

View File

@@ -1,173 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
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.swt.widgets.Shell;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.springsource.ide.eclipse.commons.frameworks.core.FrameworkCoreActivator;
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.IConversionConstants;
/**
*
* @author Andrew Eisenberg
* @since 3.0.0
*/
public class ListMessageDialog extends MessageDialogWithToggle implements IConversionConstants {
class TableContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
if (inputElement instanceof IProject[]) {
return (IProject[]) inputElement;
}
return null;
}
public void dispose() { }
public void inputChanged(Viewer viewer2, Object oldInput, Object newInput) { }
}
private static final IPreferenceStore PREFERENCE_STORE = FrameworkCoreActivator.getDefault().getPreferenceStore();
private static final String PREFERENCE_QUESTION = "Don't show this dialog again."; //$NON-NLS-1$
private static final String TITLE = "Should convert legacy STS projects?"; //$NON-NLS-1$
private final IProject[] legacyProjects;
private IProject[] checkedLegacyProjects;
private CheckboxTableViewer viewer;
/**
* Opens the legacy maven project conversion dialog focusing on the selected projects
* @param legacyProjects
* @return
*/
public static IProject[] openViewer(Shell shell, IProject[] legacyProjects) {
ListMessageDialog dialog = new ListMessageDialog(shell, legacyProjects);
int res = dialog.open();
PREFERENCE_STORE.setValue(AUTO_CHECK_FOR_LEGACY_STS_PROJECTS, ! dialog.getToggleState());
if (res == IDialogConstants.YES_ID) {
return dialog.getAllChecked();
} else {
return null;
}
}
@Override
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.YES_ID) {
Object[] checkedElements = viewer.getCheckedElements();
checkedLegacyProjects = new IProject[checkedElements.length];
System.arraycopy(checkedElements, 0, checkedLegacyProjects, 0, checkedElements.length);
// don't want to do workspace preferences again
PREFERENCE_STORE.setValue(LEGACY_MIGRATION_ALREADY_DONE, true);
}
super.buttonPressed(buttonId);
}
@Override
protected boolean isResizable() {
return true;
}
public ListMessageDialog(Shell shell, IProject[] legacyProjects) {
super(shell, TITLE, null, createMessage(legacyProjects), QUESTION, new String[] { IDialogConstants.YES_LABEL,
IDialogConstants.NO_LABEL }, 0, PREFERENCE_QUESTION,
PREFERENCE_STORE.getBoolean(AUTO_CHECK_FOR_LEGACY_STS_PROJECTS));
this.legacyProjects = legacyProjects;
}
protected Control createCustomArea(Composite parent) {
((GridLayout) parent.getLayout()).numColumns = 2;
((GridLayout) parent.getLayout()).makeColumnsEqualWidth = false;
viewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 150;
gd.verticalSpan = 2;
viewer.getTable().setLayoutData(gd);
viewer.setContentProvider(new TableContentProvider());
viewer.setLabelProvider(new WorkbenchLabelProvider());
viewer.setInput(legacyProjects);
viewer.setAllChecked(true);
applyDialogFont(viewer.getControl());
createButton(parent, "Select all", new SelectionAdapter() { //$NON-NLS-1$
@Override
public void widgetSelected(SelectionEvent e) {
viewer.setAllChecked(true);
}
});
createButton(parent, "Select none", new SelectionAdapter() { //$NON-NLS-1$
@Override
public void widgetSelected(SelectionEvent e) {
viewer.setAllChecked(false);
}
});
return viewer.getControl();
}
protected Button createButton(Composite parent, String label, SelectionListener listener) {
return createButton(parent, label, SWT.PUSH, listener);
}
protected Button createButton(Composite parent, String label, int style, SelectionListener listener) {
Button button= new Button(parent, SWT.PUSH);
button.setFont(parent.getFont());
button.setText(label);
button.addSelectionListener(listener);
GridData gd= new GridData();
gd.horizontalAlignment= GridData.FILL;
gd.grabExcessHorizontalSpace= false;
gd.verticalAlignment= GridData.BEGINNING;
gd.widthHint = 100;
button.setLayoutData(gd);
return button;
}
IProject[] getAllChecked() {
return checkedLegacyProjects;
}
private static String createMessage(IProject[] allLegacyProjects) {
StringBuilder sb = new StringBuilder();
if (allLegacyProjects.length > 1) {
sb.append("The following legacy STS projects have been found:\n"); //$NON-NLS-1$
} else {
sb.append("The following legacy STS project has been found:\n"); //$NON-NLS-1$
}
if (allLegacyProjects.length > 1) {
sb.append("\n** These projects may not compile until they are upgraded to STS 3.0. **\n\n"); //$NON-NLS-1$
} else {
sb.append("\n** This project may not compile until it is upgraded to STS 3.0. **\n\n"); //$NON-NLS-1$
}
sb.append("Do you want to upgrade now?\n" + //$NON-NLS-1$
"You can choose to upgrade later by going to:\n" + //$NON-NLS-1$
"Project -> Configure -> Convert legacy STS projects..."); //$NON-NLS-1$
return sb.toString();
}
}

View File

@@ -1,85 +0,0 @@
/*
* Copyright 2011 SpringSource, a division of VMware, Inc
*
* andrew - Initial API and implementation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
import java.lang.reflect.Method;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchPage;
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.IConversionConstants;
import org.springsource.ide.eclipse.commons.frameworks.ui.FrameworkUIActivator;
/**
* Migrates legacy perspectives to new perspectives.
*
* Actually, we're having a bit of trouble removing the persective from the Perspective bar in the UI, but
* this ensures that the new perspective is opened if necessary.
* @author Andrew Eisenberg
* @since 3.0.0
*/
public class PerspectiveMigrator {
public IStatus migratePerspective(String oldPerspectiveId, String newPerspectiveId, IProgressMonitor monitor) {
try {
monitor = SubMonitor.convert(monitor, "Migrating legacy perspectives", 3);
IPerspectiveRegistry registry = PlatformUI.getWorkbench().getPerspectiveRegistry();
monitor.worked(1);
IWorkbenchPage page = null;
try {
page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
} catch (NullPointerException e) {
// something wasn't initialized...ignore
}
if (page != null) {
if (page.getPerspective() == null || page.getPerspective().getId().equals(oldPerspectiveId)) {
IPerspectiveDescriptor newPerspective = registry.findPerspectiveWithId(newPerspectiveId);
page.setPerspective(newPerspective);
IPerspectiveDescriptor oldPerspective = registry.findPerspectiveWithId(oldPerspectiveId);
monitor.worked(1);
if (oldPerspective != null) {
page.closePerspective(oldPerspective, false, false);
registry.deletePerspective(oldPerspective);
}
}
// Actually, there is no mechanism to close this kind of perspective
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=381473
if (page instanceof WorkbenchPage) {
try {
Method closePerspectiveMethod = WorkbenchPage.class.getDeclaredMethod("closePerspective", IPerspectiveDescriptor.class, String.class, boolean.class, boolean.class);
closePerspectiveMethod.invoke(page, null, IConversionConstants.GRAILS_OLD_PERSPECTIVE_ID, true, false);
} catch (Exception e) {
// this method doesn't exist on e37. OK to ignore
// FrameworkUIActivator.getDefault().getLog().log(new Status(IStatus.INFO, FrameworkUIActivator.PLUGIN_ID, "Cannot use reflection to close legacy perspective on Eclipse 3.7.", e));
}
}
}
monitor.worked(1);
monitor.done();
return new Status(IStatus.OK, FrameworkUIActivator.PLUGIN_ID, "Migrate legacy perspectives.");
} catch (Exception e) {
return new Status(IStatus.ERROR, FrameworkUIActivator.PLUGIN_ID, "Problem migrating legacy perspectives.", e);
}
}
}