From ac70ae6fb318cb4a06d9a332c287bc63cc064dfb Mon Sep 17 00:00:00 2001 From: Raphael Moll Date: Wed, 17 Nov 2010 16:03:09 -0800 Subject: Remove AdtPlugin dependency from AttrsXmlParser. The AdtPluin was used just for logging. Instead the AttrsXmlParser takes an ILogger (AdtPlug implements ILogger and can be used directly in unit tests too). For unit tests there is a new StdSdkLog convenience class that prints to stdout/stderr (formerly MockStdLogger from the Sdk Manager was doing that.) Change-Id: I658af61d04efb19ad6e3bf9c0bf471452372885a --- .../sdkmanager/CommandLineProcessorTest.java | 5 ++- .../com/android/sdkmanager/MockStdLogger.java | 48 -------------------- .../com/android/sdkmanager/SdkCommandLineTest.java | 5 ++- .../sdklib/src/com/android/sdklib/ISdkLog.java | 31 ++++++++++--- .../sdklib/src/com/android/sdklib/StdSdkLog.java | 51 ++++++++++++++++++++++ 5 files changed, 81 insertions(+), 59 deletions(-) delete mode 100644 sdkmanager/app/tests/com/android/sdkmanager/MockStdLogger.java create mode 100644 sdkmanager/libs/sdklib/src/com/android/sdklib/StdSdkLog.java (limited to 'sdkmanager') diff --git a/sdkmanager/app/tests/com/android/sdkmanager/CommandLineProcessorTest.java b/sdkmanager/app/tests/com/android/sdkmanager/CommandLineProcessorTest.java index a213652..688ce52 100644 --- a/sdkmanager/app/tests/com/android/sdkmanager/CommandLineProcessorTest.java +++ b/sdkmanager/app/tests/com/android/sdkmanager/CommandLineProcessorTest.java @@ -17,13 +17,14 @@ package com.android.sdkmanager; import com.android.sdklib.ISdkLog; +import com.android.sdklib.StdSdkLog; import junit.framework.TestCase; public class CommandLineProcessorTest extends TestCase { - private MockStdLogger mLog; + private StdSdkLog mLog; /** * A mock version of the {@link CommandLineProcessor} class that does not @@ -92,7 +93,7 @@ public class CommandLineProcessorTest extends TestCase { @Override protected void setUp() throws Exception { - mLog = new MockStdLogger(); + mLog = new StdSdkLog(); super.setUp(); } diff --git a/sdkmanager/app/tests/com/android/sdkmanager/MockStdLogger.java b/sdkmanager/app/tests/com/android/sdkmanager/MockStdLogger.java deleted file mode 100644 index 961e88d..0000000 --- a/sdkmanager/app/tests/com/android/sdkmanager/MockStdLogger.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2008 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.sdkmanager; - -import com.android.sdklib.ISdkLog; - -/** - * - */ -public class MockStdLogger implements ISdkLog { - - public void error(Throwable t, String errorFormat, Object... args) { - if (errorFormat != null) { - System.err.printf("Error: " + errorFormat, args); - if (!errorFormat.endsWith("\n")) { - System.err.printf("\n"); - } - } - if (t != null) { - System.err.printf("Error: %s\n", t.getMessage()); - } - } - - public void warning(String warningFormat, Object... args) { - System.out.printf("Warning: " + warningFormat, args); - if (!warningFormat.endsWith("\n")) { - System.out.printf("\n"); - } - } - - public void printf(String msgFormat, Object... args) { - System.out.printf(msgFormat, args); - } -} diff --git a/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java b/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java index 07a32e0..8206e2a 100644 --- a/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java +++ b/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java @@ -17,12 +17,13 @@ package com.android.sdkmanager; import com.android.sdklib.ISdkLog; +import com.android.sdklib.StdSdkLog; import junit.framework.TestCase; public class SdkCommandLineTest extends TestCase { - private MockStdLogger mLog; + private StdSdkLog mLog; /** * A mock version of the {@link SdkCommandLine} class that does not @@ -69,7 +70,7 @@ public class SdkCommandLineTest extends TestCase { @Override protected void setUp() throws Exception { - mLog = new MockStdLogger(); + mLog = new StdSdkLog(); super.setUp(); } diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/ISdkLog.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/ISdkLog.java index 163f7a9..ec22177 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/ISdkLog.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/ISdkLog.java @@ -20,9 +20,26 @@ import java.util.Formatter; /** * Interface used to display warnings/errors while parsing the SDK content. + *

+ * There are a few default implementations available: + *

*/ public interface ISdkLog { - + /** * Prints a warning message on stdout. *

@@ -30,13 +47,13 @@ public interface ISdkLog { * need to put such a prefix in the format string. *

* Implementations should only display warnings in verbose mode. - * + * * @param warningFormat is an optional error format. If non-null, it will be printed * using a {@link Formatter} with the provided arguments. * @param args provides the arguments for warningFormat. */ void warning(String warningFormat, Object... args); - + /** * Prints an error message on stderr. *

@@ -44,7 +61,7 @@ public interface ISdkLog { * need to put such a prefix in the format string. *

* Implementation should always display errors, independent of verbose mode. - * + * * @param t is an optional {@link Throwable} or {@link Exception}. If non-null, it's * message will be printed out. * @param errorFormat is an optional error format. If non-null, it will be printed @@ -52,13 +69,13 @@ public interface ISdkLog { * @param args provides the arguments for errorFormat. */ void error(Throwable t, String errorFormat, Object... args); - + /** * Prints a message as-is on stdout. *

- * Implementation should always display errors, independent of verbose mode. + * Implementation can omit printing such messages when not in verbose mode. * No prefix is used, the message is printed as-is after formatting. - * + * * @param msgFormat is an optional error format. If non-null, it will be printed * using a {@link Formatter} with the provided arguments. * @param args provides the arguments for msgFormat. diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/StdSdkLog.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/StdSdkLog.java new file mode 100644 index 0000000..1683808 --- /dev/null +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/StdSdkLog.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2008 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.sdklib; + + +/** + * An implementation of {@link ISdkLog} that prints to {@link System#out} and {@link System#err}. + *

+ * This is mostly useful for unit tests. It should not be used by GUI-based tools (e.g. + * Eclipse plugin or SWT-based apps) which should have a better way to expose their logging + * error and warnings. + */ +public class StdSdkLog implements ISdkLog { + + public void error(Throwable t, String errorFormat, Object... args) { + if (errorFormat != null) { + System.err.printf("Error: " + errorFormat, args); + if (!errorFormat.endsWith("\n")) { + System.err.printf("\n"); + } + } + if (t != null) { + System.err.printf("Error: %s\n", t.getMessage()); + } + } + + public void warning(String warningFormat, Object... args) { + System.out.printf("Warning: " + warningFormat, args); + if (!warningFormat.endsWith("\n")) { + System.out.printf("\n"); + } + } + + public void printf(String msgFormat, Object... args) { + System.out.printf(msgFormat, args); + } +} -- cgit v1.1