aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs/sdklib
diff options
context:
space:
mode:
Diffstat (limited to 'sdkmanager/libs/sdklib')
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ExtraPackage.java6
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevisionPackage.java20
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/LayoutlibVersionMixin.java10
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevisionPackage.java3
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MinToolsPackage.java6
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/Package.java33
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SamplePackage.java12
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ToolPackage.java7
-rwxr-xr-xsdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PackageTest.java16
9 files changed, 67 insertions, 46 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ExtraPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ExtraPackage.java
index b16e189..ed82206 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ExtraPackage.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ExtraPackage.java
@@ -256,10 +256,8 @@ public class ExtraPackage extends MinToolsPackage
mOldPaths = getProperty(props, PkgProps.EXTRA_OLD_PATHS, null);
- mMinApiLevel = Integer.parseInt(
- getProperty(props,
- PkgProps.EXTRA_MIN_API_LEVEL,
- Integer.toString(MIN_API_LEVEL_NOT_SPECIFIED)));
+ mMinApiLevel = getPropertyInt(props, PkgProps.EXTRA_MIN_API_LEVEL,
+ MIN_API_LEVEL_NOT_SPECIFIED);
String projectFiles = getProperty(props, PkgProps.EXTRA_PROJECT_FILES, null);
ArrayList<String> filePaths = new ArrayList<String>();
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevisionPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevisionPackage.java
index 4fad28d..10c4ce0 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevisionPackage.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevisionPackage.java
@@ -102,22 +102,10 @@ public abstract class FullRevisionPackage extends Package
super(source, props, revision, license, description, descUrl,
archiveOs, archiveArch, archiveOsPath);
- int major = Integer.parseInt(
- getProperty(props,
- PkgProps.PKG_MAJOR_REV,
- Integer.toString(revision)));
- int minor = Integer.parseInt(
- getProperty(props,
- PkgProps.PKG_MINOR_REV,
- Integer.toString(FullRevision.IMPLICIT_MINOR_REV)));
- int micro = Integer.parseInt(
- getProperty(props,
- PkgProps.PKG_MICRO_REV,
- Integer.toString(FullRevision.IMPLICIT_MINOR_REV)));
- int preview = Integer.parseInt(
- getProperty(props,
- PkgProps.PKG_PREVIEW_REV,
- Integer.toString(FullRevision.NOT_A_PREVIEW)));
+ int major = getPropertyInt(props, PkgProps.PKG_MAJOR_REV,revision);
+ int minor = getPropertyInt(props, PkgProps.PKG_MINOR_REV, FullRevision.IMPLICIT_MINOR_REV);
+ int micro = getPropertyInt(props, PkgProps.PKG_MICRO_REV, FullRevision.IMPLICIT_MINOR_REV);
+ int preview = getPropertyInt(props, PkgProps.PKG_PREVIEW_REV, FullRevision.NOT_A_PREVIEW);
mPreviewVersion = new FullRevision(major, minor, micro, preview);
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/LayoutlibVersionMixin.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/LayoutlibVersionMixin.java
index c043578..2713fe7 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/LayoutlibVersionMixin.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/LayoutlibVersionMixin.java
@@ -65,12 +65,10 @@ public class LayoutlibVersionMixin implements ILayoutlibVersion {
* Parses the layoutlib version optionally available in the given {@link Properties}.
*/
public LayoutlibVersionMixin(Properties props) {
- int layoutlibApi = Integer.parseInt(
- Package.getProperty(props, PkgProps.LAYOUTLIB_API,
- Integer.toString(LAYOUTLIB_API_NOT_SPECIFIED)));
- int layoutlibRev = Integer.parseInt(
- Package.getProperty(props, PkgProps.LAYOUTLIB_REV,
- Integer.toString(LAYOUTLIB_REV_NOT_SPECIFIED)));
+ int layoutlibApi = Package.getPropertyInt(props, PkgProps.LAYOUTLIB_API,
+ LAYOUTLIB_API_NOT_SPECIFIED);
+ int layoutlibRev = Package.getPropertyInt(props, PkgProps.LAYOUTLIB_REV,
+ LAYOUTLIB_REV_NOT_SPECIFIED);
mLayoutlibVersion = Pair.of(layoutlibApi, layoutlibRev);
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevisionPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevisionPackage.java
index cbd6706..7e61e5f 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevisionPackage.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevisionPackage.java
@@ -77,8 +77,7 @@ public abstract class MajorRevisionPackage extends Package {
super(source, props, revision, license, description, descUrl,
archiveOs, archiveArch, archiveOsPath);
- mRevision = new MajorRevision(Integer.parseInt(
- getProperty(props, PkgProps.PKG_MAJOR_REV, Integer.toString(revision))));
+ mRevision = new MajorRevision(getPropertyInt(props, PkgProps.PKG_MAJOR_REV, revision));
}
/**
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MinToolsPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MinToolsPackage.java
index 05ac96a..3de46b4 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MinToolsPackage.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MinToolsPackage.java
@@ -78,10 +78,8 @@ public abstract class MinToolsPackage extends MajorRevisionPackage implements IM
super(source, props, revision, license, description, descUrl,
archiveOs, archiveArch, archiveOsPath);
- mMinToolsRevision = Integer.parseInt(
- getProperty(props,
- PkgProps.MIN_TOOLS_REV,
- Integer.toString(MIN_TOOLS_REV_NOT_SPECIFIED)));
+ mMinToolsRevision = getPropertyInt(props, PkgProps.MIN_TOOLS_REV,
+ MIN_TOOLS_REV_NOT_SPECIFIED);
}
/**
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/Package.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/Package.java
index ef85f7b..9c6bd44 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/Package.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/Package.java
@@ -16,6 +16,8 @@
package com.android.sdklib.internal.repository.packages;
+import com.android.annotations.NonNull;
+import com.android.annotations.Nullable;
import com.android.annotations.VisibleForTesting;
import com.android.annotations.VisibleForTesting.Visibility;
import com.android.sdklib.AndroidVersion;
@@ -209,7 +211,11 @@ public abstract class Package implements IDescription, Comparable<Package> {
* @return The string value of the given key in the properties, or null if the key
* isn't found or if {@code props} is null.
*/
- static String getProperty(Properties props, String propKey, String defaultValue) {
+ @Nullable
+ static String getProperty(
+ @Nullable Properties props,
+ @NonNull String propKey,
+ @Nullable String defaultValue) {
if (props == null) {
return defaultValue;
}
@@ -217,6 +223,31 @@ public abstract class Package implements IDescription, Comparable<Package> {
}
/**
+ * Utility method that returns an integer property from a {@link Properties} object.
+ * Returns the default value if props is null or if the property is not defined or
+ * cannot be parsed to an integer.
+ *
+ * @param props The {@link Properties} to search into.
+ * If null, the default value is returned.
+ * @param propKey The name of the property. Must not be null.
+ * @param defaultValue The default value to return if {@code props} is null or if the
+ * key is not found. Can be null.
+ * @return The integer value of the given key in the properties, or the {@code defaultValue}.
+ */
+ static int getPropertyInt(
+ @Nullable Properties props,
+ @NonNull String propKey,
+ int defaultValue) {
+ String s = props != null ? props.getProperty(propKey, null) : null;
+ if (s != null) {
+ try {
+ return Integer.parseInt(s);
+ } catch (Exception ignore) {}
+ }
+ return defaultValue;
+ }
+
+ /**
* Save the properties of the current packages in the given {@link Properties} object.
* These properties will later be give the constructor that takes a {@link Properties} object.
*/
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SamplePackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SamplePackage.java
index c2985cf..dcaccf1 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SamplePackage.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SamplePackage.java
@@ -121,10 +121,8 @@ public class SamplePackage extends MinToolsPackage
mVersion = target.getVersion();
- mMinApiLevel = Integer.parseInt(
- getProperty(props,
- PkgProps.SAMPLE_MIN_API_LEVEL,
- Integer.toString(MIN_API_LEVEL_NOT_SPECIFIED)));
+ mMinApiLevel = getPropertyInt(props, PkgProps.SAMPLE_MIN_API_LEVEL,
+ MIN_API_LEVEL_NOT_SPECIFIED);
}
/**
@@ -158,10 +156,8 @@ public class SamplePackage extends MinToolsPackage
mVersion = new AndroidVersion(props);
- mMinApiLevel = Integer.parseInt(
- getProperty(props,
- PkgProps.SAMPLE_MIN_API_LEVEL,
- Integer.toString(MIN_API_LEVEL_NOT_SPECIFIED)));
+ mMinApiLevel = getPropertyInt(props, PkgProps.SAMPLE_MIN_API_LEVEL,
+ MIN_API_LEVEL_NOT_SPECIFIED);
}
/**
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ToolPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ToolPackage.java
index 7ccd617..3fc7405 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ToolPackage.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ToolPackage.java
@@ -144,11 +144,8 @@ public class ToolPackage extends FullRevisionPackage implements IMinPlatformTool
archiveArch,
archiveOsPath);
- mMinPlatformToolsRevision = Integer.parseInt(
- getProperty(
- props,
- PkgProps.MIN_PLATFORM_TOOLS_REV,
- Integer.toString(MIN_PLATFORM_TOOLS_REV_INVALID)));
+ mMinPlatformToolsRevision = getPropertyInt(props, PkgProps.MIN_PLATFORM_TOOLS_REV,
+ MIN_PLATFORM_TOOLS_REV_INVALID);
}
/**
diff --git a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PackageTest.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PackageTest.java
index 4e8ee2e..6023b5a 100755
--- a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PackageTest.java
+++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PackageTest.java
@@ -197,4 +197,20 @@ public class PackageTest extends TestCase {
"Vendor Path, revision 5]",
Arrays.toString(list.toArray()));
}
+
+ public void testGetPropertyInt() {
+ Properties p = new Properties();
+
+ assertEquals(42, Package.getPropertyInt(p, "key", 42));
+
+ p.setProperty("key", "");
+ assertEquals(43, Package.getPropertyInt(p, "key", 43));
+
+ p.setProperty("key", "I am not a number");
+ assertEquals(44, Package.getPropertyInt(p, "key", 44));
+
+ p.setProperty("key", "6");
+ assertEquals(6, Package.getPropertyInt(p, "key", 45));
+ }
+
}