forked from alibaba/ARouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add deploy shell and rename plugin name.
- Loading branch information
Showing
15 changed files
with
161 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
arouter-auto-register/src/main/groovy/com/billy/android/register/RouterRegisterPlugin.groovy
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...auto-register/src/main/resources/META-INF/gradle-plugins/arouter-auto-register.properties
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apply plugin: 'groovy' | ||
|
||
ext { | ||
bintrayName = 'arouter-register' | ||
artifact = bintrayName | ||
libraryName = 'ARouter register gradle plugin' | ||
libraryDescription = 'A gradle plugin used for arouter route map register' | ||
libraryVersion = arouter_register_version | ||
} | ||
|
||
dependencies { | ||
compile gradleApi() | ||
compile localGroovy() | ||
} | ||
|
||
dependencies { | ||
compile 'com.android.tools.build:gradle:2.1.3' | ||
} | ||
|
||
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' | ||
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.billy.android.register | ||
package com.alibaba.android.arouter.register.core | ||
|
||
import com.alibaba.android.arouter.register.utils.Logger | ||
import com.alibaba.android.arouter.register.utils.ScanSetting | ||
import org.apache.commons.io.IOUtils | ||
import org.objectweb.asm.* | ||
|
||
|
@@ -11,17 +13,17 @@ import java.util.zip.ZipEntry | |
* generate register code into LogisticsCenter.class | ||
* @author billy.qi email: [email protected] | ||
*/ | ||
class RouterRegisterCodeGenerator { | ||
RouterRegisterSetting extension | ||
class RegisterCodeGenerator { | ||
ScanSetting extension | ||
|
||
private RouterRegisterCodeGenerator(RouterRegisterSetting extension) { | ||
private RegisterCodeGenerator(ScanSetting extension) { | ||
this.extension = extension | ||
} | ||
|
||
static void insertInitCodeTo(RouterRegisterSetting registerSetting) { | ||
static void insertInitCodeTo(ScanSetting registerSetting) { | ||
if (registerSetting != null && !registerSetting.classList.isEmpty()) { | ||
RouterRegisterCodeGenerator processor = new RouterRegisterCodeGenerator(registerSetting) | ||
File file = RouterRegisterTransform.fileContainsInitClass | ||
RegisterCodeGenerator processor = new RegisterCodeGenerator(registerSetting) | ||
File file = RegisterTransform.fileContainsInitClass | ||
if (file.getName().endsWith('.jar')) | ||
processor.insertInitCodeIntoJarFile(file) | ||
} | ||
|
@@ -47,8 +49,10 @@ class RouterRegisterCodeGenerator { | |
ZipEntry zipEntry = new ZipEntry(entryName) | ||
InputStream inputStream = file.getInputStream(jarEntry) | ||
jarOutputStream.putNextEntry(zipEntry) | ||
if (RouterRegisterSetting.GENERATE_TO_CLASS_FILE_NAME == entryName) { | ||
println('codeInsertToClassName:' + entryName) | ||
if (ScanSetting.GENERATE_TO_CLASS_FILE_NAME == entryName) { | ||
|
||
Logger.i('Insert init code to class >> ' + entryName) | ||
|
||
def bytes = referHackWhenInit(inputStream) | ||
jarOutputStream.write(bytes) | ||
} else { | ||
|
@@ -92,16 +96,16 @@ class RouterRegisterCodeGenerator { | |
String signature, String[] exceptions) { | ||
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions) | ||
//generate code into this method | ||
if (name == RouterRegisterSetting.GENERATE_TO_METHOD_NAME) { | ||
mv = new MyMethodVisitor(Opcodes.ASM5, mv) | ||
if (name == ScanSetting.GENERATE_TO_METHOD_NAME) { | ||
mv = new RouteMethodVisitor(Opcodes.ASM5, mv) | ||
} | ||
return mv | ||
} | ||
} | ||
|
||
class MyMethodVisitor extends MethodVisitor { | ||
class RouteMethodVisitor extends MethodVisitor { | ||
|
||
MyMethodVisitor(int api, MethodVisitor mv) { | ||
RouteMethodVisitor(int api, MethodVisitor mv) { | ||
super(api, mv) | ||
} | ||
|
||
|
@@ -116,7 +120,7 @@ class RouterRegisterCodeGenerator { | |
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, name, "<init>", "()V", false) | ||
// generate invoke register method into LogisticsCenter.loadRouterMap() | ||
mv.visitMethodInsn(Opcodes.INVOKESTATIC | ||
, RouterRegisterSetting.GENERATE_TO_CLASS_NAME | ||
, ScanSetting.GENERATE_TO_CLASS_NAME | ||
, extension.registerMethodName | ||
, "(L${extension.interfaceName};)V" | ||
, false) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package com.billy.android.register | ||
package com.alibaba.android.arouter.register.core | ||
|
||
import com.alibaba.android.arouter.register.utils.Logger | ||
import com.alibaba.android.arouter.register.utils.ScanSetting | ||
import com.alibaba.android.arouter.register.utils.ScanUtil | ||
import com.android.build.api.transform.* | ||
import com.android.build.gradle.internal.pipeline.TransformManager | ||
import org.apache.commons.codec.digest.DigestUtils | ||
|
@@ -10,17 +13,17 @@ import org.gradle.api.Project | |
* transform api | ||
* <p> | ||
* 1. Scan all classes to find which classes implement the specified interface | ||
* 2. Generate register code into class file: {@link RouterRegisterSetting#GENERATE_TO_CLASS_FILE_NAME} | ||
* 2. Generate register code into class file: {@link ScanSetting#GENERATE_TO_CLASS_FILE_NAME} | ||
* @author billy.qi email: [email protected] | ||
* @since 17/3/21 11:48 | ||
*/ | ||
class RouterRegisterTransform extends Transform { | ||
class RegisterTransform extends Transform { | ||
|
||
Project project | ||
static ArrayList<RouterRegisterSetting> registerList | ||
static ArrayList<ScanSetting> registerList | ||
static File fileContainsInitClass; | ||
|
||
RouterRegisterTransform(Project project) { | ||
RegisterTransform(Project project) { | ||
this.project = project | ||
} | ||
|
||
|
@@ -30,7 +33,7 @@ class RouterRegisterTransform extends Transform { | |
*/ | ||
@Override | ||
String getName() { | ||
return "arouter-auto-register" | ||
return ScanSetting.PLUGIN_NAME | ||
} | ||
|
||
@Override | ||
|
@@ -58,8 +61,11 @@ class RouterRegisterTransform extends Transform { | |
, Collection<TransformInput> referencedInputs | ||
, TransformOutputProvider outputProvider | ||
, boolean isIncremental) throws IOException, TransformException, InterruptedException { | ||
println("\n\n============================ start arouter-auto-register ============================\n") | ||
long time = System.currentTimeMillis() | ||
|
||
Logger.i('Start scan register info in jar file.') | ||
|
||
long startTime = System.currentTimeMillis() | ||
|
||
inputs.each { TransformInput input -> | ||
|
||
// scan all jars | ||
|
@@ -76,8 +82,8 @@ class RouterRegisterTransform extends Transform { | |
File dest = outputProvider.getContentLocation(destName + "_" + hexName, jarInput.contentTypes, jarInput.scopes, Format.JAR) | ||
|
||
//scan jar file to find classes | ||
if (RouterScanUtil.shouldProcessPreDexJar(src.absolutePath)) { | ||
RouterScanUtil.scanJar(src, dest) | ||
if (ScanUtil.shouldProcessPreDexJar(src.absolutePath)) { | ||
ScanUtil.scanJar(src, dest) | ||
} | ||
FileUtils.copyFile(src, dest) | ||
|
||
|
@@ -90,35 +96,33 @@ class RouterRegisterTransform extends Transform { | |
root += File.separator | ||
directoryInput.file.eachFileRecurse { File file -> | ||
def path = file.absolutePath.replace(root, '') | ||
if(file.isFile() && RouterScanUtil.shouldProcessClass(path)){ | ||
RouterScanUtil.scanClass(file) | ||
if(file.isFile() && ScanUtil.shouldProcessClass(path)){ | ||
ScanUtil.scanClass(file) | ||
} | ||
} | ||
|
||
// copy to dest | ||
FileUtils.copyDirectory(directoryInput.file, dest) | ||
} | ||
} | ||
def scanFinishTime = System.currentTimeMillis() | ||
println(">>>>>> register scan all class cost time: " + (scanFinishTime - time) + " ms") | ||
|
||
Logger.i('Scan finish, current cost time ' + (System.currentTimeMillis() - startTime) + "ms") | ||
|
||
if (fileContainsInitClass) { | ||
registerList.each { ext -> | ||
println("\ninsert register code to file:" + fileContainsInitClass.absolutePath) | ||
Logger.i('Insert register code to file ' + fileContainsInitClass.absolutePath) | ||
|
||
if (ext.classList.isEmpty()) { | ||
project.logger.error("No class implements found for interface:" + ext.interfaceName) | ||
Logger.e("No class implements found for interface:" + ext.interfaceName) | ||
} else { | ||
ext.classList.each { | ||
println(it) | ||
Logger.i(it) | ||
} | ||
RouterRegisterCodeGenerator.insertInitCodeTo(ext) | ||
RegisterCodeGenerator.insertInitCodeTo(ext) | ||
} | ||
} | ||
} | ||
def finishTime = System.currentTimeMillis() | ||
println("\n>>>>>> register insert code cost time: " + (finishTime - scanFinishTime) + " ms") | ||
println(">>>>>> register cost time: " + (finishTime - time) + " ms") | ||
println("\n============================ finish arouter-auto-register ============================\n\n") | ||
} | ||
|
||
Logger.i("Generate code finish, current cost time: " + (System.currentTimeMillis() - startTime) + "ms") | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...-register/src/main/groovy/com/alibaba/android/arouter/register/launch/PluginLaunch.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.alibaba.android.arouter.register.launch | ||
|
||
import com.alibaba.android.arouter.register.utils.Logger | ||
import com.android.build.gradle.AppExtension | ||
import com.android.build.gradle.AppPlugin | ||
import com.alibaba.android.arouter.register.utils.ScanSetting | ||
import com.alibaba.android.arouter.register.core.RegisterTransform | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
/** | ||
* Simple version of AutoRegister plugin for ARouter | ||
* @author billy.qi email: [email protected] | ||
* @since 17/12/06 15:35 | ||
*/ | ||
public class PluginLaunch implements Plugin<Project> { | ||
|
||
@Override | ||
public void apply(Project project) { | ||
def isApp = project.plugins.hasPlugin(AppPlugin) | ||
//only application module needs this plugin to generate register code | ||
if (isApp) { | ||
Logger.make(project) | ||
|
||
Logger.i('project(' + project.name + ') apply arouter-register plugin') | ||
|
||
def android = project.extensions.getByType(AppExtension) | ||
def transformImpl = new RegisterTransform(project) | ||
|
||
//init arouter-auto-register settings | ||
ArrayList<ScanSetting> list = new ArrayList<>(3) | ||
list.add(new ScanSetting('IRouteRoot', 'registerRouteRoot')) | ||
list.add(new ScanSetting('IInterceptorGroup', 'registerInterceptor')) | ||
list.add(new ScanSetting('IProviderGroup', 'registerProvider')) | ||
RegisterTransform.registerList = list | ||
//register this plugin | ||
android.registerTransform(transformImpl) | ||
} | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
arouter-register/src/main/groovy/com/alibaba/android/arouter/register/utils/Logger.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.alibaba.android.arouter.register.utils | ||
|
||
import org.gradle.api.Project | ||
|
||
/** | ||
* Format log | ||
* | ||
* @author zhilong <a href="mailto:[email protected]">Contact me.</a> | ||
* @version 1.0 | ||
* @since 2017/12/18 下午2:43 | ||
*/ | ||
class Logger { | ||
static org.gradle.api.logging.Logger logger | ||
|
||
static void make(Project project) { | ||
logger = project.getLogger() | ||
} | ||
|
||
static void i(String info) { | ||
if (null != info && null != logger) { | ||
logger.info("ARouter::Register >>> " + info) | ||
} | ||
} | ||
|
||
static void e(String error) { | ||
if (null != error && null != logger) { | ||
logger.error("ARouter::Register >>> " + error) | ||
} | ||
} | ||
|
||
static void w(String warning) { | ||
if (null != warning && null != logger) { | ||
logger.warn("ARouter::Register >>> " + warning) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package com.billy.android.register | ||
package com.alibaba.android.arouter.register.utils | ||
/** | ||
* register setting | ||
* @author billy.qi email: [email protected] | ||
* @since 17/3/28 11:48 | ||
*/ | ||
class RouterRegisterSetting { | ||
class ScanSetting { | ||
static final String PLUGIN_NAME = "com.alibaba.arouter" | ||
/** | ||
* The register code is generated into this class | ||
*/ | ||
|
@@ -50,7 +51,7 @@ class RouterRegisterSetting { | |
* @param interfaceName interface to scan | ||
* @param registerMethod method to generate code into | ||
*/ | ||
RouterRegisterSetting(String interfaceName, String registerMethod){ | ||
ScanSetting(String interfaceName, String registerMethod){ | ||
this.interfaceName = INTERFACE_PACKAGE_NAME + interfaceName | ||
this.registerMethodName = registerMethod | ||
} | ||
|
Oops, something went wrong.