ADT: Remove StreamHelper and integrate it in AdtPlugin.

StreamHelper was used before by AdtPlugin, DdmsPlugin and EditorsPlugin. It's now
only used by AdtPlugin, so the only 2 methods in it can go in AdtPlugin.
I merged the externalized string in the messages.properties file used by AdtPlugin.
This commit is contained in:
Xavier Ducrohet
2009-05-13 16:46:31 -07:00
parent 9eedccd52c
commit f127736264
7 changed files with 117 additions and 162 deletions

View File

@@ -54,7 +54,6 @@ Export-Package: com.android.ide.eclipse.adt;x-friends:="com.android.ide.eclipse.
com.android.ide.eclipse.adt.sdk;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.sdk;x-friends:="com.android.ide.eclipse.tests",
com.android.ide.eclipse.adt.wizards.newproject;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.wizards.newproject;x-friends:="com.android.ide.eclipse.tests",
com.android.ide.eclipse.adt.ui;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.ui;x-friends:="com.android.ide.eclipse.tests",
com.android.ide.eclipse.common;x-friends:="com.android.ide.eclipse.tests",
com.android.ide.eclipse.common.project;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.common.project;x-friends:="com.android.ide.eclipse.tests",
com.android.ide.eclipse.common.resources;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.common.resources;x-friends:="com.android.ide.eclipse.tests",
com.android.ide.eclipse.editors;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.editors;x-friends:="com.android.ide.eclipse.tests",

View File

