├── analysis-sample
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── dimens.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zen
│ │ │ │ └── android
│ │ │ │ └── analysis
│ │ │ │ └── sample
│ │ │ │ ├── DemoApplication.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── InitManager.java
│ │ │ │ └── BaseActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zen
│ │ │ └── android
│ │ │ └── analysis
│ │ │ └── sample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zen
│ │ └── android
│ │ └── analysis
│ │ └── sample
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── kotlin-sample
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── dimens.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ └── values-w820dp
│ │ │ │ └── dimens.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zen
│ │ │ │ └── android
│ │ │ │ └── kotlin
│ │ │ │ └── sample
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zen
│ │ │ └── android
│ │ │ └── analysis
│ │ │ └── sample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zen
│ │ └── android
│ │ └── analysis
│ │ └── sample
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── module-library
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zen
│ │ │ └── android
│ │ │ └── lib
│ │ │ └── report
│ │ │ └── module
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zen
│ │ └── android
│ │ └── lib
│ │ └── report
│ │ └── module
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── image
├── tree.png
├── tree-x.png
└── module-list.png
├── .gitignore
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── gradle-mvn-push.gradle
├── plugin
├── src
│ ├── main
│ │ ├── resources
│ │ │ ├── META-INF
│ │ │ │ └── gradle-plugins
│ │ │ │ │ └── com.zen.lib.analysis.properties
│ │ │ └── com
│ │ │ │ └── zen
│ │ │ │ └── plugin
│ │ │ │ └── lib
│ │ │ │ └── analysis
│ │ │ │ ├── css
│ │ │ │ ├── z
│ │ │ │ │ ├── img
│ │ │ │ │ │ ├── aar.png
│ │ │ │ │ │ ├── jar.png
│ │ │ │ │ │ ├── line_conn.gif
│ │ │ │ │ │ ├── loading.gif
│ │ │ │ │ │ ├── zTreeStandard.gif
│ │ │ │ │ │ └── zTreeStandard.png
│ │ │ │ │ └── ztree.css
│ │ │ │ └── demo.css
│ │ │ │ ├── support.html
│ │ │ │ ├── Tree.html
│ │ │ │ └── js
│ │ │ │ ├── cytoscape-dagre.js
│ │ │ │ └── jquery.ztree.core.min.js
│ │ └── groovy
│ │ │ └── com
│ │ │ └── zen
│ │ │ └── plugin
│ │ │ └── lib
│ │ │ └── analysis
│ │ │ ├── util
│ │ │ ├── Logger.groovy
│ │ │ ├── Timer.groovy
│ │ │ ├── FileUtils.groovy
│ │ │ ├── ResourceUtils.groovy
│ │ │ └── PackageChecker.groovy
│ │ │ ├── model
│ │ │ ├── FileInfo.groovy
│ │ │ ├── Node.groovy
│ │ │ ├── FileDictionary.groovy
│ │ │ └── Library.groovy
│ │ │ ├── ext
│ │ │ ├── LimitSizeConfig.groovy
│ │ │ └── LibraryAnalysisExtension.groovy
│ │ │ ├── render
│ │ │ ├── HtmlRenderer.groovy
│ │ │ ├── OutputModuleList.groovy
│ │ │ └── TextRenderer.groovy
│ │ │ ├── LibraryAnalysisPlugin.groovy
│ │ │ ├── convert
│ │ │ └── NodeConvert.groovy
│ │ │ └── task
│ │ │ └── DependencyTreeReportTask.groovy
│ └── test
│ │ └── groovy
│ │ └── com
│ │ └── zen
│ │ └── plugin
│ │ └── lib
│ │ └── analysis
│ │ ├── task
│ │ └── DependencyTreeReportTaskTest.groovy
│ │ ├── mock
│ │ ├── BaseGenerator.groovy
│ │ └── DependencyGenerator.groovy
│ │ ├── render
│ │ └── TextRendererTest.groovy
│ │ ├── convert
│ │ └── NodeConvertTest.groovy
│ │ ├── util
│ │ └── ResourceUtilsTest.groovy
│ │ ├── model
│ │ ├── DependencyTestBase.groovy
│ │ ├── LibraryTest.groovy
│ │ └── FileDictionaryTest.groovy
│ │ └── ext
│ │ └── LibraryAnalysisExtensionTest.groovy
└── build.gradle
├── settings.gradle
├── .travis.yml
├── gradle.properties
├── jacoco.gradle
├── gradlew.bat
├── README.md
└── gradlew
/analysis-sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/kotlin-sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module-library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/kotlin-sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/analysis-sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/image/tree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/image/tree.png
--------------------------------------------------------------------------------
/image/tree-x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/image/tree-x.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .idea/
3 | .gradle/
4 | build/
5 | *.log
6 | local.properties
7 | *.ipr
8 | *.iws
--------------------------------------------------------------------------------
/image/module-list.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/image/module-list.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/module-library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | module-library
3 |
4 |
--------------------------------------------------------------------------------
/plugin/src/main/resources/META-INF/gradle-plugins/com.zen.lib.analysis.properties:
--------------------------------------------------------------------------------
1 | implementation-class=com.zen.plugin.lib.analysis.LibraryAnalysisPlugin
--------------------------------------------------------------------------------
/kotlin-sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/kotlin-sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/kotlin-sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/kotlin-sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/module-library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/analysis-sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/analysis-sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/analysis-sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/analysis-sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/analysis-sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/analysis-sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/kotlin-sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/kotlin-sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/kotlin-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/kotlin-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/kotlin-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/kotlin-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/analysis-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/analysis-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/analysis-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/analysis-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/aar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/aar.png
--------------------------------------------------------------------------------
/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/jar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/jar.png
--------------------------------------------------------------------------------
/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/line_conn.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/line_conn.gif
--------------------------------------------------------------------------------
/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/loading.gif
--------------------------------------------------------------------------------
/kotlin-sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AnalysisSample
3 | Success
4 | Fail!
5 |
6 |
--------------------------------------------------------------------------------
/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/zTreeStandard.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/zTreeStandard.gif
--------------------------------------------------------------------------------
/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/zTreeStandard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/znyang/library-analysis/HEAD/plugin/src/main/resources/com/zen/plugin/lib/analysis/css/z/img/zTreeStandard.png
--------------------------------------------------------------------------------
/analysis-sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AnalysisSample
3 | Success
4 | Fail!
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=http\://services.gradle.org/distributions/gradle-4.4-all.zip
6 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | if(VERSION_NAME.endsWith("-SNAPSHOT")){
2 | include ':analysis-sample', ':module-library'
3 | include ':kotlin-sample'
4 | }
5 | // Sets the output JAR filename
6 | rootProject.name = 'library-analysis-gradle-plugin'
7 | include 'plugin'
--------------------------------------------------------------------------------
/analysis-sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/analysis-sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/kotlin-sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/kotlin-sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/plugin/src/test/groovy/com/zen/plugin/lib/analysis/task/DependencyTreeReportTaskTest.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.task;
2 |
3 | /**
4 | * @author zen
5 | * @version 2016/9/11
6 | */
7 |
8 | class DependencyTreeReportTaskTest {
9 |
10 |
11 |
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk8
4 |
5 | before_install:
6 | - chmod +x gradlew
7 | - export JAVA8_HOME=/usr/lib/jvm/java-8-oracle
8 | - export JAVA_HOME=$JAVA8_HOME
9 | - export ENV_CI=true
10 |
11 | script: ./gradlew :plugin:clean :plugin:build :plugin:jacocoReport --info --stacktrace
12 |
13 | after_success:
14 | - bash <(curl -s https://codecov.io/bash)
--------------------------------------------------------------------------------
/kotlin-sample/src/main/java/com/zen/android/kotlin/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.zen.android.kotlin.sample
2 |
3 | import android.app.Activity
4 | import android.os.Bundle
5 |
6 | class MainActivity : Activity() {
7 |
8 | override fun onCreate(savedInstanceState: Bundle?) {
9 | super.onCreate(savedInstanceState)
10 | setContentView(R.layout.activity_main)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/kotlin-sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/kotlin-sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/analysis-sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/analysis-sample/src/main/java/com/zen/android/analysis/sample/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.zen.android.analysis.sample;
2 |
3 | import android.app.Application;
4 |
5 | /**
6 | * @author zen
7 | * @version 2016/9/13
8 | */
9 |
10 | public class DemoApplication extends Application {
11 |
12 | @Override
13 | public void onCreate() {
14 | super.onCreate();
15 |
16 | InitManager.initLazy(this);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/plugin/src/main/groovy/com/zen/plugin/lib/analysis/util/Logger.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.util;
2 |
3 | /**
4 | * @author zen
5 | * @version 2016/9/10
6 | */
7 |
8 | class Logger {
9 |
10 | static Logger D = new Logger()
11 | static Logger W = new Logger()
12 |
13 | private Logger() {
14 | }
15 |
16 | void log(def message) {
17 | print "LibReport "
18 | println message
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/plugin/src/main/groovy/com/zen/plugin/lib/analysis/model/FileInfo.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.model
2 | /**
3 | * Node
4 | *
5 | * @author yangz
6 | * @version 2016/7/8
7 | */
8 | class FileInfo {
9 | String id
10 | long size
11 | String type
12 | File file
13 |
14 | FileInfo(String id, long size, String type, File file) {
15 | this.id = id
16 | this.size = size
17 | this.type = type
18 | this.file = file
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/plugin/src/main/groovy/com/zen/plugin/lib/analysis/util/Timer.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.util;
2 |
3 | /**
4 | * @author zen
5 | * @version 2016/9/10
6 | */
7 |
8 | class Timer {
9 |
10 | long start
11 |
12 | Timer() {
13 | start = System.currentTimeMillis()
14 | }
15 |
16 | void mark(Logger logger, String message) {
17 | long now = System.currentTimeMillis()
18 | logger?.log "${message ?: ""} cost ${now - start}ms"
19 | start = now
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/module-library/src/test/java/com/zen/android/lib/report/module/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zen.android.lib.report.module;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 |
14 | @Test
15 | public void addition_isCorrect() {
16 | assertEquals(4, 2 + 2);
17 | }
18 | }
--------------------------------------------------------------------------------
/plugin/src/test/groovy/com/zen/plugin/lib/analysis/mock/BaseGenerator.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.mock
2 |
3 | import org.gmock.GMockController
4 | import org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency
5 |
6 | import java.util.concurrent.atomic.AtomicInteger
7 |
8 | /**
9 | * @author zen
10 | * @version 2016/9/11
11 | */
12 | class BaseGenerator {
13 |
14 | protected final GMockController gmc
15 |
16 | BaseGenerator(GMockController gmc) {
17 | this.gmc = gmc
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/plugin/src/test/groovy/com/zen/plugin/lib/analysis/render/TextRendererTest.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.render
2 |
3 | import org.junit.Assert
4 | import org.junit.Test
5 |
6 | /**
7 | *
8 | * @author: zen
9 | * date: 2017/4/14 0014.
10 | */
11 | class TextRendererTest {
12 |
13 | @Test
14 | void testTextAlign() {
15 | def content = "123"
16 | def target = " 123"
17 | def aligned = TextRenderer.textAlign(content, 9)
18 | Assert.assertEquals(aligned, target)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/analysis-sample/src/test/java/com/zen/android/analysis/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zen.android.analysis.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/kotlin-sample/src/test/java/com/zen/android/analysis/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zen.android.analysis.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/kotlin-sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/kotlin-sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\sdk\Android/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/analysis-sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\sdk\Android/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/analysis-sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP=com.github.znyang
2 | VERSION_NAME=0.2.2
3 |
4 | POM_ARTIFACT_ID=library-analysis
5 | POM_NAME=Library Analysis Gradle Plugin
6 | POM_PACKAGING=jar
7 |
8 | POM_DESCRIPTION=A Gradle plugin for analysis library
9 | POM_INCEPTION_YEAR=2016
10 |
11 | POM_URL=http://github.com/znyang/library-analysis-gradle-plugin/
12 | POM_SCM_URL=http://github.com/znyang/library-analysis-gradle-plugin/
13 | POM_SCM_CONNECTION=scm:git:git@github.com:znyang/library-analysis-gradle-plugin.git
14 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com:znyang/library-analysis-gradle-plugin.git
15 |
16 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
17 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
18 | POM_LICENCE_DIST=repo
19 |
20 | POM_DEVELOPER_ID=zen
21 | POM_DEVELOPER_NAME=ZenYang Software, Inc.
--------------------------------------------------------------------------------
/plugin/src/main/groovy/com/zen/plugin/lib/analysis/ext/LimitSizeConfig.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.ext;
2 |
3 | /**
4 | * @author zen
5 | * @version 2016/6/21
6 | */
7 | class LimitSizeConfig {
8 |
9 | static final long DEFAULT_LIB_SIZE_LIMIT = 1024 * 1024;
10 | static final long DEFAULT_FILE_SIZE_LIMIT = 100 * 1024;
11 |
12 | private long fileSize = DEFAULT_FILE_SIZE_LIMIT;
13 | private long libSize = DEFAULT_LIB_SIZE_LIMIT;
14 |
15 | public long getFileSize() {
16 | return fileSize;
17 | }
18 |
19 | public void setFileSize(long fileSize) {
20 | this.fileSize = fileSize;
21 | }
22 |
23 | public long getLibSize() {
24 | return libSize;
25 | }
26 |
27 | public void setLibSize(long libSize) {
28 | this.libSize = libSize;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/module-library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/module-library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 |
6 | defaultConfig {
7 | minSdkVersion 9
8 | targetSdkVersion 25
9 | versionCode 1
10 | versionName "1.0"
11 |
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 |
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 |
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: 'libs', include: ['*.jar'])
27 |
28 | testImplementation 'junit:junit:4.12'
29 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
31 | }
32 |
--------------------------------------------------------------------------------
/module-library/src/androidTest/java/com/zen/android/lib/report/module/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zen.android.lib.report.module;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 |
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.zen.android.lib.report.module.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/plugin/src/test/groovy/com/zen/plugin/lib/analysis/convert/NodeConvertTest.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.convert
2 |
3 | import com.zen.plugin.lib.analysis.model.DependencyTestBase
4 | import com.zen.plugin.lib.analysis.model.Library
5 |
6 | /**
7 | *
8 | * @author: zen
9 | * date: 2017/6/26 0026.
10 | */
11 | class NodeConvertTest extends DependencyTestBase {
12 |
13 | void testConvert() {
14 | play {
15 | prePlay()
16 |
17 | long start = System.currentTimeMillis()
18 | Library output = Library.create(root, fileDic)
19 | def node = NodeConvert.convert(output, NodeConvert.Args.get(fileDic))
20 | long cost = System.currentTimeMillis() - start
21 |
22 | System.out.println("${cost}ms")
23 | assertTrue(cost < 500)
24 |
25 | printLibrary(output, "")
26 | printNode(node, "")
27 | }
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/kotlin-sample/src/androidTest/java/com/zen/android/analysis/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zen.android.analysis.sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zen.android.analysis.sample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/analysis-sample/src/androidTest/java/com/zen/android/analysis/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zen.android.analysis.sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zen.android.analysis.sample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/plugin/src/main/resources/com/zen/plugin/lib/analysis/support.html:
--------------------------------------------------------------------------------
1 |
13 |
--------------------------------------------------------------------------------
/plugin/src/test/groovy/com/zen/plugin/lib/analysis/util/ResourceUtilsTest.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.util
2 |
3 | import org.junit.Test;
4 |
5 | /**
6 | * @author zen
7 | * @version 2016/9/11
8 | */
9 | class ResourceUtilsTest {
10 |
11 | private static final SEP = File.separator
12 |
13 | @Test
14 | public void testCopyResources() {
15 | def target = ".${SEP}build${SEP}test${SEP}"
16 | def path = new File(target).absolutePath
17 | println path
18 |
19 | ResourceUtils.copyResources(path)
20 |
21 | ResourceUtils.RESOURCE_FILES.each {
22 | def file = new File(target, it)
23 | assert file.exists()
24 | // if (file.isFile()) {
25 | // assert !file.text.equals("null")
26 | // }
27 | }
28 | }
29 |
30 | @Test
31 | public void testGetTemplate() {
32 | //assert !ResourceUtils.getTemplateFileContent("Tree.html").isEmpty()
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/plugin/src/main/groovy/com/zen/plugin/lib/analysis/util/FileUtils.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.util;
2 |
3 | /**
4 | * @author zen
5 | * @version 2016/6/5
6 | */
7 | class FileUtils {
8 |
9 | static String convertFileSize(long size) {
10 | long kb = 1024
11 | long mb = kb * 1024
12 | long gb = mb * 1024
13 |
14 | if (size >= gb) {
15 | String.format("%.3f GB", (float) size / gb)
16 | } else if (size >= mb) {
17 | float f = (float) size / mb
18 | String.format(f > 100 ? "%.0f MB" : "%.3f MB", f)
19 | } else if (size >= kb) {
20 | float f = (float) size / kb;
21 | String.format(f > 100 ? "%.0f KB" : "%.3f KB", f)
22 | } else {
23 | String.format("%d B", size)
24 | }
25 | }
26 |
27 | static String getFileType(String fileName) {
28 | int index = fileName.lastIndexOf(".")
29 | if (index >= 0) {
30 | return fileName.substring(index + 1)
31 | }
32 | fileName
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/analysis-sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
20 |
26 |
27 |
--------------------------------------------------------------------------------
/plugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 | apply plugin: 'java'
3 | apply from: "${rootDir}/jacoco.gradle"
4 |
5 | sourceCompatibility = 1.7
6 | javadoc.options.encoding = 'UTF-8'
7 |
8 | group = GROUP
9 | version = VERSION_NAME
10 |
11 | sourceSets {
12 | main {
13 | java {
14 | srcDir 'src/main/java'
15 | }
16 |
17 | groovy {
18 | srcDir 'src/main/groovy'
19 | }
20 | }
21 | }
22 |
23 | repositories repoProvider
24 |
25 | dependencies {
26 | compile gradleApi()
27 | compile 'com.android.tools.build:gradle:2.2.2'
28 | compile 'com.google.code.gson:gson:2.5'
29 |
30 | testCompile group: 'junit', name: 'junit', version: '4.12'
31 | testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
32 | exclude module: 'groovy-all'
33 | }
34 | testCompile 'org.gmock:gmock:0.8.2'
35 | }
36 |
37 | task groovydocJar(type: Jar, dependsOn: groovydoc) {
38 | classifier = 'groovydoc'
39 | from 'build/docs/groovydoc'
40 | }
41 |
42 | task javadocJar(type: Jar, dependsOn: javadoc) {
43 | classifier = 'javadoc'
44 | from 'build/docs/javadoc'
45 | }
46 |
47 | artifacts {
48 | archives jar
49 | archives groovydocJar
50 | archives javadocJar
51 | }
52 |
53 | apply from: "${rootDir}/gradle/gradle-mvn-push.gradle"
54 |
--------------------------------------------------------------------------------
/plugin/src/main/groovy/com/zen/plugin/lib/analysis/model/Node.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.model
2 | /**
3 | * Node
4 | *
5 | * @author yangz
6 | * @version 2016/7/8
7 | */
8 | class Node {
9 | String id
10 | String name
11 | boolean open
12 | List children
13 | long fileSize
14 | long totalSize
15 | String iconSkin
16 | String detail
17 | // 可移除的依赖库(重复添加)
18 | boolean canRemove
19 |
20 | void addNode(Node node) {
21 | if (node == null) {
22 | return
23 | }
24 | List children = getChildren()
25 | if (children == null) {
26 | children = new ArrayList<>()
27 | setChildren(children)
28 | }
29 | children.add(node)
30 | }
31 |
32 | int getChildrenSize() {
33 | children == null ? 0 : children.size()
34 | }
35 |
36 | boolean hasChildren() {
37 | return children != null && !children.isEmpty()
38 | }
39 |
40 | @Override
41 | String toString() {
42 | return "Node{" +
43 | "id='" + id + '\'' +
44 | ", name='" + name + '\'' +
45 | ", open=" + open +
46 | ", children=" + children +
47 | ", fileSize=" + fileSize +
48 | ", totalSize=" + totalSize +
49 | ", iconSkin='" + iconSkin + '\'' +
50 | '}'
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/plugin/src/test/groovy/com/zen/plugin/lib/analysis/model/DependencyTestBase.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.model
2 |
3 | import com.zen.plugin.lib.analysis.mock.DependencyGenerator
4 | import org.gmock.GMockController
5 | import org.gmock.GMockTestCase
6 | import org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency
7 |
8 | /**
9 | *
10 | * @author: zen
11 | * date: 2017/6/26 0026.
12 | */
13 | class DependencyTestBase extends GMockTestCase {
14 |
15 | RenderableDependency root
16 | FileDictionary fileDic
17 | def files
18 |
19 | @Override
20 | void setUp() {
21 | super.setUp()
22 | def generator = new DependencyGenerator(gMockController as GMockController)
23 | root = generator.mockRootDependency()
24 | files = generator.mockFileCollection()
25 | }
26 |
27 | void prePlay() {
28 | fileDic = new FileDictionary(files)
29 | }
30 |
31 | void printLibrary(Library lib, String deep) {
32 | println "【U=${lib.useCount}】【C=${lib.contains.size()}】${deep}${lib.name} - ${lib.useCountImmediate}"
33 | lib.children?.each {
34 | printLibrary(it, deep + " ")
35 | }
36 | }
37 |
38 | void printNode(Node lib, String deep) {
39 | println "【C=${lib.getChildrenSize()}】${deep}${lib.name} - 重复? ${lib.canRemove}"
40 | lib.children?.each {
41 | printNode(it, deep + " ")
42 | }
43 | }
44 |
45 | void testEmpty() {
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/plugin/src/test/groovy/com/zen/plugin/lib/analysis/ext/LibraryAnalysisExtensionTest.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.ext
2 |
3 | import org.junit.Test
4 |
5 | /**
6 | * @author zen
7 | * @version 2016/9/11
8 | */
9 | class LibraryAnalysisExtensionTest {
10 |
11 | static final DATA = [
12 | [
13 | 'size' : 9 * 1024,
14 | 'style': 'tag-normal'
15 | ],
16 | [
17 | 'size' : 300 * 1024,
18 | 'style': 'tag-warning'
19 | ],
20 | [
21 | 'size' : 2048 * 1024,
22 | 'style': 'tag-danger'
23 | ]
24 | ]
25 |
26 | static final IGNORE = [
27 | "com.android.support": [
28 | ['target': 'com.android.support:support-v4:22.2.0', 'result': true],
29 | ['target': 'com.squareup.retrofit2:retrofit:2.1.0', 'result': false]
30 | ]
31 | ]
32 |
33 | @Test
34 | public void testGetSIzeStyle() throws Exception {
35 | DATA.each {
36 | assert new LibraryAnalysisExtension().getSizeTag(it.size).equals(it.style)
37 | }
38 | }
39 |
40 | @Test
41 | public void testIsIgnore() throws Exception {
42 | def ext = new LibraryAnalysisExtension()
43 | IGNORE.each {
44 | ext.ignore = [it.key]
45 | it.value.each { data ->
46 | assert ext.isIgnore(data.target) == data.result
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/plugin/src/test/groovy/com/zen/plugin/lib/analysis/model/LibraryTest.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.model
2 | /**
3 | *
4 | * @author: zen
5 | * date: 2017/6/26 0026.
6 | */
7 | class LibraryTest extends DependencyTestBase {
8 |
9 | void testCreate() {
10 | play {
11 | prePlay()
12 |
13 | long start = System.currentTimeMillis()
14 | Library output = Library.create(root, fileDic)
15 | long cost = System.currentTimeMillis() - start
16 |
17 | System.out.println("${cost}ms")
18 | assertTrue(cost < 500)
19 |
20 | assertEquals(root.id, output.id)
21 | assertEquals(root.name, output.name)
22 | assertEquals(output.children.size(), root.children.size())
23 | assertTrue(output.children.size() > 0)
24 |
25 | printLibrary(output, "")
26 | }
27 | }
28 |
29 | void testIgnore() {
30 | play {
31 | prePlay()
32 |
33 | long start = System.currentTimeMillis()
34 | Library output = Library.create(root, fileDic)
35 | output.applyIgnoreLibrary("com.android.support:support-v4", "com.android.support")
36 | long cost = System.currentTimeMillis() - start
37 |
38 | System.out.println("${cost}ms")
39 | assertTrue(cost < 500)
40 |
41 | printLibrary(output, "")
42 | assertEquals(output.getTotalSizeWithoutIgnore(), 0)
43 | assertTrue(output.getTotalSize() > 0)
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/kotlin-sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.zen.lib.analysis'
3 | apply plugin: 'kotlin-android'
4 | apply plugin: 'kotlin-android-extensions'
5 |
6 | android {
7 | compileSdkVersion 25
8 |
9 | defaultConfig {
10 | applicationId "com.zen.android.kotlin.sample"
11 | minSdkVersion 9
12 | targetSdkVersion 25
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 |
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | lintOptions {
26 | abortOnError false
27 | }
28 | compileOptions {
29 | sourceCompatibility JavaVersion.VERSION_1_8
30 | targetCompatibility JavaVersion.VERSION_1_8
31 | }
32 | }
33 |
34 | dependencies {
35 | implementation fileTree(dir: 'libs', include: ['*.jar'])
36 |
37 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.51"
38 | provided 'com.android.support:support-annotations:26.1.0'
39 |
40 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
41 | exclude group: 'com.android.support', module: 'support-annotations'
42 | })
43 |
44 | testImplementation 'junit:junit:4.12'
45 | }
46 |
47 | libReport {
48 | // log = true
49 | // fullTree = true
50 | // output = [
51 | // "txt", "html"
52 | // ]
53 | }
--------------------------------------------------------------------------------
/analysis-sample/src/main/java/com/zen/android/analysis/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zen.android.analysis.sample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 | import android.widget.Button;
10 | import android.widget.TextView;
11 |
12 | public class MainActivity extends BaseActivity {
13 |
14 | TextView mTextMain;
15 | Button mBtnGo;
16 |
17 | @Override
18 | protected void afterCreate(@Nullable Bundle state) {
19 | Log.d("MAIN", "set fail!");
20 | mTextMain.setText(InitManager.getContext().getString(R.string.fail));
21 | }
22 |
23 | @Override
24 | protected void onBaseCreate(@Nullable Bundle savedInstanceState) {
25 | setContentView(R.layout.activity_main);
26 | mTextMain = (TextView) findViewById(R.id.tv_main);
27 | mBtnGo = (Button) findViewById(R.id.btn_go);
28 | }
29 |
30 | @Override
31 | protected void onObsResume() {
32 | super.onObsResume();
33 | mTextMain.setText(InitManager.getContext().getString(R.string.success));
34 | mBtnGo.setOnClickListener(new OnClickListener() {
35 | @Override
36 | public void onClick(View listener) {
37 | InitManager.clear();
38 | Intent intent = new Intent(MainActivity.this, MainActivity.class);
39 | MainActivity.this.startActivity(intent);
40 | }
41 | });
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/jacoco.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "jacoco"
2 |
3 | task jacocoReport(type: JacocoReport, dependsOn: ['test']) {
4 | group = 'Reporting'
5 | description = 'Generate Jacoco coverage reports after running tests.'
6 |
7 | reports {
8 | xml.enabled = true
9 | html.enabled = true
10 | }
11 |
12 | // "gradle dependencies" - shows configurations
13 | // "jacocoAgent/jacocoAnt" and "androidJacocoAgent/androidJacocoAnt"
14 | // The Android version is a newer version
15 | // Use hidden configuration, for details look into JacocoPlugin.groovy
16 | // jacocoClasspath = configurations['androidJacocoAnt']
17 |
18 | // exclude auto-generated classes and tests
19 | // def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
20 | def debugTree = fileTree(dir: "${buildDir}/classes/main")
21 | def javaSrc = "${projectDir}/src/main/java"
22 | def groovySrc = "${projectDir}/src/main/groovy"
23 |
24 | sourceDirectories = files([javaSrc, groovySrc])
25 | classDirectories = files([debugTree])
26 | executionData = fileTree(dir: projectDir, includes: ['**/*.exec'])
27 |
28 | // Bit hacky but fixes https://code.google.com/p/android/issues/detail?id=69174.
29 | // We iterate through the compiled .class tree and rename $$ to $.
30 | doFirst {
31 | new File("$buildDir/classes/").eachFileRecurse { file ->
32 | if (file.name.contains('$$')) {
33 | file.renameTo(file.path.replace('$$', '$'))
34 | }
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/plugin/src/main/groovy/com/zen/plugin/lib/analysis/render/HtmlRenderer.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.render
2 |
3 | import com.google.gson.Gson
4 | import com.zen.plugin.lib.analysis.ext.LibraryAnalysisExtension
5 | import com.zen.plugin.lib.analysis.model.Node
6 | import com.zen.plugin.lib.analysis.util.ResourceUtils
7 | import groovy.json.JsonOutput
8 |
9 | /**
10 | * @author zen
11 | * @version 2016/9/9
12 | */
13 |
14 | class HtmlRenderer {
15 |
16 | private static final GSON = new Gson()
17 |
18 | private String targetDir
19 |
20 | HtmlRenderer(target) {
21 | this.targetDir = target
22 | }
23 |
24 | public String render(Node root, OutputModuleList list, String msg, LibraryAnalysisExtension ext) {
25 | String json = root ? "[${GSON.toJson(root)}]" : '[]'
26 | if (msg && msg.length() > 0) {
27 | msg = msg.replace("\r\n", "
")
28 | } else {
29 | msg = ""
30 | }
31 |
32 | def modules = JsonOutput.toJson(list)
33 | def target = new File(targetDir, "Tree.html")
34 | def support = ext.showSupport ? ResourceUtils.getTemplateFileContent("support.html") : ""
35 |
36 | def html = ResourceUtils.getTemplateFileContent("Tree.html")
37 | .replace("%output_support%", support)
38 | .replace("%output_msg%", msg)
39 | .replace("%data%", modules)
40 | .replace("%title%", root.id)
41 | .replace("%nodes%", json)
42 | target.setText(html, "UTF-8")
43 |
44 | target.path
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/analysis-sample/src/main/java/com/zen/android/analysis/sample/InitManager.java:
--------------------------------------------------------------------------------
1 | package com.zen.android.analysis.sample;
2 |
3 |
4 | import android.content.Context;
5 | import android.os.SystemClock;
6 |
7 | import rx.Observable;
8 | import rx.android.schedulers.AndroidSchedulers;
9 | import rx.functions.Func0;
10 | import rx.schedulers.Schedulers;
11 |
12 | /**
13 | * @author zen
14 | * @version 2016/9/13
15 | */
16 |
17 | public class InitManager {
18 |
19 | private static Context sContext;
20 |
21 | private static Context sCache;
22 | private static boolean hasInit;
23 |
24 | public static void initLazy(Context ctx) {
25 | sCache = ctx;
26 | }
27 |
28 | public static boolean isHasInit() {
29 | return hasInit;
30 | }
31 |
32 | public static Context getContext() {
33 | return sContext;
34 | }
35 |
36 | public static Observable> ready() {
37 | return Observable.defer(
38 | new Func0>() {
39 | @Override
40 | public Observable call() {
41 | init(sCache);
42 | return Observable.just(true);
43 | }
44 | })
45 | .subscribeOn(Schedulers.io())
46 | .observeOn(AndroidSchedulers.mainThread());
47 | }
48 |
49 | public static void clear() {
50 | hasInit = false;
51 | sContext = null;
52 | }
53 |
54 | private static synchronized void init(Context ctx) {
55 | if (hasInit) {
56 | return;
57 | }
58 | SystemClock.sleep(2000);
59 | sContext = ctx;
60 | hasInit = true;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/plugin/src/main/groovy/com/zen/plugin/lib/analysis/ext/LibraryAnalysisExtension.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.ext
2 |
3 | import org.gradle.util.ConfigureUtil
4 |
5 | /**
6 | * @author zen
7 | * @version 2016/5/29
8 | */
9 | class LibraryAnalysisExtension {
10 |
11 | private static final ANALYSIS_OUTPUT_PATH = "reports/zen/analysis/library"
12 | private static final SIZE_STYLES = ['tag-normal', 'tag-warning', 'tag-danger']
13 | private static final LAST_INDEX = SIZE_STYLES.size() - 1
14 |
15 | final Set cacheIgnoreIds = new HashSet<>()
16 |
17 | String outputPath = ANALYSIS_OUTPUT_PATH
18 | List ignore
19 | List output = ["txt", "html"]
20 | final LimitSizeConfig limit
21 | boolean showTree = false
22 | boolean log = false
23 | List region = [200 * 1024, 1024 * 1024]
24 | boolean fullTree = false
25 | boolean showSize = true
26 | boolean showSupport = true
27 |
28 | LibraryAnalysisExtension() {
29 | limit = new LimitSizeConfig()
30 | }
31 |
32 | void limit(Closure closure) {
33 | ConfigureUtil.configure(closure, limit)
34 | }
35 |
36 | String getSizeTag(long s) {
37 | def index = region.findIndexOf {
38 | s <= it
39 | }
40 | index = index < 0 ? LAST_INDEX : index
41 |
42 | SIZE_STYLES[index]
43 | }
44 |
45 | boolean isIgnore(String id) {
46 | if (cacheIgnoreIds.contains(id)) {
47 | return true
48 | }
49 | boolean result = ignore?.find {
50 | id.contains(it)
51 | }
52 | if (result) {
53 | cacheIgnoreIds.add(id)
54 | }
55 | result
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/plugin/src/main/groovy/com/zen/plugin/lib/analysis/util/ResourceUtils.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.util;
2 |
3 | /**
4 | * @author zen
5 | * @version 2016/9/9
6 | */
7 |
8 | class ResourceUtils {
9 |
10 | static final RESOURCE_PATH = "/com/zen/plugin/lib/analysis/"
11 | static final RESOURCE_FILES = [
12 | "css/z/img/",
13 | "css/demo.css",
14 | "css/z/ztree.css",
15 | "css/z/img/line_conn.gif",
16 | "css/z/img/loading.gif",
17 | "css/z/img/zTreeStandard.gif",
18 | "css/z/img/zTreeStandard.png",
19 | "css/z/img/jar.png",
20 | "css/z/img/aar.png",
21 |
22 | "js/",
23 | "js/jquery.ztree.core.min.js",
24 | "js/jquery.min.js",
25 | "js/cytoscape-dagre.js",
26 | "js/dagre.min.js"
27 | ]
28 |
29 | private static obj = new ResourceUtils()
30 |
31 | private ResourceUtils() {
32 | }
33 |
34 | static void copyResources(String targetPath) {
35 | RESOURCE_FILES.each {
36 | if (it.endsWith('/')) {
37 | new File(targetPath, it).mkdirs()
38 | return
39 | }
40 |
41 | def target = new File(targetPath, it)
42 | if (!target.exists()) {
43 | def source = obj.getClass().getResourceAsStream("${RESOURCE_PATH}${it}")
44 | target.withDataOutputStream {
45 | os -> os << source
46 | }
47 | }
48 | }
49 | }
50 |
51 | static String getTemplateFileContent(String fileName) {
52 | return obj.getClass().getResourceAsStream("${RESOURCE_PATH}${fileName}").getText("UTF-8")
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/gradle/gradle-mvn-push.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven'
2 | apply plugin: 'signing'
3 |
4 | def isReleaseBuild() {
5 | return VERSION_NAME.contains("SNAPSHOT") == false
6 | }
7 |
8 | afterEvaluate { project ->
9 | uploadArchives {
10 | repositories {
11 | mavenDeployer {
12 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
13 |
14 | pom.groupId = GROUP
15 | pom.artifactId = POM_ARTIFACT_ID
16 | pom.version = VERSION_NAME
17 |
18 | repository(url: "file:///c:/repo/")
19 | snapshotRepository(url: "file:///c:/repo/")
20 |
21 | pom.project {
22 | name POM_NAME
23 | packaging POM_PACKAGING
24 | description POM_DESCRIPTION
25 | url POM_URL
26 | inceptionYear POM_INCEPTION_YEAR
27 |
28 | scm {
29 | url POM_SCM_URL
30 | connection POM_SCM_CONNECTION
31 | developerConnection POM_SCM_DEV_CONNECTION
32 | }
33 |
34 | licenses {
35 | license {
36 | name POM_LICENCE_NAME
37 | url POM_LICENCE_URL
38 | distribution POM_LICENCE_DIST
39 | }
40 | }
41 |
42 | developers {
43 | developer {
44 | id POM_DEVELOPER_ID
45 | name POM_DEVELOPER_NAME
46 | }
47 | }
48 | }
49 | }
50 | }
51 | }
52 |
53 | signing {
54 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
55 | sign configurations.archives
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/plugin/src/main/groovy/com/zen/plugin/lib/analysis/render/OutputModuleList.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis.render
2 |
3 | import com.zen.plugin.lib.analysis.util.FileUtils
4 |
5 | /**
6 | * OutputModuleList
7 | *
8 | * @author znyang 2017/2/13 0013
9 | */
10 |
11 | class OutputModuleList {
12 |
13 | List modules = new ArrayList<>()
14 |
15 | void sortModules(Closure closure = {
16 | first, two ->
17 | two.sizeValue - first.sizeValue
18 | }) {
19 | modules.sort(closure)
20 |
21 | }
22 |
23 | void addModule(DependencyOutput output) {
24 | if (!modules.contains(output)) {
25 | modules.add(output)
26 | }
27 | }
28 |
29 | static class DependencyOutput {
30 |
31 | String name
32 | String size
33 | String type
34 | String pkgName
35 | String extInfo
36 | String level
37 | // 被使用次数
38 | int useCount
39 | // 直接依赖次数
40 | int useCountImmediate
41 | // 依赖库个数
42 | int libCount
43 | long sizeValue
44 |
45 | DependencyOutput(String name, long size, String pkgName, String type, String extInfo,
46 | int libCount = 0, int useCount = 0, int useCountImmediate = 0, String level = "") {
47 | this.name = name
48 | this.sizeValue = size
49 | this.size = FileUtils.convertFileSize(size)
50 | this.pkgName = pkgName
51 | this.type = type
52 | this.extInfo = extInfo
53 | this.level = level
54 | this.libCount = libCount
55 | this.useCount = useCount
56 | this.useCountImmediate = useCountImmediate
57 | }
58 |
59 | boolean equals(o) {
60 | if (this.is(o)) return true
61 | if (getClass() != o.class) return false
62 |
63 | DependencyOutput that = (DependencyOutput) o
64 |
65 | if (name != that.name) return false
66 |
67 | return true
68 | }
69 |
70 | int hashCode() {
71 | return (name != null ? name.hashCode() : 0)
72 | }
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/plugin/src/main/groovy/com/zen/plugin/lib/analysis/LibraryAnalysisPlugin.groovy:
--------------------------------------------------------------------------------
1 | package com.zen.plugin.lib.analysis
2 |
3 | import com.zen.plugin.lib.analysis.ext.LibraryAnalysisExtension
4 | import com.zen.plugin.lib.analysis.task.DependencyTreeReportTask
5 | import com.zen.plugin.lib.analysis.util.Logger
6 | import org.gradle.api.Plugin
7 | import org.gradle.api.Project
8 | import org.gradle.api.artifacts.Configuration
9 |
10 | /**
11 | * 1. 白名单
12 | * 2. 数据统计
13 | * 3. 共用标识
14 | */
15 | class LibraryAnalysisPlugin implements Plugin {
16 | private static final EXTENSION_NAME = 'libReport'
17 | private static final BASE_GROUP = 'reporting'
18 | private static final TASK_PREFIX = 'libReport'
19 |
20 | private LibraryAnalysisExtension extension
21 |
22 | @Override
23 | void apply(Project project) {
24 | extension = project.extensions.create(EXTENSION_NAME, LibraryAnalysisExtension)
25 |
26 | project.afterEvaluate {
27 | createTask(project)
28 | }
29 | }
30 |
31 | void createTask(Project project) {
32 | def configurations = project.configurations
33 |
34 | configurations.findAll {
35 | return !it.allDependencies.isEmpty() && getConfigurationSize(it) > 0
36 | }.each {
37 | def conf = it.getName()
38 | def task = project.tasks.create(genTaskName(conf), DependencyTreeReportTask)
39 | task.configuration = it
40 | task.group = BASE_GROUP
41 | task.extension = extension
42 | if (!extension.log) {
43 | Logger.D = null
44 | }
45 | }
46 | }
47 |
48 | static String genTaskName(String name) {
49 | char[] arr = name.toCharArray()
50 | if (arr[0].lowerCase) {
51 | arr[0] = Character.toUpperCase(arr[0])
52 | "${TASK_PREFIX}${String.valueOf(arr)}"
53 | } else {
54 | "${TASK_PREFIX}${name}"
55 | }
56 | }
57 |
58 | static int getConfigurationSize(Configuration conf) {
59 | try {
60 | return conf.incoming.resolutionResult.allDependencies.size()
61 | } catch (Exception e) {
62 | // ignore
63 | }
64 | 0
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/analysis-sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.zen.lib.analysis'
3 | //apply plugin: 'kotlin-android'
4 | //apply plugin: 'kotlin-android-extensions'
5 |
6 | android {
7 | compileSdkVersion 25
8 |
9 | defaultConfig {
10 | applicationId "com.zen.android.analysis.sample"
11 | minSdkVersion 9
12 | targetSdkVersion 25
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 |
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | lintOptions {
26 | abortOnError false
27 | }
28 | compileOptions {
29 | sourceCompatibility JavaVersion.VERSION_1_8
30 | targetCompatibility JavaVersion.VERSION_1_8
31 | }
32 | }
33 |
34 | dependencies {
35 | implementation fileTree(dir: 'libs', include: ['*.jar'])
36 |
37 | implementation 'com.android.support:multidex:1.0.1'
38 | implementation project(":module-library")
39 |
40 | implementation 'com.squareup.moshi:moshi:1.2.0'
41 | implementation 'com.alibaba:fastjson:1.1.54.android'
42 | implementation 'com.fasterxml.jackson.core:jackson-databind:2.7.0'
43 |
44 | implementation "com.github.Raizlabs.DBFlow:dbflow:3.1.1"
45 |
46 | implementation 'com.squareup.retrofit:retrofit:1.9.0'
47 | implementation 'com.squareup.retrofit2:retrofit:2.1.0'
48 |
49 | implementation 'com.github.bumptech.glide:glide:3.7.0'
50 | implementation 'com.squareup.picasso:picasso:2.5.2'
51 | implementation 'com.facebook.fresco:fresco:0.13.0'
52 |
53 | implementation 'com.jakewharton.timber:timber:4.3.0'
54 |
55 | implementation 'io.reactivex:rxandroid:1.2.1'
56 | implementation 'io.reactivex:rxjava:1.3.0'
57 | // implementation 'io.reactivex.rxjava2:rxjava:2.0.0-RC2'
58 |
59 | implementation 'com.jakewharton:butterknife:8.4.0'
60 | implementation 'com.jakewharton.scalpel:scalpel:1.1.2'
61 | implementation 'com.jakewharton:process-phoenix:1.0.2'
62 |
63 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
64 | exclude group: 'com.android.support', module: 'support-annotations'
65 | })
66 |
67 | testImplementation 'junit:junit:4.12'
68 | }
69 |
70 | libReport {
71 | // log = true
72 | // fullTree = true
73 | // output = [
74 | // "txt", "html"
75 | // ]
76 | ignore = [
77 | "com.android.support:support-v4"
78 | ]
79 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/analysis-sample/src/main/java/com/zen/android/analysis/sample/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.zen.android.analysis.sample;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 |
7 | import rx.Observable;
8 | import rx.Observable.OnSubscribe;
9 | import rx.Subscriber;
10 | import rx.functions.Func1;
11 |
12 | /**
13 | * @author zen
14 | * @version 2016/9/13
15 | */
16 |
17 | public abstract class BaseActivity extends Activity {
18 |
19 | Observable> ready;
20 |
21 | @Override
22 | protected final void onCreate(@Nullable Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | onBaseCreate(savedInstanceState);
25 | onAfterCreate(savedInstanceState);
26 | }
27 |
28 | private void onAfterCreate(@Nullable Bundle state) {
29 | if (InitManager.isHasInit()) {
30 | ready = null;
31 | afterCreate(state);
32 | return;
33 | }
34 | createReady(state);
35 | }
36 |
37 | private void createReady(Bundle state) {
38 | if (ready == null) {
39 | ready = InitManager
40 | .ready()
41 | .map(new Func1