OSDN Git Service

SDK Manager: Fix log printf calls.
authorRaphael Moll <ralf@android.com>
Fri, 26 Aug 2011 19:09:08 +0000 (12:09 -0700)
committerRaphael Moll <ralf@android.com>
Fri, 26 Aug 2011 19:09:08 +0000 (12:09 -0700)
The SDK manager used to have log(String) calls which were
replaced by log(printfFormat, printfArgs..) calls in R12.

In a few places, we pass a string to the printf format that
comes from some user variable or URL or another method and
this string might contain % occurences that should not be
taken as formatters.

Change-Id: Ida29a18ba70d869a4f9d66f1d66edc010d9ec62d

sdkmanager/app/src/com/android/sdkmanager/Main.java
sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java
sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkSource.java
sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/UrlOpener.java
sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkLogAdapter.java

index 10f0853..7a01c3d 100644 (file)
@@ -798,8 +798,7 @@ public class Main {
                     for (IOptionalLibrary library : libraries) {
                         mSdkLog.printf("      * %1$s (%2$s)\n",
                                 library.getName(), library.getJarName());
-                        mSdkLog.printf(String.format(
-                                "          %1$s\n", library.getDescription()));
+                        mSdkLog.printf("          %1$s\n", library.getDescription());
                     }
                 }
             }
