⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 v075to090migrator.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 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.IOException;

import javax.xml.transform.TransformerException;

import org.eclipse.core.resources.IProject;
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.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;

import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.launching.ILaunchConstants;
import eclipseme.core.model.Version;
import eclipseme.core.nature.J2MENature;
import eclipseme.core.persistence.PersistenceException;

/**
 * Helper class for doing migration of the changes between
 * version 0.5.0 to 0.5.5.
 * <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.8 $
 * <br>
 * $Date: 2006/02/11 21:26:59 $
 * <br>
 * @author Craig Setera
 */

public class V075To090Migrator {
	// The root of the workspace that allows us to look through projects
	private IWorkspaceRoot workspaceRoot;
	private Version migrateVersion;
	
	/**
	 * Construct a new migration helper.
	 * 
	 * @param workspaceRoot
	 */
	public V075To090Migrator(IWorkspaceRoot workspaceRoot) {
		super();
		this.workspaceRoot = workspaceRoot;
		migrateVersion = new Version("0.9.0");
	}
	
	/**
	 * Do the work of this migration.
	 * 
	 * @throws CoreException
	 */
	public void doMigration(IProgressMonitor monitor) 
		throws CoreException
	{
		IProject[] projects = workspaceRoot.getProjects();
		for (int i = 0; i < projects.length; i++) {
			try {
				migrateProjectIfNecessary(projects[i], monitor);
			} catch (CoreException e) {
				EclipseMECorePlugin.log(IStatus.WARNING, "doMigration", e);
			}
		}
		
		try {
			migratePlatformComponents(monitor);
			migrateLaunchConfigurations(monitor);
		} catch (IOException e) {
			EclipseMECorePlugin.log(IStatus.WARNING, "doMigration", e);
		} catch (PersistenceException e) {
			EclipseMECorePlugin.log(IStatus.WARNING, "doMigration", e);
		} catch (TransformerException e) {
			EclipseMECorePlugin.log(IStatus.WARNING, "doMigration", e);
		}
	}

	/**
	 * Migrate the launch configurations.
	 * @param monitor
	 * @throws CoreException
	 */
	private void migrateLaunchConfigurations(IProgressMonitor monitor) 
		throws CoreException 
	{
		ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
		ILaunchConfigurationType launchType = 
			launchManager.getLaunchConfigurationType(ILaunchConstants.LAUNCH_CONFIG_TYPE);
		ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations();
		
		for (int i = 0; i < configs.length; i++) {
			ILaunchConfiguration configuration = configs[i];
			if (configuration.getType().equals(launchType)) {
				migrateLaunchConfiguration(configuration.getWorkingCopy());
			}
		}
	}

	/**
	 * Migrate the specified launch configuration.
	 * @param launchType
	 * 
	 * @param workingCopy
	 * @throws CoreException
	 */
	private void migrateLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy) 
		throws CoreException 
	{
//		PlatformComponentRegistry registry = PlatformComponentRegistry.getInstance();
//		String defId = workingCopy.getAttribute(ILaunchConstants.EMULATION_PLATFORM_DEF_ID, "");
//		if (defId.length() == 0) {
//			String defName = workingCopy.getAttribute(ILaunchConstants.EMULATION_PLATFORM_DEF, "");
//			if (defName.length() > 0) {
//				IPlatformDefinition def = registry.getPlatformDefinitionByName(defName);
//				if ((def != null) && (def != UnspecifiedPlatformDefinition.singleton)) {
//					workingCopy.setAttribute(
//							ILaunchConstants.EMULATION_PLATFORM_DEF_ID, 
//							def.getIdentifier());
//					workingCopy.doSave();
//				}
//			}
//		}
	}

	/**
	 * Migrate the platform components registry.
	 * 
	 * @param monitor
	 * @throws PersistenceException
	 * @throws IOException
	 * @throws TransformerException
	 */
	private void migratePlatformComponents(IProgressMonitor monitor) 
		throws PersistenceException, IOException, TransformerException 
	{
//		Version v = new Version("1.0.1");
//		
//		PlatformComponentsStore store = PlatformComponentsStore.getInstance();
//		Version version = store.restoreComponents(monitor);
//		if ((version != null) && (version.compareTo(v) < 0)) {
//			store.storeComponents(monitor);
//		}
	}

	/**
	 * Migrate the specified project if it hasn't already been
	 * migrated.
	 * 
	 * @param project
	 * @param monitor
	 * @throws CoreException
	 */
	private void migrateProjectIfNecessary(IProject project, IProgressMonitor monitor) 
		throws CoreException 
	{
		if (project.isOpen() && J2MENature.hasJ2MENature(project)) {
			migrateOpenProjectIfNecessary(project, monitor);
		}
	}

	/**
	 * Migrate the specified project.
	 * 
	 * @param project
	 * @param monitor
	 * @throws CoreException
	 */
	private void migrateOpenProjectIfNecessary(IProject project, IProgressMonitor monitor) 
		throws CoreException 
	{
//		IJavaProject javaProject = JavaCore.create(project);
//		if (javaProject != null) {
//			IMidletSuiteProject suite = MidletSuiteProject.getMidletSuiteProject(javaProject);
//			if (suite instanceof MidletSuiteProject) {
//				MetaData metadata = ((MidletSuiteProject) suite).getMetaData();
//				if ((metadata != null) && (metadata.getVersion().compareTo(migrateVersion) < 0)) {
//					IPlatformDefinition definition = suite.getPlatformDefinition();
//					suite.setPlatformDefinition(definition);
//					suite.saveMetaData();
//				}
//			}
//		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -