Skip to content

Commit

Permalink
Merge pull request #175 from Meituan-Dianping/bugfix/AddMethod
Browse files Browse the repository at this point in the history
fix bugs when add method in patch without using ProGuard
  • Loading branch information
mivanzhang authored Jul 20, 2017
2 parents 79e995b + a3d466e commit 88ab62e
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 31 deletions.
8 changes: 4 additions & 4 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/Meituan-Dianping/Robust/master/LICENSE)


新一代热更新系统Robust,对Android版本无差别兼容。无需发版就可以做到随时修改线上bug,快速对重大线上问题作出反应,补丁修补成功率高达99.9%。
新一代热更新系统Robust,对Android版本无差别兼容。无需发版就可以做到随时修改线上bug,快速对重大线上问题0.4.7作出反应,补丁修补成功率高达99.9%。

[English Introduction](README.md)

Expand All @@ -28,7 +28,7 @@
apply plugin: 'robust'
compile 'com.meituan.robust:robust:0.4.5'
compile 'com.meituan.robust:robust:0.4.7'
```
2. 在整个项目的build.gradle加入classpath
Expand All @@ -39,8 +39,8 @@
jcenter()
}
dependencies {
classpath 'com.meituan.robust:gradle-plugin:0.4.5'
classpath 'com.meituan.robust:auto-patch-plugin:0.4.5'
classpath 'com.meituan.robust:gradle-plugin:0.4.7'
classpath 'com.meituan.robust:auto-patch-plugin:0.4.7'
}
}
```
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Robust is an Android HotFix solution with high compatibility and high stability.
//please uncomment fellow line before you build a patch
//apply plugin: 'auto-patch-plugin'
apply plugin: 'robust'
compile 'com.meituan.robust:robust:0.4.5'
compile 'com.meituan.robust:robust:0.4.7'
```
2. Add below codes in the outest project's build.gradle file.

Expand All @@ -36,8 +36,8 @@ Robust is an Android HotFix solution with high compatibility and high stability.
jcenter()
}
dependencies {
classpath 'com.meituan.robust:gradle-plugin:0.4.5'
classpath 'com.meituan.robust:auto-patch-plugin:0.4.5'
classpath 'com.meituan.robust:gradle-plugin:0.4.7'
classpath 'com.meituan.robust:auto-patch-plugin:0.4.7'
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InlineClassFactory {
Set newlyAddedClassInlineSet = getAllInlineClasses(usedClass, null);
usedClass.addAll(newlyAddedClassInlineSet);
usedClass.addAll(Config.modifiedClassNameList)
Set inLineClassNameSet = getAllInlineClasses(usedClass, Config.patchMethodSignureSet);
Set inLineClassNameSet = getAllInlineClasses(usedClass, Config.patchMethodSignatureSet);
inLineClassNameSet.removeAll(newlyAddedClassInlineSet)
inLineClassNameSet.addAll(classInLineMethodsMap.keySet())
//all inline patch class
Expand Down Expand Up @@ -117,7 +117,7 @@ class InlineClassFactory {
//找出modifiedclass中所有内联的类
allPatchMethodSignureSet.addAll(classInLineMethodsMap.getOrDefault(fullClassName, new ArrayList()))
if (isNewClass||allPatchMethodSignureSet.contains(method.longName)) {
isNewClass=false;
// isNewClass=false;
method.instrument(new ExprEditor() {
@Override
void edit(MethodCall m) throws CannotCompileException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,25 @@ class PatchesFactory {
* @param modifiedClass
* @param isInline
* @param patchName
* @param patchMethodSignureSet methods need patch,if patchMethodSignureSet length is 0,then will patch all methods in modifiedClass
* @param patchMethodSignureSet methods need patch,if patchMethodSignatureSet length is 0,then will patch all methods in modifiedClass
* @return
*/
private CtClass createPatchClass(CtClass modifiedClass, boolean isInline, String patchName, Set patchMethodSignureSet, String patchPath) throws CannotCompileException, IOException, NotFoundException {
List methodNoNeedPatchList = new ArrayList();
//just keep methods need patch
if (patchMethodSignureSet.size() != 0) {
for (CtMethod method : modifiedClass.getDeclaredMethods()) {
if ((!patchMethodSignureSet.contains(method.getLongName()) || (!isInline && Config.methodMap.get(modifiedClass.getName() + "." + JavaUtils.getJavaMethodSignure(method)) == null))) {
//新增方法需要保留在补丁类中
if(!Config.supportProGuard&&Config.newlyAddedMethodSet.contains(method.longName)){
continue;
}
//不是被补丁的方法
if ((!patchMethodSignureSet.contains(method.getLongName()) ||
//不是内联并且是新增的方法
(!isInline && Config.methodMap.get(modifiedClass.getName() + "." + JavaUtils.getJavaMethodSignure(method)) == null))) {
methodNoNeedPatchList.add(method);
} else {
//移除methodNeedPatchSet中需要补丁的方法,留在补丁类中的方法默认全部会被处理
Config.methodNeedPatchSet.remove(method.getLongName());
}
}
Expand All @@ -65,8 +73,8 @@ class PatchesFactory {

for (CtMethod method : temPatchClass.getDeclaredMethods()) {
// shit !!too many situations need take into consideration
// methods has methodid and in patchMethodSignureSet
if (!Config.addedSuperMethodList.contains(method) && !reaLParameterMethod.equals(method) && !method.getName().startsWith(Constants.ROBUST_PUBLIC_SUFFIX)) {
// methods has methodid and in patchMethodSignatureSet
if (!Config.addedSuperMethodList.contains(method) && reaLParameterMethod != method && !method.getName().startsWith(Constants.ROBUST_PUBLIC_SUFFIX)) {
method.instrument(
new ExprEditor() {
public void edit(FieldAccess f) throws CannotCompileException {
Expand Down Expand Up @@ -283,7 +291,7 @@ class PatchesFactory {
* @param modifiedClass
* @param isInline
* @param patchName
* @param patchMethodSignureSet methods need patch,if patchMethodSignureSet length is 0,then will patch all methods in modifiedClass
* @param patchMethodSignureSet methods need patch,if patchMethodSignatureSet length is 0,then will patch all methods in modifiedClass
* @return
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class ReadAnnotation {
JavaUtils.printList(Config.newlyAddedMethodSet.toList())
println("new add classes list is ")
JavaUtils.printList(Config.newlyAddedClassNameList)
println(" patchMethodSignureSet is printed below ")
println(" patchMethodSignatureSet is printed below ")
JavaUtils.printList(patchMethodSignureSet.asList())
Config.patchMethodSignureSet.addAll(patchMethodSignureSet);
Config.patchMethodSignatureSet.addAll(patchMethodSignureSet);
}

public static boolean scanClassForAddClassAnnotation(CtClass ctclass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ class ReadXML {
robust = new XmlSlurper().parse(new File("${path}${File.separator}${Constants.ROBUST_XML}"))

//读取配置的补丁包名
if (robust.patchPackname.name.text() != null && !"".equals(robust.patchPackname.name.text()))
if (robust.patchPackname.name.text() != null && "" != robust.patchPackname.name.text())
Config.patchPackageName = robust.patchPackname.name.text()

Config.isManual = robust.switch.manual != null && "true".equals(String.valueOf(robust.switch.manual.text()))
Config.isManual = robust.switch.manual != null && "true" == String.valueOf(robust.switch.manual.text())
//读取mapping文件
if (robust.switch.proguard.text() != null && !"".equals(robust.switch.proguard.text()))
if (robust.switch.proguard.text() != null && "" != robust.switch.proguard.text())
Config.supportProGuard = Boolean.valueOf(robust.switch.proguard.text()).booleanValue();

if (robust.mappingFile.name.text() != null && !"".equals(robust.mappingFile.name.text())) {
if (robust.mappingFile.name.text() != null && "" != robust.mappingFile.name.text()) {
Config.mappingFilePath = robust.mappingFile.name.text()
} else {
Config.mappingFilePath = "${path}${Constants.DEFAULT_MAPPING_FILE}"
}

if (Config.supportProGuard&&(Config.mappingFilePath == null || "".equals(Config.mappingFilePath) || !(new File(Config.mappingFilePath)).exists())) {
if (Config.supportProGuard&&(Config.mappingFilePath == null || "" == Config.mappingFilePath || !(new File(Config.mappingFilePath)).exists())) {
throw new RuntimeException("Not found ${Config.mappingFilePath}, please put it on your project's robust dir or change your robust.xml !");
}

Expand All @@ -35,7 +35,7 @@ class ReadXML {
for (name in robust.patchMethodSignure.name) {
if (!JavaUtils.isMethodSignureContainPatchClassName(String.valueOf(name.text()), Config.modifiedClassNameList))
throw new RuntimeException("input patchMethodSignure in robust.xml error,there are more than one patch classes,you need to config full class name and java method sigure");
Config.patchMethodSignureSet.add(String.valueOf(name.text()).trim());
Config.patchMethodSignatureSet.add(String.valueOf(name.text()).trim());
}

for (name in robust.packname.name) {
Expand All @@ -44,10 +44,10 @@ class ReadXML {
for (name in robust.newlyAddClass.name) {
Config.newlyAddedClassNameList.add(name.text());
}
if (robust.switch.catchReflectException.text() != null && !"".equals(robust.switch.catchReflectException.text()))
if (robust.switch.catchReflectException.text() != null && "" != robust.switch.catchReflectException.text())
Config.catchReflectException = Boolean.valueOf(robust.switch.catchReflectException.text()).booleanValue();

if (robust.switch.patchLog.text() != null && !"".equals(robust.switch.patchLog.text()))
if (robust.switch.patchLog.text() != null && "" != robust.switch.patchLog.text())
Constants.isLogging = Boolean.valueOf(robust.switch.patchLog.text()).booleanValue();

for (name in robust.noNeedReflectClass.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,16 @@ class AutoPatchTransform extends Transform implements Plugin<Project> {

def generatPatch(List<CtClass> box,String patchPath){
if (!Config.isManual) {
if (Config.patchMethodSignureSet.size() < 1) {
if (Config.patchMethodSignatureSet.size() < 1) {
throw new RuntimeException(" patch method is empty ,please check your Modify annotation or use RobustModify.modify() to mark modified methods")
}
Config.methodNeedPatchSet.addAll(Config.patchMethodSignureSet)
Config.methodNeedPatchSet.addAll(Config.patchMethodSignatureSet)
InlineClassFactory.dealInLineClass(patchPath, Config.newlyAddedClassNameList)
initSuperMethodInClass(Config.modifiedClassNameList);
//auto generate all class
for (String fullClassName : Config.modifiedClassNameList) {
CtClass ctClass = Config.classPool.get(fullClassName)
CtClass patchClass = PatchesFactory.createPatch(patchPath, ctClass, false, NameManger.getInstance().getPatchName(ctClass.name), Config.patchMethodSignureSet)
CtClass patchClass = PatchesFactory.createPatch(patchPath, ctClass, false, NameManger.getInstance().getPatchName(ctClass.name), Config.patchMethodSignatureSet)
patchClass.writeFile(patchPath)
patchClass.defrost();
createControlClass(patchPath, ctClass)
Expand Down Expand Up @@ -249,7 +249,7 @@ class AutoPatchTransform extends Transform implements Plugin<Project> {
modifiedCtClass = Config.classPool.get(modifiedFullClassName);
modifiedCtClass.defrost();
modifiedCtClass.declaredMethods.findAll {
return Config.patchMethodSignureSet.contains(it.longName)||InlineClassFactory.allInLineMethodLongname.contains(it.longName);
return Config.patchMethodSignatureSet.contains(it.longName)||InlineClassFactory.allInLineMethodLongname.contains(it.longName);
}.each { behavior ->
behavior.instrument(new ExprEditor() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class Config {
public static boolean isManual = false;
public static String patchPackageName = Constants.PATCH_PACKAGENAME;
public static String mappingFilePath;
public static Set<String> patchMethodSignureSet = new HashSet<>();
public static Set<String> patchMethodSignatureSet = new HashSet<>();
public static List<String> newlyAddedClassNameList = new ArrayList<String>();
public static Set newlyAddedMethodSet = new HashSet<String>();
public static List<String> modifiedClassNameList = new ArrayList<String>();
Expand All @@ -47,7 +47,7 @@ public static void init() {
isManual = false;
patchPackageName = Constants.PATCH_PACKAGENAME;
mappingFilePath = DEFAULT_MAPPING_FILE;
patchMethodSignureSet = new HashSet<>();
patchMethodSignatureSet = new HashSet<>();
newlyAddedClassNameList = new ArrayList<String>();
modifiedClassNameList = new ArrayList<String>();
hotfixPackageList = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
VERSION_NAME=0.4.5
VERSION_NAME=0.4.7
GROUP=com.meituan.robust

0 comments on commit 88ab62e

Please sign in to comment.