📄 v045to050migrator.java
字号:
/**
* Copyright (c) 2003-2005 Craig Setera
* All Rights Reserved.
* Licensed under the Eclipse Public License - v 1.0
* For more information see http://www.eclipse.org/legal/epl-v10.html
*/
package eclipseme.core.internal.migration;
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.utils.XMLUtils;
/**
* Helper class for doing migration of the changes between
* version 0.4.5 and 0.5.0.
* <p />
* Copyright (c) 2003-2005 Craig Setera<br>
* All Rights Reserved.<br>
* Licensed under the Eclipse Public License - v 1.0<p/>
* <br>
* $Revision: 1.5 $
* <br>
* $Date: 2005/07/07 02:37:17 $
* <br>
* @author Craig Setera
*/
public class V045To050Migrator {
private static final String STATE_FILE = "platcomp.xml";
/** Internal preference value for marking that the preferences have been migrated */
public static final String PREF_V050_MIGRATED = "v050migrated";
/**
*
* @uml.property name="workspaceRoot"
* @uml.associationEnd
* @uml.property name="workspaceRoot" multiplicity="(1 1)"
*/
// The root of the workspace that allows us to look through projects
private IWorkspaceRoot workspaceRoot;
/**
* Construct a new migration helper.
*
* @param workspaceRoot
*/
public V045To050Migrator(IWorkspaceRoot workspaceRoot) {
super();
this.workspaceRoot = workspaceRoot;
}
/**
* Do the work of this migration.
*
* @throws CoreException
*/
public void doMigration(IProgressMonitor monitor)
throws CoreException
{
migratePreferences();
migratePlatformComponents(monitor);
}
/**
* Migrate the platform components from the EclipseME plugin
* to the eclipseme.core plugin.
* @param monitor
* @throws CoreException
*/
private void migratePlatformComponents(IProgressMonitor monitor)
throws CoreException
{
// Figure out the old and new file locations
// IPath srcPluginStatePath = EclipseMEPlugin.getDefault().getStateLocation();
// IPath srcStorePath = srcPluginStatePath.append(STATE_FILE);
// File srcFile = srcStorePath.toFile();
//
// IPath tgtPluginStatePath = EclipseMECorePlugin.getDefault().getStateLocation();
// IPath tgtStorePath = tgtPluginStatePath.append(STATE_FILE);
// File tgtFile = tgtStorePath.toFile();
//
// if (srcFile.exists() && !tgtFile.exists()) {
// migratePlatformComponents(srcFile, tgtFile, monitor);
// }
}
/**
* Migrate the platform components from the source file to the target location.
*
* @param srcFile
* @param tgtFile
* @param monitor
*/
private void migratePlatformComponents(
File srcFile,
File tgtFile,
IProgressMonitor monitor)
throws CoreException
{
try {
Document componentsDoc = XMLUtils.readDocument(srcFile);
migratePlatformComponents(componentsDoc);
XMLUtils.writeDocument(tgtFile, componentsDoc);
} catch (ParserConfigurationException e) {
EclipseMECorePlugin.throwCoreException(IStatus.WARNING, -999, e);
} catch (SAXException e) {
EclipseMECorePlugin.throwCoreException(IStatus.WARNING, -999, e);
} catch (IOException e) {
EclipseMECorePlugin.throwCoreException(IStatus.WARNING, -999, e);
} catch (TransformerException e) {
EclipseMECorePlugin.throwCoreException(IStatus.WARNING, -999, e);
}
}
/**
* Migrate the platform components by rewriting the package references
* from the old names to the new package names.
*
* @param componentsDoc
*/
private void migratePlatformComponents(Document componentsDoc) {
migratePlatformComponents(componentsDoc.getDocumentElement());
}
/**
* Migrate the platform components in the specified element.
*
* @param element
*/
private void migratePlatformComponents(Element element) {
// Walk through all of the elements and all of the attributes
// in that element
NodeList nodeList = element.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) node;
migratePlatformComponents(childElement);
// Migrate the attributes in the element
NamedNodeMap attributes = childElement.getAttributes();
for (int j = 0; j < attributes.getLength(); j++) {
Attr attribute = (Attr) attributes.item(j);
migratePlatformComponent(attribute);
}
}
}
}
/**
* Migrate the specified platform component as necessary.
*
* @param attribute
*/
private void migratePlatformComponent(Attr attribute) {
String value = attribute.getValue();
if (value.startsWith("eclipseme.model.impl.generic")) {
int lastDot = value.lastIndexOf('.');
if (lastDot != -1) {
value = "eclipseme.core.model.impl." + value.substring(lastDot + 1);
attribute.setValue(value);
}
} else if (value.startsWith("eclipseme.model.impl.nokia")) {
int lastDot = value.lastIndexOf('.');
if (lastDot != -1) {
value = "eclipseme.toolkit.nokia.impl." + value.substring(lastDot + 1);
attribute.setValue(value);
}
} else if (value.startsWith("eclipseme.model.impl.sun")) {
int lastDot = value.lastIndexOf('.');
if (lastDot != -1) {
value = "eclipseme.toolkit.sun.impl." + value.substring(lastDot + 1);
attribute.setValue(value);
}
}
}
/**
* Migrate the preferences from the old EclipseME plugin to the eclipseme.core
* plugin.
*/
private void migratePreferences() {
// Migrate the preferences
// Preferences oldPrefs = EclipseMEPlugin.getDefault().getPluginPreferences();
// Preferences newPrefs = EclipseMECorePlugin.getDefault().getPluginPreferences();
//
// boolean migrated = newPrefs.getBoolean(PREF_V050_MIGRATED);
// if (!migrated) {
// String[] names = oldPrefs.propertyNames();
// for (int i = 0; i < names.length; i++) {
// String name = names[i];
// newPrefs.setValue(name, oldPrefs.getString(name));
// }
//
// newPrefs.setValue(PREF_V050_MIGRATED, true);
// EclipseMECorePlugin.getDefault().savePluginPreferences();
// }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -