diff options
author | Brett Chabot <brettchabot@google.com> | 2023-08-17 13:40:09 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-08-17 13:40:59 -0700 |
commit | deffdc039642fa70d8d90aff0e2c49a13a9911bc (patch) | |
tree | 09c7d1565c88e78b34ee561a5a35629afe53226c /processor | |
parent | f22588428f110ddead10dec82b1958e610eec081 (diff) | |
download | robolectric-deffdc039642fa70d8d90aff0e2c49a13a9911bc.tar.gz |
Use AndroidVersions for determining SDK level in annotation processor.
Robolectric's annotation validator currently has its own, duplicate logic
for reading Android SDK data from the build.prop android-all jar.
This commit replaces this logic with the equivalent AndroidVersions logic.
This change will unlock a consistent view of SDK levels across
Robolectric and future use of the AndroidVersions constants in Robolectric
shadows.
PiperOrigin-RevId: 557923360
Diffstat (limited to 'processor')
-rw-r--r-- | processor/build.gradle | 1 | ||||
-rw-r--r-- | processor/src/main/java/org/robolectric/annotation/processing/validator/SdkStore.java | 20 |
2 files changed, 5 insertions, 16 deletions
diff --git a/processor/build.gradle b/processor/build.gradle index 9185d088a..c2f00d77d 100644 --- a/processor/build.gradle +++ b/processor/build.gradle @@ -34,6 +34,7 @@ tasks['classes'].dependsOn(generateSdksFile) dependencies { api project(":annotations") api project(":shadowapi") + implementation project(":shadows:versioning") compileOnly libs.findbugs.jsr305 api libs.asm diff --git a/processor/src/main/java/org/robolectric/annotation/processing/validator/SdkStore.java b/processor/src/main/java/org/robolectric/annotation/processing/validator/SdkStore.java index 05822d783..e08b3acd1 100644 --- a/processor/src/main/java/org/robolectric/annotation/processing/validator/SdkStore.java +++ b/processor/src/main/java/org/robolectric/annotation/processing/validator/SdkStore.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Properties; import java.util.Set; import java.util.TreeSet; import java.util.jar.JarFile; @@ -40,6 +39,7 @@ import org.objectweb.asm.Type; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode; import org.robolectric.annotation.Implementation; +import org.robolectric.versioning.AndroidVersionInitTools; /** Encapsulates a collection of Android framework jars. */ public class SdkStore { @@ -248,26 +248,14 @@ public class SdkStore { /** * Determine the API level for this SDK jar by inspecting its {@code build.prop} file. * - * <p>If the {@code ro.build.version.codename} value isn't {@code REL}, this is an unreleased - * SDK, which is represented as 10000 (see {@link - * android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}. - * - * @return the API level, or 10000 + * @return the API level */ private int readSdkInt() { - Properties properties = new Properties(); - try (InputStream inputStream = jarFile.getInputStream(jarFile.getJarEntry("build.prop"))) { - properties.load(inputStream); + try { + return AndroidVersionInitTools.computeReleaseVersion(jarFile).getSdkInt(); } catch (IOException e) { throw new RuntimeException("failed to read build.prop from " + path); } - int sdkInt = Integer.parseInt(properties.getProperty("ro.build.version.sdk")); - String codename = properties.getProperty("ro.build.version.codename"); - if (!"REL".equals(codename)) { - sdkInt = 10000; - } - - return sdkInt; } private JarFile ensureJar() { |