├── .gitignore
├── .gradle
└── 4.1
│ └── fileHashes
│ ├── fileHashes.bin
│ └── fileHashes.lock
├── .idea
├── misc.xml
└── workspace.xml
├── AutoApi.iml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── app.iml
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── netease
│ │ └── demo
│ │ └── abtest
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── abtest.json
│ ├── java
│ │ └── com
│ │ │ └── netease
│ │ │ └── demo
│ │ │ └── autoapi
│ │ │ ├── AddUtil.java
│ │ │ ├── Calculator.java
│ │ │ ├── DataModel.java
│ │ │ ├── DataModelOperator.java
│ │ │ ├── DemoApplication.java
│ │ │ ├── DeviceUtil.java
│ │ │ ├── EventA.java
│ │ │ ├── MainActivity.java
│ │ │ ├── Minus.java
│ │ │ ├── Singleton.java
│ │ │ ├── http
│ │ │ ├── BaseHttpListener.java
│ │ │ ├── HttpListener.java
│ │ │ ├── HttpUtil.java
│ │ │ └── Request.java
│ │ │ ├── test
│ │ │ ├── BaseWzpCommonRequestTask.java
│ │ │ └── SharedWzpCommonRequestTask.java
│ │ │ └── test1
│ │ │ ├── Adder.java
│ │ │ ├── Calculator.java
│ │ │ └── Mutiplier.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── netease
│ └── demo
│ └── apiprovider
│ └── ExampleUnitTest.java
├── build.gradle
├── demomodule1
├── .gitignore
├── build.gradle
├── demomodule1.iml
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── netease
│ │ └── demo
│ │ └── demomodule1
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── netease
│ │ │ └── demo
│ │ │ └── demomodule1
│ │ │ ├── ModuleActivity.java
│ │ │ └── ModuleFunctionUtil.java
│ └── res
│ │ ├── layout
│ │ └── activity_module.xml
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── netease
│ └── demo
│ └── demomodule1
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── local.properties
├── module
├── autoapi-api
│ ├── .gitignore
│ ├── api_records
│ │ ├── com.netease.demo.autoapi.records.txt
│ │ └── com.netease.demo.demomodule1.records.txt
│ ├── autoapi-api.iml
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── netease
│ │ │ └── libs
│ │ │ └── apiservice_api
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── netease
│ │ │ │ ├── demo
│ │ │ │ ├── autoapi
│ │ │ │ │ └── auto_api
│ │ │ │ │ │ ├── AddUtilApi.java
│ │ │ │ │ │ ├── AppCalculator.java
│ │ │ │ │ │ ├── AppDataModel.java
│ │ │ │ │ │ ├── AppSingleton.java
│ │ │ │ │ │ ├── CalculatorAlias.java
│ │ │ │ │ │ ├── CalculatorApi.java
│ │ │ │ │ │ ├── DataModelApi.java
│ │ │ │ │ │ ├── DataModelOperatorApi.java
│ │ │ │ │ │ ├── DeviceUtilApi.java
│ │ │ │ │ │ ├── EventAApi.java
│ │ │ │ │ │ ├── HttpListenerApi.java
│ │ │ │ │ │ ├── HttpUtilApi.java
│ │ │ │ │ │ ├── MinusApi.java
│ │ │ │ │ │ ├── RequestApi.java
│ │ │ │ │ │ ├── SharedWzpCommonRequestTaskApi.java
│ │ │ │ │ │ ├── SingletonApi.java
│ │ │ │ │ │ └── factory
│ │ │ │ │ │ ├── AddUtilApiFactory.java
│ │ │ │ │ │ ├── AppCalculatorApiFactory.java
│ │ │ │ │ │ ├── AppDataModelApiFactory.java
│ │ │ │ │ │ ├── AppSingletonApiFactory.java
│ │ │ │ │ │ ├── CalculatorAliasApiFactory.java
│ │ │ │ │ │ ├── CalculatorApiFactory.java
│ │ │ │ │ │ ├── DataModelApiFactory.java
│ │ │ │ │ │ ├── DataModelOperatorApiFactory.java
│ │ │ │ │ │ ├── DeviceUtilApiFactory.java
│ │ │ │ │ │ ├── EventAApiFactory.java
│ │ │ │ │ │ ├── HttpListenerApiFactory.java
│ │ │ │ │ │ ├── HttpUtilApiFactory.java
│ │ │ │ │ │ ├── MinusApiFactory.java
│ │ │ │ │ │ ├── RequestApiFactory.java
│ │ │ │ │ │ ├── SharedWzpCommonRequestTaskApiFactory.java
│ │ │ │ │ │ └── SingletonApiFactory.java
│ │ │ │ └── demomodule1
│ │ │ │ │ └── auto_api
│ │ │ │ │ ├── ModuleFunction.java
│ │ │ │ │ └── factory
│ │ │ │ │ └── ModuleFunctionApiFactory.java
│ │ │ │ └── libs
│ │ │ │ └── auto_api
│ │ │ │ └── ApiBase.java
│ │ └── res
│ │ │ └── values
│ │ │ └── strings.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── netease
│ │ └── libs
│ │ └── apiservice_api
│ │ └── ExampleUnitTest.java
├── autoapi-plugin
│ ├── .gitignore
│ ├── README-CN.md
│ ├── README.md
│ ├── autoapi-plugin.iml
│ ├── build.gradle
│ └── src
│ │ └── main
│ │ ├── groovy
│ │ └── com
│ │ │ └── netease
│ │ │ └── plugin
│ │ │ └── apiprovider
│ │ │ ├── ApiProvider.groovy
│ │ │ ├── Config.groovy
│ │ │ └── FileUtil.groovy
│ │ └── resources
│ │ └── META-INF
│ │ └── gradle-plugins
│ │ └── ApiProviderPlugin.properties
├── autoapi
│ ├── .gitignore
│ ├── autoapi.iml
│ ├── build.gradle
│ ├── gradle.properties
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── netease
│ │ └── libs
│ │ └── autoapi
│ │ ├── AutoApi.java
│ │ └── anno
│ │ ├── AutoApiCallbackAnno.java
│ │ ├── AutoApiClassAnno.java
│ │ ├── AutoApiClassBuildMethodAnno.java
│ │ ├── AutoApiConstructAnno.java
│ │ └── AutoApiMethodAnno.java
└── autoapi_process
│ ├── .gitignore
│ ├── autoapi_process.iml
│ ├── build.gradle
│ └── src
│ └── main
│ └── java
│ └── com
│ └── netease
│ └── libs
│ └── autoapi_process
│ ├── AutoApiClass.java
│ ├── AutoApiProcess.java
│ ├── BaseClassGenerator.java
│ ├── ElementUtil.java
│ ├── FileUtil.java
│ ├── Logger.java
│ └── generator
│ ├── ApiBaseGenerator.java
│ ├── ApiFactoryGenerator.java
│ ├── ApiGenerator.java
│ ├── ApiRegisterGenerator.java
│ ├── BaseApiClassGenerator.java
│ ├── CallbackClassGenerator.java
│ ├── StubClassGenerator.java
│ └── StubFactoryGenerator.java
├── repo
└── com
│ └── netease
│ └── libs
│ ├── autoapi
│ ├── 1.1.0
│ │ ├── autoapi-1.1.0.jar.md5
│ │ ├── autoapi-1.1.0.jar.sha1
│ │ ├── autoapi-1.1.0.pom
│ │ ├── autoapi-1.1.0.pom.md5
│ │ └── autoapi-1.1.0.pom.sha1
│ ├── maven-metadata.xml
│ ├── maven-metadata.xml.md5
│ └── maven-metadata.xml.sha1
│ └── autoapi_process
│ ├── 1.1.0
│ ├── autoapi_process-1.1.0.jar.md5
│ ├── autoapi_process-1.1.0.jar.sha1
│ ├── autoapi_process-1.1.0.pom
│ ├── autoapi_process-1.1.0.pom.md5
│ └── autoapi_process-1.1.0.pom.sha1
│ ├── maven-metadata.xml
│ ├── maven-metadata.xml.md5
│ └── maven-metadata.xml.sha1
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | .idea/*
26 | .gradle/*
27 | build/*
28 |
29 | module/autoapi-plugin/autoapi-plugin.iml
30 | module/autoapi/autoapi.iml
31 | autoapi.iml
32 | /module/autoapi/src/api/
33 |
--------------------------------------------------------------------------------
/.gradle/4.1/fileHashes/fileHashes.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/.gradle/4.1/fileHashes/fileHashes.bin
--------------------------------------------------------------------------------
/.gradle/4.1/fileHashes/fileHashes.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/.gradle/4.1/fileHashes/fileHashes.lock
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
16 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/AutoApi.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | //apply plugin: 'ApiProviderPlugin'
3 | apply plugin: 'android-aspectjx'
4 |
5 | sourceCompatibility = "1.7"
6 | targetCompatibility = "1.7"
7 |
8 | repositories {
9 | mavenLocal()
10 | // maven { url uri('../../repo') }
11 | maven { url 'https://raw.githubusercontent.com/bitterbee/mvn-repo/master/' }
12 | maven { url 'https://dl.google.com/dl/android/maven2/' }
13 | jcenter()
14 | flatDir {
15 | dirs 'libs'
16 | }
17 | }
18 |
19 | android {
20 | compileSdkVersion COMPILE_SDK_VERSION.toInteger()
21 | buildToolsVersion BUILD_TOOLS_VERSION
22 | defaultConfig {
23 | applicationId "com.netease.demo.autoapi"
24 | minSdkVersion MIN_SDK_VERSION.toInteger()
25 | targetSdkVersion TARGET_SDK_VERSION.toInteger()
26 | versionCode 1
27 | versionName "1.0"
28 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
29 |
30 | javaCompileOptions {
31 | annotationProcessorOptions {
32 | def path = "${rootProject.projectDir}/module/autoapi-api".toString()
33 | arguments = [apiProjectPath: path,
34 | packageName: "com.netease.demo.autoapi",
35 | apiBuildEnable: "true",
36 | logOpen: "true"]
37 | }
38 | }
39 | }
40 | buildTypes {
41 | release {
42 | minifyEnabled false
43 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
44 | }
45 | }
46 | //
47 | // sourceSets {
48 | // main {
49 | // def dirs = ['main', 'p_widget', 'p_theme']
50 | // dirs.each { dir ->
51 | // java.srcDir("src/$dir/java")
52 | // res.srcDir("src/$dir/res")
53 | // }
54 | // }
55 | // }
56 | }
57 |
58 | configurations.all {
59 | resolutionStrategy.force "com.android.support:support-annotations:${APPCOMPAT_V7_VERSION}"
60 | }
61 |
62 | //ApiProviderConfig {
63 | // apiProjectPath = "module/neapiprovider"
64 | //}
65 |
66 | //jackOptions {
67 | // enabled = true
68 | //}
69 |
70 | dependencies {
71 | implementation fileTree(dir: 'libs', include: ['*.jar'])
72 | implementation "com.android.support:appcompat-v7:${APPCOMPAT_V7_VERSION}"
73 | implementation "com.android.support.constraint:constraint-layout:${CONSTRAINT_LAYOUT_VERSION}"
74 | testImplementation "junit:junit:${JUNIT_VERSION}"
75 | androidTestImplementation "com.android.support.test:runner:${TEST_RUNNER}"
76 | androidTestImplementation "com.android.support.test.espresso:espresso-core:${TEST_ESPRESSO_CORE_VERSION}"
77 |
78 | compile project(':demomodule1')
79 |
80 | // compile project(':autoapi')
81 | compile project(':autoapi-api')
82 | // annotationProcessor project(':autoapi_process')
83 |
84 | compile 'com.netease.libs:autoapi:1.1.0'
85 | annotationProcessor 'com.netease.libs:autoapi_process:1.1.0'
86 |
87 | compileOnly "org.aspectj:aspectjrt:${ASPECTJRT_VERSION}"
88 | }
89 |
--------------------------------------------------------------------------------
/app/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 |
23 | -keepattributes Signature
24 | -keep class sun.misc.Unsafe { *; }
25 | -keep class com.eyeofcloud.JSON.** { *; }
26 | -dontwarn okio.**
27 |
28 | -dontwarn com.squareup.okhttp.**
29 | -keep class com.squareup.okhttp.** { *; }
30 | -keep interface com.squareup.okhttp.** { *; }
31 |
32 | -dontwarn com.eyeofcloud.integrations.**
33 | -dontwarn com.mixpanel.android.mpmetrics.MixpanelApiRetriever*
34 | -dontwarn com.amplitude.api.EyeofcloudAmplitudeBridge
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/netease/demo/abtest/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.abtest;
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 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.netease.demo.autoapi", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
23 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/assets/abtest.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "itemId":"SimpleTest_001",
4 | "accessory":"",
5 | "testCase":{
6 | "caseId":"001",
7 | "accessory":""
8 | }
9 | },
10 | {
11 | "itemId":"SimpleTest_002",
12 | "accessory":"",
13 | "testCase":{
14 | "caseId":"000",
15 | "accessory":""
16 | }
17 | }
18 | ]
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/AddUtil.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 | import com.netease.libs.autoapi.anno.AutoApiClassBuildMethodAnno;
5 | import com.netease.libs.autoapi.anno.AutoApiConstructAnno;
6 | import com.netease.libs.autoapi.anno.AutoApiMethodAnno;
7 |
8 | /**
9 | * Created by zyl06 on 2018/11/25.
10 | */
11 | @AutoApiClassAnno
12 | public class AddUtil {
13 |
14 | private int mData1 = 0;
15 | private int mData2 = 0;
16 |
17 | @AutoApiConstructAnno
18 | public AddUtil(int data1, int data2) {
19 | mData1 = data1;
20 | mData2 = data2;
21 | }
22 |
23 | @AutoApiConstructAnno
24 | public AddUtil(int data) {
25 | mData1 = data;
26 | mData2 = data;
27 | }
28 |
29 | @AutoApiClassBuildMethodAnno
30 | public static AddUtil getInstance(int data1, int data2) {
31 | return new AddUtil(data1, data2);
32 | }
33 |
34 | @AutoApiMethodAnno
35 | public int calu() {
36 | return mData1 + mData2;
37 | }
38 |
39 | @AutoApiMethodAnno
40 | public static int add(int a, int b) {
41 | return a + b;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/Calculator.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 | import com.netease.libs.autoapi.anno.AutoApiConstructAnno;
5 | import com.netease.libs.autoapi.anno.AutoApiMethodAnno;
6 |
7 | import java.util.Timer;
8 |
9 | /**
10 | * Created by zyl06 on 2018/10/18.
11 | */
12 | @AutoApiClassAnno(name = "AppCalculator", allPublicStaticApi = true)
13 | public class Calculator {
14 |
15 | private int mIncrement = 2;
16 |
17 | @AutoApiConstructAnno()
18 | public Calculator() {
19 |
20 | }
21 |
22 | @AutoApiConstructAnno(alias = "newWithIncr")
23 | public Calculator(int incre) {
24 | this.mIncrement = incre;
25 | }
26 |
27 | @AutoApiMethodAnno(alias = "appMinus")
28 | public static int minus(int a, int b) {
29 | return a - b;
30 | }
31 |
32 | public static int add(int a, int b) {
33 | return a + b;
34 | }
35 |
36 | public static float add(float a, float b) {
37 | return a + b;
38 | }
39 |
40 | @AutoApiMethodAnno(provide = false)
41 | public static double innerAdd(double a, double b) {
42 | return a + b;
43 | }
44 |
45 | public static Timer getTimer() {
46 | return null;
47 | }
48 |
49 | @AutoApiMethodAnno(provide = true)
50 | public double nonStaticAdd(double a, double b) {
51 | return a + b;
52 | }
53 |
54 | @AutoApiMethodAnno(provide = true, alias = "increase")
55 | public int incr(int a) {
56 | return a + mIncrement;
57 | }
58 |
59 | @AutoApiMethodAnno(provide = true, alias = "decrease")
60 | public int decr(int a) {
61 | return a - mIncrement;
62 | }
63 |
64 | public static int add(DataModel model) {
65 | return model != null ? add(model.getA(), model.getB()) : 0;
66 | }
67 |
68 | public static DataModel add(DataModel a, DataModel b) {
69 | return a == null || b == null ? null :
70 | new DataModel(a.getA() + b.getA(), a.getB() + b.getB());
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/DataModel.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 | import com.netease.libs.autoapi.anno.AutoApiConstructAnno;
5 |
6 | /**
7 | * Created by zyl06 on 2018/10/27.
8 | */
9 | @AutoApiClassAnno
10 | public class DataModel {
11 |
12 | private int a;
13 | private int b;
14 |
15 | @AutoApiConstructAnno()
16 | public DataModel(int a, int b) {
17 | this.a = a;
18 | this.b = b;
19 | }
20 |
21 | public DataModel() {
22 | this.a = 0;
23 | this.b = 0;
24 | }
25 |
26 | public int getA() {
27 | return a;
28 | }
29 |
30 | public int getB() {
31 | return b;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/DataModelOperator.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 | import com.netease.libs.autoapi.anno.AutoApiMethodAnno;
5 |
6 | /**
7 | * Created by zyl06 on 2019/3/26.
8 | */
9 | @AutoApiClassAnno
10 | public class DataModelOperator {
11 |
12 | @AutoApiMethodAnno
13 | public static DataModel add(DataModel a, DataModel b) {
14 | return a == null || b == null ?
15 | null :
16 | new DataModel(a.getA() + b.getA(), a.getB() + b.getB());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi;
2 |
3 | import android.app.Application;
4 |
5 | import com.netease.libs.autoapi.AutoApi;
6 |
7 | /**
8 | * Created by zyl06 on 2018/7/30.
9 | */
10 |
11 | public class DemoApplication extends Application {
12 |
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 | AutoApi.init();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/DeviceUtil.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 | import com.netease.libs.autoapi.anno.AutoApiConstructAnno;
5 | import com.netease.libs.autoapi.anno.AutoApiMethodAnno;
6 |
7 | /**
8 | * Created by zyl06 on 2018/10/27.
9 | */
10 | @AutoApiClassAnno
11 | public class DeviceUtil {
12 |
13 | @AutoApiMethodAnno
14 | public int getDeviceId() {
15 | return 0;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/EventA.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 |
5 | /**
6 | * Created by zyl06 on 2018/11/25.
7 | */
8 | @AutoApiClassAnno()
9 | public class EventA {
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Toast;
8 |
9 | import com.netease.demo.demomodule1.ModuleActivity;
10 | import com.netease.demo.demomodule1.auto_api.ModuleFunction;
11 | import com.netease.demo.demomodule1.auto_api.factory.ModuleFunctionApiFactory;
12 | import com.netease.libs.autoapi.AutoApi;
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 | }
21 |
22 | public void onButton0Click(View v) {
23 | ModuleFunctionApiFactory factory = AutoApi.getApiFactory("ModuleFunction");
24 | ModuleFunction moduleFunction = factory.newInstance();
25 | int result = moduleFunction.multiple(2, 3);
26 | Toast.makeText(this, "multiple 2, 3 is " + result, Toast.LENGTH_LONG).show();
27 | }
28 |
29 | public void onButton1Click(View v) {
30 | Intent i = new Intent(this, ModuleActivity.class);
31 | startActivity(i);
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/Minus.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 | import com.netease.libs.autoapi.anno.AutoApiConstructAnno;
5 | import com.netease.libs.autoapi.anno.AutoApiMethodAnno;
6 |
7 | /**
8 | * Created by zyl06 on 2019/3/26.
9 | */
10 | @AutoApiClassAnno
11 | public class Minus {
12 |
13 | private int mData1 = 0;
14 | private int mData2 = 0;
15 |
16 | @AutoApiConstructAnno
17 | public Minus(int data1, int data2) {
18 | mData1 = data1;
19 | mData2 = data2;
20 | }
21 |
22 | @AutoApiMethodAnno
23 | public int calu() {
24 | return mData1 - mData2;
25 | }
26 |
27 | @AutoApiMethodAnno
28 | public static int minus(int a, int b) {
29 | return a - b;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/Singleton.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi;
2 |
3 | import android.util.Log;
4 |
5 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
6 | import com.netease.libs.autoapi.anno.AutoApiClassBuildMethodAnno;
7 | import com.netease.libs.autoapi.anno.AutoApiMethodAnno;
8 |
9 | /**
10 | * Created by zyl06 on 2018/10/28.
11 | */
12 | @AutoApiClassAnno
13 | public class Singleton {
14 |
15 | private static Singleton sInstance = null;
16 |
17 | @AutoApiClassBuildMethodAnno()
18 | public static Singleton getInstance() {
19 | if (sInstance == null) {
20 | synchronized (Singleton.class) {
21 | if (sInstance == null) {
22 | sInstance = new Singleton();
23 | }
24 | }
25 | }
26 |
27 | return sInstance;
28 | }
29 |
30 | private Singleton() {
31 | }
32 |
33 | @AutoApiMethodAnno()
34 | public String foo1(String str1, String str2) {
35 | Log.i("Singleton", "foo1 called");
36 | return str1 + "_" + str2;
37 | }
38 |
39 | @AutoApiMethodAnno()
40 | public void foo2() {
41 | Log.i("Singleton", "foo2 called");
42 | }
43 |
44 | @AutoApiMethodAnno()
45 | public void foo3() {
46 | Log.i("Singleton", "foo3 called ");
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/http/BaseHttpListener.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.http;
2 |
3 | /**
4 | * Created by zyl06 on 2018/11/5.
5 | */
6 |
7 | public interface BaseHttpListener {
8 | void onHttpSuccess(String httpName, Object result);
9 |
10 | void onHttpError(String httpName, int errorCode, String errorMsg);
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/http/HttpListener.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.http;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 |
5 | /**
6 | * Created by zyl06 on 2018/11/5.
7 | */
8 | @AutoApiClassAnno(allPublicNormalApi = true, includeSuperApi = true)
9 | public interface HttpListener extends BaseHttpListener {
10 | void onCancel();
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/http/HttpUtil.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.http;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiCallbackAnno;
4 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Created by zyl06 on 2018/11/5.
10 | */
11 |
12 | @AutoApiClassAnno(allPublicNormalApi = true)
13 | public class HttpUtil {
14 |
15 | public Request query(@AutoApiCallbackAnno HttpListener listener) {
16 | return new Request();
17 | }
18 |
19 | public Request queryNoCallback(HttpListener listener) {
20 | return new Request();
21 | }
22 |
23 | public T get(Class aaaaaa) {
24 | return null;
25 | }
26 |
27 | public List toJsonArr(String jsonStr, Class clazz) {
28 | return null;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/http/Request.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.http;
2 |
3 | import android.util.Log;
4 |
5 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
6 |
7 | /**
8 | * Created by zyl06 on 2018/11/5.
9 | */
10 | @AutoApiClassAnno(allPublicNormalApi = true)
11 | public class Request {
12 |
13 | public void cancel() {
14 | Log.i("AutoApi", "cancel request");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/test/BaseWzpCommonRequestTask.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.test;
2 |
3 | import com.netease.demo.autoapi.http.HttpListener;
4 | import com.netease.demo.autoapi.http.Request;
5 | import com.netease.libs.autoapi.anno.AutoApiCallbackAnno;
6 | import com.netease.libs.autoapi.anno.AutoApiMethodAnno;
7 |
8 | /**
9 | * Created by zyl06 on 2018/11/8.
10 | */
11 | public class BaseWzpCommonRequestTask {
12 |
13 | /**
14 | * async query for the task.
15 | *
16 | * @param listener the callback listener for the response.
17 | * @return the request for the task to be cancelled.
18 | */
19 | @AutoApiMethodAnno()
20 | public Request query(@AutoApiCallbackAnno HttpListener listener) {
21 | return null;
22 | }
23 |
24 |
25 |
26 | @AutoApiMethodAnno()
27 | public Request queryArray(@AutoApiCallbackAnno HttpListener listener) {
28 | return null;
29 | }
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/test/SharedWzpCommonRequestTask.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.test;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 | import com.netease.libs.autoapi.anno.AutoApiClassBuildMethodAnno;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | /**
10 | * Created by zyl06 on 2018/11/8.
11 | */
12 |
13 | @AutoApiClassAnno(includeSuperApi = true)
14 | public class SharedWzpCommonRequestTask extends BaseWzpCommonRequestTask {
15 |
16 | private String mUrl;
17 | private String mApi;
18 | private Class mModelClass;
19 |
20 | @AutoApiClassBuildMethodAnno()
21 | public static SharedWzpCommonRequestTask newInstance(String url, Class modelClass,
22 | Map queryParams,
23 | Map headerMap,
24 | Map bodyMap) {
25 | Builder builder = new Builder();
26 | return builder.setApi(url)
27 | .setModelClass(modelClass)
28 | .setQueryParams(queryParams)
29 | .setHeaders(headerMap)
30 | .setBodyMap(bodyMap)
31 | .build();
32 | }
33 |
34 | private SharedWzpCommonRequestTask(SharedWzpDataModel data) {
35 | mUrl = data.mUrl;
36 | mApi = data.mApi;
37 | mModelClass = data.mModelClass;
38 | }
39 |
40 | public static class SharedWzpDataModel {
41 | private String mUrl;
42 | private String mApi;
43 | private Class mModelClass;
44 | private Map mHeaderMap = new HashMap<>();
45 | private Map mBodyMap = new HashMap<>();
46 | private Map mQueryParamsMap = new HashMap<>();
47 |
48 | private int mAppId = 11;
49 | private int mServiceId = 137;
50 | }
51 |
52 | public static class Builder {
53 |
54 | private SharedWzpDataModel mData = new SharedWzpDataModel();
55 |
56 | public Builder setUrl(String url) {
57 | mData.mUrl = url;
58 | return this;
59 | }
60 |
61 | public Builder setApi(String api) {
62 | mData.mApi = api;
63 | return this;
64 | }
65 |
66 | public Builder setModelClass(Class clazz) {
67 | mData.mModelClass = clazz;
68 | return this;
69 | }
70 |
71 | public Builder setHeaders(Map headerMap) {
72 | if (headerMap != null) {
73 | mData.mHeaderMap = headerMap;
74 | }
75 | return this;
76 | }
77 |
78 | public Builder setBodyMap(Map bodyMap) {
79 | if (bodyMap != null) {
80 | mData.mBodyMap = bodyMap;
81 | }
82 | return this;
83 | }
84 |
85 | public Builder setQueryParams(Map queryParamsMap) {
86 | if (queryParamsMap != null) {
87 | mData.mQueryParamsMap = queryParamsMap;
88 | }
89 | return this;
90 | }
91 |
92 | public Builder setAppId(int appId) {
93 | mData.mAppId = appId;
94 | return this;
95 | }
96 |
97 | public Builder setServiceId(int serviceId) {
98 | mData.mServiceId = serviceId;
99 | return this;
100 | }
101 |
102 | public SharedWzpCommonRequestTask build() {
103 | return new SharedWzpCommonRequestTask(mData);
104 | }
105 | }
106 |
107 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/test1/Adder.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.test1;
2 |
3 | /**
4 | * Created by zyl06 on 2018/11/27.
5 | */
6 |
7 | public class Adder {
8 |
9 | public static int add(int a, int b) {
10 | return a + b;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/test1/Calculator.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.test1;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 |
5 | /**
6 | * Created by zyl06 on 2018/10/18.
7 | */
8 | @AutoApiClassAnno(name = "CalculatorAlias", allPublicStaticApi = true, includeSuperApi = true)
9 | public class Calculator extends Adder {
10 |
11 | public static int minuse(int a, int b) {
12 | return a - b;
13 | }
14 |
15 | public static int multiply(int a, int b) {
16 | return a * b;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/netease/demo/autoapi/test1/Mutiplier.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.test1;
2 |
3 | /**
4 | * Created by zyl06 on 2018/11/27.
5 | */
6 |
7 | public class Mutiplier {
8 |
9 | public static int multiply(int a, int b) {
10 | return a * b;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitterbee/auto-api/d477774dea0669314a98c3130368a8275165d184/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
8 | #00000000
9 | #80000000
10 |
11 | #00CC00
12 |
13 |
14 |
15 | #333333
16 | #7F7F7F
17 | #D9D9D9
18 |
19 | @color/gray_33
20 | @color/gray_d9
21 |
22 |
23 | @color/black_alpha50
24 |
25 |
26 | @color/gray_7f
27 | #b4282d
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 18dp
5 | 16dp
6 | 15dp
7 | 14dp
8 | 12dp
9 |
10 | 1px
11 | 50dp
12 |
13 | 49dp
14 | 28dp
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AutoApi
3 |
4 | 确认
5 | 取消
6 |
7 | 首页
8 | 发现
9 | 购物车
10 | 个人
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/netease/demo/apiprovider/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.apiprovider;
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | mavenLocal()
7 | maven { url 'https://github.com/bitterbee/mvn-repo' }
8 | // maven { url uri('../repo') }
9 | google()
10 | jcenter()
11 | }
12 | dependencies {
13 | classpath 'com.android.tools.build:gradle:3.0.1'
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | // classpath "com.netease.plugin:neapiprovider-plugin:${API_PROVIDER_PLUGIN_VERSION}"
18 | classpath "com.hujiang.aspectjx:gradle-android-plugin-aspectjx:${ASPECTJRT_GRADLE_VERSION}"
19 | }
20 | }
21 |
22 | allprojects {
23 | repositories {
24 | mavenLocal()
25 | // maven { url uri('../repo') }
26 | maven { url 'https://raw.githubusercontent.com/bitterbee/mvn-repo/master/' }
27 | google()
28 | jcenter()
29 | }
30 | }
31 |
32 | task clean(type: Delete) {
33 | delete rootProject.buildDir
34 | }
35 |
--------------------------------------------------------------------------------
/demomodule1/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/demomodule1/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'android-aspectjx'
3 |
4 | repositories {
5 | mavenLocal()
6 | maven { url 'https://raw.githubusercontent.com/bitterbee/mvn-repo/master/' }
7 | maven { url 'https://dl.google.com/dl/android/maven2/' }
8 | jcenter()
9 | flatDir {
10 | dirs 'libs'
11 | }
12 | }
13 |
14 | android {
15 | compileSdkVersion COMPILE_SDK_VERSION.toInteger()
16 | defaultConfig {
17 | minSdkVersion MIN_SDK_VERSION.toInteger()
18 | targetSdkVersion TARGET_SDK_VERSION.toInteger()
19 | versionCode 1
20 | versionName "1.0"
21 |
22 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
23 |
24 | javaCompileOptions {
25 | annotationProcessorOptions {
26 | def path = "${rootProject.projectDir}/module/autoapi-api".toString()
27 | arguments = [apiProjectPath: path,
28 | packageName: "com.netease.demo.demomodule1"]
29 | }
30 | }
31 | }
32 |
33 | buildTypes {
34 | release {
35 | minifyEnabled false
36 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
37 | }
38 | }
39 |
40 | }
41 |
42 | dependencies {
43 | implementation fileTree(dir: 'libs', include: ['*.jar'])
44 | implementation "com.android.support:appcompat-v7:${APPCOMPAT_V7_VERSION}"
45 | testImplementation "junit:junit:${JUNIT_VERSION}"
46 | androidTestImplementation "com.android.support.test:runner:${TEST_RUNNER}"
47 | androidTestImplementation "com.android.support.test.espresso:espresso-core:${TEST_ESPRESSO_CORE_VERSION}"
48 |
49 | compile project(':autoapi-api')
50 |
51 | // compile project(':autoapi')
52 | // annotationProcessor project(':autoapi_process')
53 |
54 | compile 'com.netease.libs:autoapi:1.1.0'
55 | annotationProcessor 'com.netease.libs:autoapi_process:1.1.0'
56 |
57 | compileOnly "org.aspectj:aspectjrt:${ASPECTJRT_VERSION}"
58 | }
59 |
--------------------------------------------------------------------------------
/demomodule1/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 |
--------------------------------------------------------------------------------
/demomodule1/src/androidTest/java/com/netease/demo/demomodule1/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.demomodule1;
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 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.netease.demo.demomodule1.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/demomodule1/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/demomodule1/src/main/java/com/netease/demo/demomodule1/ModuleActivity.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.demomodule1;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.view.View;
7 | import android.widget.Toast;
8 |
9 | import com.netease.demo.autoapi.auto_api.AddUtilApi;
10 | import com.netease.demo.autoapi.auto_api.AppCalculator;
11 | import com.netease.demo.autoapi.auto_api.CalculatorAlias;
12 | import com.netease.demo.autoapi.auto_api.CalculatorApi;
13 | import com.netease.demo.autoapi.auto_api.DataModelApi;
14 | import com.netease.demo.autoapi.auto_api.DataModelOperatorApi;
15 | import com.netease.demo.autoapi.auto_api.DeviceUtilApi;
16 | import com.netease.demo.autoapi.auto_api.EventAApi;
17 | import com.netease.demo.autoapi.auto_api.HttpListenerApi;
18 | import com.netease.demo.autoapi.auto_api.HttpUtilApi;
19 | import com.netease.demo.autoapi.auto_api.MinusApi;
20 | import com.netease.demo.autoapi.auto_api.RequestApi;
21 | import com.netease.demo.autoapi.auto_api.SharedWzpCommonRequestTaskApi;
22 | import com.netease.demo.autoapi.auto_api.SingletonApi;
23 | import com.netease.demo.autoapi.auto_api.factory.AddUtilApiFactory;
24 | import com.netease.demo.autoapi.auto_api.factory.AppCalculatorApiFactory;
25 | import com.netease.demo.autoapi.auto_api.factory.CalculatorAliasApiFactory;
26 | import com.netease.demo.autoapi.auto_api.factory.CalculatorApiFactory;
27 | import com.netease.demo.autoapi.auto_api.factory.DataModelApiFactory;
28 | import com.netease.demo.autoapi.auto_api.factory.DataModelOperatorApiFactory;
29 | import com.netease.demo.autoapi.auto_api.factory.DeviceUtilApiFactory;
30 | import com.netease.demo.autoapi.auto_api.factory.EventAApiFactory;
31 | import com.netease.demo.autoapi.auto_api.factory.HttpUtilApiFactory;
32 | import com.netease.demo.autoapi.auto_api.factory.MinusApiFactory;
33 | import com.netease.demo.autoapi.auto_api.factory.SharedWzpCommonRequestTaskApiFactory;
34 | import com.netease.demo.autoapi.auto_api.factory.SingletonApiFactory;
35 | import com.netease.libs.autoapi.AutoApi;
36 |
37 | /**
38 | * Created by zyl06 on 2018/10/26.
39 | */
40 | public class ModuleActivity extends Activity {
41 |
42 | private AppCalculator mCalculator;
43 |
44 | @Override
45 | protected void onCreate(@Nullable Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_module);
48 |
49 | AppCalculatorApiFactory apiFactory = AutoApi.getApiFactory("AppCalculator");
50 | mCalculator = apiFactory.newInstance();
51 |
52 | DeviceUtilApiFactory deviceUtilFactory = AutoApi.getApiFactory("DeviceUtilApi");
53 | DeviceUtilApi deviceUtil = deviceUtilFactory.newInstance();
54 | int id = deviceUtil.getDeviceId();
55 |
56 | CalculatorAliasApiFactory calculatorFactory = AutoApi.getApiFactory("CalculatorAlias");
57 | CalculatorAlias calculator = calculatorFactory.newInstance();
58 | int add = calculator.add(1,2); // 3
59 | int minuse = calculator.minuse(2, 1); // 1
60 | int multiply = calculator.multiply(2,3); //6
61 | }
62 |
63 | public void onButton0Click(View v) {
64 |
65 | MinusApiFactory factory = AutoApi.getApiFactory("MinusApi");
66 | MinusApi api = factory.newInstance(10, 5);
67 | int result0 = api.calu(); // 5
68 | int result1 = api.minus(10, 5); // 5
69 | }
70 |
71 | public void onButton1Click(View v) {
72 |
73 | AddUtilApiFactory factory = AutoApi.getApiFactory("AddUtilApi");
74 | AddUtilApi api0 = factory.newInstance(11, 12);
75 | AddUtilApi api1 = factory.newInstance(3);
76 | AddUtilApi api2 = factory.getInstance(1, 2);
77 | int result0 = api0.calu(); // 23
78 | int result1 = api1.calu(); // 6
79 | int result2 = api1.calu(); // 3
80 |
81 | // AddUtilApiFactory factory = AutoApi.getApiFactory("AddUtilApi");
82 | // AddUtilApi api = factory.newInstance(11, 12);
83 | // int result0 = api.calu(); // 23
84 | // int result1 = api.add(11,12); // 23
85 |
86 | // Toast.makeText(this, "Calculator add 11,12 is " + api.calu(), Toast.LENGTH_LONG).show();
87 | // Toast.makeText(this, "Calculator add 11,12 is " + api.add(11, 12), Toast.LENGTH_LONG).show();
88 | }
89 |
90 | public void onButton2Click(View v) {
91 | int result = mCalculator.add(1, 2);
92 | Toast.makeText(this, "Calculator add 1,2 is " + result, Toast.LENGTH_LONG).show();
93 | }
94 |
95 | public void onButton3Click(View v) {
96 | SingletonApiFactory apiFactory = AutoApi.getApiFactory("SingletonApi");
97 | SingletonApi singleton = apiFactory.getInstance();
98 | String result = singleton.foo1("var1", "var2");
99 | Toast.makeText(this, "singleton foo1 var1, var2 is " + result, Toast.LENGTH_LONG).show();
100 | }
101 |
102 | public void onButton4Click(View v) {
103 | DataModelApiFactory apiFactory = AutoApi.getApiFactory("DataModelApi");
104 | DataModelApi model = apiFactory.newInstance(4, 5);
105 | int result = mCalculator.add(model);
106 | Toast.makeText(this, "Calculator add DataModel(4, 5) is " + result, Toast.LENGTH_LONG).show();
107 | }
108 |
109 | public void onButton5Click(View v) {
110 | DataModelOperatorApiFactory factory = AutoApi.getApiFactory("DataModelOperatorApi");
111 | DataModelOperatorApi api = factory.newInstance();
112 |
113 | DataModelApiFactory dataFactory = AutoApi.getApiFactory("DataModelApi");
114 | DataModelApi model1 = dataFactory.newInstance(4, 5);
115 | DataModelApi model2 = dataFactory.newInstance(1, 2);
116 | DataModelApi result = api.add(model1, model2);
117 | }
118 |
119 | public void onButton6Click(View v) {
120 | SharedWzpCommonRequestTaskApiFactory apiFactory = AutoApi.getApiFactory("SharedWzpCommonRequestTaskApi");
121 | SharedWzpCommonRequestTaskApi api = apiFactory.newInstance("/xhr/test/a", null, null, null, null);
122 | RequestApi request = api.query(new HttpListenerApi() {
123 | @Override
124 | public void onCancel() { }
125 |
126 | @Override
127 | public void onHttpSuccess(String httpName, Object result) { }
128 |
129 | @Override
130 | public void onHttpError(String httpName, int errorCode, String errorMsg) { }
131 |
132 | @Override
133 | public Object getApiServiceTarget() {
134 | return null;
135 | }
136 | });
137 |
138 | // 取消请求
139 | request.cancel();
140 | }
141 |
142 | public void onButton7Click(View v) {
143 | EventAApiFactory factory = AutoApi.getApiFactory("EventAApi");
144 | EventAApi api = factory.newInstance();
145 | // EventBus.getDefault().post(api.getApiServiceTarget());
146 | }
147 |
148 | public void onButton8Click(View v) {
149 | HttpUtilApiFactory factory = AutoApi.getApiFactory("HttpUtilApi");
150 | HttpUtilApi api = factory.newInstance();
151 | RequestApi request = api.query(new HttpListenerApi() {
152 | @Override
153 | public void onCancel() {
154 |
155 | }
156 |
157 | @Override
158 | public void onHttpSuccess(String httpName, Object result) {
159 |
160 | }
161 |
162 | @Override
163 | public void onHttpError(String httpName, int errorCode, String errorMsg) {
164 |
165 | }
166 |
167 | @Override
168 | public Object getApiServiceTarget() {
169 | return null;
170 | }
171 | });
172 |
173 | // 根据业务场景执行请求取消操作
174 | request.cancel();
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/demomodule1/src/main/java/com/netease/demo/demomodule1/ModuleFunctionUtil.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.demomodule1;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 |
5 | /**
6 | * Created by zyl06 on 2018/10/26.
7 | */
8 | @AutoApiClassAnno(name = "ModuleFunction", allPublicStaticApi = true)
9 | public class ModuleFunctionUtil {
10 |
11 | public static int multiple(int a, int b) {
12 | return a * b;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/demomodule1/src/main/res/layout/activity_module.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
28 |
29 |
35 |
36 |
42 |
43 |
--------------------------------------------------------------------------------
/demomodule1/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DemoModule1
3 |
4 |
--------------------------------------------------------------------------------
/demomodule1/src/test/java/com/netease/demo/demomodule1/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.demomodule1;
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 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
19 | COMPILE_SDK_VERSION=26
20 | TARGET_SDK_VERSION=26
21 | BUILD_TOOLS_VERSION=26.0.2
22 | MIN_SDK_VERSION=18
23 |
24 | APPCOMPAT_V7_VERSION=26.0.0
25 | RECYCLER_VIEW_VERSION=26.0.0
26 |
27 | CONSTRAINT_LAYOUT_VERSION=1.1.2
28 | GSON_VERSION=2.8.5
29 | ASPECTJRT_VERSION=1.8.9
30 | FRESCO_VERSION=1.10.0
31 | SUPPORT_DESIGN_VERSION=26.0.0
32 |
33 | JUNIT_VERSION=4.12
34 | TEST_RUNNER=1.0.2
35 | TEST_ESPRESSO_CORE_VERSION=3.0.2
36 |
37 | AUTO_SERVICE_VERSION=1.0-rc2
38 | JAVAPOET_VERSION=1.0.0
39 |
40 | API_PROVIDER_PLUGIN_VERSION=0.0.1-snapshot
41 | AUTO_API_VERSION=1.1.0
42 |
43 | VERSION_NAME=1.1.0
44 | VERSION_CODE=1
45 | GROUP=com.netease.libs
46 |
47 | ASPECTJRT_VERSION=1.8.9
48 | ASPECTJRT_GRADLE_VERSION=2.0.1
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jul 26 17:52:58 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | #Thu Jul 26 17:52:58 CST 2018
11 | ndk.dir=/Users/zyl06/android-sdks/ndk-bundle
12 | sdk.dir=/Users/zyl06/android-sdks
13 |
--------------------------------------------------------------------------------
/module/autoapi-api/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module/autoapi-api/api_records/com.netease.demo.autoapi.records.txt:
--------------------------------------------------------------------------------
1 | com/netease/libs/auto_api/ApiBase.java;
2 | com/netease/demo/autoapi/auto_api/AddUtilApi.java;
3 | com/netease/demo/autoapi/auto_api/factory/AddUtilApiFactory.java;
4 | com/netease/demo/autoapi/auto_api/DataModelOperatorApi.java;
5 | com/netease/demo/autoapi/auto_api/factory/DataModelOperatorApiFactory.java;
6 | com/netease/demo/autoapi/auto_api/DeviceUtilApi.java;
7 | com/netease/demo/autoapi/auto_api/factory/DeviceUtilApiFactory.java;
8 | com/netease/demo/autoapi/auto_api/SharedWzpCommonRequestTaskApi.java;
9 | com/netease/demo/autoapi/auto_api/factory/SharedWzpCommonRequestTaskApiFactory.java;
10 | com/netease/demo/autoapi/auto_api/CalculatorAlias.java;
11 | com/netease/demo/autoapi/auto_api/factory/CalculatorAliasApiFactory.java;
12 | com/netease/demo/autoapi/auto_api/SingletonApi.java;
13 | com/netease/demo/autoapi/auto_api/factory/SingletonApiFactory.java;
14 | com/netease/demo/autoapi/auto_api/HttpListenerApi.java;
15 | com/netease/demo/autoapi/auto_api/factory/HttpListenerApiFactory.java;
16 | com/netease/demo/autoapi/auto_api/HttpUtilApi.java;
17 | com/netease/demo/autoapi/auto_api/factory/HttpUtilApiFactory.java;
18 | com/netease/demo/autoapi/auto_api/RequestApi.java;
19 | com/netease/demo/autoapi/auto_api/factory/RequestApiFactory.java;
20 | com/netease/demo/autoapi/auto_api/EventAApi.java;
21 | com/netease/demo/autoapi/auto_api/factory/EventAApiFactory.java;
22 | com/netease/demo/autoapi/auto_api/AppCalculator.java;
23 | com/netease/demo/autoapi/auto_api/factory/AppCalculatorApiFactory.java;
24 | com/netease/demo/autoapi/auto_api/MinusApi.java;
25 | com/netease/demo/autoapi/auto_api/factory/MinusApiFactory.java;
26 | com/netease/demo/autoapi/auto_api/DataModelApi.java;
27 | com/netease/demo/autoapi/auto_api/factory/DataModelApiFactory.java;
28 | com/netease/libs/auto_api/ApiBase.java;
29 | com/netease/libs/auto_api/ApiBase.java;
30 |
--------------------------------------------------------------------------------
/module/autoapi-api/api_records/com.netease.demo.demomodule1.records.txt:
--------------------------------------------------------------------------------
1 | com/netease/libs/auto_api/ApiBase.java;
2 | com/netease/demo/demomodule1/auto_api/ModuleFunction.java;
3 | com/netease/demo/demomodule1/auto_api/factory/ModuleFunctionApiFactory.java;
4 | com/netease/libs/auto_api/ApiBase.java;
5 | com/netease/libs/auto_api/ApiBase.java;
6 |
--------------------------------------------------------------------------------
/module/autoapi-api/autoapi-api.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
--------------------------------------------------------------------------------
/module/autoapi-api/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion COMPILE_SDK_VERSION.toInteger()
5 | defaultConfig {
6 | minSdkVersion MIN_SDK_VERSION.toInteger()
7 | targetSdkVersion TARGET_SDK_VERSION.toInteger()
8 | versionCode 1
9 | versionName "1.0"
10 |
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 |
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | implementation "com.android.support:appcompat-v7:${APPCOMPAT_V7_VERSION}"
25 | testImplementation "junit:junit:${JUNIT_VERSION}"
26 | androidTestImplementation "com.android.support.test:runner:${TEST_RUNNER}"
27 | androidTestImplementation "com.android.support.test.espresso:espresso-core:${TEST_ESPRESSO_CORE_VERSION}"
28 | }
29 |
30 | clean.doLast {
31 | def recordDir = file("${project.projectDir}/api_records/")
32 | if (!recordDir.exists() || !recordDir.directory) {
33 | return
34 | }
35 |
36 | def contents = new ArrayList()
37 | for (File recordFile : recordDir.listFiles()) {
38 | if (recordFile.exists() && !recordFile.directory) {
39 | def text = recordFile.text
40 | if (text != null && !text.empty) {
41 | contents.add(recordFile.text)
42 | }
43 | }
44 | }
45 |
46 | if (contents.empty) {
47 | return
48 | }
49 |
50 | def sourcePath = "${project.projectDir}/src/main/java/"
51 | def sourceDir = file(sourcePath)
52 | def records = new ArrayList()
53 | for (String content : contents) {
54 | for (String r : content.split(";\\n")) {
55 | def record = r.trim()
56 | if (record != null && !record.isEmpty()) {
57 | // println "record file " + sourcePath + record
58 | records.add(sourcePath + record)
59 | }
60 | }
61 | }
62 |
63 | def removePaths = subtract(recursivlyGetFiles(sourceDir), records)
64 | for (String path : removePaths) {
65 | if (path.endsWith(".java")) {
66 | file(path).delete()
67 | println "remove file " + path
68 | }
69 | }
70 | }
71 |
72 | List subtract(List a, List b) {
73 | if (a == null || a.empty || b == null || b.empty) {
74 | return a
75 | }
76 | def res = new ArrayList(a)
77 | for (String item : b) {
78 | if (res.contains(item)) {
79 | res.remove(item)
80 | }
81 | }
82 | return res
83 | }
84 |
85 | List recursivlyGetFiles(File dir) {
86 | def result = new ArrayList()
87 | if (dir == null || !dir.exists() || !dir.directory) {
88 | return result
89 | }
90 | for (File sub : dir.listFiles()) {
91 | if (sub.directory) {
92 | result.addAll(recursivlyGetFiles(sub))
93 | } else {
94 | result.add(sub.absolutePath)
95 | }
96 | }
97 | return result
98 | }
--------------------------------------------------------------------------------
/module/autoapi-api/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/autoapi-api/src/androidTest/java/com/netease/libs/apiservice_api/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.apiservice_api;
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 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.netease.libs.apiprovider_api.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/AddUtilApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.autoapi.AddUtil's api Interface
7 | */
8 | public interface AddUtilApi extends ApiBase {
9 | int calu();
10 |
11 | int add(int a, int b);
12 | }
13 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/AppCalculator.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 | import java.util.Timer;
5 |
6 | /**
7 | * com.netease.demo.autoapi.Calculator's api Interface
8 | */
9 | public interface AppCalculator extends ApiBase {
10 | int appMinus(int a, int b);
11 |
12 | int add(int a, int b);
13 |
14 | float add(float a, float b);
15 |
16 | Timer getTimer();
17 |
18 | double nonStaticAdd(double a, double b);
19 |
20 | int increase(int a);
21 |
22 | int decrease(int a);
23 |
24 | int add(DataModelApi model);
25 |
26 | DataModelApi add(DataModelApi a, DataModelApi b);
27 | }
28 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/AppDataModel.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.autoapi.DataModel's api Interface
7 | */
8 | public interface AppDataModel extends ApiBase {
9 | int getA();
10 |
11 | int getB();
12 | }
13 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/AppSingleton.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 | import java.lang.String;
5 |
6 | /**
7 | * com.netease.demo.autoapi.Singleton's api Interface
8 | */
9 | public interface AppSingleton extends ApiBase {
10 | String foo1(String str1, String str2);
11 |
12 | void foo2();
13 |
14 | void foo3();
15 | }
16 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/CalculatorAlias.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.autoapi.test1.Calculator's api Interface
7 | */
8 | public interface CalculatorAlias extends ApiBase {
9 | int minuse(int a, int b);
10 |
11 | int multiply(int a, int b);
12 |
13 | int add(int a, int b);
14 | }
15 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/CalculatorApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.autoapi.test1.Calculator's api Interface
7 | */
8 | public interface CalculatorApi extends ApiBase {
9 | int minuse(int a, int b);
10 |
11 | int multiply(int a, int b);
12 |
13 | int add(int a, int b);
14 | }
15 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/DataModelApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.autoapi.DataModel's api Interface
7 | */
8 | public interface DataModelApi extends ApiBase {
9 | }
10 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/DataModelOperatorApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.autoapi.DataModelOperator's api Interface
7 | */
8 | public interface DataModelOperatorApi extends ApiBase {
9 | DataModelApi add(DataModelApi a, DataModelApi b);
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/DeviceUtilApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.autoapi.DeviceUtil's api Interface
7 | */
8 | public interface DeviceUtilApi extends ApiBase {
9 | int getDeviceId();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/EventAApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.autoapi.EventA's api Interface
7 | */
8 | public interface EventAApi extends ApiBase {
9 | }
10 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/HttpListenerApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 | import java.lang.Object;
5 | import java.lang.String;
6 |
7 | /**
8 | * com.netease.demo.autoapi.http.HttpListener's api Interface
9 | */
10 | public interface HttpListenerApi extends ApiBase {
11 | void onCancel();
12 |
13 | void onHttpSuccess(String httpName, Object result);
14 |
15 | void onHttpError(String httpName, int errorCode, String errorMsg);
16 | }
17 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/HttpUtilApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 | import java.lang.Class;
5 | import java.lang.String;
6 | import java.util.List;
7 |
8 | /**
9 | * com.netease.demo.autoapi.http.HttpUtil's api Interface
10 | */
11 | public interface HttpUtilApi extends ApiBase {
12 | RequestApi query(HttpListenerApi listener);
13 |
14 | RequestApi queryNoCallback(HttpListenerApi listener);
15 |
16 | T get(Class aaaaaa);
17 |
18 | List toJsonArr(String jsonStr, Class clazz);
19 | }
20 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/MinusApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.autoapi.Minus's api Interface
7 | */
8 | public interface MinusApi extends ApiBase {
9 | int calu();
10 |
11 | int minus(int a, int b);
12 | }
13 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/RequestApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.autoapi.http.Request's api Interface
7 | */
8 | public interface RequestApi extends ApiBase {
9 | void cancel();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/SharedWzpCommonRequestTaskApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.autoapi.test.SharedWzpCommonRequestTask's api Interface
7 | */
8 | public interface SharedWzpCommonRequestTaskApi extends ApiBase {
9 | RequestApi query(HttpListenerApi listener);
10 |
11 | RequestApi queryArray(HttpListenerApi listener);
12 | }
13 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/SingletonApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 | import java.lang.String;
5 |
6 | /**
7 | * com.netease.demo.autoapi.Singleton's api Interface
8 | */
9 | public interface SingletonApi extends ApiBase {
10 | String foo1(String str1, String str2);
11 |
12 | void foo2();
13 |
14 | void foo3();
15 | }
16 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/AddUtilApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.AddUtilApi;
4 |
5 | /**
6 | * com.netease.demo.autoapi.AddUtil api Class's factory Interface
7 | */
8 | public interface AddUtilApiFactory {
9 | AddUtilApi newInstance(int data1, int data2);
10 |
11 | AddUtilApi newInstance(int data);
12 |
13 | AddUtilApi getInstance(int data1, int data2);
14 | }
15 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/AppCalculatorApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.AppCalculator;
4 |
5 | /**
6 | * com.netease.demo.autoapi.Calculator api Class's factory Interface
7 | */
8 | public interface AppCalculatorApiFactory {
9 | AppCalculator newInstance();
10 |
11 | AppCalculator newWithIncr(int incre);
12 | }
13 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/AppDataModelApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.AppDataModel;
4 |
5 | /**
6 | * com.netease.demo.autoapi.DataModel api Class's factory Interface
7 | */
8 | public interface AppDataModelApiFactory {
9 | AppDataModel newInstance(int a, int b);
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/AppSingletonApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.AppSingleton;
4 |
5 | /**
6 | * com.netease.demo.autoapi.Singleton api Class's factory Interface
7 | */
8 | public interface AppSingletonApiFactory {
9 | AppSingleton getInstance();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/CalculatorAliasApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.CalculatorAlias;
4 |
5 | /**
6 | * com.netease.demo.autoapi.test1.Calculator api Class's factory Interface
7 | */
8 | public interface CalculatorAliasApiFactory {
9 | CalculatorAlias newInstance();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/CalculatorApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.CalculatorApi;
4 |
5 | /**
6 | * com.netease.demo.autoapi.test1.Calculator api Class's factory Interface
7 | */
8 | public interface CalculatorApiFactory {
9 | CalculatorApi newInstance();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/DataModelApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.DataModelApi;
4 |
5 | /**
6 | * com.netease.demo.autoapi.DataModel api Class's factory Interface
7 | */
8 | public interface DataModelApiFactory {
9 | DataModelApi newInstance(int a, int b);
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/DataModelOperatorApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.DataModelOperatorApi;
4 |
5 | /**
6 | * com.netease.demo.autoapi.DataModelOperator api Class's factory Interface
7 | */
8 | public interface DataModelOperatorApiFactory {
9 | DataModelOperatorApi newInstance();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/DeviceUtilApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.DeviceUtilApi;
4 |
5 | /**
6 | * com.netease.demo.autoapi.DeviceUtil api Class's factory Interface
7 | */
8 | public interface DeviceUtilApiFactory {
9 | DeviceUtilApi newInstance();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/EventAApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.EventAApi;
4 |
5 | /**
6 | * com.netease.demo.autoapi.EventA api Class's factory Interface
7 | */
8 | public interface EventAApiFactory {
9 | EventAApi newInstance();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/HttpListenerApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.HttpListenerApi;
4 |
5 | /**
6 | * com.netease.demo.autoapi.http.HttpListener api Class's factory Interface
7 | */
8 | public interface HttpListenerApiFactory {
9 | HttpListenerApi newInstance();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/HttpUtilApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.HttpUtilApi;
4 |
5 | /**
6 | * com.netease.demo.autoapi.http.HttpUtil api Class's factory Interface
7 | */
8 | public interface HttpUtilApiFactory {
9 | HttpUtilApi newInstance();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/MinusApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.MinusApi;
4 |
5 | /**
6 | * com.netease.demo.autoapi.Minus api Class's factory Interface
7 | */
8 | public interface MinusApiFactory {
9 | MinusApi newInstance(int data1, int data2);
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/RequestApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.RequestApi;
4 |
5 | /**
6 | * com.netease.demo.autoapi.http.Request api Class's factory Interface
7 | */
8 | public interface RequestApiFactory {
9 | RequestApi newInstance();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/SharedWzpCommonRequestTaskApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.SharedWzpCommonRequestTaskApi;
4 | import java.lang.Class;
5 | import java.lang.Object;
6 | import java.lang.String;
7 | import java.util.Map;
8 |
9 | /**
10 | * com.netease.demo.autoapi.test.SharedWzpCommonRequestTask api Class's factory Interface
11 | */
12 | public interface SharedWzpCommonRequestTaskApiFactory {
13 | SharedWzpCommonRequestTaskApi newInstance(String url, Class modelClass, Map queryParams, Map headerMap, Map bodyMap);
14 | }
15 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/autoapi/auto_api/factory/SingletonApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.autoapi.auto_api.factory;
2 |
3 | import com.netease.demo.autoapi.auto_api.SingletonApi;
4 |
5 | /**
6 | * com.netease.demo.autoapi.Singleton api Class's factory Interface
7 | */
8 | public interface SingletonApiFactory {
9 | SingletonApi getInstance();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/demomodule1/auto_api/ModuleFunction.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.demomodule1.auto_api;
2 |
3 | import com.netease.libs.auto_api.ApiBase;
4 |
5 | /**
6 | * com.netease.demo.demomodule1.ModuleFunctionUtil's api Interface
7 | */
8 | public interface ModuleFunction extends ApiBase {
9 | int multiple(int a, int b);
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/demo/demomodule1/auto_api/factory/ModuleFunctionApiFactory.java:
--------------------------------------------------------------------------------
1 | package com.netease.demo.demomodule1.auto_api.factory;
2 |
3 | import com.netease.demo.demomodule1.auto_api.ModuleFunction;
4 |
5 | /**
6 | * com.netease.demo.demomodule1.ModuleFunctionUtil api Class's factory Interface
7 | */
8 | public interface ModuleFunctionApiFactory {
9 | ModuleFunction newInstance();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/java/com/netease/libs/auto_api/ApiBase.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.auto_api;
2 |
3 | import java.lang.Object;
4 |
5 | /**
6 | * api service Interface's parent Interface
7 | */
8 | public interface ApiBase {
9 | Object getApiServiceTarget();
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | apiprovider-api
3 |
4 |
--------------------------------------------------------------------------------
/module/autoapi-api/src/test/java/com/netease/libs/apiservice_api/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.apiservice_api;
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 | }
--------------------------------------------------------------------------------
/module/autoapi-plugin/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .gradle
3 | build/
4 | out/
5 | local.properties
6 | .DS_Store
7 | gradlew
8 | gradlew.bat
9 | gradle
10 |
11 | # Ignore Gradle GUI config
12 | gradle-app.setting
13 |
14 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
15 | !gradle-wrapper.jar
16 |
17 | # Cache of project
18 | .gradletasknamecache
19 |
20 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
21 | # gradle/wrapper/gradle-wrapper.properties
22 |
--------------------------------------------------------------------------------
/module/autoapi-plugin/README-CN.md:
--------------------------------------------------------------------------------
1 | # api-provider
--------------------------------------------------------------------------------
/module/autoapi-plugin/README.md:
--------------------------------------------------------------------------------
1 | # api-provider
--------------------------------------------------------------------------------
/module/autoapi-plugin/autoapi-plugin.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/module/autoapi-plugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 | apply plugin: 'maven'
3 | //apply from: 'bintray.gradle'
4 | //apply from: 'publish.gradle'
5 |
6 | buildscript {
7 | repositories {
8 | jcenter()
9 | }
10 |
11 | dependencies {
12 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | dependencies {
23 | compile gradleApi()
24 | compile localGroovy()
25 | compile 'com.android.tools.build:gradle:2.3.0'
26 | }
27 |
28 | version = '0.0.1-snapshot'
29 | group = 'com.netease.plugin'
30 |
31 | uploadArchives {
32 | repositories {
33 | mavenDeployer {
34 | repository(url: uri("${rootProject.projectDir}/../repo"))
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/module/autoapi-plugin/src/main/groovy/com/netease/plugin/apiprovider/ApiProvider.groovy:
--------------------------------------------------------------------------------
1 | package com.netease.plugin.apiprovider
2 |
3 | import com.android.build.gradle.AppPlugin
4 | import org.gradle.api.GradleException
5 | import org.gradle.api.Plugin
6 | import org.gradle.api.Project
7 |
8 | class ApiProvider implements Plugin {
9 |
10 | Project mProject
11 | Config mConfig
12 |
13 | @Override
14 | void apply(Project project) {
15 |
16 | mProject = project
17 |
18 | //判断是library还是application
19 | def hasAppPlugin = project.plugins.withType(AppPlugin)
20 | def variants = hasAppPlugin ? project.android.applicationVariants : project.android.libraryVariants
21 |
22 | //set config
23 | project.extensions.create('ApiProviderConfig', Config)
24 | mConfig = project.ApiProviderConfig
25 |
26 | def taskNames = project.gradle.startParameter.taskNames
27 | def isContainAssembleTask = false
28 | for (int index = 0; index < taskNames.size(); ++index) {
29 | def taskName = taskNames[index]
30 |
31 | println "---- ApiProvider Plugin taskname ${taskName} ----"
32 |
33 | if (taskName.contains("assemble") || taskName.contains("JavaWithJavac")) {
34 | isContainAssembleTask = true
35 | break
36 | }
37 | }
38 |
39 | //export build clean
40 | // if (!isContainAssembleTask) {
41 | // return
42 | // }
43 |
44 | project.afterEvaluate {
45 | variants.all { variant ->
46 |
47 | for (def task : project.tasks) {
48 | println "---- ApiProvider Plugin taskname ${task.toString()} ----"
49 | }
50 |
51 | def compileJavaTask = project.tasks.getByName("compile${variant.name.capitalize()}JavaWithJavac")
52 | def apiTaskName = "ApiProvider${variant.name.capitalize()}"
53 |
54 | println "---- ApiProvider Plugin compileJavaTask ${compileJavaTask.toString()} ----"
55 | println "---- ApiProvider Plugin apiTask ${apiTaskName.toString()} ----"
56 |
57 | compileJavaTask.doLast {
58 | println '---- ApiProvider Plugin Start ----'
59 |
60 | def fromPath = "${project.projectDir}/build/generated/source/apt/debug/com/netease/libs/apiprovider/"
61 | def toPath = "${project.rootProject.projectDir}/${mConfig.apiProjectPath}/src/api/java/com/netease/libs/apiprovider/"
62 |
63 | def fromDir = new File("${fromPath}")
64 | def toDir = new File("${toPath}")
65 |
66 | if (!fromDir.exists()) {
67 | println "---- ApiProvider Plugin Error ${fromPath} folder not exist"
68 | return
69 | }
70 | if (!toDir.exists()) {
71 | if (!toDir.mkdirs()) {
72 | println "---- ApiProvider Plugin Error ${toPath} folder create error"
73 | return
74 | }
75 | }
76 |
77 | boolean success = false
78 | try {
79 | success = FileUtil.directoryCopy(fromPath, toPath)
80 | } catch (IOException e) {
81 | throw GradleException("---- ApiProvider Plugin Error ${e.toString()} ----")
82 | }
83 | if (!success) {
84 | throw GradleException("---- ApiProvider Plugin Failed ----")
85 | }
86 |
87 | println '---- ApiProvider Plugin End ----'
88 | }
89 |
90 | //inject task
91 | // def apiTask = project.tasks.getByName(apiTaskName)
92 | // apiTask.dependsOn compileJavaTask.taskDependencies.getDependencies(compileJavaTask)
93 | // compileJavaTask.dependsOn apiTask
94 | }
95 | }
96 | }
97 | }
--------------------------------------------------------------------------------
/module/autoapi-plugin/src/main/groovy/com/netease/plugin/apiprovider/Config.groovy:
--------------------------------------------------------------------------------
1 | package com.netease.plugin.apiprovider
2 |
3 | /**
4 | * Created by zyl06 on 2018/10/19.
5 | */
6 |
7 | class Config {
8 | // 相对rootProject的相对路径
9 | def apiProjectPath = "neapiprovider"
10 | }
11 |
--------------------------------------------------------------------------------
/module/autoapi-plugin/src/main/groovy/com/netease/plugin/apiprovider/FileUtil.groovy:
--------------------------------------------------------------------------------
1 | package com.netease.plugin.apiprovider;
2 |
3 | /**
4 | * Created by zyl06 on 2018/10/19.
5 | */
6 |
7 | class FileUtil {
8 |
9 | static boolean fileCopy(String fromPath, String toPath) throws IOException {
10 | //如果原文件不存在
11 | File fromFile = new File(fromPath)
12 |
13 | if (!fromFile.exists()) {
14 | return false
15 | }
16 | //获得原文件流
17 | FileInputStream inputStream = new FileInputStream(fromFile)
18 | return fileCopy(inputStream, toPath)
19 | }
20 |
21 | /**
22 | * 复制单个文件(一般用于将Assets目录下的文件拷贝)
23 | * @param inputStream InputStream
24 | * @param outFilePath
25 | * @return
26 | * @throws IOException
27 | */
28 | public static boolean fileCopy(InputStream inputStream, String outFilePath) throws IOException {
29 | if (inputStream == null) {
30 | return false
31 | }
32 |
33 | File outFile = new File(outFilePath)
34 | if (outFile.exists()) {
35 | outFile.delete()
36 | }
37 |
38 | File parentDir = outFile.getParentFile()
39 | if (parentDir != null && !parentDir.exists()) {
40 | parentDir.mkdirs()
41 | }
42 |
43 | byte[] data = new byte[4 * 1024]
44 | int length//保存每次读取到的字节个数
45 | //输出流
46 | FileOutputStream outputStream = new FileOutputStream(outFile)
47 | //开始处理流
48 | while ((length = inputStream.read(data)) != -1) {
49 | outputStream.write(data, 0, length)
50 | }
51 | inputStream.close()
52 | outputStream.close()
53 | return true
54 | }
55 |
56 | public static boolean directoryCopy(String fromPath, String toPath) throws IOException {
57 | File fromDir = new File(fromPath)
58 | if (fromDir.exists()) {
59 | if (fromDir.isFile()) {
60 | fileCopy(fromDir.getAbsolutePath(), toPath + File.separator + fromDir.getName())
61 | } else if (fromDir.isDirectory()) {
62 | File[] files = fromDir.listFiles()
63 | for (File f : files) {
64 | fileCopy(f.getAbsolutePath(), toPath + File.separator + f.getName())
65 | }
66 | }
67 | }
68 | return true
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/module/autoapi-plugin/src/main/resources/META-INF/gradle-plugins/ApiProviderPlugin.properties:
--------------------------------------------------------------------------------
1 | implementation-class=com.netease.plugin.apiprovider.ApiProvider
--------------------------------------------------------------------------------
/module/autoapi/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module/autoapi/autoapi.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/module/autoapi/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'android-aspectjx'
3 | apply plugin: 'maven'
4 |
5 | sourceCompatibility = JavaVersion.VERSION_1_7
6 | targetCompatibility = JavaVersion.VERSION_1_7
7 |
8 | repositories {
9 | mavenLocal()
10 | maven { url 'https://raw.githubusercontent.com/bitterbee/mvn-repo/master/' }
11 | // maven { url uri('../../repo') }
12 | maven{ url 'https://dl.google.com/dl/android/maven2/'}
13 | jcenter()
14 | maven { url 'https://maven.google.com'}
15 |
16 | flatDir {
17 | dirs 'libs'
18 | }
19 | }
20 |
21 | sourceSets {
22 | main {
23 | def dirs = ['main', 'api']
24 | dirs.each { dir ->
25 | java.srcDir("src/$dir/java")
26 | }
27 | }
28 | }
29 |
30 | dependencies {
31 | compileOnly "org.aspectj:aspectjrt:${ASPECTJRT_VERSION}"
32 | }
33 |
34 | version = AUTO_API_VERSION
35 | group = 'com.netease.libs'
36 |
37 | uploadArchives {
38 | repositories {
39 | mavenDeployer {
40 | repository(url: uri("${rootProject.projectDir}/repo"))
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/module/autoapi/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=AutoApi Library
2 | POM_ARTIFACT_ID=autoapi
3 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/module/autoapi/src/main/java/com/netease/libs/autoapi/AutoApi.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * Created by zyl06 on 2018/10/19.
8 | */
9 | public class AutoApi {
10 |
11 | public static void init() {
12 | // inner call ApiRegister.init();
13 | }
14 |
15 | public static final Map API_FACTORYS = new HashMap<>();
16 |
17 | public static T getApiFactory(String name) {
18 | return (T) API_FACTORYS.get(name);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/module/autoapi/src/main/java/com/netease/libs/autoapi/anno/AutoApiCallbackAnno.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi.anno;
2 |
3 | /**
4 | * Created by zyl06 on 2018/11/5.
5 | */
6 |
7 | public @interface AutoApiCallbackAnno {
8 | }
9 |
--------------------------------------------------------------------------------
/module/autoapi/src/main/java/com/netease/libs/autoapi/anno/AutoApiClassAnno.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi.anno;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by zyl06 on 2018/10/16.
10 | */
11 | @Target(ElementType.TYPE)
12 | @Retention(RetentionPolicy.CLASS)
13 | public @interface AutoApiClassAnno {
14 | /**
15 | * 接口提供者名字
16 | * @return
17 | */
18 | String name() default "";
19 |
20 | /**
21 | * 是否提供全部 public static 方法?
22 | * @return
23 | */
24 | boolean allPublicStaticApi() default false;
25 |
26 | /**
27 | * 是否提供全部 public(非 static) 方法?
28 | * @return
29 | */
30 | boolean allPublicNormalApi() default false;
31 |
32 | /**
33 | * 是否提供基类接口,默认不提供
34 | * @return
35 | */
36 | boolean includeSuperApi() default false;
37 | }
38 |
--------------------------------------------------------------------------------
/module/autoapi/src/main/java/com/netease/libs/autoapi/anno/AutoApiClassBuildMethodAnno.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi.anno;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by zyl06 on 2018/10/28.
10 | */
11 | @Target(ElementType.METHOD)
12 | @Retention(RetentionPolicy.CLASS)
13 | public @interface AutoApiClassBuildMethodAnno {
14 | String alias() default "";
15 | }
16 |
--------------------------------------------------------------------------------
/module/autoapi/src/main/java/com/netease/libs/autoapi/anno/AutoApiConstructAnno.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi.anno;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by zyl06 on 2018/10/27.
10 | */
11 | @Target(ElementType.CONSTRUCTOR)
12 | @Retention(RetentionPolicy.CLASS)
13 | public @interface AutoApiConstructAnno {
14 | String alias() default "";
15 | }
16 |
--------------------------------------------------------------------------------
/module/autoapi/src/main/java/com/netease/libs/autoapi/anno/AutoApiMethodAnno.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi.anno;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by zyl06 on 2018/10/26.
10 | */
11 | @Target(ElementType.METHOD)
12 | @Retention(RetentionPolicy.CLASS)
13 | public @interface AutoApiMethodAnno {
14 | /**
15 | * 是否暴露该 api
16 | * @return
17 | */
18 | boolean provide() default true;
19 |
20 | /**
21 | * 方法别名,如果为空则使用原方法名
22 | * @return
23 | */
24 | String alias() default "";
25 |
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/module/autoapi_process/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module/autoapi_process/autoapi_process.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/module/autoapi_process/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'maven'
3 |
4 | sourceCompatibility = JavaVersion.VERSION_1_7
5 | targetCompatibility = JavaVersion.VERSION_1_7
6 |
7 | repositories {
8 | mavenLocal()
9 | maven { url 'https://raw.githubusercontent.com/bitterbee/mvn-repo/master/' }
10 | // maven { url uri('../../repo') }
11 | maven{ url 'https://dl.google.com/dl/android/maven2/'}
12 | jcenter()
13 | maven { url 'https://maven.google.com'}
14 |
15 | flatDir {
16 | dirs 'libs'
17 | }
18 | }
19 |
20 | dependencies {
21 | implementation fileTree(dir: 'libs', include: ['*.jar'])
22 |
23 | compile "com.netease.libs:autoapi:${AUTO_API_VERSION}"
24 | // compile project(':autoapi')
25 | compile "com.google.auto.service:auto-service:${AUTO_SERVICE_VERSION}"
26 | compile "com.squareup:javapoet:${JAVAPOET_VERSION}"
27 | }
28 |
29 | version = AUTO_API_VERSION
30 | group = 'com.netease.libs'
31 |
32 | uploadArchives {
33 | repositories {
34 | mavenDeployer {
35 | repository(url: uri("${rootProject.projectDir}/repo"))
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/AutoApiClass.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process;
2 |
3 | import javax.lang.model.element.TypeElement;
4 |
5 | /**
6 | * Created by zyl06 on 2018/10/17.
7 | */
8 |
9 | public class AutoApiClass {
10 | // NEApiProviderAnno 注解对应的类型
11 | public TypeElement clazz;
12 |
13 | // api provider 名称
14 | public String name;
15 |
16 | // 是否提供全部的 public static 方法
17 | public boolean allPublicStaticApi;
18 |
19 | // 是否提供全部的 public normal 方法
20 | public boolean allPublicNormalApi;
21 |
22 | // 是否判断基类方法
23 | public boolean includeSuperApi;
24 | }
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/AutoApiProcess.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process;
2 |
3 | import com.google.auto.service.AutoService;
4 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
5 | import com.netease.libs.autoapi_process.generator.ApiBaseGenerator;
6 | import com.netease.libs.autoapi_process.generator.ApiRegisterGenerator;
7 | import com.netease.libs.autoapi_process.generator.CallbackClassGenerator;
8 | import com.netease.libs.autoapi_process.generator.StubClassGenerator;
9 | import com.netease.libs.autoapi_process.generator.StubFactoryGenerator;
10 | import com.squareup.javapoet.ClassName;
11 | import com.squareup.javapoet.JavaFile;
12 | import com.squareup.javapoet.TypeSpec;
13 |
14 | import java.util.ArrayList;
15 | import java.util.List;
16 | import java.util.Map;
17 | import java.util.Set;
18 |
19 | import javax.annotation.processing.AbstractProcessor;
20 | import javax.annotation.processing.Filer;
21 | import javax.annotation.processing.FilerException;
22 | import javax.annotation.processing.ProcessingEnvironment;
23 | import javax.annotation.processing.Processor;
24 | import javax.annotation.processing.RoundEnvironment;
25 | import javax.lang.model.SourceVersion;
26 | import javax.lang.model.element.Element;
27 | import javax.lang.model.element.TypeElement;
28 |
29 | import static com.squareup.javapoet.JavaFile.builder;
30 | import static java.util.Collections.singleton;
31 | import static javax.lang.model.SourceVersion.latestSupported;
32 |
33 | /**
34 | * Created by zyl06 on 2018/10/16.
35 | */
36 | @AutoService(Processor.class)
37 | public class AutoApiProcess extends AbstractProcessor {
38 |
39 | private String mPkgName;
40 | private String mApiProjectPath;
41 |
42 | private Filer mFiler;
43 |
44 | @Override
45 | public synchronized void init(ProcessingEnvironment processingEnv) {
46 | super.init(processingEnv);
47 |
48 | Logger.sMessager = processingEnv.getMessager();
49 |
50 | Map options = processingEnv.getOptions();
51 | if (options != null && !options.isEmpty()) {
52 | mApiProjectPath = options.get("apiProjectPath");
53 | mPkgName = options.get("packageName");
54 |
55 | String strLogOpen = options.get("logOpen");
56 | Logger.sLogOpen = Boolean.parseBoolean(strLogOpen);
57 |
58 | String strApiBuildEnable = options.get("apiBuildEnable");
59 | if (strApiBuildEnable != null) {
60 | FileUtil.sApiBuildEnable = Boolean.parseBoolean(strApiBuildEnable);
61 | }
62 |
63 | Logger.w("apiBuildEnable " + strApiBuildEnable);
64 | }
65 |
66 | mFiler = processingEnv.getFiler();
67 | ElementUtil.sElementUtil = processingEnv.getElementUtils();
68 |
69 | FileUtil.sFromPkgName = mPkgName;
70 | FileUtil.sToProjectPath = mApiProjectPath;
71 | FileUtil.deleteRecord();
72 | Logger.i("delete record.txt");
73 | }
74 |
75 | @Override
76 | public Set getSupportedAnnotationTypes() {
77 | return singleton(AutoApiClassAnno.class.getCanonicalName());
78 | }
79 |
80 | @Override
81 | public SourceVersion getSupportedSourceVersion() {
82 | return latestSupported();
83 | }
84 |
85 | @Override
86 | public boolean process(Set extends TypeElement> set, RoundEnvironment roundEnv) {
87 |
88 | Logger.i("api provider apt run begin");
89 |
90 | ElementUtil.ORIGIN_TO_API.clear();
91 | ElementUtil.ORIGIAN_TO_STUB.clear();
92 | ElementUtil.ORIGIN_TO_CALLBACK.clear();
93 |
94 | List classGenerators = new ArrayList<>();
95 | List stubFactoryGenerators = new ArrayList<>();
96 |
97 | // api 接口的统一父接口
98 | classGenerators.add(new ApiBaseGenerator());
99 |
100 | for (Element annoElement : roundEnv.getElementsAnnotatedWith(AutoApiClassAnno.class)) {
101 | TypeElement annoClass = (TypeElement) annoElement;
102 | //检测是否是支持的注解类型,如果不是里面会报错
103 | if (!isValidElement(annoClass, AutoApiClassAnno.class)) {
104 | continue;
105 | }
106 | //获取到信息,把注解类的信息加入到列表中
107 | AutoApiClassAnno anno = annoElement.getAnnotation(AutoApiClassAnno.class);
108 |
109 | AutoApiClass providerClass = new AutoApiClass();
110 | providerClass.clazz = annoClass;
111 | providerClass.name = anno.name();
112 | providerClass.allPublicStaticApi = anno.allPublicStaticApi();
113 | providerClass.allPublicNormalApi = anno.allPublicNormalApi();
114 | providerClass.includeSuperApi = anno.includeSuperApi();
115 |
116 | com.netease.libs.autoapi_process.generator.ApiGenerator apiGen = new com.netease.libs.autoapi_process.generator.ApiGenerator(providerClass, mPkgName);
117 | classGenerators.add(apiGen);
118 | ElementUtil.ORIGIN_TO_API.put(ClassName.get(annoClass), ElementUtil.getClassName(apiGen));
119 |
120 | if (ElementUtil.isInterface(annoClass)) {
121 | CallbackClassGenerator callbackGen = new CallbackClassGenerator(providerClass, apiGen, mPkgName);
122 | classGenerators.add(callbackGen);
123 | ElementUtil.ORIGIN_TO_CALLBACK.put(ClassName.get(annoClass), ElementUtil.getClassName(callbackGen));
124 | }
125 |
126 | StubClassGenerator stubGen = new StubClassGenerator(providerClass, apiGen, mPkgName);
127 | classGenerators.add(stubGen);
128 | ElementUtil.ORIGIAN_TO_STUB.put(ClassName.get(annoClass), ElementUtil.getClassName(stubGen));
129 |
130 | com.netease.libs.autoapi_process.generator.ApiFactoryGenerator apiFactoryGen = new com.netease.libs.autoapi_process.generator.ApiFactoryGenerator(providerClass, mPkgName, apiGen);
131 | classGenerators.add(apiFactoryGen);
132 |
133 | StubFactoryGenerator stubFactoryGen = new StubFactoryGenerator(providerClass, mPkgName, apiGen, stubGen, apiFactoryGen);
134 | classGenerators.add(stubFactoryGen);
135 | stubFactoryGenerators.add(stubFactoryGen);
136 | }
137 |
138 | ApiRegisterGenerator registerGenerator = new ApiRegisterGenerator(mPkgName, stubFactoryGenerators);
139 | classGenerators.add(registerGenerator);
140 |
141 | for (com.netease.libs.autoapi_process.BaseClassGenerator generator : classGenerators) {
142 | try {
143 | TypeSpec generatedClass = generator.generate();
144 | JavaFile javaFile = builder(generator.packageName(), generatedClass).build();
145 | generator.writeTo(javaFile, mFiler);
146 | } catch (FilerException e) {
147 | e.printStackTrace();
148 | } catch (Exception e) {
149 | StringBuilder sb = new StringBuilder(128);
150 | sb.append(e.toString()).append("\n");
151 | for (StackTraceElement element : e.getStackTrace()) {
152 | sb.append(element.toString()).append("\n");
153 | }
154 |
155 | Logger.e(sb.toString());
156 | }
157 | }
158 |
159 | Logger.i("api provider apt run finish");
160 |
161 | return true;
162 | }
163 |
164 | private boolean isValidElement(Element elem, Class annoClass) {
165 |
166 | if (!ElementUtil.isPublic(elem)) {
167 | String message = String.format("Classes annotated with %s must be public.", "@" + annoClass.getSimpleName());
168 | Logger.e(message, elem);
169 | return false;
170 | }
171 |
172 | // public interface 直接 true
173 | Logger.w("isValidElement " + elem.toString());
174 | if (elem instanceof TypeElement && ElementUtil.isInterface((TypeElement) elem)) {
175 | Logger.w("isInterface " + elem.toString());
176 | return true;
177 | }
178 |
179 | if (ElementUtil.isAbstract(elem)) {
180 | String message = String.format("Classes annotated with %s must not be abstract.", "@" + annoClass.getSimpleName());
181 | Logger.e(message, elem);
182 | return false;
183 | }
184 |
185 | return true;
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/BaseClassGenerator.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process;
2 |
3 | import com.squareup.javapoet.ClassName;
4 | import com.squareup.javapoet.JavaFile;
5 | import com.squareup.javapoet.TypeSpec;
6 |
7 | import java.io.IOException;
8 |
9 | import javax.annotation.processing.Filer;
10 | import javax.annotation.processing.Messager;
11 | import javax.lang.model.element.Element;
12 | import javax.lang.model.util.Elements;
13 | import javax.tools.Diagnostic;
14 |
15 | /**
16 | * Created by zyl06 on 2018/10/17.
17 | */
18 |
19 | public abstract class BaseClassGenerator {
20 |
21 | public BaseClassGenerator() {
22 | }
23 |
24 | public abstract TypeSpec generate();
25 |
26 | public void writeTo(JavaFile javaFile, Filer filer) throws IOException {
27 | javaFile.writeTo(filer);
28 | }
29 |
30 | public abstract String packageName();
31 |
32 | public abstract String className();
33 |
34 | protected String getClassName(Element element) {
35 | ClassName className = ClassName.bestGuess(element.toString());
36 |
37 | // get class full name
38 | StringBuilder sbClazzName = new StringBuilder(32);
39 | sbClazzName.append(className.packageName()).append(".");
40 | for (String simplename : className.simpleNames()) {
41 | sbClazzName.append(simplename);
42 | sbClazzName.append("$");
43 | }
44 | sbClazzName.deleteCharAt(sbClazzName.length() - 1);
45 |
46 | return sbClazzName.toString();
47 | }
48 |
49 | protected Class primaryTypeGuess(String typeName) {
50 | if ("int".equals(typeName)) {
51 | return int.class;
52 | } else if ("long".equals(typeName)) {
53 | return long.class;
54 | } else if ("float".equals(typeName)) {
55 | return float.class;
56 | } else if ("boolean".equals(typeName)) {
57 | return boolean.class;
58 | } else if ("double".equals(typeName)) {
59 | return double.class;
60 | } else if ("char".equals(typeName)) {
61 | return char.class;
62 | } else if ("short".equals(typeName)) {
63 | return short.class;
64 | } else if ("byte".equals(typeName)) {
65 | return byte.class;
66 | }
67 |
68 | return null;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/ElementUtil.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassAnno;
4 | import com.squareup.javapoet.ClassName;
5 | import com.squareup.javapoet.TypeName;
6 |
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 | import javax.lang.model.element.Element;
11 | import javax.lang.model.element.ElementKind;
12 | import javax.lang.model.element.Modifier;
13 | import javax.lang.model.element.TypeElement;
14 | import javax.lang.model.element.VariableElement;
15 | import javax.lang.model.type.TypeMirror;
16 | import javax.lang.model.util.Elements;
17 |
18 | /**
19 | * Created by zyl06 on 2018/10/18.
20 | */
21 |
22 | public class ElementUtil {
23 | static final Map ORIGIN_TO_API = new HashMap<>();
24 | static final Map ORIGIAN_TO_STUB = new HashMap<>();
25 | static final Map ORIGIN_TO_CALLBACK = new HashMap<>();
26 |
27 | static Elements sElementUtil;
28 |
29 | public static boolean isPublic(Element element) {
30 | return element.getModifiers().contains(Modifier.PUBLIC);
31 | }
32 |
33 | public static boolean isAbstract(Element element) {
34 | return element.getModifiers().contains(Modifier.ABSTRACT);
35 | }
36 |
37 | public static boolean isStatic(Element element) {
38 | return element.getModifiers().contains(Modifier.STATIC);
39 | }
40 |
41 | public static boolean isInterface(TypeElement elem) {
42 | return elem.getKind() == ElementKind.INTERFACE;
43 | }
44 |
45 | public static ClassName getClassName(BaseClassGenerator classGen) {
46 | return ClassName.get(classGen.packageName(), classGen.className());
47 | }
48 |
49 | /**
50 | *
51 | * @param e 具体 Element
52 | * @return 返回 对应 Api 类 TypeName
53 | */
54 | public static TypeName getApiServiceClassName(Element e) {
55 | if (e instanceof TypeElement) {
56 | AutoApiClassAnno anno = e.getAnnotation(AutoApiClassAnno.class);
57 | if (anno == null) {
58 | return null;
59 | }
60 | ClassName className = ClassName.get((TypeElement) e);
61 | return ORIGIN_TO_API.get(className);
62 | }
63 |
64 | if (e instanceof VariableElement) {
65 | VariableElement varElem = (VariableElement) e;
66 | return ORIGIN_TO_API.get(ClassName.get(varElem.asType()));
67 | }
68 |
69 | return null;
70 | }
71 |
72 | public static TypeName getApiServiceClassName(TypeMirror type) {
73 | return ORIGIN_TO_API.get(ClassName.get(type));
74 | }
75 |
76 | public static TypeName getStubServiceClassName(TypeMirror type) {
77 | return ORIGIAN_TO_STUB.get(ClassName.get(type));
78 | }
79 |
80 | public static TypeName getCallbackClassName(TypeMirror type) {
81 | return ORIGIN_TO_CALLBACK.get(ClassName.get(type));
82 | }
83 |
84 | public static String defaultValue(TypeName tn) {
85 | if (!tn.isPrimitive()) {
86 | return "null";
87 | }
88 |
89 | if (tn.equals(TypeName.BOOLEAN)) {
90 | return "false";
91 | } else if (tn.equals(TypeName.BYTE) ||
92 | tn.equals(TypeName.SHORT) ||
93 | tn.equals(TypeName.INT) ||
94 | tn.equals(TypeName.LONG) ||
95 | tn.equals(TypeName.CHAR)) {
96 | return "0";
97 | } else if (tn.equals(TypeName.FLOAT) ||
98 | tn.equals(TypeName.DOUBLE)) {
99 | return "0.f";
100 | }
101 | return null;
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/FileUtil.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process;
2 |
3 | import com.squareup.javapoet.JavaFile;
4 |
5 | import java.io.Closeable;
6 | import java.io.File;
7 | import java.io.FileInputStream;
8 | import java.io.FileOutputStream;
9 | import java.io.FileWriter;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 |
13 | /**
14 | * Created by zyl06 on 2018/10/19.
15 | */
16 |
17 | public class FileUtil {
18 |
19 | public static String sToProjectPath;
20 | public static String sFromPkgName;
21 | public static boolean sApiBuildEnable = true;
22 |
23 | public static void writeTo(JavaFile javaFile) throws IOException {
24 |
25 | if (!sApiBuildEnable) {
26 | return;
27 | }
28 |
29 | String to = sToProjectPath + "/src/main/java/";
30 |
31 | // 写文件
32 | File toDir = new File(to);
33 | if (!toDir.exists()) {
34 | boolean success = toDir.mkdirs();
35 | if (!success) {
36 | Logger.e(to + " folder not exists!!!");
37 | return;
38 | }
39 | }
40 | javaFile.writeTo(toDir);
41 |
42 | // 生成 record 文件
43 | String pkgName = javaFile.packageName;
44 | String name = javaFile.typeSpec.name;
45 |
46 | String relativePath = null;
47 | if (pkgName == null || pkgName.isEmpty()) {
48 | relativePath = name + ".java";
49 |
50 | } else {
51 | pkgName = pkgName.replaceAll("\\.", "/");
52 | relativePath = pkgName + "/" + name + ".java";
53 | }
54 |
55 | String filePath = to + relativePath;
56 | Logger.i("java filePath = " + filePath);
57 |
58 | FileWriter fw = null;
59 | try {
60 | File file = new File(getRecordFilePath());
61 | if (!file.exists()) {
62 | file.getParentFile().mkdirs();
63 | file.createNewFile();
64 | }
65 |
66 | fw = new FileWriter(file, true);
67 | fw.append(relativePath).append(";").append("\n");
68 | fw.flush();
69 | } catch (IOException e) {
70 | Logger.e(e.toString());
71 | } finally {
72 | safeClose(fw);
73 | }
74 | }
75 |
76 | public static String getRecordFilePath() {
77 | return sFromPkgName == null || sFromPkgName.isEmpty() ?
78 | sToProjectPath + "/api_records/records.txt" :
79 | sToProjectPath + "/api_records/" + sFromPkgName + ".records.txt";
80 | }
81 |
82 | public static void deleteRecord() {
83 | deleteFile(getRecordFilePath());
84 | }
85 |
86 | // 不处理文件夹
87 | public static boolean deleteFile(String path) {
88 | if (path == null || path.isEmpty()) {
89 | return false;
90 | }
91 |
92 | File file = new File(path);
93 | return file.exists() && file.delete();
94 | }
95 |
96 |
97 | static boolean fileCopy(String fromPath, String toPath) {
98 | //如果原文件不存在
99 | File fromFile = new File(fromPath);
100 |
101 | if (!fromFile.exists()) {
102 | return false;
103 | }
104 | //获得原文件流
105 | FileInputStream is = null;
106 | try {
107 | is = new FileInputStream(fromFile);
108 | return fileCopy(is, toPath);
109 | } catch (IOException e) {
110 | e.printStackTrace();
111 | } finally {
112 | safeClose(is);
113 | }
114 |
115 | return false;
116 | }
117 |
118 | private static void safeClose(Closeable c) {
119 | if (c != null) {
120 | try {
121 | c.close();
122 | } catch (Exception e) {
123 | e.printStackTrace();
124 | }
125 | }
126 | }
127 |
128 | /**
129 | * 复制单个文件(一般用于将Assets目录下的文件拷贝)
130 | * @param is InputStream
131 | * @param outFilePath
132 | * @return
133 | * @throws IOException
134 | */
135 | public static boolean fileCopy(InputStream is, String outFilePath) {
136 | if (is == null) {
137 | return false;
138 | }
139 |
140 | File outFile = new File(outFilePath);
141 | if (outFile.exists()) {
142 | outFile.delete();
143 | }
144 |
145 | File parentDir = outFile.getParentFile();
146 | if (parentDir != null && !parentDir.exists()) {
147 | parentDir.mkdirs();
148 | }
149 |
150 | byte[] data = new byte[4 * 1024];
151 | int length;//保存每次读取到的字节个数
152 | //输出流
153 | FileOutputStream os = null;
154 | try {
155 | os = new FileOutputStream(outFile);
156 |
157 | //开始处理流
158 | while ((length = is.read(data)) != -1) {
159 | os.write(data, 0, length);
160 | }
161 |
162 | return true;
163 | } catch (IOException e) {
164 | e.printStackTrace();
165 | } finally {
166 | safeClose(os);
167 | }
168 |
169 | return false;
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/Logger.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process;
2 |
3 | import javax.annotation.processing.Messager;
4 | import javax.lang.model.element.Element;
5 | import javax.tools.Diagnostic;
6 |
7 | /**
8 | * Created by zyl06 on 2018/11/8.
9 | */
10 |
11 | public class Logger {
12 |
13 | static Messager sMessager;
14 | static boolean sLogOpen = false;
15 |
16 | public static void i(String msg) {
17 | if (sMessager != null && sLogOpen) {
18 | sMessager.printMessage(Diagnostic.Kind.NOTE, msg);
19 | }
20 | }
21 |
22 | public static void w(String msg) {
23 | if (sMessager != null && sLogOpen) {
24 | sMessager.printMessage(Diagnostic.Kind.WARNING, msg);
25 | }
26 | }
27 |
28 | public static void e(String msg) {
29 | if (sMessager != null && sLogOpen) {
30 | sMessager.printMessage(Diagnostic.Kind.ERROR, msg);
31 | }
32 | }
33 |
34 | public static void e(String msg, Element element) {
35 | if (sMessager != null && sLogOpen) {
36 | sMessager.printMessage(Diagnostic.Kind.ERROR, msg, element);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/generator/ApiBaseGenerator.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process.generator;
2 |
3 | import com.netease.libs.autoapi_process.BaseClassGenerator;
4 | import com.squareup.javapoet.ClassName;
5 | import com.squareup.javapoet.JavaFile;
6 | import com.squareup.javapoet.MethodSpec;
7 | import com.squareup.javapoet.TypeName;
8 | import com.squareup.javapoet.TypeSpec;
9 |
10 | import java.io.IOException;
11 |
12 | import javax.annotation.processing.Filer;
13 | import javax.lang.model.element.Modifier;
14 |
15 | import static com.squareup.javapoet.TypeSpec.interfaceBuilder;
16 | import static javax.lang.model.element.Modifier.PUBLIC;
17 |
18 | /**
19 | * Created by zyl06 on 2018/10/29.
20 | */
21 |
22 | public class ApiBaseGenerator extends BaseClassGenerator {
23 |
24 | private static final String PACKNAME = "com.netease.libs.auto_api";
25 | private static final String CLASS_NAME = "ApiBase";
26 | public static final String GET_TARGET_METHOD_NAME = "getApiServiceTarget";
27 |
28 | public ApiBaseGenerator() {
29 | super();
30 | }
31 |
32 | @Override
33 | public String packageName() {
34 | return PACKNAME;
35 | }
36 |
37 | @Override
38 | public String className() {
39 | return CLASS_NAME;
40 | }
41 |
42 | @Override
43 | public TypeSpec generate() {
44 | TypeSpec.Builder builder = interfaceBuilder(className())
45 | .addModifiers(PUBLIC);
46 | builder.addJavadoc("api service Interface's parent Interface\n");
47 |
48 | MethodSpec.Builder methodBuilder = MethodSpec
49 | .methodBuilder(GET_TARGET_METHOD_NAME)
50 | .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
51 | .returns(TypeName.OBJECT);
52 | builder.addMethod(methodBuilder.build());
53 |
54 | return builder.build();
55 | }
56 |
57 | @Override
58 | public void writeTo(JavaFile javaFile, Filer filer) throws IOException {
59 | com.netease.libs.autoapi_process.FileUtil.writeTo(javaFile);
60 | }
61 |
62 | public static ClassName getClassName() {
63 | return ClassName.get(PACKNAME, CLASS_NAME);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/generator/ApiFactoryGenerator.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process.generator;
2 |
3 | import com.netease.libs.autoapi_process.AutoApiClass;
4 | import com.netease.libs.autoapi_process.FileUtil;
5 | import com.squareup.javapoet.ClassName;
6 | import com.squareup.javapoet.JavaFile;
7 | import com.squareup.javapoet.MethodSpec;
8 | import com.squareup.javapoet.TypeName;
9 | import com.squareup.javapoet.TypeSpec;
10 |
11 | import java.io.IOException;
12 |
13 | import javax.annotation.processing.Filer;
14 | import javax.lang.model.element.ExecutableElement;
15 | import javax.lang.model.element.Modifier;
16 | import javax.lang.model.element.VariableElement;
17 |
18 | import static com.squareup.javapoet.TypeSpec.interfaceBuilder;
19 | import static javax.lang.model.element.Modifier.PUBLIC;
20 |
21 | /**
22 | * Created by zyl06 on 2018/10/27.
23 | */
24 |
25 | public class ApiFactoryGenerator extends BaseApiClassGenerator {
26 |
27 | private ClassName mReturnType;
28 | private int mFactoryMethodCount = 0;
29 |
30 | public ApiFactoryGenerator(AutoApiClass providerClass, String pkgName, com.netease.libs.autoapi_process.generator.ApiGenerator apiGenerator) {
31 | super(providerClass, pkgName);
32 | mReturnType = ClassName.get(apiGenerator.packageName(), apiGenerator.className());
33 | }
34 |
35 | @Override
36 | public String packageName() {
37 | return (mPkgName == null || mPkgName.isEmpty()) ?
38 | "com.netease.libs.auto_api.factory" :
39 | mPkgName + ".auto_api.factory";
40 | }
41 |
42 | @Override
43 | public String className() {
44 | return className("ApiFactory", "ApiFactory");
45 | }
46 |
47 | @Override
48 | public TypeSpec generate() {
49 | TypeSpec.Builder builder = interfaceBuilder(className())
50 | .addModifiers(PUBLIC);
51 | builder.addJavadoc(mApiTarget.getQualifiedName().toString() + " api Class's factory Interface\n");
52 |
53 | generate(builder);
54 |
55 | if (mFactoryMethodCount == 0) {
56 | addFactoryMethod(builder, null, "newInstance");
57 | }
58 |
59 | return builder.build();
60 | }
61 |
62 | @Override
63 | public void writeTo(JavaFile javaFile, Filer filer) throws IOException {
64 | FileUtil.writeTo(javaFile);
65 | }
66 |
67 | @Override
68 | protected void addMethod(TypeSpec.Builder builder, ExecutableElement e, String methodName) {
69 |
70 | }
71 |
72 | @Override
73 | protected void addFactoryMethod(TypeSpec.Builder builder, ExecutableElement e, String methodName) {
74 |
75 | mFactoryMethodCount ++;
76 |
77 | MethodSpec.Builder methodBuilder = MethodSpec
78 | .methodBuilder(methodName)
79 | .returns(mReturnType)
80 | .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT);
81 | if (e != null) {
82 | for (VariableElement param : e.getParameters()) {
83 | methodBuilder.addParameter(TypeName.get(param.asType()), param.getSimpleName().toString());
84 | }
85 | }
86 |
87 | builder.addMethod(methodBuilder.build());
88 | }
89 |
90 | @Override
91 | protected void addClassBuildMethod(TypeSpec.Builder builder, ExecutableElement e, String methodName) {
92 | TypeName returnType = ClassName.get(e.getReturnType());
93 | if (!returnType.equals(ClassName.get(mApiTarget))) {
94 | com.netease.libs.autoapi_process.Logger.e(mApiTarget.toString() + "." + methodName + " return type is not " + mApiTarget.toString());
95 | return;
96 | }
97 |
98 | mFactoryMethodCount ++;
99 |
100 | MethodSpec.Builder methodBuilder = MethodSpec
101 | .methodBuilder(methodName)
102 | .returns(mReturnType)
103 | .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT);
104 | if (e != null) {
105 | for (VariableElement param : e.getParameters()) {
106 | methodBuilder.addParameter(TypeName.get(param.asType()), param.getSimpleName().toString());
107 | }
108 | }
109 |
110 | builder.addMethod(methodBuilder.build());
111 |
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/generator/ApiGenerator.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process.generator;
2 |
3 | import com.netease.libs.autoapi_process.AutoApiClass;
4 | import com.netease.libs.autoapi_process.FileUtil;
5 | import com.squareup.javapoet.JavaFile;
6 | import com.squareup.javapoet.MethodSpec;
7 | import com.squareup.javapoet.TypeName;
8 | import com.squareup.javapoet.TypeSpec;
9 |
10 | import java.io.IOException;
11 |
12 | import javax.annotation.processing.Filer;
13 | import javax.lang.model.element.ExecutableElement;
14 | import javax.lang.model.element.Modifier;
15 | import javax.lang.model.element.VariableElement;
16 | import javax.lang.model.type.TypeMirror;
17 |
18 | import static com.squareup.javapoet.TypeSpec.interfaceBuilder;
19 | import static javax.lang.model.element.Modifier.PUBLIC;
20 |
21 | /**
22 | * Created by zyl06 on 2018/10/17.
23 | */
24 |
25 | public class ApiGenerator extends BaseApiClassGenerator {
26 |
27 | public ApiGenerator(AutoApiClass providerClass, String pkgName) {
28 | super(providerClass, pkgName);
29 | }
30 |
31 | @Override
32 | public String packageName() {
33 | return (mPkgName == null || mPkgName.isEmpty()) ?
34 | "com.netease.libs.auto_api" :
35 | mPkgName + ".auto_api";
36 | }
37 |
38 | @Override
39 | public String className() {
40 | return className(null, "Api");
41 | }
42 |
43 | @Override
44 | public TypeSpec generate() {
45 | TypeSpec.Builder builder = interfaceBuilder(className())
46 | .addSuperinterface(com.netease.libs.autoapi_process.generator.ApiBaseGenerator.getClassName())
47 | .addModifiers(PUBLIC);
48 | builder.addJavadoc(mApiTarget.getQualifiedName().toString() + "'s api Interface\n");
49 |
50 | generate(builder);
51 |
52 | return builder.build();
53 | }
54 |
55 | @Override
56 | public void writeTo(JavaFile javaFile, Filer filer) throws IOException {
57 | FileUtil.writeTo(javaFile);
58 | }
59 |
60 | @Override
61 | protected void addMethod(TypeSpec.Builder builder, ExecutableElement e, String methodName) {
62 | MethodSpec.Builder methodBuilder = MethodSpec
63 | .methodBuilder(methodName)
64 | .returns(tryConvertApiTypeName(e.getReturnType()));
65 | addTemplateTypes(methodBuilder, e.getReturnType());
66 |
67 | for (VariableElement param : e.getParameters()) {
68 | methodBuilder.addParameter(tryConvertApiTypeName(param),
69 | param.getSimpleName().toString());
70 | }
71 | for (TypeMirror throwType : e.getThrownTypes()) {
72 | methodBuilder.addException(TypeName.get(throwType));
73 | }
74 | methodBuilder.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT);
75 |
76 | builder.addMethod(methodBuilder.build());
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/generator/ApiRegisterGenerator.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process.generator;
2 |
3 | import com.netease.libs.autoapi.AutoApi;
4 | import com.netease.libs.autoapi_process.BaseClassGenerator;
5 | import com.squareup.javapoet.AnnotationSpec;
6 | import com.squareup.javapoet.ClassName;
7 | import com.squareup.javapoet.MethodSpec;
8 | import com.squareup.javapoet.TypeName;
9 | import com.squareup.javapoet.TypeSpec;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import javax.lang.model.element.Modifier;
15 |
16 | import static com.squareup.javapoet.TypeSpec.classBuilder;
17 | import static javax.lang.model.element.Modifier.PUBLIC;
18 |
19 | /**
20 | * Created by zyl06 on 2018/10/19.
21 | */
22 |
23 | public class ApiRegisterGenerator extends BaseClassGenerator {
24 |
25 | private String mPkgName;
26 | private List mStubFactoryGenerators = new ArrayList<>();
27 |
28 | public ApiRegisterGenerator(String pkgName,
29 | List stubFactoryGenerators) {
30 | super();
31 | mPkgName = pkgName;
32 | mStubFactoryGenerators = stubFactoryGenerators;
33 | }
34 |
35 | @Override
36 | public String packageName() {
37 | return mPkgName + ".auto_api";
38 | }
39 |
40 | @Override
41 | public String className() {
42 | return "ApiRegister";
43 | }
44 |
45 | @Override
46 | public TypeSpec generate() {
47 | TypeSpec.Builder builder = classBuilder(className())
48 | .addModifiers(PUBLIC)
49 | .addAnnotation(ClassName.get("org.aspectj.lang.annotation", "Aspect"));
50 | builder.addJavadoc("ApiService Register Class\n");
51 |
52 | MethodSpec.Builder initMethod = MethodSpec.methodBuilder("init")
53 | .addModifiers(Modifier.PUBLIC)
54 | .addParameter(ClassName.get("org.aspectj.lang", "JoinPoint"), "joinPoint")
55 | .addJavadoc("Collect & Register All StubFactories\n")
56 | .returns(TypeName.VOID);
57 |
58 | AnnotationSpec.Builder annoBuilder = AnnotationSpec.builder(ClassName.get("org.aspectj.lang.annotation", "After"));
59 | annoBuilder.addMember("value", "\"execution(void com.netease.libs.autoapi.AutoApi.init())\"");
60 | initMethod.addAnnotation(annoBuilder.build());
61 |
62 | for (StubFactoryGenerator subFactory : mStubFactoryGenerators) {
63 | ClassName stubFactoryType = ClassName.get(subFactory.packageName(), subFactory.className());
64 |
65 | initMethod.addStatement("$T.API_FACTORYS.put($S, new $T())", AutoApi.class,
66 | subFactory.mApiName, stubFactoryType);
67 | }
68 | builder.addMethod(initMethod.build());
69 |
70 | return builder.build();
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/generator/BaseApiClassGenerator.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process.generator;
2 |
3 | import com.netease.libs.autoapi.anno.AutoApiClassBuildMethodAnno;
4 | import com.netease.libs.autoapi.anno.AutoApiConstructAnno;
5 | import com.netease.libs.autoapi.anno.AutoApiMethodAnno;
6 | import com.netease.libs.autoapi_process.AutoApiClass;
7 | import com.netease.libs.autoapi_process.BaseClassGenerator;
8 | import com.squareup.javapoet.ClassName;
9 | import com.squareup.javapoet.MethodSpec;
10 | import com.squareup.javapoet.TypeName;
11 | import com.squareup.javapoet.TypeSpec;
12 | import com.squareup.javapoet.TypeVariableName;
13 | import com.sun.tools.javac.code.Symbol;
14 | import com.sun.tools.javac.code.Type;
15 |
16 | import java.util.HashSet;
17 | import java.util.LinkedList;
18 | import java.util.List;
19 | import java.util.Set;
20 |
21 | import javax.lang.model.element.Element;
22 | import javax.lang.model.element.ElementKind;
23 | import javax.lang.model.element.ExecutableElement;
24 | import javax.lang.model.element.TypeElement;
25 | import javax.lang.model.element.VariableElement;
26 | import javax.lang.model.type.DeclaredType;
27 | import javax.lang.model.type.TypeMirror;
28 | import javax.lang.model.type.TypeVariable;
29 |
30 | /**
31 | * Created by zyl06 on 2018/10/18.
32 | */
33 |
34 | public abstract class BaseApiClassGenerator extends BaseClassGenerator {
35 |
36 | protected AutoApiClass mProviderClass;
37 | protected TypeElement mApiTarget;
38 | protected String mPkgName;
39 | private Set mMethodSignatures = new HashSet<>();
40 |
41 | public BaseApiClassGenerator(AutoApiClass providerClass, String packageName) {
42 | super();
43 | mProviderClass = providerClass;
44 | mApiTarget = providerClass.clazz;
45 | mPkgName = packageName;
46 | }
47 |
48 | private boolean addSignature(ExecutableElement e) {
49 | StringBuilder sb = new StringBuilder(64);
50 | sb.append(e.getSimpleName()).append("_");
51 | for (VariableElement ve : e.getParameters()) {
52 | sb.append(ClassName.get(ve.asType()).toString())
53 | .append("_");
54 | }
55 | return mMethodSignatures.add(sb.toString());
56 | }
57 |
58 | protected void generate(TypeSpec.Builder builder) {
59 | for (Element e : mApiTarget.getEnclosedElements()) {
60 | if (!com.netease.libs.autoapi_process.ElementUtil.isPublic(e)) {
61 | continue;
62 | }
63 | if (e instanceof ExecutableElement) {
64 | AutoApiConstructAnno constructAnno = e.getAnnotation(AutoApiConstructAnno.class);
65 | if (constructAnno != null) {
66 | String methodName = !constructAnno.alias().isEmpty() ? constructAnno.alias() : "newInstance";
67 | addFactoryMethod(builder, (ExecutableElement) e, methodName);
68 | continue;
69 | }
70 |
71 | AutoApiClassBuildMethodAnno classBuildAnno = e.getAnnotation(AutoApiClassBuildMethodAnno.class);
72 | if (classBuildAnno != null) {
73 | if (com.netease.libs.autoapi_process.ElementUtil.isPublic(e) && com.netease.libs.autoapi_process.ElementUtil.isStatic(e)) {
74 | String methodName = !classBuildAnno.alias().isEmpty() ? constructAnno.alias() : e.getSimpleName().toString();
75 | addClassBuildMethod(builder, (ExecutableElement) e, methodName);
76 | }
77 | continue;
78 | }
79 |
80 | runExeElement(builder, (ExecutableElement) e);
81 | }
82 | }
83 |
84 | // 处理基类
85 | if (mProviderClass.includeSuperApi) {
86 | ClassName targetCn = ClassName.get(mApiTarget);
87 | TypeMirror tm = mApiTarget.getSuperclass();
88 |
89 | com.netease.libs.autoapi_process.Logger.w(targetCn + " superclass TypeMirror Class = " + tm.getClass());
90 |
91 | while (tm instanceof Type) {
92 | Symbol.TypeSymbol superElem = ((Type) tm).asElement();
93 | if (superElem == null) {
94 | com.netease.libs.autoapi_process.Logger.w(targetCn + " is interface.");
95 | break;
96 | }
97 |
98 | TypeName cn = ClassName.get(superElem.asType());
99 |
100 | com.netease.libs.autoapi_process.Logger.w(targetCn + " superclass = " + cn + "; super elem: " + superElem.getClass());
101 |
102 | if (cn.isPrimitive() || cn.equals(ClassName.OBJECT)) {
103 | break;
104 | }
105 |
106 | for (Element e : superElem.getEnclosedElements()) {
107 | if (com.netease.libs.autoapi_process.ElementUtil.isPublic(e) && e instanceof ExecutableElement) {
108 | com.netease.libs.autoapi_process.Logger.w(targetCn + " ExecutableElement=" + e);
109 |
110 | runExeElement(builder, (ExecutableElement) e);
111 | }
112 | }
113 |
114 | boolean finish = true;
115 | if (superElem instanceof Symbol.ClassSymbol) {
116 | tm = ((Symbol.ClassSymbol) superElem).getSuperclass();
117 | finish = (tm == null || ClassName.get(tm).equals(ClassName.OBJECT));
118 | }
119 | if (finish) {
120 | break;
121 | }
122 | }
123 |
124 | if (com.netease.libs.autoapi_process.ElementUtil.isInterface(mApiTarget)) {
125 | for (TypeMirror funcInter : mApiTarget.getInterfaces()) {
126 | com.netease.libs.autoapi_process.Logger.w("funcInter = " + funcInter);
127 | Element funcTypeElem = ((DeclaredType) funcInter).asElement();
128 |
129 | for (Element e : funcTypeElem.getEnclosedElements()) {
130 | if (e instanceof ExecutableElement && com.netease.libs.autoapi_process.ElementUtil.isPublic(e)) {
131 | runExeElement(builder, (ExecutableElement) e);
132 | }
133 | }
134 | }
135 | }
136 |
137 | }
138 | }
139 |
140 | private void runExeElement(TypeSpec.Builder builder, ExecutableElement e) {
141 | if (!addSignature(e)) {
142 | return;
143 | }
144 |
145 | AutoApiMethodAnno anno = e.getAnnotation(AutoApiMethodAnno.class);
146 | if (anno != null && !anno.provide()) {
147 | return;
148 | }
149 |
150 | if (e.getKind() == ElementKind.CONSTRUCTOR) {
151 | return;
152 | }
153 |
154 | boolean provide = (anno != null && anno.provide()) ||
155 | (mProviderClass.allPublicStaticApi && com.netease.libs.autoapi_process.ElementUtil.isStatic(e)) ||
156 | (mProviderClass.allPublicNormalApi && !com.netease.libs.autoapi_process.ElementUtil.isStatic(e));
157 | if (provide) {
158 | String methodName = anno != null && !anno.alias().isEmpty() ?
159 | anno.alias() : e.getSimpleName().toString();
160 | addMethod(builder, e, methodName);
161 | }
162 | }
163 |
164 | protected void addCustomFields(TypeSpec.Builder builder) {
165 |
166 | }
167 |
168 | protected void addMethod(TypeSpec.Builder builder, ExecutableElement e, String methodName) {
169 |
170 | }
171 |
172 | protected void addFactoryMethod(TypeSpec.Builder builder, ExecutableElement e, String methodName) {
173 |
174 | }
175 |
176 | protected void addClassBuildMethod(TypeSpec.Builder builder, ExecutableElement e, String methodName) {
177 |
178 | }
179 |
180 | protected String className(String providerNameSuffix, String anonymousSuffix) {
181 | if (mProviderClass.name != null && !mProviderClass.name.equals("")) {
182 | return providerNameSuffix != null ?
183 | mProviderClass.name + providerNameSuffix :
184 | mProviderClass.name;
185 | }
186 |
187 | List enclosingNames = new LinkedList<>();
188 | Element enclosingElem = mApiTarget.getEnclosingElement();
189 | while (enclosingElem instanceof TypeElement) {
190 | enclosingNames.add(0, enclosingElem.getSimpleName().toString());
191 | enclosingElem = enclosingElem.getEnclosingElement();
192 | }
193 |
194 | StringBuilder sb = new StringBuilder();
195 | for (String enclosingName : enclosingNames) {
196 | sb.append(enclosingName).append("_");
197 | }
198 | sb.append(mApiTarget.getSimpleName());
199 | if (anonymousSuffix != null) {
200 | sb.append(anonymousSuffix);
201 | }
202 |
203 | return sb.toString();
204 | }
205 |
206 | /**
207 | *
208 | * @param e 具体真实 Element
209 | * @return 返回 对应 Api 类 TypeName 或元素自身的 TypeName
210 | */
211 | public TypeName tryConvertApiTypeName(Element e) {
212 | TypeName apiTypeName = com.netease.libs.autoapi_process.ElementUtil.getApiServiceClassName(e);
213 | return apiTypeName != null ? apiTypeName : ClassName.get(e.asType());
214 | }
215 |
216 | /**
217 | *
218 | * @param type 真实类型
219 | * @return 返回 对应 Api 类 TypeName 或元素自身的 TypeName
220 | */
221 | public TypeName tryConvertApiTypeName(TypeMirror type) {
222 | TypeName apiTypeName = com.netease.libs.autoapi_process.ElementUtil.getApiServiceClassName(type);
223 | return apiTypeName != null ? apiTypeName : ClassName.get(type);
224 | }
225 |
226 | protected void addTemplateTypes(MethodSpec.Builder builder, TypeMirror returnType) {
227 | com.netease.libs.autoapi_process.Logger.w("return " + returnType + "; class " + returnType.getClass());
228 |
229 |
230 |
231 | if (returnType instanceof Type.TypeVar) {
232 | Type.TypeVar typeVar = (Type.TypeVar) returnType;
233 | builder.addTypeVariable(TypeVariableName.get(typeVar));
234 | } else if (returnType instanceof Type.ClassType) {
235 | Type.ClassType classType = (Type.ClassType) returnType;
236 | List types = classType.getTypeArguments();
237 | for (Type type : types) {
238 | if (type instanceof TypeVariable) {
239 | TypeVariable tv = (TypeVariable) type;
240 | builder.addTypeVariable(TypeVariableName.get(tv));
241 | }
242 | }
243 | }
244 | }
245 | }
246 |
--------------------------------------------------------------------------------
/module/autoapi_process/src/main/java/com/netease/libs/autoapi_process/generator/CallbackClassGenerator.java:
--------------------------------------------------------------------------------
1 | package com.netease.libs.autoapi_process.generator;
2 |
3 | import com.netease.libs.autoapi_process.AutoApiClass;
4 | import com.squareup.javapoet.ClassName;
5 | import com.squareup.javapoet.FieldSpec;
6 | import com.squareup.javapoet.MethodSpec;
7 | import com.squareup.javapoet.TypeName;
8 | import com.squareup.javapoet.TypeSpec;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import javax.lang.model.element.ExecutableElement;
14 | import javax.lang.model.element.Modifier;
15 | import javax.lang.model.element.VariableElement;
16 | import javax.lang.model.type.TypeMirror;
17 |
18 | import static com.squareup.javapoet.TypeSpec.classBuilder;
19 | import static javax.lang.model.element.Modifier.PUBLIC;
20 |
21 | /**
22 | * Created by zyl06 on 2018/11/5.
23 | * 针对 interface
24 | */
25 | public class CallbackClassGenerator extends BaseApiClassGenerator {
26 |
27 | private ClassName mApiClassName;
28 | private boolean mMakeTargetField = false;
29 | private static final String TARGET_FILED_NAME = "mTarget";
30 |
31 | public CallbackClassGenerator(AutoApiClass providerClass,
32 | ApiGenerator apiGen,
33 | String packageName) {
34 | super(providerClass, packageName);
35 | this.mApiClassName = ClassName.get(apiGen.packageName(), apiGen.className());
36 | }
37 |
38 | @Override
39 | public String packageName() {
40 | return (mPkgName == null || mPkgName.isEmpty()) ?
41 | "com.netease.libs.auto_api" :
42 | mPkgName + ".auto_api";
43 | }
44 |
45 | @Override
46 | public String className() {
47 | return className("Callback", "Callback");
48 | }
49 |
50 | @Override
51 | public TypeSpec generate() {
52 |
53 | TypeSpec.Builder builder = classBuilder(className())
54 | .addSuperinterface(TypeName.get(mApiTarget.asType()))
55 | .addModifiers(PUBLIC);
56 | builder.addJavadoc(mApiTarget.getQualifiedName().toString() + "'s Callback Class\n");
57 |
58 | generate(builder);
59 |
60 | addCustomFields(builder);
61 | addCustomMethods(builder);
62 |
63 | return builder.build();
64 | }
65 |
66 | protected void addCustomMethods(TypeSpec.Builder builder) {
67 | MethodSpec.Builder methodBuilder = MethodSpec
68 | .methodBuilder(com.netease.libs.autoapi_process.generator.ApiBaseGenerator.GET_TARGET_METHOD_NAME)
69 | .returns(TypeName.OBJECT)
70 | .addModifiers(Modifier.PUBLIC);
71 | methodBuilder.addStatement(mMakeTargetField ?
72 | "return " + TARGET_FILED_NAME :
73 | "return null");
74 | builder.addMethod(methodBuilder.build());
75 | }
76 |
77 | protected void addCustomFields(TypeSpec.Builder builder) {
78 | // 生成成员变量
79 | if (mMakeTargetField) {
80 | FieldSpec.Builder targetBuild = FieldSpec.builder(mApiClassName,
81 | TARGET_FILED_NAME, Modifier.PUBLIC);
82 | FieldSpec target = targetBuild.addJavadoc("Callback's original Object\n").build();
83 | builder.addField(target);
84 | }
85 | }
86 |
87 | @Override
88 | protected void addMethod(TypeSpec.Builder builder, ExecutableElement e, String methodName) {
89 | TypeName returnApiType = com.netease.libs.autoapi_process.ElementUtil.getApiServiceClassName(e.getReturnType());
90 |
91 | MethodSpec.Builder methodBuilder = MethodSpec
92 | .methodBuilder(methodName)
93 | .addModifiers(Modifier.PUBLIC)
94 | // 如果是自定义类型,需要修改成 api 类
95 | .returns(returnApiType != null ? returnApiType : ClassName.get(e.getReturnType()));
96 |
97 | for (TypeMirror throwType : e.getThrownTypes()) {
98 | methodBuilder.addException(TypeName.get(throwType));
99 | }
100 |
101 | StringBuilder sb = new StringBuilder(32);
102 | if (e.getReturnType() != null && TypeName.get(e.getReturnType()) != TypeName.VOID) {
103 | if (returnApiType != null) {
104 | TypeName returnStubType = com.netease.libs.autoapi_process.ElementUtil.getStubServiceClassName(e.getReturnType());
105 | methodBuilder.addStatement("$T stub = new $T()", returnStubType, returnStubType);
106 | sb.append(String.format("stub.%s = ", TARGET_FILED_NAME));
107 | } else {
108 | sb.append("return ");
109 | }
110 | }
111 | if (com.netease.libs.autoapi_process.ElementUtil.isStatic(e)) { // 静态方法
112 | sb.append("$T.")
113 | .append(e.getSimpleName().toString())
114 | .append("(");
115 | } else { // 非静态方法
116 | mMakeTargetField = true;
117 |
118 | sb.append(TARGET_FILED_NAME).append(".")
119 | .append(e.getSimpleName().toString())
120 | .append("(");
121 | }
122 |
123 | List