diff options
Diffstat (limited to 'sdkmanager/libs/sdklib/src')
6 files changed, 103 insertions, 20 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java index a786728..8284054 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java @@ -463,7 +463,7 @@ public class SdkManager { int revision = 1; LayoutlibVersion layoutlibVersion = null; try { - revision = Integer.parseInt(platformProp.get(PkgProps.PKG_MAJOR_REV)); + revision = Integer.parseInt(platformProp.get(PkgProps.PKG_REVISION)); } catch (NumberFormatException e) { // do nothing, we'll keep the default value of 1. } diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevision.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevision.java index a90fa0a..40235c2 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevision.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevision.java @@ -16,6 +16,11 @@ package com.android.sdklib.internal.repository.packages;
+import com.android.annotations.NonNull;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* Package multi-part revision number composed of a tuple
@@ -32,6 +37,10 @@ public class FullRevision implements Comparable<FullRevision> { public static final int IMPLICIT_MICRO_REV = 0;
public static final int NOT_A_PREVIEW = 0;
+ private final static Pattern FULL_REVISION_PATTERN =
+ // 1=major 2=minor 3=micro 4=preview
+ Pattern.compile("\\s*([0-9]+)(?:\\.([0-9]+)(?:\\.([0-9]+))?)?\\s*(?:rc([0-9]+))?\\s*");
+
private final int mMajor;
private final int mMinor;
private final int mMicro;
@@ -73,6 +82,52 @@ public class FullRevision implements Comparable<FullRevision> { }
/**
+ * Parses a string of format "major.minor.micro rcPreview" and returns
+ * a new {@link FullRevision} for it. All the fields except major are
+ * optional.
+ * <p/>
+ * The parsing is equivalent to the pseudo-BNF/regexp:
+ * <pre>
+ * Major/Minor/Micro/Preview := [0-9]+
+ * Revision := Major ('.' Minor ('.' Micro)? )? \s* ('rc'Preview)?
+ * </pre>
+ *
+ * @param revision A non-null revision to parse.
+ * @return A new non-null {@link FullRevision}.
+ * @throws NumberFormatException if the parsing failed.
+ */
+ public static @NonNull FullRevision parseRevision(@NonNull String revision)
+ throws NumberFormatException {
+
+ if (revision == null) {
+ throw new NumberFormatException("revision is <null>"); //$NON-NLS-1$
+ }
+
+ Throwable cause = null;
+ try {
+ Matcher m = FULL_REVISION_PATTERN.matcher(revision);
+ if (m != null && m.matches()) {
+ int major = Integer.parseInt(m.group(1));
+ String s = m.group(2);
+ int minor = s == null ? IMPLICIT_MINOR_REV : Integer.parseInt(s);
+ s = m.group(3);
+ int micro = s == null ? IMPLICIT_MICRO_REV : Integer.parseInt(s);
+ s = m.group(4);
+ int preview = s == null ? NOT_A_PREVIEW : Integer.parseInt(s);
+
+ return new FullRevision(major, minor, micro, preview);
+ }
+ } catch (Throwable t) {
+ cause = t;
+ }
+
+ NumberFormatException n = new NumberFormatException(
+ "Invalid full revision: " + revision); //$NON-NLS-1$
+ n.initCause(cause);
+ throw n;
+ }
+
+ /**
* Returns the version in a fixed format major.minor.micro
* with an optional "rc preview#". For example it would
* return "18.0.0", "18.1.0" or "18.1.2 rc5".
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 10c4ce0..6028873 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,12 +102,19 @@ public abstract class FullRevisionPackage extends Package super(source, props, revision, license, description, descUrl,
archiveOs, archiveArch, archiveOsPath);
- 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);
+ String revStr = getProperty(props, PkgProps.PKG_REVISION, null);
- mPreviewVersion = new FullRevision(major, minor, micro, preview);
+ FullRevision rev = null;
+ if (revStr != null) {
+ try {
+ rev = FullRevision.parseRevision(revStr);
+ } catch (NumberFormatException ignore) {}
+ }
+ if (rev == null) {
+ rev = new FullRevision(revision);
+ }
+
+ mPreviewVersion = rev;
}
@Override
@@ -118,11 +125,7 @@ public abstract class FullRevisionPackage extends Package @Override
public void saveProperties(Properties props) {
super.saveProperties(props);
-
- props.setProperty(PkgProps.PKG_MAJOR_REV, Integer.toString(mPreviewVersion.getMajor()));
- props.setProperty(PkgProps.PKG_MINOR_REV, Integer.toString(mPreviewVersion.getMinor()));
- props.setProperty(PkgProps.PKG_MICRO_REV, Integer.toString(mPreviewVersion.getMicro()));
- props.setProperty(PkgProps.PKG_PREVIEW_REV, Integer.toString(mPreviewVersion.getPreview()));
+ props.setProperty(PkgProps.PKG_REVISION, mPreviewVersion.toString());
}
@Override
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevision.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevision.java index 2678b1f..9ca9e22 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevision.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevision.java @@ -16,6 +16,8 @@ package com.android.sdklib.internal.repository.packages;
+import com.android.annotations.NonNull;
+
/**
* Package revision number composed of a <em>single</em> major revision.
@@ -34,4 +36,21 @@ public class MajorRevision extends FullRevision { public String toString() {
return super.toShortString();
}
+
+ /**
+ * Parses a single-integer string and returns a new {@link MajorRevision} for it.
+ *
+ * @param revision A non-null revision to parse.
+ * @return A new non-null {@link MajorRevision}.
+ * @throws NumberFormatException if the parsing failed.
+ */
+ public static @NonNull MajorRevision parseRevision(@NonNull String revision)
+ throws NumberFormatException {
+
+ if (revision == null) {
+ throw new NumberFormatException("revision is <null>"); //$NON-NLS-1$
+ }
+
+ return new MajorRevision(Integer.parseInt(revision.trim()));
+ }
}
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 7e61e5f..1348bb9 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,7 +77,19 @@ public abstract class MajorRevisionPackage extends Package { super(source, props, revision, license, description, descUrl,
archiveOs, archiveArch, archiveOsPath);
- mRevision = new MajorRevision(getPropertyInt(props, PkgProps.PKG_MAJOR_REV, revision));
+ String revStr = getProperty(props, PkgProps.PKG_REVISION, null);
+
+ MajorRevision rev = null;
+ if (revStr != null) {
+ try {
+ rev = MajorRevision.parseRevision(revStr);
+ } catch (NumberFormatException ignore) {}
+ }
+ if (rev == null) {
+ rev = new MajorRevision(revision);
+ }
+
+ mRevision = rev;
}
/**
@@ -93,7 +105,7 @@ public abstract class MajorRevisionPackage extends Package { @Override
public void saveProperties(Properties props) {
super.saveProperties(props);
- props.setProperty(PkgProps.PKG_MAJOR_REV, Integer.toString(mRevision.getMajor()));
+ props.setProperty(PkgProps.PKG_REVISION, mRevision.toString());
}
@Override
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/PkgProps.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/PkgProps.java index 4406b42..571a4a6 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/PkgProps.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/PkgProps.java @@ -29,6 +29,7 @@ package com.android.sdklib.repository; public class PkgProps {
// Base Package
+ public static final String PKG_REVISION = "Pkg.Revision"; //$NON-NLS-1$
public static final String PKG_LICENSE = "Pkg.License"; //$NON-NLS-1$
public static final String PKG_DESC = "Pkg.Desc"; //$NON-NLS-1$
public static final String PKG_DESC_URL = "Pkg.DescUrl"; //$NON-NLS-1$
@@ -37,13 +38,6 @@ public class PkgProps { public static final String PKG_SOURCE_URL = "Pkg.SourceUrl"; //$NON-NLS-1$
public static final String PKG_OBSOLETE = "Pkg.Obsolete"; //$NON-NLS-1$
- // FullRevision
- // Note that MajorRev keeps the legacy "Pkg.Revision" property name for legacy compatibility.
- public static final String PKG_MAJOR_REV = "Pkg.Revision"; //$NON-NLS-1$
- public static final String PKG_MINOR_REV = "Pkg.MinorRev"; //$NON-NLS-1$
- public static final String PKG_MICRO_REV = "Pkg.MicroRev"; //$NON-NLS-1$
- public static final String PKG_PREVIEW_REV = "Pkg.PreviewRev"; //$NON-NLS-1$
-
// AndroidVersion
public static final String VERSION_API_LEVEL = "AndroidVersion.ApiLevel";//$NON-NLS-1$
|