apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'me.tatarka.retrolambda'
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.dingmouren.dingdingmap"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    signingConfigs {
        //调试版的keystore
        debug {
            storeFile file("files\\dingdingmap.jks")
            storePassword "dingdingmap"
            keyAlias "dingdingmap"
            keyPassword "dingdingmap"
        }
        //发布版的keystore
        release {
            storeFile file("files\\dingdingmap.jks")
            storePassword "dingdingmap"
            keyAlias "dingdingmap"
            keyPassword "dingdingmap"
        }
    }
    //java编译选项
    compileOptions{
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:recyclerview-v7:25.1.0'
    compile 'com.android.support:cardview-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    /*butterknife*/
    compile 'com.jakewharton:butterknife:8.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    /*搜索框*/
    compile 'com.github.mancj:MaterialSearchBar:0.3.5'
    /*fab菜单*/
    compile 'io.github.yavski:fab-speed-dial:1.0.6'
    compile 'com.getbase:floatingactionbutton:1.10.1'
    /*SP使用到了*/
    compile 'org.androidannotations:androidannotations:4.2.0'
    /*MetarialDesignText*/
    compile 'com.rengwuxian.materialedittext:library:2.1.4'
    /*日志*/
    compile 'com.orhanobut:logger:1.15'
    /*组件通信*/
    compile 'org.greenrobot:eventbus:3.0.0'
    /*菜单*/
    compile project(':boommenu')
    /*对话框*/
    compile 'com.afollestad.material-dialogs:core:0.9.4.1'
    compile 'com.afollestad.material-dialogs:commons:0.9.4.1'
    /* 响应式*/
    compile 'io.reactivex:rxjava:1.1.6'
    compile 'io.reactivex:rxandroid:1.2.1'
    /*retrofit*/
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    /*图片加载库*/
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.github.chrisbanes.photoview:library:1.2.3'
    /*日志*/
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.2'
    compile 'com.jiongbull:jlog:1.0.5'
    /*圆形图片*/
    compile 'de.hdodenhof:circleimageview:2.1.0'
    /*lottie动画工具库*/
    compile 'com.airbnb.android:lottie:1.5.3'
}

//核心任务：在captures文件目录下输出 基于最新.trace文件的函数调用信息的txt版本
//说明：dmtracedump 为 android sdk自带工具，要执行dmtracedump命令则需要先添加环境变量（mac）
task AppOutPutMethodOrder() {
    doLast {
        def capturesDirPath = project.getProjectDir().getParentFile().path + File.separator + "captures";
        def capturesDir = new File(capturesDirPath);
        capturesDir.traverse {
            if (it.isFile() && it.name.endsWith(".trace")) {
                def orderName = it.name.replace("trace", "txt")
                def orderFile = new File(capturesDirPath, orderName)

                //说明：dmtracedump 为 android sdk自带工具，要执行dmtracedump命令则需要先添加环境变量
                def baseComand = "dmtracedump  -ho " + it.absolutePath + " >> " + orderFile.absolutePath
                println baseComand
                String osNameMatch = System.getProperty("os.name").toLowerCase();
                if (osNameMatch.contains("windows")) {
                    ("cmd /c start  /b " + baseComand).execute()
                } else {
                    ["bash", "-c", baseComand].execute()
                }
            }
        }
    }
}

//这里AppFilterMethodOrder 任务其实也不需要 执行找到 \captures 目录找到 base_order.txt
//用Notepad++ 使用正则 先过滤 带 xit 的行 （我们只关注ent 行就行，ent代表进入执行函数　xit代表退出函数）再过滤掉你不关心的包名
// Notepad++ 中过滤将会使用到的命令行如下
//^.*xit.*$ //去除掉 含有 xit 字符串的行  然后替换为空
// ^((?!XXX).)*$  //去除不包含XXX的行  然后替换为空
//^\s+   //合并空行  然后替换为空

task AppFilterMethodOrder() {
    doLast {
        //TODO 替换为你想要过滤出来的包名
        def filterPackageName = "com.dingmouren.dingdingmap"
        //处理包名
        def filterSignature = filterPackageName.replaceAll("[.]", "/")

        def capturesDirPath = project.getProjectDir().getParentFile().path + File.separator + "captures";
        def capturesDir = new File(capturesDirPath);

        capturesDir.traverse {
            if (it.isFile() && it.name.endsWith(".txt") && !it.name.contains("--filter")) {
                def orderName = it.name.replace(".txt", "--filter.txt")
                def orderFile = new File(capturesDirPath, orderName)

                it.eachLine { line ->

                    if (line.contains(" ent ")
                            //兼容不同版本traceview 有的是方法包名有的是方法签名
                            && (line.contains(filterPackageName)
                            || line.contains(filterSignature))
                    ) {
                        println line
                        orderFile.append(line + "\n")
                    }

                }
            }
        }


    }
}

