All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mrcd.mmat.plugin.MmatPlugin.groovy Maven / Gradle / Ivy

The newest version!
package com.mrcd.mmat.plugin

import com.mrcd.mmat.AnalyzerEngine
import org.gradle.api.Plugin
import org.gradle.api.Project

/**
 * 参考: https://juejin.im/post/5a523dd56fb9a01cbf382ce9
 * 参考:
 *
 * 调试插件请参考: https://blog.csdn.net/ceabie/article/details/55271161
 */
public class MmatPlugin implements Plugin {

    MmatExtension mmatExt

    void apply(Project project) {
        try {
            System.out.println("\n\n\n========================")
            System.out.println("Link start,开始构建,config mmat plugin!")
            System.out.println("========================\n\n\n")

            project.extensions.create('mmat', MmatExtension)
            mmatExt = project.mmat

            // create mmatRunner task : startMmatRunner
            project.task("startMmatRunner", group: 'verification') {
                doLast {
                    startMmatRunner()
                }
            }

            // create mmatRunner task : startMmatSilently,不执行 monkey
            project.task("startMmatSilently", group: 'verification') {
                doLast {
                    mmatExt.disableMonkey = true
                    startMmatRunner()
                }
            }
        } catch (Throwable e) {
            e.printStackTrace()
        }
    }

    /**
     *  插件分析步骤的开始
     */
    void startMmatRunner() {
        System.out.println("current dir : " + new File("./").getAbsolutePath())
        File jsonConfigFile
        if ( TextUtils.isEmpty(mmatExt.jsonConfigFile) ) {
            // default mmat config,默认在项目根目录
            jsonConfigFile = new File("./mmat-config.json")
        } else {
            jsonConfigFile = new File(mmatExt.jsonConfigFile)
        }

        System.out.println("json config path : " + mmatExt.jsonConfigFile)
        if ( !jsonConfigFile.exists() ) {
            throw new FileNotFoundException("json config file not found!!")
        }

        File hprofFile = null
        if ( TextUtils.isNotEmpty( mmatExt.hprofFile) ) {
            hprofFile = new File(mmatExt.hprofFile)
        }
        try {
            System.out.println("mmat config : " + mmatExt)
            //分析的入口
            new AnalyzerEngine().start( (hprofFile != null && hprofFile.exists()) ? hprofFile : null,
                                        jsonConfigFile, mmatExt.disableMonkey)
        } catch (Throwable e) {
            e.printStackTrace()
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy