Giter Site home page Giter Site logo

hunter's Introduction

Hunter

Hunter is a framework to develop android gradle plugin based on ASM and Gradle Transform API. It provides a set of useful, scalable plugins for android developers. You can use Hunter to develop more plugins to monitor your app, enhance 3rd-dependency, enhance android framework.

Plugins based on Hunter support incremental and concurrent compile, so you don't need to afraid of extra build time.

  • Timing-Plugin: you can time all your ui-thread methods, and dump the block traces
  • OkHttp-Plugin: you can set a global Interceptor / Eventlistener for all your OkhttpClients(Okhttp does not provide interface to set a global Interceptor/EventListener)
  • LogLine-Plugin: you can add a line number into every lines of your logcat
  • Debug-Plugin: you can simply add a annotation to a certain method, and the method will print all parameters and costed time, return value(JakeWharton's hugo achieves it with AspectJ, I achieve it with ASM)
  • More developing plugins can be found in TODO, MeanWhile, your idea is welcome

Timing-Plugin

dependencies {
    implementation 'com.quinn.hunter:hunter-timing-library:0.8.5'
}

repositories {
    maven { url 'https://dl.bintray.com/leaking/maven' }
}

buildscript {
    repositories {
        maven { url 'https://dl.bintray.com/leaking/maven' }
    }
    dependencies {
        classpath 'com.quinn.hunter:hunter-timing-plugin:0.8.5'
    }
}

apply plugin: 'hunter-timing'
    

The Hunter-Timing has a internal default BlockHandler to process the block messages, you can set your custom BlockHandler.

IBlockHandler customBlockManager = new RankingBlockHandler();
BlockManager.installBlockManager(customBlockManager);

You can dump the block trace

customBlockManager.dump()

In addition, hunter-timing-plugin provides a extendsion

timingHunterExt {
    runVariant = 'DEBUG'
    whitelist = ['com.quinn.hunter.timing.DataSource', 'com.foo.package2']
    blacklist = ['com.quinn.hunter.timing.black', 'com.foo.package2']
}

runVariant, its default value is ALWAYS, it means this plugin will perform in both debug build and release build. There are four available runVariant, DEBUG, RELEASE, ALWAYS, NEVER.

whitelist, it means the plugin will only handle the classes in these packages, you can provide package with prefix name.

blacklist, it means the plugin will handle all classes except the classes in these packages, you can provide package with prefix name.

You'd better just provide whitelist or blacklist, if you provide both of them, blacklist is ignored.

OkHttp-Plugin

Maybe your project have serveral OkhttpClients,you need to add your custom Interceptor/EventListener/Dns to every OkhttpClients one by one. But some OkhttpClients come from 3rd library, and you can't add your custom Interceptor/EventListener/Dns to them. I have filed a issue about this problem to Okhttp team.

OkHttp-Plugin can help you to achieve it, you can set a global Interceptor/EventListener/Dns to your all OkhttpClients.

dependencies {
    implementation 'com.quinn.hunter:hunter-okhttp-library:0.8.5'
}

repositories {
    maven { url 'https://dl.bintray.com/leaking/maven' }

}

buildscript {
    repositories {
        maven { url 'https://dl.bintray.com/leaking/maven' }
    }
    dependencies {
        classpath 'com.quinn.hunter:hunter-okhttp-plugin:0.8.5'
    }
}

apply plugin: 'hunter-okhttp'
    
OkHttpHooker.installEventListenerFactory(CustomGlobalEventListener.FACTORY);
OkHttpHooker.installDns(new CustomGlobalDns());
OkHttpHooker.installInterceptor(new CustomGlobalInterceptor());
        

Debug-Plugin

It's a plugin similar to hugo but it's developed with ASM instead of AspectJ. Amd it has a quicker compile speed.

Simply add @HunterDebug to your methods will print all parameters and costed time, return value.

dependencies {
    implementation 'com.quinn.hunter:hunter-debug-library:0.8.5'
}

repositories {
    maven { url 'https://dl.bintray.com/leaking/maven' }
}

buildscript {
    repositories {
        maven { url 'https://dl.bintray.com/leaking/maven' }
    }
    dependencies {
        classpath 'com.quinn.hunter:hunter-debug-plugin:0.8.5'
    }
}

apply plugin: 'hunter-debug'

Logging works in both debug and release build mode, but you can specify certain mode or disable it.

debugHunterExt {
    runVariant = 'DEBUG'  //'DEBUG', 'RELEASE', 'ALWAYS', 'NEVER', The 'ALWAYS' is default value
}

LogLine-Plugin

This is a interesting tool/plugin, sometimes you may need line number to help you locate the logcat content, especially, same logcat print in different lines in the same one java class.

This plugin can help you.

dependencies {
    implementation 'com.quinn.hunter:hunter-linelog-library:0.8.5'
}

repositories {
    maven { url 'https://dl.bintray.com/leaking/maven' }
}

buildscript {
    repositories {
        maven { url 'https://dl.bintray.com/leaking/maven' }
    }
    dependencies {
        classpath 'com.quinn.hunter:hunter-linelog-plugin:0.8.6'
    }
}

apply plugin: 'hunter-linelog'
    

You logcat will be inserted line number automatically.

Origin logcat

I/MainActivity: onCreate

Tranformed logcat

I/MainActivity[21]: onCreate

Developer API

Wiki

License

Copyright 2018 Quinn Chen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

hunter's People

Contributors

leaking avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.