OSDN Git Service

SDK: revert c649a334 and fix missing \n properly.
authorRaphael <raphael@google.com>
Tue, 4 Oct 2011 20:25:25 +0000 (13:25 -0700)
committerRaphael <raphael@google.com>
Tue, 4 Oct 2011 20:25:25 +0000 (13:25 -0700)
Change-Id: I4affda9be00c37c4a801816625f57f7eda585ef4

sdkmanager/app/src/com/android/sdkmanager/Main.java
sdkmanager/app/tests/com/android/sdkmanager/MainTest.java
sdkmanager/libs/sdklib/src/com/android/sdklib/ISdkLog.java
sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java

index 139a4e4..7f6d415 100644 (file)
@@ -102,6 +102,12 @@ public class Main {
         new Main().run(args);
     }
 
+    /** Used by tests to set the sdk manager. */
+    @VisibleForTesting(visibility=Visibility.PRIVATE)
+    void setSdkManager(SdkManager sdkManager) {
+        mSdkManager = sdkManager;
+    }
+
     /**
      * Runs the sdk manager app
      */
@@ -143,9 +149,6 @@ public class Main {
 
             public void printf(String msgFormat, Object... args) {
                 System.out.printf(msgFormat, args);
-                if (!msgFormat.endsWith("\n")) {
-                    System.out.printf("\n");
-                }
             }
         };
     }
@@ -773,7 +776,8 @@ public class Main {
     /**
      * Displays the list of available Targets (Platforms and Add-ons)
      */
-    private void displayTargetList() {
+    @VisibleForTesting(visibility=Visibility.PRIVATE)
+    void displayTargetList() {
 
         // Compact output, suitable for scripts.
         if (mSdkCommandLine != null && mSdkCommandLine.getFlagCompact()) {
@@ -835,7 +839,8 @@ public class Main {
     /**
      * Displays the skins valid for the given target.
      */
-    private void displaySkinList(IAndroidTarget target, String message) {
+    @VisibleForTesting(visibility=Visibility.PRIVATE)
+    void displaySkinList(IAndroidTarget target, String message) {
         String[] skins = target.getSkins();
         String defaultSkin = target.getDefaultSkin();
         mSdkLog.printf(message);
@@ -862,7 +867,8 @@ public class Main {
     /**
      * Displays the ABIs valid for the given target.
      */
-    private void displayAbiList(IAndroidTarget target, String message) {
+    @VisibleForTesting(visibility=Visibility.PRIVATE)
+    void displayAbiList(IAndroidTarget target, String message) {
         ISystemImage[] systemImages = target.getSystemImages();
         mSdkLog.printf(message);
         if (systemImages.length > 0) {
@@ -886,7 +892,8 @@ public class Main {
      *
      * @param avdManager
      */
-    public void displayAvdList(AvdManager avdManager) {
+    @VisibleForTesting(visibility=Visibility.PRIVATE)
+    void displayAvdList(AvdManager avdManager) {
 
         AvdInfo[] avds = avdManager.getValidAvds();
 
@@ -1076,7 +1083,7 @@ public class Main {
                 if (systemImages != null && systemImages.length == 1) {
                     // Auto-select the single ABI available
                     abiType = systemImages[0].getAbiType();
-                    mSdkLog.printf("Auto-selecting single ABI %1$s", abiType);
+                    mSdkLog.printf("Auto-selecting single ABI %1$s\n", abiType);
                 } else {
                     displayAbiList(target, "Valid ABIs: ");
                     errorAndExit("This platform has more than one ABI. Please specify one using --%1$s.",
index c0a75c1..74cc1cb 100644 (file)
@@ -117,6 +117,50 @@ public class MainTest extends SdkManagerTestCase {
                 getLog().toString());
     }
 
+    public void testDisplayTargetList() {
+        Main main = new Main();
+        main.setLogger(getLog());
+        main.setSdkManager(getSdkManager());
+        getLog().clear();
+        main.displayTargetList();
+        assertEquals(
+                "[P Available Android targets:\n" +
+                ", P ----------\n" +
+                ", P id: 1 or \"android-0\"\n" +
+                ", P      Name: Android 0.0\n" +
+                ", P      Type: Platform\n" +
+                ", P      API level: 0\n" +
+                ", P      Revision: 1\n" +
+                ", P      Skins: , P \n" +
+                ", P      ABIs : , P armeabi, P \n" +
+                "]",
+                getLog().toString());
+    }
+
+    public void testDisplayAbiList() {
+        Main main = new Main();
+        main.setLogger(getLog());
+        main.setSdkManager(getSdkManager());
+        getLog().clear();
+        main.displayAbiList(mTarget, "message");
+        assertEquals(
+                "[P message, P armeabi, P \n" +
+                "]",
+                getLog().toString());
+    }
+
+    public void testDisplaySkinList() {
+        Main main = new Main();
+        main.setLogger(getLog());
+        main.setSdkManager(getSdkManager());
+        getLog().clear();
+        main.displaySkinList(mTarget, "message");
+        assertEquals(
+                "[P message, P \n" +
+                "]",
+                getLog().toString());
+    }
+
     public void testCheckFilterValues() {
         // These are the values we expect checkFilterValues() to match.
         String[] expectedValues = {
index b1c1f35..df7d8ac 100644 (file)
@@ -72,7 +72,7 @@ public interface ISdkLog {
 
     /**
      * Prints a message on stdout.
-     * IF the message does not end with \n, a carriage return will be inserted.
+     * This does <em>not</em> automatically end the line with \n.
      * <p/>
      * Implementation can omit printing such messages when not in verbose mode.
      * No prefix is used, the message is printed as-is after formatting.
index 5943183..c1a1544 100644 (file)
@@ -578,7 +578,7 @@ public class AvdManager {
             if (createSnapshot) {
                 File snapshotDest = new File(avdFolder, SNAPSHOTS_IMG);
                 if (snapshotDest.isFile() && editExisting) {
-                    log.printf("Snapshot image already present, was not changed.");
+                    log.printf("Snapshot image already present, was not changed.\n");
 
                 } else {
                     String toolsLib = mSdkManager.getLocation() + File.separator
@@ -678,7 +678,7 @@ public class AvdManager {
                             // There's already an sdcard file with the right size and we're
                             // not overriding it... so don't remove it.
                             runMkSdcard = false;
-                            log.printf("SD Card already present with same size, was not changed.");
+                            log.printf("SD Card already present with same size, was not changed.\n");
                         }
                     }