📄 eclipsemecoreplugin.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;
import java.io.File;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IStatusHandler;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import eclipseme.core.IEclipseMECoreConstants;
import eclipseme.core.hook.sourceMapper.SourceMapperAccess;
import eclipseme.core.internal.preprocessor.PreprocessedSourceMapper;
import eclipseme.core.model.LibrarySpecification;
import eclipseme.core.model.Version;
/**
* The main plugin class to be used in the workbench.
* <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.25 $
* <br>
* $Date: 2007/01/20 19:23:00 $
* <br>
* @author Craig Setera
*/
public class EclipseMECorePlugin
extends Plugin
implements IEclipseMECoreConstants
{
private class MigrationJob extends Job {
/** Constructor */
MigrationJob() {
super("EclipseME Migration");
setPriority(SHORT);
setSystem(true);
}
/**
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
protected IStatus run(IProgressMonitor monitor) {
IStatus status = null;
try {
doMigration(monitor);
status = OK_STATUS;
} catch (CoreException e) {
status = e.getStatus();
}
return status;
}
}
//The shared instance.
private static EclipseMECorePlugin plugin;
/** Status code for which a UI prompter is registered. */
public static final IStatus OK_STATUS = new Status(
IStatus.OK,
IEclipseMECoreConstants.PLUGIN_ID,
0,
"OK",
null);
/** Status code for which a UI prompter is registered. */
private static final IStatus PROMPTER_STATUS = new Status(
IStatus.INFO,
"org.eclipse.debug.ui", // TODO This should probably not be done....
200, "", null);
//Resource bundle.
private ResourceBundle resourceBundle;
// The configuration specifications provided by extension points
private LibrarySpecification[] configSpecs;
// The profile specifications provided by extension points
private LibrarySpecification[] profileSpecs;
/**
* The constructor.
*/
public EclipseMECorePlugin() {
super();
plugin = this;
try {
resourceBundle =
ResourceBundle.getBundle("eclipseme.core.EclipseMEPluginResources");
} catch (MissingResourceException x) {
resourceBundle = null;
}
}
/**
* Return the configuration specifications provided by the plugin
* extension points.
*
* @return the configuration specifications
* @throws CoreException
*/
public static LibrarySpecification[] getConfigurationSpecifications()
throws CoreException
{
EclipseMECorePlugin plugin = getDefault();
if (plugin.configSpecs == null) {
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(
IEclipseMECoreConstants.PLUGIN_ID,
IEclipseMECoreConstants.J2ME_CONFIGURATIONS_ID);
IConfigurationElement[] configElements = point.getConfigurationElements();
plugin.configSpecs = new LibrarySpecification[configElements.length];
for (int i = 0; i < configElements.length; i++) {
plugin.configSpecs[i] = createComponentSpecification(configElements[i]);
}
}
return plugin.configSpecs;
}
/**
* Returns the shared instance.
*/
public static EclipseMECorePlugin getDefault() {
return plugin;
}
/**
* Get the deployment directory name the user has specified in the preferences.
*
* @return
*/
public static String getDeploymentDirectoryName() {
return getDefault().getPluginPreferences().getString(PREF_DEPLOYMENT_DIR);
}
/**
* Return the current version associated with this plugin.
* @return the plugin version
*/
public static String getPluginVersion() {
Bundle bundle = EclipseMECorePlugin.getDefault().getBundle();
return (String) bundle.getHeaders().get(Constants.BUNDLE_VERSION);
}
/**
* Return the profile specifications provided by the plugin
* extension points.
*
* @return the profile specifications
* @throws CoreException
*/
public static LibrarySpecification[] getProfileSpecifications()
throws CoreException
{
EclipseMECorePlugin plugin = getDefault();
if (plugin.profileSpecs == null) {
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(
IEclipseMECoreConstants.PLUGIN_ID,
IEclipseMECoreConstants.J2ME_PROFILES_ID);
IConfigurationElement[] configElements = point.getConfigurationElements();
plugin.profileSpecs = new LibrarySpecification[configElements.length];
for (int i = 0; i < configElements.length; i++) {
plugin.profileSpecs[i] = createComponentSpecification(configElements[i]);
}
}
return plugin.profileSpecs;
}
/**
* Return the File instance representing the Proguard implementation
* jar file as defined by the user preferences.
* This File is not guaranteed to exist.
*
* @return
*/
public static File getProguardJarFile() {
String proguardDirPref = getDefault().getPluginPreferences().getString(PREF_PROGUARD_DIR);
File proguardDir = new File(proguardDirPref);
File proguardLibDir = new File(proguardDir, "lib");
File proguardJar = new File(proguardLibDir, PROGUARD_JAR);
return proguardJar;
}
/**
* Return the preferences that are specific to the project and plugin.
*
* @param context
* @return
*/
public static IEclipsePreferences getProjectPreferences(IProject context) {
ProjectScope projectScope = new ProjectScope(context);
return projectScope.getNode(IEclipseMECoreConstants.PLUGIN_ID);
}
/**
* Return a boolean preference scoped to the specified project where
* possible, otherwise falling back to instance scope.
*
* @param project
* @param key
* @return
*/
public static boolean getProjectBooleanPreference(IProject project, String key) {
IScopeContext[] searchContexts = new IScopeContext[] {
new ProjectScope(project),
new InstanceScope(),
new DefaultScope(),
};
IPreferencesService service = Platform.getPreferencesService();
return service.getBoolean(IEclipseMECoreConstants.PLUGIN_ID, key, false, searchContexts);
}
/**
* Return a String preference scoped to the specified project where
* possible, otherwise falling back to instance scope.
*
* @param project
* @param key
* @return
*/
public static String getProjectStringPreference(IProject project, String key) {
IScopeContext[] searchContexts = new IScopeContext[] {
new ProjectScope(project),
new InstanceScope(),
new DefaultScope(),
};
IPreferencesService service = Platform.getPreferencesService();
return service.getString(IEclipseMECoreConstants.PLUGIN_ID, key, null, searchContexts);
}
/**
* Get the resources directory name the user has specified in the preferences.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -