zoukankan      html  css  js  c++  java
  • MatrixTraceTransform主要逻辑在transform方法中

    @Override
    public void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
    long start = System.currentTimeMillis()
    //是否增量编译
    final boolean isIncremental = transformInvocation.isIncremental() && this.isIncremental()
    //transform的结果,重定向输出到这个目录
    final File rootOutput = new File(project.matrix.output, "classes/${getName()}/")
    if (!rootOutput.exists()) {
    rootOutput.mkdirs()
    }
    final TraceBuildConfig traceConfig = initConfig()
    Log.i("Matrix." + getName(), "[transform] isIncremental:%s rootOutput:%s", isIncremental, rootOutput.getAbsolutePath())
    //获取Class混淆的mapping信息,存储到mappingCollector中
    final MappingCollector mappingCollector = new MappingCollector()
    File mappingFile = new File(traceConfig.getMappingPath());
    if (mappingFile.exists() && mappingFile.isFile()) {
    MappingReader mappingReader = new MappingReader(mappingFile);
    mappingReader.read(mappingCollector)
    }

    Map<File, File> jarInputMap = new HashMap<>()
    Map<File, File> scrInputMap = new HashMap<>()

    transformInvocation.inputs.each { TransformInput input ->
    input.directoryInputs.each { DirectoryInput dirInput ->
    //收集、重定向目录中的class
    collectAndIdentifyDir(scrInputMap, dirInput, rootOutput, isIncremental)
    }
    input.jarInputs.each { JarInput jarInput ->
    if (jarInput.getStatus() != Status.REMOVED) {
    //收集、重定向jar包中的class
    collectAndIdentifyJar(jarInputMap, scrInputMap, jarInput, rootOutput, isIncremental)
    }
    }
    }
    //收集需要插桩的方法信息,每个插桩信息封装成TraceMethod对象
    MethodCollector methodCollector = new MethodCollector(traceConfig, mappingCollector)
    HashMap<String, TraceMethod> collectedMethodMap = methodCollector.collect(scrInputMap.keySet().toList(), jarInputMap.keySet().toList())
    //执行插桩逻辑,在需要插桩方法的入口、出口添加MethodBeat的i/o逻辑
    MethodTracer methodTracer = new MethodTracer(traceConfig, collectedMethodMap, methodCollector.getCollectedClassExtendMap(http://www.my516.com))
    methodTracer.trace(scrInputMap, jarInputMap)
    //执行原transform的逻辑;默认transformClassesWithDexBuilderForDebug这个task会将Class转换成Dex
    origTransform.transform(transformInvocation)
    Log.i("Matrix." + getName(), "[transform] cost time: %dms", System.currentTimeMillis() - start)
    }

  • 相关阅读:
    [C#]RichTextBox实现拖放
    [C#]WinForm动态删除控件 Controls.Remove()
    [C#]WinForm 中 comboBox控件之数据绑定
    [C#.Net]KeyDown(KeyUp)和KeyPress的区别
    [C#.NET]最简单的实现文本框的水印效果
    [C#.Net]对WinForm应用程序的App.config的使用及加密
    Spring MVC异常处理详解
    MAC与HMAC的介绍及其在AWS和Azure中的应用
    isDebugEnabled有什么用?
    在Mysql中Using filesort代表什么意思?
  • 原文地址:https://www.cnblogs.com/ly570/p/11291179.html
Copyright © 2011-2022 走看看