Remove old legacy project and project conversion code
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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$
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user