diff --git a/.gitignore b/.gitignore index 39b6783..9a4caa4 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,7 @@ captures/ # IntelliJ *.iml -.idea/workspace.xml +.idea .idea/tasks.xml .idea/gradle.xml .idea/assetWizardSettings.xml diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..0217106 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,54 @@ +apply plugin: 'com.android.application' +apply plugin: 'api.inspect' + +apiInspect { + + enable true + + inspectSystemApi false + +// include { +// api "com.zxy.tiny" +// } + +// exclude { +// api "com.zxy.tiny" +// } + +} + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.zxy.android.plugin.apiinspect.test" + minSdkVersion 15 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +repositories { + flatDir { + dirs 'libs' + } +} + +dependencies { + implementation(name: 'ui-release', ext: 'aar') + implementation(name: 'common-release', ext: 'aar') + implementation(name: 'base-release', ext: 'aar') + + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +} diff --git a/app/libs/base-release.aar b/app/libs/base-release.aar new file mode 100644 index 0000000..6f37d0a Binary files /dev/null and b/app/libs/base-release.aar differ diff --git a/app/libs/common-release.aar b/app/libs/common-release.aar new file mode 100644 index 0000000..a69ab87 Binary files /dev/null and b/app/libs/common-release.aar differ diff --git a/app/libs/ui-release.aar b/app/libs/ui-release.aar new file mode 100644 index 0000000..05b78e2 Binary files /dev/null and b/app/libs/ui-release.aar differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/zxy/android/plugin/apiinspect/test/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/zxy/android/plugin/apiinspect/test/ExampleInstrumentedTest.java new file mode 100644 index 0000000..14379a1 --- /dev/null +++ b/app/src/androidTest/java/com/zxy/android/plugin/apiinspect/test/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.zxy.android.plugin.apiinspect.test; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.zxy.android.plugin.apiinspect.test", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..5170939 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/zxy/android/plugin/apiinspect/test/MainActivity.java b/app/src/main/java/com/zxy/android/plugin/apiinspect/test/MainActivity.java new file mode 100644 index 0000000..c85df6f --- /dev/null +++ b/app/src/main/java/com/zxy/android/plugin/apiinspect/test/MainActivity.java @@ -0,0 +1,21 @@ +package com.zxy.android.plugin.apiinspect.test; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; + +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Arrays; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } + +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..84f1951 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..898f3ed Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..dffca36 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..64ba76f Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..dae5e08 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..e5ed465 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..14ed0af Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..b0907ca Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..d8ae031 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..2c18de9 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..beed3cd Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..69b2233 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #008577 + #00574B + #D81B60 + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..2be3ef8 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + ApiInspect + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..5885930 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/app/src/test/java/com/zxy/android/plugin/apiinspect/test/ExampleUnitTest.java b/app/src/test/java/com/zxy/android/plugin/apiinspect/test/ExampleUnitTest.java new file mode 100644 index 0000000..98aa409 --- /dev/null +++ b/app/src/test/java/com/zxy/android/plugin/apiinspect/test/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.zxy.android.plugin.apiinspect.test; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..38d28b6 --- /dev/null +++ b/build.gradle @@ -0,0 +1,27 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + + repositories { + google() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.1.4' + classpath 'com.novoda:bintray-release:0.8.1' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000..fef49b9 --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,39 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + maven { + url "https://maven.google.com" + } + mavenCentral() + mavenLocal() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.1.4' + classpath 'com.novoda:bintray-release:0.8.1' + } + configurations.all { + it.resolutionStrategy.cacheDynamicVersionsFor(5, 'minutes') + it.resolutionStrategy.cacheChangingModulesFor(0, 'seconds') + } +} + +allprojects { + repositories { + maven { + url "https://maven.google.com" + } + mavenCentral() + mavenLocal() + jcenter() + } + configurations.all { + it.resolutionStrategy.cacheDynamicVersionsFor(5, 'minutes') + it.resolutionStrategy.cacheChangingModulesFor(0, 'seconds') + } +} + +dependencies { + implementation project(":inspect-plugin") +} \ No newline at end of file diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties new file mode 100644 index 0000000..4e07ef0 --- /dev/null +++ b/buildSrc/gradle.properties @@ -0,0 +1,17 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +org.gradle.parallel=true \ No newline at end of file diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle new file mode 100644 index 0000000..95e7735 --- /dev/null +++ b/buildSrc/settings.gradle @@ -0,0 +1,3 @@ +include ':inspect-plugin' +project(":inspect-plugin").projectDir = new File("../inspect-plugin") + diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..82618ce --- /dev/null +++ b/gradle.properties @@ -0,0 +1,15 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true + + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..f6b961f Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..9a4163a --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..e95643d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/inspect-plugin/.gitignore b/inspect-plugin/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/inspect-plugin/.gitignore @@ -0,0 +1 @@ +/build diff --git a/inspect-plugin/build.gradle b/inspect-plugin/build.gradle new file mode 100644 index 0000000..d9139c6 --- /dev/null +++ b/inspect-plugin/build.gradle @@ -0,0 +1,30 @@ +apply plugin: 'groovy' +apply plugin: 'com.novoda.bintray-release' + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation gradleApi()//gradle sdk + implementation localGroovy()//groovy sdk + implementation 'com.android.tools.build:gradle:3.1.4' + implementation 'org.javassist:javassist:3.20.0-GA' +} + +Properties properties = new Properties() +properties.load(project.rootProject.file('local.properties').newDataInputStream()) + +publish { + userOrg = 'sunzxyong' + uploadName = 'ApiInspect' + groupId = 'com.zxy.android.plugin' + artifactId = 'api-inspect' + publishVersion = '0.0.1' + repoName = 'maven' + dryRun = 'false' + desc = 'An api compatibility inspect gradle plugin.' + website = 'https://github.com/Sunzxyong/ApiInspect' + issueTracker = 'https://github.com/Sunzxyong/ApiInspect/issues' + repository = 'https://github.com/Sunzxyong/ApiInspect.git' + bintrayUser = properties.getProperty("bintray.user") + bintrayKey = properties.getProperty("bintray.apikey") +} +//./gradlew :inspect-plugin:clean :inspect-plugin:build :inspect-plugin:bintrayUpload -PdryRun=false \ No newline at end of file diff --git a/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectExcludeExtension.groovy b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectExcludeExtension.groovy new file mode 100644 index 0000000..4085d1c --- /dev/null +++ b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectExcludeExtension.groovy @@ -0,0 +1,18 @@ +package com.zxy.android.plugin.api.inspect + +import com.google.common.base.Strings + +/** + * Created by zhengxiaoyong on 2018/12/22. + */ +class ApiInspectExcludeExtension { + + Set apis = new HashSet<>() + + void api(String api) { + if (Strings.isNullOrEmpty(api)) + return + apis.add(api) + } + +} diff --git a/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectExtension.groovy b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectExtension.groovy new file mode 100644 index 0000000..2d966dc --- /dev/null +++ b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectExtension.groovy @@ -0,0 +1,34 @@ +package com.zxy.android.plugin.api.inspect + +import org.gradle.api.Action +import org.gradle.api.Project +import org.gradle.api.model.ObjectFactory + +/** + * Created by zhengxiaoyong on 2018/12/22. + */ +class ApiInspectExtension { + + boolean enable = true + + boolean inspectSystemApi = false + + ApiInspectIncludeExtension include + + ApiInspectExcludeExtension exclude + + ApiInspectExtension(Project project) { + ObjectFactory objectFactory = project.getObjects() + include = objectFactory.newInstance(ApiInspectIncludeExtension.class) + exclude = objectFactory.newInstance(ApiInspectExcludeExtension.class) + } + + void include(Action action) { + action.execute(include) + } + + void exclude(Action action) { + action.execute(exclude) + } + +} diff --git a/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectFilter.groovy b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectFilter.groovy new file mode 100644 index 0000000..4e57139 --- /dev/null +++ b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectFilter.groovy @@ -0,0 +1,17 @@ +package com.zxy.android.plugin.api.inspect + +import javassist.CtClass +import javassist.CtMethod + +/** + * Created by zhengxiaoyong on 2018/12/24. + */ +interface ApiInspectFilter { + + boolean filter(CtClass clazz) + + boolean filter(String className) + + boolean filter(CtMethod method) + +} diff --git a/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectIncludeExtension.groovy b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectIncludeExtension.groovy new file mode 100644 index 0000000..5509ae5 --- /dev/null +++ b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectIncludeExtension.groovy @@ -0,0 +1,18 @@ +package com.zxy.android.plugin.api.inspect + +import com.google.common.base.Strings + +/** + * Created by zhengxiaoyong on 2018/12/22. + */ +class ApiInspectIncludeExtension { + + Set apis = new HashSet<>() + + void api(String api) { + if (Strings.isNullOrEmpty(api)) + return + apis.add(api) + } + +} diff --git a/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectPlugin.groovy b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectPlugin.groovy new file mode 100644 index 0000000..6dc405c --- /dev/null +++ b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectPlugin.groovy @@ -0,0 +1,25 @@ +package com.zxy.android.plugin.api.inspect + +import org.gradle.api.Plugin +import org.gradle.api.Project + +/** + * Created by zhengxiaoyong on 2018/12/22. + */ +class ApiInspectPlugin implements Plugin { + + @Override + void apply(Project project) { + def android = null + if (project.plugins.hasPlugin("com.android.application")) { + android = project.extensions.getByType(AppExtension) + } else if (project.plugins.hasPlugin("com.android.library")) { + android = project.extensions.getByType(LibraryExtension) + } + + if (android == null) + return + project.extensions.create("apiInspect", ApiInspectExtension.class, project) + android.registerTransform(new ApiInspectTransform(project)) + } +} diff --git a/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectTools.groovy b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectTools.groovy new file mode 100644 index 0000000..5ce999f --- /dev/null +++ b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectTools.groovy @@ -0,0 +1,106 @@ +package com.zxy.android.plugin.api.inspect + +import com.android.utils.FileUtils +import com.google.common.base.Strings +import javassist.ClassPool +import javassist.CtClass +import org.gradle.api.Project + +/** + * Created by zhengxiaoyong on 2018/12/23. + */ +class ApiInspectTools { + + static void exportApiInspectInfo(Project project, String variant, Set inspectedPackages, Set inspectedClasses) { + File target = new File(project.buildDir, "api-inspect" + File.separator + variant + File.separator + "inspect-info.txt") + target.parentFile.mkdirs() + FileUtils.deleteIfExists(target) + target.createNewFile() + BufferedWriter writer = target.newWriter("UTF-8", true) + + writer.write("==================================>Inspect Packages<==================================\n") + if (!inspectedPackages.isEmpty()) { + inspectedPackages.each { + writer.write("> $it\n") + } + } else { + writer.write("> NONE.\n") + } + writer.write("======================================================================================\n\n") + + writer.write("==================================>Inspect Classes<==================================\n") + if (!inspectedClasses.isEmpty()) { + inspectedClasses.each { + writer.write("> $it\n") + } + } else { + writer.write("> NONE.\n") + } + writer.write("======================================================================================\n\n") + writer.flush() + writer.close() + } + + static void exportApiInspectResult(Project project, String variant, Set incompatibleClassInfoSet, Set incompatibleMethodInfoSet) { + File target = new File(project.buildDir, "api-inspect" + File.separator + variant + File.separator + "inspect-result.txt") + target.parentFile.mkdirs() + FileUtils.deleteIfExists(target) + target.createNewFile() + BufferedWriter writer = target.newWriter("UTF-8", true) + + writer.write("==================================>Inspect Results<==================================\n") + if (!incompatibleClassInfoSet.isEmpty()) { + incompatibleClassInfoSet.each { + writer.write("Incompatible Api -> [ClassName: ${it.incompatibleClassName}]\n") + writer.write(" └> [Occur In Class : ${it.className}]\n") + } + } + + if (!incompatibleMethodInfoSet.isEmpty()) { + incompatibleMethodInfoSet.each { + writer.write("Incompatible Api -> [ClassName: ${it.incompatibleClassName}]\n") + writer.write(" └> [MethodName: ${it.methodName}]\n") + writer.write(" └> [Occur In Class: ${it.className}, Line: ${it.lineNumber}]\n") + } + } + + if (incompatibleClassInfoSet.isEmpty() && incompatibleMethodInfoSet.isEmpty()) { + writer.write("> NONE.\n") + } + writer.write("======================================================================================\n\n") + writer.flush() + writer.close() + } + + static String getPackageFromBuildConfig(ClassPool classPool, Project project, File jarFile) { + def jarPath = jarFile.absolutePath + if (jarPath == null) + return null + def buildConfigs = project.zipTree(jarPath).filter { + it.name == "BuildConfig.class" + } + + def packageName + + if (buildConfigs != null && buildConfigs.size() > 0) { + def classStream = null + try { + def file = buildConfigs.getSingleFile() + classStream = new FileInputStream(file) + CtClass ctClass = classPool.makeClass(classStream) + packageName = ctClass.getDeclaredField("APPLICATION_ID").constantValue + + if (Strings.isNullOrEmpty(packageName)) { + packageName = ctClass.getPackageName() + } + + return packageName + } catch (Exception e) { + if (classStream != null) + classStream.close() + } + } + return null + } + +} diff --git a/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectTransform.groovy b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectTransform.groovy new file mode 100644 index 0000000..dcf3a43 --- /dev/null +++ b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspectTransform.groovy @@ -0,0 +1,292 @@ +package com.zxy.android.plugin.api.inspect + +import com.android.SdkConstants +import com.android.build.api.transform.DirectoryInput +import com.android.build.api.transform.Format +import com.android.build.api.transform.JarInput +import com.android.build.api.transform.QualifiedContent +import com.android.build.api.transform.Status +import com.android.build.api.transform.Transform +import com.android.build.api.transform.TransformException +import com.android.build.api.transform.TransformInput +import com.android.build.api.transform.TransformInvocation +import com.android.build.api.transform.TransformOutputProvider +import com.android.build.gradle.AppExtension +import com.android.utils.FileUtils +import com.google.common.base.Strings +import com.google.common.collect.ImmutableSet +import javassist.ClassPool +import javassist.CtClass +import org.gradle.api.GradleException +import org.gradle.api.Project + +import java.util.jar.JarEntry +import java.util.jar.JarFile + +/** + * Created by zhengxiaoyong on 2018/12/22. + */ +class ApiInspectTransform extends Transform { + + Project mProject + + ClassPool mClassPool + + ApiInspector mApiInspector + + ApiInspectExtension mApiInspectExtension + + Set mClassDirectoryPaths = new HashSet<>() + + Set mJarFilePaths = new HashSet<>() + + ApiInspectTransform(Project project) { + this.mProject = project + mApiInspectExtension = mProject.extensions.findByType(ApiInspectExtension.class) + } + + @Override + String getName() { + return "apiInspect" + } + + @Override + Set getInputTypes() { + return ImmutableSet.of(QualifiedContent.DefaultContentType.CLASSES) + } + + @Override + Set getScopes() { + return ImmutableSet.of( + QualifiedContent.Scope.PROJECT, + QualifiedContent.Scope.PROJECT_LOCAL_DEPS, + QualifiedContent.Scope.SUB_PROJECTS, + QualifiedContent.Scope.SUB_PROJECTS_LOCAL_DEPS, + QualifiedContent.Scope.EXTERNAL_LIBRARIES) + } + + @Override + Set getReferencedScopes() { + return ImmutableSet.of(QualifiedContent.Scope.PROVIDED_ONLY) + } + + @Override + boolean isIncremental() { + return true + } + + @Override + void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException { + super.transform(transformInvocation) + + TransformOutputProvider outputProvider = transformInvocation.getOutputProvider() + if (outputProvider == null) { + throw new IllegalArgumentException("Missing output object for transform " + getName()) + } + + if (!mApiInspectExtension.enable) { + justNoOp(transformInvocation, outputProvider) + return + } + + initialize(transformInvocation) + + if (transformInvocation.isIncremental() && isIncremental()) { + transformInvocation.inputs.each { TransformInput input -> + input.directoryInputs.each { DirectoryInput directoryInput -> + File classDirectory = outputProvider.getContentLocation(directoryInput.name, directoryInput.contentTypes, directoryInput.scopes, Format.DIRECTORY) + + mClassPool.appendClassPath(classDirectory.absolutePath) + + Map changedFiles = directoryInput.getChangedFiles() + for (Map.Entry changedInput : changedFiles.entrySet()) { + File changeInputFile = changedInput.getKey() + Status status = changedInput.getValue() + + if (!changeInputFile.getName().endsWith(SdkConstants.DOT_CLASS)) { + continue + } + switch (status) { + case Status.NOTCHANGED: + //do nothing. + break + case Status.ADDED: + case Status.CHANGED: + String addFileName = FileUtils.relativePossiblyNonExistingPath(changeInputFile, directoryInput.file) + File addFile = new File(classDirectory, addFileName) + FileUtils.copyFile(changeInputFile, addFile) + break + case Status.REMOVED: + String removeFileName = FileUtils.relativePossiblyNonExistingPath(changeInputFile, directoryInput.file) + File removeFile = new File(classDirectory, removeFileName) + if (removeFile.exists()) { + if (removeFile.isDirectory()) { + FileUtils.deletePath(removeFile) + } else { + FileUtils.deleteIfExists(removeFile) + } + } + break + default: + break + } + } + } + + input.jarInputs.each { JarInput jarInput -> + File jarFile = outputProvider.getContentLocation(jarInput.name, jarInput.contentTypes, jarInput.scopes, Format.JAR) + + switch (jarInput.status) { + case Status.NOTCHANGED: + //do nothing. + mClassPool.appendClassPath(jarFile.absolutePath) + break + case Status.ADDED: + case Status.CHANGED: + FileUtils.copyFile(jarInput.file, jarFile) + mClassPool.appendClassPath(jarFile.absolutePath) + mJarFilePaths.add(jarFile) + break + case Status.REMOVED: + FileUtils.deleteIfExists(jarFile) + break + } + } + } + } else { + outputProvider.deleteAll() + + transformInvocation.inputs.each { TransformInput input -> + input.directoryInputs.each { DirectoryInput directoryInput -> + File classDirectory = outputProvider.getContentLocation(directoryInput.name, directoryInput.contentTypes, directoryInput.scopes, Format.DIRECTORY) + FileUtils.copyDirectory(directoryInput.file, classDirectory) + + mClassPool.appendClassPath(classDirectory.absolutePath) + mClassDirectoryPaths.add(classDirectory) + } + + input.jarInputs.each { JarInput jarInput -> + File jarFile = outputProvider.getContentLocation(jarInput.name, jarInput.contentTypes, jarInput.scopes, Format.JAR) + FileUtils.copyFile(jarInput.file, jarFile) + + mClassPool.appendClassPath(jarFile.absolutePath) + mJarFilePaths.add(jarFile) + } + } + } + + mJarFilePaths.each { jarFile -> + if (shouldInspectApi(jarFile) && jarFile.getName().endsWith(SdkConstants.DOT_JAR)) { + JarFile jar = new JarFile(jarFile) + Enumeration jarEntries = jar.entries() + while (jarEntries.hasMoreElements()) { + JarEntry jarEntry = jarEntries.nextElement() + if (jarEntry.isDirectory()) + continue + String entryName = jarEntry.getName() + if (entryName.endsWith(SdkConstants.DOT_CLASS)) { + String className = entryName.replace('\\', '.').replace(File.separator, '.') + className = className.substring(0, className.length() - SdkConstants.DOT_CLASS.length()) + try { + CtClass clazz = mClassPool.get(className) + mApiInspector.inspectClass(mClassPool, clazz) + } catch (Exception e) { + //ignore. + } + } + } + } + } + + Set incompatibleClassInfoSet = mApiInspector.getIncompatibleClasses() + Set incompatibleMethodInfoSet = mApiInspector.getIncompatibleMethods() + + if (!incompatibleClassInfoSet.isEmpty() || !incompatibleMethodInfoSet.isEmpty()) { + mProject.logger.error("\n==================================>Api Incompatible<==================================") + incompatibleClassInfoSet.each { + mProject.logger.error("Incompatible Api -> [ClassName: ${it.incompatibleClassName}]") + mProject.logger.error(" └> [Occur in class : ${it.className}]") + } + incompatibleMethodInfoSet.each { + mProject.logger.error("Incompatible Api -> [ClassName: ${it.incompatibleClassName}]") + mProject.logger.error(" └> [MethodName: ${it.methodName}]") + mProject.logger.error(" └> [Occur in class: ${it.className}, Line: ${it.lineNumber}]") + } + mProject.logger.error("======================================================================================\n") + } + + def variant = transformInvocation.context.variantName + ApiInspectTools.exportApiInspectInfo(mProject, variant, mApiInspector.getInspectedPackages(), mApiInspector.getInspectedClasses()) + ApiInspectTools.exportApiInspectResult(mProject, variant, incompatibleClassInfoSet, incompatibleMethodInfoSet) + } + + def justNoOp(TransformInvocation transformInvocation, TransformOutputProvider outputProvider) { + outputProvider.deleteAll() + + transformInvocation.inputs.each { TransformInput input -> + input.directoryInputs.each { DirectoryInput directoryInput -> + File classDirectory = outputProvider.getContentLocation(directoryInput.name, directoryInput.contentTypes, directoryInput.scopes, Format.DIRECTORY) + FileUtils.copyDirectory(directoryInput.file, classDirectory) + } + + input.jarInputs.each { JarInput jarInput -> + File jarFile = outputProvider.getContentLocation(jarInput.name, jarInput.contentTypes, jarInput.scopes, Format.JAR) + FileUtils.copyFile(jarInput.file, jarFile) + } + } + } + + def shouldInspectApi(File jarFile) { + String packageName = ApiInspectTools.getPackageFromBuildConfig(mClassPool, mProject, jarFile) + + if (Strings.isNullOrEmpty(packageName)) + return false + + ApiInspectIncludeExtension includeExtension = mApiInspectExtension.include + ApiInspectExcludeExtension excludeExtension = mApiInspectExtension.exclude + + if (includeExtension != null && !includeExtension.apis.isEmpty()) { + Set apis = includeExtension.apis + boolean include = apis.contains(packageName) + if (include) + mApiInspector.addInspectedPackage(packageName) + return include + } else if (excludeExtension != null && !excludeExtension.apis.isEmpty()) { + Set apis = excludeExtension.apis + boolean exclude = apis.contains(packageName) + if (!exclude) + mApiInspector.addInspectedPackage(packageName) + return !exclude + } + + return true + } + + def initialize(TransformInvocation transformInvocation) { + mClassPool = new ClassPool() + mApiInspector = new ApiInspector(mProject) + + def android + if (mProject.plugins.hasPlugin("com.android.application")) { + android = mProject.extensions.getByType(AppExtension) + } else if (mProject.plugins.hasPlugin("com.android.library")) { + android = mProject.extensions.getByType(LibraryExtension) + } else { + throw new GradleException("The plugin type is not supported!") + } + + def androidJar = "${android.getSdkDirectory().getAbsolutePath()}${File.separator}platforms${File.separator}" + + "${android.getCompileSdkVersion()}${File.separator}android.jar" + mClassPool.appendClassPath(androidJar) + + Collection referencedInputs = transformInvocation.getReferencedInputs() + referencedInputs.each { + it.directoryInputs.each { + mClassPool.appendClassPath(it.file.absolutePath) + } + it.jarInputs.each { + mClassPool.appendClassPath(it.file.absolutePath) + } + } + } +} diff --git a/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspector.groovy b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspector.groovy new file mode 100644 index 0000000..4f13d44 --- /dev/null +++ b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/ApiInspector.groovy @@ -0,0 +1,122 @@ +package com.zxy.android.plugin.api.inspect + +import com.google.common.base.Strings +import javassist.CannotCompileException +import javassist.ClassPool +import javassist.CtClass +import javassist.CtMethod +import javassist.NotFoundException +import javassist.expr.ExprEditor +import javassist.expr.MethodCall +import org.gradle.api.Project + +/** + * Created by zhengxiaoyong on 2018/12/22. + */ +class ApiInspector { + + private Project mProject + + private Set mInspectedClasses = new HashSet<>() + + private Set mInspectedPackages = new HashSet<>() + + private Set mIncompatibleClasses = new HashSet<>() + + private Set mIncompatibleMethods = new HashSet<>() + + private ApiInspectFilter mApiInspectFilter + + ApiInspector(Project project) { + this.mProject = project + mApiInspectFilter = new DefaultApiInspectFilter(project) + } + + Set getInspectedClasses() { + return mInspectedClasses + } + + Set getInspectedPackages() { + return mInspectedPackages + } + + Set getIncompatibleClasses() { + return mIncompatibleClasses + } + + Set getIncompatibleMethods() { + return mIncompatibleMethods + } + + void addInspectedPackage(String packageName) { + mInspectedPackages.add(packageName) + } + + void inspectClass(ClassPool classPool, CtClass clazz) { + if (mApiInspectFilter.filter(clazz)) + return + + if (!shouldInspect(clazz.name)) + return + + clazz.getRefClasses().each { + if (!mApiInspectFilter.filter(it)) { + try { + classPool.get(it) + } catch (NotFoundException e) { + IncompatibleClassInfo info = new IncompatibleClassInfo() + info.className = clazz.name + info.incompatibleClassName = it + mIncompatibleClasses.add(info) + } catch (Exception e) { + //ignore. + } + } + } + + inspectMethod(clazz) + } + + void inspectMethod(CtClass clazz) { + CtMethod[] methods = clazz.getDeclaredMethods() + if (methods == null || methods.length == 0) + return + + try { + methods.each { + it.instrument(new ExprEditor() { + @Override + void edit(MethodCall m) throws CannotCompileException { + super.edit(m) + try { + m.getMethod() + } catch (NotFoundException e) { + IncompatibleMethodInfo info = new IncompatibleMethodInfo() + info.className = clazz.name + info.incompatibleClassName = m.className + info.methodName = m.methodName + info.signature = m.signature + info.lineNumber = m.lineNumber + mIncompatibleMethods.add(info) + } catch (Exception e) { + //ignore. + } + } + }) + } + } catch (Exception e) { + //ignore. + } + } + + boolean shouldInspect(String className) { + if (Strings.isNullOrEmpty(className)) + return false + boolean inspect = mInspectedClasses.contains(className) + if (!inspect) { + mInspectedClasses.add(className) + } + return !inspect + } + +} diff --git a/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/DefaultApiInspectFilter.groovy b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/DefaultApiInspectFilter.groovy new file mode 100644 index 0000000..48656ca --- /dev/null +++ b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/DefaultApiInspectFilter.groovy @@ -0,0 +1,58 @@ +package com.zxy.android.plugin.api.inspect + +import com.android.SdkConstants +import javassist.CtClass +import javassist.CtMethod +import org.gradle.api.Project + +/** + * Created by zhengxiaoyong on 2018/12/24. + */ +class DefaultApiInspectFilter implements ApiInspectFilter { + + Project mProject + + ApiInspectExtension mApiInspectExtension + + DefaultApiInspectFilter(Project project) { + this.mProject = project + mApiInspectExtension = mProject.extensions.findByType(ApiInspectExtension.class) + } + + @Override + boolean filter(CtClass clazz) { + boolean inspectSystemApi = mApiInspectExtension.inspectSystemApi + return isSystemGenerateClass(clazz.getSimpleName()) || isJavaSystemClass(clazz.getName()) || inspectSystemApi ? true : isAndroidSystemClass(clazz.getName()) + } + + @Override + boolean filter(String className) { + boolean inspectSystemApi = mApiInspectExtension.inspectSystemApi + if (!className.endsWith(SdkConstants.DOT_CLASS)) + className += SdkConstants.DOT_CLASS + int index = className.lastIndexOf('.') + String simpleName = className + if (index >= 0) { + simpleName = className.substring(index + 1) + } + return isSystemGenerateClass(simpleName) || isJavaSystemClass(className) || inspectSystemApi ? true : isAndroidSystemClass(className) + } + + @Override + boolean filter(CtMethod method) { + return false + } + + boolean isSystemGenerateClass(String name) { + return name.endsWith(SdkConstants.DOT_CLASS) && (name.startsWith('R$') || name.contentEquals('R.class') || name.contentEquals("BuildConfig.class")) + } + + boolean isJavaSystemClass(String name) { + return name.startsWith("java.") || name.startsWith("javax.") + } + + boolean isAndroidSystemClass(String name) { + return name.startsWith("android.") || name.startsWith("androidx.") + } + +} diff --git a/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/IncompatibleClassInfo.groovy b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/IncompatibleClassInfo.groovy new file mode 100644 index 0000000..ac16a2c --- /dev/null +++ b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/IncompatibleClassInfo.groovy @@ -0,0 +1,30 @@ +package com.zxy.android.plugin.api.inspect + +/** + * Created by zhengxiaoyong on 2018/12/24. + */ +class IncompatibleClassInfo { + + String className + + String incompatibleClassName + + boolean equals(o) { + if (this.is(o)) return true + if (getClass() != o.class) return false + + IncompatibleClassInfo that = (IncompatibleClassInfo) o + + if (className != that.className) return false + if (incompatibleClassName != that.incompatibleClassName) return false + + return true + } + + int hashCode() { + int result + result = (className != null ? className.hashCode() : 0) + result = 31 * result + (incompatibleClassName != null ? incompatibleClassName.hashCode() : 0) + return result + } +} diff --git a/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/IncompatibleMethodInfo.groovy b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/IncompatibleMethodInfo.groovy new file mode 100644 index 0000000..9704609 --- /dev/null +++ b/inspect-plugin/src/main/groovy/com/zxy/android/plugin/api/inspect/IncompatibleMethodInfo.groovy @@ -0,0 +1,42 @@ +package com.zxy.android.plugin.api.inspect + +/** + * Created by zhengxiaoyong on 2018/12/24. + */ +class IncompatibleMethodInfo { + + String className + + String incompatibleClassName + + String methodName + + String signature + + String lineNumber + + boolean equals(o) { + if (this.is(o)) return true + if (getClass() != o.class) return false + + IncompatibleMethodInfo that = (IncompatibleMethodInfo) o + + if (className != that.className) return false + if (incompatibleClassName != that.incompatibleClassName) return false + if (lineNumber != that.lineNumber) return false + if (methodName != that.methodName) return false + if (signature != that.signature) return false + + return true + } + + int hashCode() { + int result + result = (className != null ? className.hashCode() : 0) + result = 31 * result + (incompatibleClassName != null ? incompatibleClassName.hashCode() : 0) + result = 31 * result + (methodName != null ? methodName.hashCode() : 0) + result = 31 * result + (signature != null ? signature.hashCode() : 0) + result = 31 * result + (lineNumber != null ? lineNumber.hashCode() : 0) + return result + } +} diff --git a/inspect-plugin/src/main/resources/META-INF/gradle-plugins/api.inspect.properties b/inspect-plugin/src/main/resources/META-INF/gradle-plugins/api.inspect.properties new file mode 100644 index 0000000..dc0eeed --- /dev/null +++ b/inspect-plugin/src/main/resources/META-INF/gradle-plugins/api.inspect.properties @@ -0,0 +1 @@ +implementation-class=com.zxy.android.plugin.api.inspect.ApiInspectPlugin \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..3cf2a1d --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':app', ':inspect-plugin'