remove addition
This commit is contained in:
@@ -2,7 +2,7 @@ apply from: "./gradleScript/config.gradle"
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.50'
|
||||
ext.component_version = '1.0.3-beta'
|
||||
ext.component_version = '1.0.4-beta'
|
||||
|
||||
repositories {
|
||||
google()
|
||||
@@ -10,10 +10,10 @@ buildscript {
|
||||
maven { url 'https://dl.bintray.com/yummylau/maven' }
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.effective.plugins:component:$component_version"
|
||||
// classpath "com.effective.plugins:component:$component_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
//调试需要
|
||||
// classpath "com.effective.plugins:component-plugin"
|
||||
classpath "com.effective.plugins:component-plugin"
|
||||
|
||||
//发布需要
|
||||
// classpath 'com.novoda:bintray-release:0.9.1'
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.plugin.component.support;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MethodCostHelper {
|
||||
|
||||
public static Map<String, Long> sStartTime = new HashMap<>();
|
||||
public static Map<String, Long> sEndTime = new HashMap<>();
|
||||
|
||||
public static void start(String methodName, long startTime) {
|
||||
sStartTime.put(methodName, startTime);
|
||||
}
|
||||
|
||||
public static void end(String methodName, long endTime) {
|
||||
sEndTime.put(methodName, endTime);
|
||||
}
|
||||
|
||||
public static String cost(String methodName) {
|
||||
long start = sStartTime.get(methodName);
|
||||
long end = sEndTime.get(methodName);
|
||||
return "[" + methodName + "] cost " + (end - start) + " ms";
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.plugin.component.anno;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
public @interface MethodCost {
|
||||
}
|
||||
@@ -4,7 +4,7 @@ apply plugin: 'maven'
|
||||
|
||||
group = 'com.effective.plugins'
|
||||
archivesBaseName = 'component'
|
||||
version = '1.0.3-beta'
|
||||
version = '1.0.4-beta'
|
||||
|
||||
//设置本地发布路径
|
||||
uploadArchives {
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.plugin.component.extension.option.debug.DebugDependenciesOption
|
||||
import com.plugin.component.extension.option.publication.PublicationDependenciesOption
|
||||
import com.plugin.component.extension.option.publication.PublicationOption
|
||||
import com.plugin.component.transform.InjectCodeTransform
|
||||
import com.plugin.component.transform.MethodCostTransform
|
||||
|
||||
import com.plugin.component.transform.ScanCodeTransform
|
||||
import com.plugin.component.utils.JarUtil
|
||||
import com.plugin.component.utils.ProjectUtil
|
||||
@@ -232,10 +232,6 @@ class ComponentPlugin implements Plugin<Project> {
|
||||
Logger.buildOutput("registerTransform", "InjectCodeTransform")
|
||||
childProject.extensions.findByType(BaseExtension.class).registerTransform(new ScanCodeTransform(childProject))
|
||||
childProject.extensions.findByType(BaseExtension.class).registerTransform(new InjectCodeTransform(childProject))
|
||||
if (Runtimes.enbaleMethodCost()) {
|
||||
Logger.buildOutput("registerTransform", "MethodCostTransform")
|
||||
childProject.extensions.findByType(BaseExtension.class).registerTransform(new MethodCostTransform(project))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.plugin.component
|
||||
import com.plugin.component.extension.ComponentExtension
|
||||
import com.plugin.component.extension.module.ProjectInfo
|
||||
import com.plugin.component.extension.option.CompileOptions
|
||||
import com.plugin.component.extension.option.addition.AdditionOption
|
||||
import com.plugin.component.extension.option.debug.DebugConfiguration
|
||||
import com.plugin.component.extension.option.publication.PublicationOption
|
||||
import com.plugin.component.extension.option.debug.DebugOption
|
||||
@@ -26,7 +25,6 @@ class Runtimes {
|
||||
public static String sAndroidJarPath
|
||||
public static String sMainModuleName
|
||||
public static CompileOptions sCompileOption
|
||||
private static AdditionOption sAdditionOption
|
||||
public static DebugOption sDebugOption
|
||||
public static int sCompileSdkVersion
|
||||
public static Set<String> sValidComponents
|
||||
@@ -36,7 +34,6 @@ class Runtimes {
|
||||
sAndroidJarPath = ProjectUtil.getAndroidJarPath(root, componentExtension.compileSdkVersion)
|
||||
sMainModuleName = componentExtension.mainModuleName
|
||||
sCompileSdkVersion = componentExtension.compileSdkVersion
|
||||
sAdditionOption = componentExtension.additionOption
|
||||
sCompileOption = componentExtension.compileOption
|
||||
sDebugOption = componentExtension.debugOption
|
||||
Set<String> includeModules = ProjectUtil.getModuleName(componentExtension.includes)
|
||||
@@ -55,7 +52,6 @@ class Runtimes {
|
||||
Logger.buildOutput("Select module by " + (includeModel ? "include" : "exclude"))
|
||||
Logger.buildOutput("生效模块", sValidComponents.toList().toString())
|
||||
Logger.buildOutput("调试信息", sDebugOption.toString())
|
||||
Logger.buildOutput("扩展信息", sAdditionOption.toString())
|
||||
}
|
||||
|
||||
static boolean shouldApplyComponentPlugin(Project project) {
|
||||
@@ -81,10 +77,6 @@ class Runtimes {
|
||||
return sDebugOption.configurationList
|
||||
}
|
||||
|
||||
static boolean enbaleMethodCost() {
|
||||
return sAdditionOption != null && sAdditionOption.methodCostOption.enable
|
||||
}
|
||||
|
||||
static void addImplPublication(String projectName, PublicationOption publicationOption) {
|
||||
sImplPublicationMap.put(projectName, publicationOption)
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.plugin.component.anno;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 方法耗时
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
public @interface MethodCost {
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.plugin.component.extension
|
||||
import com.plugin.component.Logger
|
||||
import com.plugin.component.Runtimes
|
||||
import com.plugin.component.extension.option.CompileOptions
|
||||
import com.plugin.component.extension.option.addition.AdditionOption
|
||||
import com.plugin.component.extension.option.publication.PublicationOption
|
||||
import com.plugin.component.extension.option.debug.DebugOption
|
||||
import com.plugin.component.utils.ProjectUtil
|
||||
@@ -24,7 +23,6 @@ class ComponentExtension {
|
||||
int compileSdkVersion //编译版本
|
||||
CompileOptions compileOption //编译选项
|
||||
DebugOption debugOption //调试选项
|
||||
AdditionOption additionOption //扩展选项
|
||||
Action<? super RepositoryHandler> configure //仓库配置
|
||||
String includes = ""
|
||||
String excludes = ""
|
||||
@@ -34,7 +32,6 @@ class ComponentExtension {
|
||||
this.project = project
|
||||
compileOption = new CompileOptions()
|
||||
debugOption = new DebugOption(project)
|
||||
additionOption = new AdditionOption()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,13 +140,4 @@ class ComponentExtension {
|
||||
void debug(Closure closure) {
|
||||
ConfigureUtil.configure(closure, debugOption)
|
||||
}
|
||||
|
||||
/**
|
||||
* 调试模块
|
||||
* @param closure
|
||||
*/
|
||||
void addition(Closure closure) {
|
||||
ConfigureUtil.configure(closure, additionOption)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.plugin.component.extension.option.addition
|
||||
|
||||
import org.gradle.util.ConfigureUtil
|
||||
|
||||
/**
|
||||
* 扩展模块选项
|
||||
*/
|
||||
class AdditionOption {
|
||||
|
||||
MethodCostOption methodCostOption = new MethodCostOption()
|
||||
|
||||
/**
|
||||
* 配置方法耗时
|
||||
* @param closure
|
||||
*/
|
||||
void methodCost(Closure closure) {
|
||||
ConfigureUtil.configure(closure, methodCostOption)
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AdditionOption{" + '\n' +
|
||||
" methodCostOption = " + methodCostOption + '\n' +
|
||||
' }';
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.plugin.component.extension.option.addition
|
||||
|
||||
|
||||
/**
|
||||
* 方法耗时选项
|
||||
*/
|
||||
class MethodCostOption {
|
||||
|
||||
boolean enable = false
|
||||
|
||||
void enable(boolean open) {
|
||||
this.enable = open
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MethodCostOption{ " +
|
||||
"enable=" + enable +
|
||||
' }';
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package com.plugin.component.transform
|
||||
|
||||
import com.plugin.component.Logger
|
||||
import com.plugin.component.anno.MethodCost
|
||||
import org.objectweb.asm.*
|
||||
import org.objectweb.asm.commons.AdviceAdapter
|
||||
|
||||
class MethodCostAdapter extends ClassVisitor {
|
||||
|
||||
private static final String sCostCachePath = "com/plugin/component/MethodCostHelper"
|
||||
private String className
|
||||
|
||||
MethodCostAdapter(ClassVisitor classVisitor) {
|
||||
super(Opcodes.ASM7, classVisitor)
|
||||
}
|
||||
|
||||
@Override
|
||||
void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
className = name
|
||||
super.visit(version, access, name, signature, superName, interfaces)
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
MethodVisitor visitMethod(int access, String name, String methodDescriptor, String signature, String[] exceptions) {
|
||||
MethodVisitor mv = super.visitMethod(access, name, methodDescriptor, signature, exceptions)
|
||||
mv = new AdviceAdapter(Opcodes.ASM7, mv, access, name, methodDescriptor) {
|
||||
|
||||
private boolean injectMethodCostCode = false
|
||||
private String methodName
|
||||
private String methodNameDescriptor
|
||||
|
||||
@Override
|
||||
AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||
injectMethodCostCode = Type.getDescriptor(MethodCost.class) == descriptor
|
||||
methodName = className + "#" + name
|
||||
methodNameDescriptor = methodName + "(" + methodDescriptor + ")"
|
||||
return super.visitAnnotation(descriptor, visible)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMethodEnter() {
|
||||
if (injectMethodCostCode) {
|
||||
mv.visitLdcInsn(methodName)
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false)
|
||||
mv.visitMethodInsn(INVOKESTATIC, sCostCachePath, "start",
|
||||
"(Ljava/lang/String;J)V", false)
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMethodExit(int opcode) {
|
||||
if (injectMethodCostCode) {
|
||||
mv.visitLdcInsn(methodName)
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false)
|
||||
mv.visitMethodInsn(INVOKESTATIC, sCostCachePath, "end",
|
||||
"(Ljava/lang/String;J)V", false)
|
||||
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;")
|
||||
mv.visitLdcInsn(methodName)
|
||||
mv.visitMethodInsn(INVOKESTATIC, sCostCachePath, "cost",
|
||||
"(Ljava/lang/String;)Ljava/lang/String;", false)
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println",
|
||||
"(Ljava/lang/String;)V", false)
|
||||
Logger.buildOutput("methodCost(" + methodNameDescriptor + ")")
|
||||
}
|
||||
}
|
||||
}
|
||||
return mv
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.plugin.component.transform
|
||||
|
||||
import com.android.build.api.transform.Context
|
||||
import com.android.build.api.transform.TransformException
|
||||
import com.android.build.api.transform.TransformInput
|
||||
import com.android.build.api.transform.TransformOutputProvider
|
||||
import com.plugin.component.Logger
|
||||
import com.quinn.hunter.transform.HunterTransform
|
||||
import com.quinn.hunter.transform.RunVariant
|
||||
import org.gradle.api.Project
|
||||
|
||||
class MethodCostTransform extends HunterTransform {
|
||||
|
||||
MethodCostTransform(Project project) {
|
||||
super(project)
|
||||
this.bytecodeWeaver = new MethodCostWeaver()
|
||||
}
|
||||
|
||||
@Override
|
||||
void transform(Context context, Collection<TransformInput> inputs, Collection<TransformInput> referencedInputs, TransformOutputProvider outputProvider, boolean isIncremental) throws IOException, TransformException, InterruptedException {
|
||||
long startTime = System.currentTimeMillis()
|
||||
super.transform(context, inputs, referencedInputs, outputProvider, isIncremental)
|
||||
Logger.buildOutput("MethodCostTransform cost : " + (System.currentTimeMillis() - startTime) + "ms")
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RunVariant getRunVariant() {
|
||||
return super.getRunVariant()
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean inDuplcatedClassSafeMode() {
|
||||
return super.inDuplcatedClassSafeMode()
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.plugin.component.transform
|
||||
|
||||
import com.quinn.hunter.transform.asm.BaseWeaver
|
||||
import org.objectweb.asm.ClassVisitor
|
||||
import org.objectweb.asm.ClassWriter
|
||||
|
||||
class MethodCostWeaver extends BaseWeaver {
|
||||
|
||||
@Override
|
||||
protected ClassVisitor wrapClassWriter(ClassWriter classWriter) {
|
||||
return new MethodCostAdapter(classWriter)
|
||||
}
|
||||
}
|
||||
@@ -94,16 +94,6 @@ component {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
addition {
|
||||
|
||||
methodCost {
|
||||
enable false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
//发布调试 core
|
||||
//include ':component-core'
|
||||
include ':component-core'
|
||||
//
|
||||
//发布插件
|
||||
//include ':component-plugin'
|
||||
|
||||
//调试插件
|
||||
//includeBuild './component-plugin'
|
||||
////
|
||||
includeBuild './component-plugin'
|
||||
|
||||
include ':app'
|
||||
include ':debugModule'
|
||||
include ':library', ':libraryKotlin', ':libraryWithoutPlugin'
|
||||
|
||||
Reference in New Issue
Block a user