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.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.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.resources;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.ITargetChangeListener;
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.ExportHelper;
import com.android.ide.eclipse.common.project.ExportHelper.IExportCallback;
@@ -109,6 +108,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
/**
@@ -203,7 +203,7 @@ public class AdtPlugin extends AbstractUIPlugin {
@Override
public void println(String message) {
// 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);
if (mPrefix != null) {
@@ -732,7 +732,7 @@ public class AdtPlugin extends AbstractUIPlugin {
String message = String.format(format, args);
Status status = new Status(IStatus.ERROR, PLUGIN_ID, message, exception);
getDefault().getLog().log(status);
StreamHelper.printToStream(sPlugin.mAndroidConsoleErrorStream, tag, message);
printToStream(sPlugin.mAndroidConsoleErrorStream, tag, message);
showAndroidConsole();
}
}
@@ -744,7 +744,7 @@ public class AdtPlugin extends AbstractUIPlugin {
*/
public static synchronized void printErrorToConsole(String tag, Object... objects) {
if (sPlugin != null) {
StreamHelper.printToStream(sPlugin.mAndroidConsoleErrorStream, tag, objects);
printToStream(sPlugin.mAndroidConsoleErrorStream, tag, objects);
showAndroidConsole();
}
@@ -782,7 +782,7 @@ public class AdtPlugin extends AbstractUIPlugin {
if (sPlugin != null) {
if (level <= sPlugin.mBuildVerbosity) {
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) {
if (sPlugin != null) {
StreamHelper.printToStream(sPlugin.mAndroidConsoleStream, tag, objects);
printToStream(sPlugin.mAndroidConsoleStream, tag, objects);
}
}
@@ -1398,4 +1398,40 @@ public class AdtPlugin extends AbstractUIPlugin {
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 Console_Data_Project_Tag;
public static String Console_Date_Tag;
public static String Could_Not_Find;
public static String Could_Not_Find_Folder;

View File

@@ -14,3 +14,5 @@ AdtPlugin_Android_SDK_Content_Loader=Android SDK Content Loader
AdtPlugin_Parsing_Resources=Parsing Resources
AdtPlugin_Android_SDK_Resource_Parser=Android SDK Resource Parser
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]