Skip to content

Commit

Permalink
Merge pull request #186 from Meituan-Dianping/AddImages
Browse files Browse the repository at this point in the history
add images for wiki
  • Loading branch information
mivanzhang authored Aug 22, 2017
2 parents cf3afa4 + 231fab0 commit 9e57998
Show file tree
Hide file tree
Showing 19 changed files with 618 additions and 576 deletions.
25 changes: 14 additions & 11 deletions app/src/main/java/com/meituan/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class MainActivity extends AppCompatActivity {

Hll hll = new Hll(false);



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -104,27 +106,28 @@ public void onClick(View v) {
e.printStackTrace();
}

System.out.println(" run(String x) "+run("robust ",123));
System.out.println(" run(People x) "+run(new People(),123d));
System.out.println(" run(float x) "+run(123f));
System.out.println(" double run() "+run());
System.out.println(" run(String x) " + run("robust ", 123));
System.out.println(" run(People x) " + run(new People(), 123d));
System.out.println(" run(float x) " + run(123f));
System.out.println(" double run() " + run());
System.out.println("in MainActivity end ");
}



private String run(String x,int p){
return x+"meituan";
private String run(String x, int p) {
return x + "meituan";
}
private String run(People x,double d){

private String run(People x, double d) {
x.setAddr("meituan");
return x.getAddr();
}
private int run(float x){
return (int)x;

private int run(float x) {
return (int) x;
}

private double run(){
private double run() {
return 1d;
}

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/meituan/sample/robusttest/Super.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class Super extends Hll {
}



public String[] methodWithArrayParameters(String[] flag) {
return flag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public Hll(boolean t) {
public Hll() {

}

private String privateMethod(int index, String name) {
Log.d("robust", "in hll.getStrings() ");
packageMethod(1,name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/**
* Created by mivanzhang on 16/12/9.
* <p>
* A backup for annotation Modify, in some situation Modify will not work, such as Generic
*/

public final class RobustModify {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/**
* Created by mivanzhang on 16/12/19.
* 用来标记新增的类和方法
* annotaion used for add classes or methods,classes and methods will be packed into patch.jar/patch.apk
*/

@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* Created by mivanzhang on 16/12/9.
* annotaion used for modify classes or methods,classes and methods will be packed into patch.jar/patch.apk
*/
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR})
@Retention(RetentionPolicy.CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* Created by mivanzhang on 16/8/15.
* <p>
* A reflect utility class, providing methods for reflecting methods and set/get fields
*/
public class EnhancedRobustUtils {
public static boolean isThrowable = true;
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ buildscript {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
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'
classpath 'me.tatarka:gradle-retrolambda:3.2.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@
*/

public abstract class InsertcodeStrategy {
protected List<String> hotfixPackageList = new ArrayList<>();
protected List<String> hotfixMethodList = new ArrayList<>();
protected List<String> exceptPackageList = new ArrayList<>();
protected List<String> exceptMethodList = new ArrayList<>();
protected boolean isHotfixMethodLevel = false;
protected boolean isExceptMethodLevel = false;
//packnames need to be insert code 需要插桩的包名列表,
protected List<String> hotfixPackageList = new ArrayList<>();
//methods list need to insert code 需要插桩的方法列表
protected List<String> hotfixMethodList = new ArrayList<>();

//packnames don`t need to be insert code 不需要插桩的包名列表,
protected List<String> exceptPackageList = new ArrayList<>();

//methods list do not need to insert code 不需要插桩的方法列表
protected List<String> exceptMethodList = new ArrayList<>();
//a switch control whether need to filter method in hotfixMethodList, if false ,hotfixMethodList will be ignored
protected boolean isHotfixMethodLevel = false;

//a switch control whether need to filter method in exceptMethodList, if false ,exceptMethodList will be ignored
protected boolean isExceptMethodLevel = false;
protected AtomicInteger insertMethodCount = new AtomicInteger(0);
//record every method with unique method number
public HashMap<String, Integer> methodMap = new HashMap();

public InsertcodeStrategy(List<String> hotfixPackageList, List<String> hotfixMethodList, List<String> exceptPackageList, List<String> exceptMethodList, boolean isHotfixMethodLevel, boolean isExceptMethodLevel) {
Expand All @@ -37,8 +47,16 @@ public InsertcodeStrategy(List<String> hotfixPackageList, List<String> hotfixMet
insertMethodCount.set(0);
}

/**
* @param box all classes which will be packed into apk,所有需要打入apk中的类
* @param jarFile 所有的插桩处理过的class都会被输出的jarFile
* @throws CannotCompileException
* @throws IOException
* @throws NotFoundException
*/
protected abstract void insertCode(List<CtClass> box, File jarFile) throws CannotCompileException, IOException, NotFoundException;
protected boolean isNeedInsertClass(String className) {

protected boolean isNeedInsertClass(String className) {

//这样子可以在需要埋点的剔除指定的类
for (String exceptName : exceptPackageList) {
Expand All @@ -54,14 +72,14 @@ protected boolean isNeedInsertClass(String className) {
return false;
}

protected void zipFile(byte[] classBytesArray, ZipOutputStream zos, String entryName){
protected void zipFile(byte[] classBytesArray, ZipOutputStream zos, String entryName) {
try {
ZipEntry entry = new ZipEntry(entryName);
zos.putNextEntry(entry);
zos.write(classBytesArray, 0, classBytesArray.length);
zos.closeEntry();
zos.flush();
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import java.security.MessageDigest

/**
* Created by hedex on 17/2/14.
*
* calculate unique string for each apk,you can get the string in file located in build/outputs/robust/robust.apkhash
*/
class RobustApkHashAction implements Action<Project> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package robust.gradle.plugin
import com.meituan.robust.Constants

import java.util.zip.*

/**
* Created by hedex on 17/2/14.
*/
Expand Down Expand Up @@ -82,7 +83,7 @@ class RobustApkHashZipUtils {
while (entries.hasMoreElements()) {
// ZipEntry zipEntry = entries.nextElement();//保守
ZipEntry zipEntry = new ZipEntry(entries.nextElement().name);
if (null != zipEntry ) {
if (null != zipEntry) {
addZipEntry(zipOutputStream, zipEntry, apZipFile.getInputStream(zipEntry))
}
}
Expand Down Expand Up @@ -116,7 +117,6 @@ class RobustApkHashZipUtils {
return crc.getValue();
}


/**
* add zip entry
*
Expand All @@ -125,7 +125,8 @@ class RobustApkHashZipUtils {
* @param inputStream
* @throws Exception
*/
private static void addZipEntry(ZipOutputStream zipOutputStream, ZipEntry zipEntry, InputStream inputStream) throws Exception {
private
static void addZipEntry(ZipOutputStream zipOutputStream, ZipEntry zipEntry, InputStream inputStream) throws Exception {
try {
zipOutputStream.putNextEntry(zipEntry);
byte[] buffer = new byte[1024];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RobustTransform extends Transform implements Plugin<Project> {
robust = new XmlSlurper().parse(new File("${project.projectDir}/${Constants.ROBUST_XML}"))
logger = project.logger
initConfig()
//turnOnDevelopModel 是true的话,则强制执行插入
//isForceInsert 是true的话,则强制执行插入
if (!isForceInsert) {
def taskNames = project.gradle.startParameter.taskNames
def isDebugTask = false;
Expand Down
Loading

0 comments on commit 9e57998

Please sign in to comment.