@@ -30,7 +30,6 @@ import com.android.ide.eclipse.adt.sdk.LoadStatus;
import com.android.ide.eclipse.adt.sdk.Sdk; import com.android.ide.eclipse.adt.sdk.Sdk;
import com.android.ide.eclipse.adt.sdk.Sdk.ITargetChangeListener; import com.android.ide.eclipse.adt.sdk.Sdk.ITargetChangeListener;
import com.android.ide.eclipse.adt.ui.EclipseUiHelper; import com.android.ide.eclipse.adt.ui.EclipseUiHelper;
import com.android.ide.eclipse.common.StreamHelper;
import com.android.ide.eclipse.common.project.BaseProjectHelper; import com.android.ide.eclipse.common.project.BaseProjectHelper;
import com.android.ide.eclipse.common.project.ExportHelper; import com.android.ide.eclipse.common.project.ExportHelper;
import com.android.ide.eclipse.common.project.ExportHelper.IExportCallback; import com.android.ide.eclipse.common.project.ExportHelper.IExportCallback;
@@ -109,6 +108,7 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar;
import java.util.List; import java.util.List;
/** /**
@@ -117,7 +117,7 @@ import java.util.List;
public class AdtPlugin extends AbstractUIPlugin { public class AdtPlugin extends AbstractUIPlugin {
/** The plug-in ID */ /** The plug-in ID */
public static final String PLUGIN_ID = "com.android.ide.eclipse.adt"; //$NON-NLS-1$ public static final String PLUGIN_ID = "com.android.ide.eclipse.adt"; //$NON-NLS-1$
public final static String PREFS_SDK_DIR = PLUGIN_ID + ".sdk"; //$NON-NLS-1$ public final static String PREFS_SDK_DIR = PLUGIN_ID + ".sdk"; //$NON-NLS-1$
public final static String PREFS_RES_AUTO_REFRESH = PLUGIN_ID + ".resAutoRefresh"; //$NON-NLS-1$ public final static String PREFS_RES_AUTO_REFRESH = PLUGIN_ID + ".resAutoRefresh"; //$NON-NLS-1$
@@ -131,7 +131,7 @@ public class AdtPlugin extends AbstractUIPlugin {
public final static String PREFS_HOME_PACKAGE = PLUGIN_ID + ".homePackage"; //$NON-NLS-1$ public final static String PREFS_HOME_PACKAGE = PLUGIN_ID + ".homePackage"; //$NON-NLS-1$
public final static String PREFS_EMU_OPTIONS = PLUGIN_ID + ".emuOptions"; //$NON-NLS-1$ public final static String PREFS_EMU_OPTIONS = PLUGIN_ID + ".emuOptions"; //$NON-NLS-1$
/** singleton instance */ /** singleton instance */
private static AdtPlugin sPlugin; private static AdtPlugin sPlugin;
@@ -161,7 +161,7 @@ public class AdtPlugin extends AbstractUIPlugin {
/** Color used in the error console */ /** Color used in the error console */
private Color mRed; private Color mRed;
/** Load status of the SDK. Any access MUST be in a synchronized(mPostLoadProjects) block */ /** Load status of the SDK. Any access MUST be in a synchronized(mPostLoadProjects) block */
private LoadStatus mSdkIsLoaded = LoadStatus.LOADING; private LoadStatus mSdkIsLoaded = LoadStatus.LOADING;
/** Project to update once the SDK is loaded. /** Project to update once the SDK is loaded.
@@ -171,7 +171,7 @@ public class AdtPlugin extends AbstractUIPlugin {
/** Project to check validity of cache vs actual once the SDK is loaded. /** Project to check validity of cache vs actual once the SDK is loaded.
* Any access MUST be in a synchronized(mPostLoadProjectsToResolve) block */ * Any access MUST be in a synchronized(mPostLoadProjectsToResolve) block */
private final ArrayList<IJavaProject> mPostLoadProjectsToCheck = new ArrayList<IJavaProject>(); private final ArrayList<IJavaProject> mPostLoadProjectsToCheck = new ArrayList<IJavaProject>();
private ResourceMonitor mResourceMonitor; private ResourceMonitor mResourceMonitor;
private ArrayList<ITargetChangeListener> mTargetChangeListeners = private ArrayList<ITargetChangeListener> mTargetChangeListeners =
new ArrayList<ITargetChangeListener>(); new ArrayList<ITargetChangeListener>();
@@ -203,7 +203,7 @@ public class AdtPlugin extends AbstractUIPlugin {
@Override @Override
public void println(String message) { public void println(String message) {
// write the date/project tag first. // write the date/project tag first.
String tag = StreamHelper.getMessageTag(mProject != null ? mProject.getName() : null); String tag = getMessageTag(mProject != null ? mProject.getName() : null);
print(tag); print(tag);
if (mPrefix != null) { if (mPrefix != null) {
@@ -311,7 +311,7 @@ public class AdtPlugin extends AbstractUIPlugin {
// get the SDK location and build id. // get the SDK location and build id.
if (checkSdkLocationAndId()) { if (checkSdkLocationAndId()) {
// if sdk if valid, reparse it // if sdk if valid, reparse it
// add all the opened Android projects to the list of projects to be updated // add all the opened Android projects to the list of projects to be updated
// after the SDK is reloaded // after the SDK is reloaded
synchronized (getSdkLockObject()) { synchronized (getSdkLockObject()) {
@@ -319,7 +319,7 @@ public class AdtPlugin extends AbstractUIPlugin {
IJavaProject[] androidProjects = BaseProjectHelper.getAndroidProjects(); IJavaProject[] androidProjects = BaseProjectHelper.getAndroidProjects();
mPostLoadProjectsToResolve.addAll(Arrays.asList(androidProjects)); mPostLoadProjectsToResolve.addAll(Arrays.asList(androidProjects));
} }
// parse the SDK resources at the new location // parse the SDK resources at the new location
parseSdkContent(); parseSdkContent();
} }
@@ -340,7 +340,7 @@ public class AdtPlugin extends AbstractUIPlugin {
// check the location of SDK // check the location of SDK
final boolean isSdkLocationValid = checkSdkLocationAndId(); final boolean isSdkLocationValid = checkSdkLocationAndId();
mBuildVerbosity = BuildPreferencePage.getBuildLevel( mBuildVerbosity = BuildPreferencePage.getBuildLevel(
mStore.getString(PREFS_BUILD_VERBOSITY)); mStore.getString(PREFS_BUILD_VERBOSITY));
@@ -355,7 +355,7 @@ public class AdtPlugin extends AbstractUIPlugin {
// and give it the debug launcher for android projects // and give it the debug launcher for android projects
DdmsPlugin.setRunningAppDebugLauncher(new DdmsPlugin.IDebugLauncher() { DdmsPlugin.setRunningAppDebugLauncher(new DdmsPlugin.IDebugLauncher() {
public boolean debug(String appName, int port) { public boolean debug(String appName, int port) {
// search for an android project matching the process name // search for an android project matching the process name
IProject project = ProjectHelper.findAndroidProjectByAppName(appName); IProject project = ProjectHelper.findAndroidProjectByAppName(appName);
if (project != null) { if (project != null) {
AndroidLaunchController.debugRunningApp(project, port); AndroidLaunchController.debugRunningApp(project, port);
@@ -365,7 +365,7 @@ public class AdtPlugin extends AbstractUIPlugin {
} }
} }
}); });
StackTracePanel.setSourceRevealer(new ISourceRevealer() { StackTracePanel.setSourceRevealer(new ISourceRevealer() {
public void reveal(String applicationName, String className, int line) { public void reveal(String applicationName, String className, int line) {
IProject project = ProjectHelper.findAndroidProjectByAppName(applicationName); IProject project = ProjectHelper.findAndroidProjectByAppName(applicationName);
@@ -374,12 +374,12 @@ public class AdtPlugin extends AbstractUIPlugin {
} }
} }
}); });
// setup export callback for editors // setup export callback for editors
ExportHelper.setCallback(new IExportCallback() { ExportHelper.setCallback(new IExportCallback() {
public void startExportWizard(IProject project) { public void startExportWizard(IProject project) {
StructuredSelection selection = new StructuredSelection(project); StructuredSelection selection = new StructuredSelection(project);
ExportWizard wizard = new ExportWizard(); ExportWizard wizard = new ExportWizard();
wizard.init(PlatformUI.getWorkbench(), selection); wizard.init(PlatformUI.getWorkbench(), selection);
WizardDialog dialog = new WizardDialog(getDisplay().getActiveShell(), WizardDialog dialog = new WizardDialog(getDisplay().getActiveShell(),
@@ -387,7 +387,7 @@ public class AdtPlugin extends AbstractUIPlugin {
dialog.open(); dialog.open();
} }
}); });
// initialize editors // initialize editors
startEditors(); startEditors();
@@ -399,16 +399,16 @@ public class AdtPlugin extends AbstractUIPlugin {
@Override @Override
public void done(IJobChangeEvent event) { public void done(IJobChangeEvent event) {
super.done(event); super.done(event);
// Once the ping job is finished, start the SDK parser // Once the ping job is finished, start the SDK parser
if (isSdkLocationValid) { if (isSdkLocationValid) {
// parse the SDK resources. // parse the SDK resources.
parseSdkContent(); parseSdkContent();
} }
} }
}); });
// build jobs are run after other interactive jobs // build jobs are run after other interactive jobs
pingJob.setPriority(Job.BUILD); pingJob.setPriority(Job.BUILD);
// Wait 2 seconds before starting the ping job. This leaves some time to the // Wait 2 seconds before starting the ping job. This leaves some time to the
// other bundles to initialize. // other bundles to initialize.
pingJob.schedule(2000 /*milliseconds*/); pingJob.schedule(2000 /*milliseconds*/);
@@ -416,15 +416,15 @@ public class AdtPlugin extends AbstractUIPlugin {
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/ */
@Override @Override
public void stop(BundleContext context) throws Exception { public void stop(BundleContext context) throws Exception {
super.stop(context); super.stop(context);
stopEditors(); stopEditors();
mRed.dispose(); mRed.dispose();
synchronized (AdtPlugin.class) { synchronized (AdtPlugin.class) {
sPlugin = null; sPlugin = null;
@@ -524,7 +524,7 @@ public class AdtPlugin extends AbstractUIPlugin {
if (sPlugin != null) { if (sPlugin != null) {
return sPlugin.mBuildVerbosity; return sPlugin.mBuildVerbosity;
} }
return 0; return 0;
} }
@@ -536,7 +536,7 @@ public class AdtPlugin extends AbstractUIPlugin {
* @return the image descriptor * @return the image descriptor
*/ */
public static ImageDescriptor getImageDescriptor(String path) { public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path); return imageDescriptorFromPlugin(PLUGIN_ID, path);
} }
/** /**
@@ -554,7 +554,7 @@ public class AdtPlugin extends AbstractUIPlugin {
return null; return null;
} }
} }
// attempt to get a file to one of the template. // attempt to get a file to one of the template.
try { try {
URL url = bundle.getEntry(AndroidConstants.WS_SEP + filepath); URL url = bundle.getEntry(AndroidConstants.WS_SEP + filepath);
@@ -682,10 +682,10 @@ public class AdtPlugin extends AbstractUIPlugin {
}); });
return result[0]; return result[0];
} }
/** /**
* Logs a message to the default Eclipse log. * Logs a message to the default Eclipse log.
* *
* @param severity The severity code. Valid values are: {@link IStatus#OK}, * @param severity The severity code. Valid values are: {@link IStatus#OK},
* {@link IStatus#ERROR}, {@link IStatus#INFO}, {@link IStatus#WARNING} or * {@link IStatus#ERROR}, {@link IStatus#INFO}, {@link IStatus#WARNING} or
* {@link IStatus#CANCEL}. * {@link IStatus#CANCEL}.
@@ -703,7 +703,7 @@ public class AdtPlugin extends AbstractUIPlugin {
* Logs an exception to the default Eclipse log. * Logs an exception to the default Eclipse log.
* <p/> * <p/>
* The status severity is always set to ERROR. * The status severity is always set to ERROR.
* *
* @param exception the exception to log. * @param exception the exception to log.
* @param format The format string, like for {@link String#format(String, Object...)}. * @param format The format string, like for {@link String#format(String, Object...)}.
* @param args The arguments for the format string, like for * @param args The arguments for the format string, like for
@@ -714,13 +714,13 @@ public class AdtPlugin extends AbstractUIPlugin {
Status status = new Status(IStatus.ERROR, PLUGIN_ID, message, exception); Status status = new Status(IStatus.ERROR, PLUGIN_ID, message, exception);
getDefault().getLog().log(status); getDefault().getLog().log(status);
} }
/** /**
* This is a mix between log(Throwable) and printErrorToConsole. * This is a mix between log(Throwable) and printErrorToConsole.
* <p/> * <p/>
* This logs the exception with an ERROR severity and the given printf-like format message. * This logs the exception with an ERROR severity and the given printf-like format message.
* The same message is then printed on the Android error console with the associated tag. * The same message is then printed on the Android error console with the associated tag.
* *
* @param exception the exception to log. * @param exception the exception to log.
* @param format The format string, like for {@link String#format(String, Object...)}. * @param format The format string, like for {@link String#format(String, Object...)}.
* @param args The arguments for the format string, like for * @param args The arguments for the format string, like for
@@ -732,7 +732,7 @@ public class AdtPlugin extends AbstractUIPlugin {
String message = String.format(format, args); String message = String.format(format, args);
Status status = new Status(IStatus.ERROR, PLUGIN_ID, message, exception); Status status = new Status(IStatus.ERROR, PLUGIN_ID, message, exception);
getDefault().getLog().log(status); getDefault().getLog().log(status);
StreamHelper.printToStream(sPlugin.mAndroidConsoleErrorStream, tag, message); printToStream(sPlugin.mAndroidConsoleErrorStream, tag, message);
showAndroidConsole(); showAndroidConsole();
} }
} }
@@ -744,8 +744,8 @@ public class AdtPlugin extends AbstractUIPlugin {
*/ */
public static synchronized void printErrorToConsole(String tag, Object... objects) { public static synchronized void printErrorToConsole(String tag, Object... objects) {
if (sPlugin != null) { if (sPlugin != null) {
StreamHelper.printToStream(sPlugin.mAndroidConsoleErrorStream, tag, objects); printToStream(sPlugin.mAndroidConsoleErrorStream, tag, objects);
showAndroidConsole(); showAndroidConsole();
} }
} }
@@ -782,7 +782,7 @@ public class AdtPlugin extends AbstractUIPlugin {
if (sPlugin != null) { if (sPlugin != null) {
if (level <= sPlugin.mBuildVerbosity) { if (level <= sPlugin.mBuildVerbosity) {
String tag = project != null ? project.getName() : null; String tag = project != null ? project.getName() : null;
StreamHelper.printToStream(sPlugin.mAndroidConsoleStream, tag, objects); printToStream(sPlugin.mAndroidConsoleStream, tag, objects);
} }
} }
} }
@@ -794,7 +794,7 @@ public class AdtPlugin extends AbstractUIPlugin {
*/ */
public static synchronized void printToConsole(String tag, Object... objects) { public static synchronized void printToConsole(String tag, Object... objects) {
if (sPlugin != null) { if (sPlugin != null) {
StreamHelper.printToStream(sPlugin.mAndroidConsoleStream, tag, objects); printToStream(sPlugin.mAndroidConsoleStream, tag, objects);
} }
} }
@@ -812,7 +812,7 @@ public class AdtPlugin extends AbstractUIPlugin {
public static void showAndroidConsole() { public static void showAndroidConsole() {
// first make sure the console is in the workbench // first make sure the console is in the workbench
EclipseUiHelper.showView(IConsoleConstants.ID_CONSOLE_VIEW, true); EclipseUiHelper.showView(IConsoleConstants.ID_CONSOLE_VIEW, true);
// now make sure it's not docked. // now make sure it's not docked.
ConsolePlugin.getDefault().getConsoleManager().showConsoleView( ConsolePlugin.getDefault().getConsoleManager().showConsoleView(
AdtPlugin.getDefault().getAndroidConsole()); AdtPlugin.getDefault().getAndroidConsole());
@@ -831,7 +831,7 @@ public class AdtPlugin extends AbstractUIPlugin {
if (sPlugin != null) { if (sPlugin != null) {
return new AndroidPrintStream(project, prefix, sPlugin.mAndroidConsoleStream); return new AndroidPrintStream(project, prefix, sPlugin.mAndroidConsoleStream);
} }
return null; return null;
} }
@@ -848,10 +848,10 @@ public class AdtPlugin extends AbstractUIPlugin {
if (sPlugin != null) { if (sPlugin != null) {
return new AndroidPrintStream(project, prefix, sPlugin.mAndroidConsoleErrorStream); return new AndroidPrintStream(project, prefix, sPlugin.mAndroidConsoleErrorStream);
} }
return null; return null;
} }
/** /**
* Returns whether the Sdk has been loaded. * Returns whether the Sdk has been loaded.
*/ */
@@ -860,7 +860,7 @@ public class AdtPlugin extends AbstractUIPlugin {
return mSdkIsLoaded; return mSdkIsLoaded;
} }
} }
/** /**
* Returns the lock object for SDK loading. If you wish to do things while the SDK is loading, * Returns the lock object for SDK loading. If you wish to do things while the SDK is loading,
* you must synchronize on this object. * you must synchronize on this object.
@@ -868,7 +868,7 @@ public class AdtPlugin extends AbstractUIPlugin {
public final Object getSdkLockObject() { public final Object getSdkLockObject() {
return mPostLoadProjectsToResolve; return mPostLoadProjectsToResolve;
} }
/** /**
* Sets the given {@link IJavaProject} to have its target resolved again once the SDK finishes * Sets the given {@link IJavaProject} to have its target resolved again once the SDK finishes
* to load. * to load.
@@ -878,14 +878,14 @@ public class AdtPlugin extends AbstractUIPlugin {
mPostLoadProjectsToResolve.add(javaProject); mPostLoadProjectsToResolve.add(javaProject);
} }
} }
/** /**
* Sets the given {@link IJavaProject} to have its target checked for consistency * Sets the given {@link IJavaProject} to have its target checked for consistency
* once the SDK finishes to load. This is used if the target is resolved using cached * once the SDK finishes to load. This is used if the target is resolved using cached
* information while the SDK is loading. * information while the SDK is loading.
*/ */
public final void setProjectToCheck(IJavaProject javaProject) { public final void setProjectToCheck(IJavaProject javaProject) {
// only lock on // only lock on
synchronized (getSdkLockObject()) { synchronized (getSdkLockObject()) {
mPostLoadProjectsToCheck.add(javaProject); mPostLoadProjectsToCheck.add(javaProject);
} }
@@ -983,7 +983,7 @@ public class AdtPlugin extends AbstractUIPlugin {
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
try { try {
pingUsageServer(); //$NON-NLS-1$ pingUsageServer(); //$NON-NLS-1$
return Status.OK_STATUS; return Status.OK_STATUS;
} catch (Throwable t) { } catch (Throwable t) {
log(t, "pingUsageServer failed"); //$NON-NLS-1$ log(t, "pingUsageServer failed"); //$NON-NLS-1$
@@ -994,7 +994,7 @@ public class AdtPlugin extends AbstractUIPlugin {
}; };
return job; return job;
} }
/** /**
* Parses the SDK resources. * Parses the SDK resources.
*/ */
@@ -1011,18 +1011,18 @@ public class AdtPlugin extends AbstractUIPlugin {
return new Status(IStatus.WARNING, PLUGIN_ID, return new Status(IStatus.WARNING, PLUGIN_ID,
"An Android SDK is already being loaded. Please try again later."); "An Android SDK is already being loaded. Please try again later.");
} }
mSdkIsLoading = true; mSdkIsLoading = true;
SubMonitor progress = SubMonitor.convert(monitor, SubMonitor progress = SubMonitor.convert(monitor,
"Initialize SDK Manager", 100); "Initialize SDK Manager", 100);
Sdk sdk = Sdk.loadSdk(mOsSdkLocation); Sdk sdk = Sdk.loadSdk(mOsSdkLocation);
if (sdk != null) { if (sdk != null) {
progress.setTaskName(Messages.AdtPlugin_Parsing_Resources); progress.setTaskName(Messages.AdtPlugin_Parsing_Resources);
int n = sdk.getTargets().length; int n = sdk.getTargets().length;
if (n > 0) { if (n > 0) {
int w = 60 / n; int w = 60 / n;
@@ -1043,7 +1043,7 @@ public class AdtPlugin extends AbstractUIPlugin {
mSdkIsLoaded = LoadStatus.LOADED; mSdkIsLoaded = LoadStatus.LOADED;
progress.setTaskName("Check Projects"); progress.setTaskName("Check Projects");
ArrayList<IJavaProject> list = new ArrayList<IJavaProject>(); ArrayList<IJavaProject> list = new ArrayList<IJavaProject>();
for (IJavaProject javaProject : mPostLoadProjectsToResolve) { for (IJavaProject javaProject : mPostLoadProjectsToResolve) {
if (javaProject.getProject().isOpen()) { if (javaProject.getProject().isOpen()) {
@@ -1059,24 +1059,24 @@ public class AdtPlugin extends AbstractUIPlugin {
// do not need to be resolved again). // do not need to be resolved again).
AndroidClasspathContainerInitializer.checkProjectsCache( AndroidClasspathContainerInitializer.checkProjectsCache(
mPostLoadProjectsToCheck); mPostLoadProjectsToCheck);
list.addAll(mPostLoadProjectsToCheck); list.addAll(mPostLoadProjectsToCheck);
// update the project that needs recompiling. // update the project that needs recompiling.
if (list.size() > 0) { if (list.size() > 0) {
IJavaProject[] array = list.toArray( IJavaProject[] array = list.toArray(
new IJavaProject[list.size()]); new IJavaProject[list.size()]);
AndroidClasspathContainerInitializer.updateProjects(array); AndroidClasspathContainerInitializer.updateProjects(array);
} }
progress.worked(10); progress.worked(10);
} }
} }
// Notify resource changed listeners // Notify resource changed listeners
progress.setTaskName("Refresh UI"); progress.setTaskName("Refresh UI");
progress.setWorkRemaining(mTargetChangeListeners.size()); progress.setWorkRemaining(mTargetChangeListeners.size());
// Clone the list before iterating, to avoid Concurrent Modification // Clone the list before iterating, to avoid Concurrent Modification
// exceptions // exceptions
final List<ITargetChangeListener> listeners = final List<ITargetChangeListener> listeners =
@@ -1108,19 +1108,19 @@ public class AdtPlugin extends AbstractUIPlugin {
job.setPriority(Job.BUILD); // build jobs are run after other interactive jobs job.setPriority(Job.BUILD); // build jobs are run after other interactive jobs
job.schedule(); job.schedule();
} }
/** Returns the global android console */ /** Returns the global android console */
public MessageConsole getAndroidConsole() { public MessageConsole getAndroidConsole() {
return mAndroidConsole; return mAndroidConsole;
} }
// ----- Methods for Editors ------- // ----- Methods for Editors -------
public void startEditors() { public void startEditors() {
sAndroidLogoDesc = imageDescriptorFromPlugin(AdtPlugin.PLUGIN_ID, sAndroidLogoDesc = imageDescriptorFromPlugin(AdtPlugin.PLUGIN_ID,
"/icons/android.png"); //$NON-NLS-1$ "/icons/android.png"); //$NON-NLS-1$
sAndroidLogo = sAndroidLogoDesc.createImage(); sAndroidLogo = sAndroidLogoDesc.createImage();
// get the stream to write in the android console. // get the stream to write in the android console.
MessageConsole androidConsole = AdtPlugin.getDefault().getAndroidConsole(); MessageConsole androidConsole = AdtPlugin.getDefault().getAndroidConsole();
mAndroidConsoleStream = androidConsole.newMessageStream(); mAndroidConsoleStream = androidConsole.newMessageStream();
@@ -1153,19 +1153,19 @@ public class AdtPlugin extends AbstractUIPlugin {
/** /**
* The <code>AbstractUIPlugin</code> implementation of this <code>Plugin</code> * The <code>AbstractUIPlugin</code> implementation of this <code>Plugin</code>
* method saves this plug-in's preference and dialog stores and shuts down * method saves this plug-in's preference and dialog stores and shuts down
* its image registry (if they are in use). Subclasses may extend this * its image registry (if they are in use). Subclasses may extend this
* method, but must send super <b>last</b>. A try-finally statement should * method, but must send super <b>last</b>. A try-finally statement should
* be used where necessary to ensure that <code>super.shutdown()</code> is * be used where necessary to ensure that <code>super.shutdown()</code> is
* always done. * always done.
* *
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/ */
public void stopEditors() { public void stopEditors() {
sAndroidLogo.dispose(); sAndroidLogo.dispose();
IconFactory.getInstance().Dispose(); IconFactory.getInstance().Dispose();
// Remove the resource listener that handles compiled resources. // Remove the resource listener that handles compiled resources.
IWorkspace ws = ResourcesPlugin.getWorkspace(); IWorkspace ws = ResourcesPlugin.getWorkspace();
ResourceMonitor.stopMonitoring(ws); ResourceMonitor.stopMonitoring(ws);
@@ -1175,7 +1175,7 @@ public class AdtPlugin extends AbstractUIPlugin {
/** /**
* Returns an Image for the small Android logo. * Returns an Image for the small Android logo.
* *
* Callers should not dispose it. * Callers should not dispose it.
*/ */
public static Image getAndroidLogo() { public static Image getAndroidLogo() {
@@ -1184,13 +1184,13 @@ public class AdtPlugin extends AbstractUIPlugin {
/** /**
* Returns an {@link ImageDescriptor} for the small Android logo. * Returns an {@link ImageDescriptor} for the small Android logo.
* *
* Callers should not dispose it. * Callers should not dispose it.
*/ */
public static ImageDescriptor getAndroidLogoDesc() { public static ImageDescriptor getAndroidLogoDesc() {
return sAndroidLogoDesc; return sAndroidLogoDesc;
} }
/** /**
* Returns the ResourceMonitor object. * Returns the ResourceMonitor object.
*/ */
@@ -1200,23 +1200,23 @@ public class AdtPlugin extends AbstractUIPlugin {
/** /**
* Sets up the editor to register default editors for resource files when needed. * Sets up the editor to register default editors for resource files when needed.
* *
* This is called by the {@link AdtPlugin} during initialization. * This is called by the {@link AdtPlugin} during initialization.
* *
* @param monitor The main Resource Monitor object. * @param monitor The main Resource Monitor object.
*/ */
public void setupDefaultEditor(ResourceMonitor monitor) { public void setupDefaultEditor(ResourceMonitor monitor) {
monitor.addFileListener(new IFileListener() { monitor.addFileListener(new IFileListener() {
private static final String UNKNOWN_EDITOR = "unknown-editor"; //$NON-NLS-1$ private static final String UNKNOWN_EDITOR = "unknown-editor"; //$NON-NLS-1$
/* (non-Javadoc) /* (non-Javadoc)
* Sent when a file changed. * Sent when a file changed.
* @param file The file that changed. * @param file The file that changed.
* @param markerDeltas The marker deltas for the file. * @param markerDeltas The marker deltas for the file.
* @param kind The change kind. This is equivalent to * @param kind The change kind. This is equivalent to
* {@link IResourceDelta#accept(IResourceDeltaVisitor)} * {@link IResourceDelta#accept(IResourceDeltaVisitor)}
* *
* @see IFileListener#fileChanged * @see IFileListener#fileChanged
*/ */
public void fileChanged(IFile file, IMarkerDelta[] markerDeltas, int kind) { public void fileChanged(IFile file, IMarkerDelta[] markerDeltas, int kind) {
@@ -1226,7 +1226,7 @@ public class AdtPlugin extends AbstractUIPlugin {
// There is no support for sub folders, so the segment count must be 4 // There is no support for sub folders, so the segment count must be 4
if (file.getFullPath().segmentCount() == 4) { if (file.getFullPath().segmentCount() == 4) {
// check if we are inside the res folder. // check if we are inside the res folder.
String segment = file.getFullPath().segment(1); String segment = file.getFullPath().segment(1);
if (segment.equalsIgnoreCase(SdkConstants.FD_RESOURCES)) { if (segment.equalsIgnoreCase(SdkConstants.FD_RESOURCES)) {
// we are inside a res/ folder, get the actual ResourceFolder // we are inside a res/ folder, get the actual ResourceFolder
ProjectResources resources = ResourceManager.getInstance(). ProjectResources resources = ResourceManager.getInstance().
@@ -1245,7 +1245,7 @@ public class AdtPlugin extends AbstractUIPlugin {
ResourceFolder resFolder = resources.getResourceFolder( ResourceFolder resFolder = resources.getResourceFolder(
(IFolder)file.getParent()); (IFolder)file.getParent());
if (resFolder != null) { if (resFolder != null) {
if (kind == IResourceDelta.ADDED) { if (kind == IResourceDelta.ADDED) {
resourceAdded(file, resFolder.getType()); resourceAdded(file, resFolder.getType());
@@ -1313,7 +1313,7 @@ public class AdtPlugin extends AbstractUIPlugin {
file.setPersistentProperty(qname, null); file.setPersistentProperty(qname, null);
IWorkbenchPage page = PlatformUI.getWorkbench(). IWorkbenchPage page = PlatformUI.getWorkbench().
getActiveWorkbenchWindow().getActivePage(); getActiveWorkbenchWindow().getActivePage();
IEditorPart oldEditor = page.findEditor(new FileEditorInput(file)); IEditorPart oldEditor = page.findEditor(new FileEditorInput(file));
if (oldEditor != null && if (oldEditor != null &&
AdtPlugin.displayPrompt("Android XML Editor", AdtPlugin.displayPrompt("Android XML Editor",
@@ -1325,7 +1325,7 @@ public class AdtPlugin extends AbstractUIPlugin {
XmlEditor.ID, XmlEditor.ID,
true, /* activate */ true, /* activate */
IWorkbenchPage.MATCH_NONE); IWorkbenchPage.MATCH_NONE);
if (newEditor != null) { if (newEditor != null) {
page.closeEditor(oldEditor, true /* save */); page.closeEditor(oldEditor, true /* save */);
} }
@@ -1378,7 +1378,7 @@ public class AdtPlugin extends AbstractUIPlugin {
} }
}); });
} }
public static synchronized OutputStream getErrorStream() { public static synchronized OutputStream getErrorStream() {
return sPlugin.mAndroidConsoleErrorStream; return sPlugin.mAndroidConsoleErrorStream;
} }
@@ -1398,4 +1398,40 @@ public class AdtPlugin extends AbstractUIPlugin {
SdkStatsService.ping("adt", versionString, getDisplay()); //$NON-NLS-1$ SdkStatsService.ping("adt", versionString, getDisplay()); //$NON-NLS-1$
} }
/**
* Prints messages, associated with a project to the specified stream
* @param stream The stream to write to
* @param tag The tag associated to the message. Can be null
* @param objects The objects to print through their toString() method (or directly for
* {@link String} objects.
*/
public static synchronized void printToStream(MessageConsoleStream stream, String tag,
Object... objects) {
String dateTag = getMessageTag(tag);
for (Object obj : objects) {
stream.print(dateTag);
if (obj instanceof String) {
stream.println((String)obj);
} else {
stream.println(obj.toString());
}
}
}
/**
* Creates a string containing the current date/time, and the tag
* @param tag The tag associated to the message. Can be null
* @return The dateTag
*/
public static String getMessageTag(String tag) {
Calendar c = Calendar.getInstance();
if (tag == null) {
return String.format(Messages.Console_Date_Tag, c);
}
return String.format(Messages.Console_Data_Project_Tag, c, tag);
}
} }

View File

@@ -16,6 +16,10 @@ public class Messages extends NLS {
public static String AdtPlugin_Parsing_Resources; public static String AdtPlugin_Parsing_Resources;
public static String Console_Data_Project_Tag;
public static String Console_Date_Tag;
public static String Could_Not_Find; public static String Could_Not_Find;
public static String Could_Not_Find_Folder; public static String Could_Not_Find_Folder;

View File

@@ -13,4 +13,6 @@ AdtPlugin_Failed_To_Start_s=Failed to start %1$s
AdtPlugin_Android_SDK_Content_Loader=Android SDK Content Loader AdtPlugin_Android_SDK_Content_Loader=Android SDK Content Loader
AdtPlugin_Parsing_Resources=Parsing Resources AdtPlugin_Parsing_Resources=Parsing Resources
AdtPlugin_Android_SDK_Resource_Parser=Android SDK Resource Parser AdtPlugin_Android_SDK_Resource_Parser=Android SDK Resource Parser
AdtPlugin_Failed_To_Parse_s=Failed to parse: AdtPlugin_Failed_To_Parse_s=Failed to parse:
Console_Date_Tag=[%1$tF %1$tT]
Console_Data_Project_Tag=[%1$tF %1$tT - %2$s]

View File

@@ -1,21 +0,0 @@
package com.android.ide.eclipse.common;
import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "com.android.ide.eclipse.common.messages"; //$NON-NLS-1$
public static String Console_Data_Project_Tag;
public static String Console_Date_Tag;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
private Messages() {
}
}

View File

@@ -1,63 +0,0 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Eclipse Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.eclipse.org/org/documents/epl-v10.php
*
* 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 com.android.ide.eclipse.common;
import org.eclipse.ui.console.MessageConsoleStream;
import java.util.Calendar;
/**
* Stream helper class.
*/
public class StreamHelper {
/**
* Prints messages, associated with a project to the specified stream
* @param stream The stream to write to
* @param tag The tag associated to the message. Can be null
* @param objects The objects to print through their toString() method (or directly for
* {@link String} objects.
*/
public static synchronized void printToStream(MessageConsoleStream stream, String tag,
Object... objects) {
String dateTag = getMessageTag(tag);
for (Object obj : objects) {
stream.print(dateTag);
if (obj instanceof String) {
stream.println((String)obj);
} else {
stream.println(obj.toString());
}
}
}
/**
* Creates a string containing the current date/time, and the tag
* @param tag The tag associated to the message. Can be null
* @return The dateTag
*/
public static String getMessageTag(String tag) {
Calendar c = Calendar.getInstance();
if (tag == null) {
return String.format(Messages.Console_Date_Tag, c);
}
return String.format(Messages.Console_Data_Project_Tag, c, tag);
}
}

View File

@@ -1,2 +0,0 @@
Console_Date_Tag=[%1$tF %1$tT]
Console_Data_Project_Tag=[%1$tF %1$tT - %2$s]