index 06e64df..bc95c0c 100755 (executable)
@@ -106,10 +106,9 @@ public class ArchiveInstaller {
             ITaskMonitor monitor,\r
             boolean forceHttp) {\r
 \r
-        String name = archive.getParentPackage().getShortDescription();\r
-        String desc = String.format("Downloading %1$s", name);\r
-        monitor.setDescription(desc);\r
-        monitor.log(desc);\r
+        String pkgName = archive.getParentPackage().getShortDescription();\r
+        monitor.setDescription("Downloading %1$s", pkgName);\r
+        monitor.log("Downloading %1$s", pkgName);\r
 \r
         String link = archive.getUrl();\r
         if (!link.startsWith("http://")                          //$NON-NLS-1$\r
@@ -119,7 +118,7 @@ public class ArchiveInstaller {
             Package pkg = archive.getParentPackage();\r
             SdkSource src = pkg.getParentSource();\r
             if (src == null) {\r
-                monitor.logError("Internal error: no source for archive %1$s", name);\r
+                monitor.logError("Internal error: no source for archive %1$s", pkgName);\r
                 return null;\r
             }\r
 \r
@@ -180,7 +179,7 @@ public class ArchiveInstaller {
             OsHelper.deleteFileOrFolder(tmpFile);\r
         }\r
 \r
-        if (fetchUrl(archive, tmpFile, link, desc, monitor)) {\r
+        if (fetchUrl(archive, tmpFile, link, pkgName, monitor)) {\r
             // Fetching was successful, let's use this file.\r
             return tmpFile;\r
         } else {\r
@@ -216,7 +215,7 @@ public class ArchiveInstaller {
             monitor.logError("File not found: %1$s", e.getMessage());\r
 \r
         } catch (Exception e) {\r
-            monitor.logError(e.getMessage());\r
+            monitor.logError("%1$s", e.getMessage());   //$NON-NLS-1$\r
 \r
         } finally {\r
             if (is != null) {\r
@@ -263,11 +262,9 @@ public class ArchiveInstaller {
     private boolean fetchUrl(Archive archive,\r
             File tmpFile,\r
             String urlString,\r
-            String description,\r
+            String pkgName,\r
             ITaskMonitor monitor) {\r
 \r
-        description += " (%1$d%%, %2$.0f KiB/s, %3$d %4$s left)";\r
-\r
         FileOutputStream os = null;\r
         InputStream is = null;\r
         try {\r
@@ -318,7 +315,13 @@ public class ArchiveInstaller {
                             timeLeft /= 60;\r
                         }\r
 \r
-                        monitor.setDescription(description, percent, speed, timeLeft, timeUnit);\r
+                        monitor.setDescription(\r
+                                "Downloading %1$s (%2$d%%, %3$.0f KiB/s, %4$d %5$s left)",\r
+                                pkgName,\r
+                                percent,\r
+                                speed,\r
+                                timeLeft,\r
+                                timeUnit);\r
                     }\r
                     nextMs = timeMs + 1000;  // update every second\r
                 }\r
@@ -353,7 +356,7 @@ public class ArchiveInstaller {
             monitor.logError("File not found: %1$s", e.getMessage());\r
 \r
         } catch (Exception e) {\r
-            monitor.logError(e.getMessage());\r
+            monitor.logError("%1$s", e.getMessage());   //$NON-NLS-1$\r
 \r
         } finally {\r
             if (os != null) {\r
@@ -387,9 +390,8 @@ public class ArchiveInstaller {
         boolean success = false;\r
         Package pkg = archive.getParentPackage();\r
         String pkgName = pkg.getShortDescription();\r
-        String pkgDesc = String.format("Installing %1$s", pkgName);\r
-        monitor.setDescription(pkgDesc);\r
-        monitor.log(pkgDesc);\r
+        monitor.setDescription("Installing %1$s", pkgName);\r
+        monitor.log("Installing %1$s", pkgName);\r
 \r
         // Ideally we want to always unzip in a temp folder which name depends on the package\r
         // type (e.g. addon, tools, etc.) and then move the folder to the destination folder.\r
@@ -491,7 +493,7 @@ public class ArchiveInstaller {
                 return false;\r
             }\r
 \r
-            if (!unzipFolder(archiveFile, archive.getSize(), destFolder, pkgDesc, monitor)) {\r
+            if (!unzipFolder(archiveFile, archive.getSize(), destFolder, pkgName, monitor)) {\r
                 return false;\r
             }\r
 \r
@@ -574,11 +576,9 @@ public class ArchiveInstaller {
     private boolean unzipFolder(File archiveFile,\r
             long compressedSize,\r
             File unzipDestFolder,\r
-            String description,\r
+            String pkgName,\r
             ITaskMonitor monitor) {\r
 \r
-        description += " (%1$d%%)";\r
-\r
         ZipFile zipFile = null;\r
         try {\r
             zipFile = new ZipFile(archiveFile);\r
@@ -675,7 +675,7 @@ public class ArchiveInstaller {
 \r
                 int percent = (int) (100 * incTotal / compressedSize);\r
                 if (percent != lastPercent) {\r
-                    monitor.setDescription(description, percent);\r
+                    monitor.setDescription("Unzipping %1$s (%2$d%%)", pkgName, percent);\r
                     lastPercent = percent;\r
                 }\r
 \r
index 0f33732..ed40d54 100755 (executable)
@@ -289,7 +289,7 @@ public abstract class SdkSource implements IDescription, Comparable<SdkSource> {
         }\r
 \r
         if (xml != null) {\r
-            monitor.setDescription(String.format("Validate XML: %1$s", url));\r
+            monitor.setDescription("Validate XML: %1$s", url);\r
 \r
             ITaskMonitor subMonitor = monitor.createSubMonitor(2);\r
             subMonitor.setProgressMax(2);\r
@@ -439,7 +439,7 @@ public abstract class SdkSource implements IDescription, Comparable<SdkSource> {
         monitor.incProgress(1);\r
 \r
         if (xml != null) {\r
-            monitor.setDescription(String.format("Parse XML:    %1$s", url));\r
+            monitor.setDescription("Parse XML:    %1$s", url);\r
             monitor.incProgress(1);\r
             parsePackages(validatedDoc, validatedUri, monitor);\r
             if (mPackages == null || mPackages.length == 0) {\r
index 142a77a..74f2b29 100644 (file)
@@ -191,6 +191,13 @@ public class UrlOpener {
                 else {
                     // Use a buffered entity because the stream in which it will
                     // be transfered, will not be closed later, unexpectedly
+
+                    // TODO: an unfortunate side effect is that creating the BufferedHttpEntity
+                    // seems to perform the *actual* download (looking at it, there's a buffer
+                    // being filled in there). So the caller doesn't have a chance to produce
+                    // a meaningful callback with download speed/ETA stats.
+                    // Behavior might be different with a slower network.
+
                     BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity);
                     stream = bufferedEntity.getContent();
                 }
index dc4beb1..1dce2d9 100755 (executable)
@@ -510,8 +510,8 @@ public class UpdaterData implements IUpdaterData {
                                     baos.toString());\r
                         }\r
 \r
-                        monitor.log(msg);\r
-                        mSdkLog.error(t, msg);\r
+                        monitor.log(     "%1$s", msg);      //$NON-NLS-1$\r
+                        mSdkLog.error(t, "%1$s", msg);      //$NON-NLS-1$\r
                     } finally {\r
 \r
                         // Always move the progress bar to the desired position.\r
index aa0b6a5..6ce8b1e 100755 (executable)
@@ -43,7 +43,7 @@ public final class SdkLogAdapter implements ILogUiProvider {
      */\r
     public void setDescription(final String description) {\r
         if (acceptLog(description)) {\r
-            mSdkLog.printf("%1$s", description);\r
+            mSdkLog.printf("%1$s", description);    //$NON-NLS-1$\r
         }\r
     }\r
 \r
@@ -53,7 +53,7 @@ public final class SdkLogAdapter implements ILogUiProvider {
      */\r
     public void log(String log) {\r
         if (acceptLog(log)) {\r
-            mSdkLog.printf("  %1$s", log);\r
+            mSdkLog.printf("  %1$s", log);          //$NON-NLS-1$\r
         }\r
     }\r
 \r
@@ -63,7 +63,7 @@ public final class SdkLogAdapter implements ILogUiProvider {
      */\r
     public void logError(String log) {\r
         if (acceptLog(log)) {\r
-            mSdkLog.error(null, "  %1$s", log);\r
+            mSdkLog.error(null, "  %1$s", log);     //$NON-NLS-1$\r
         }\r
     }\r
 \r
@@ -74,7 +74,7 @@ public final class SdkLogAdapter implements ILogUiProvider {
      */\r
     public void logVerbose(String log) {\r
         if (acceptLog(log)) {\r
-            mSdkLog.printf("    %1$s", log);\r
+            mSdkLog.printf("    %1$s", log);        //$NON-NLS-1$\r
         }\r
     }\r
 \r