├── example
├── settings.gradle
├── loglifecycle-example
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── styles.xml
│ │ │ ├── dimens.xml
│ │ │ └── strings.xml
│ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── layout
│ │ │ ├── fragment_main.xml
│ │ │ └── activity_main.xml
│ │ ├── menu
│ │ │ └── main.xml
│ │ └── values-w820dp
│ │ │ └── dimens.xml
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── loglifecycle
│ │ │ ├── MainActivity.java
│ │ │ ├── MainFragment.java
│ │ │ └── CustomTextView.java
│ │ └── AndroidManifest.xml
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── loglifecycle-plugin
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── META-INF
│ │ │ │ └── gradle-plugins
│ │ │ │ ├── loglifecycle.properties
│ │ │ │ └── com.github.stephanenicolas.loglifecycle.properties
│ │ ├── groovy
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── stephanenicolas
│ │ │ │ └── loglifecycle
│ │ │ │ ├── LogLifeCyclePluginExtension.groovy
│ │ │ │ └── LogLifeCyclePlugin.groovy
│ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── stephanenicolas
│ │ │ └── loglifecycle
│ │ │ └── LogLifeCycleProcessor.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── stephanenicolas
│ │ └── loglifecycle
│ │ ├── LogLifeCycleTestRunner.java
│ │ └── LogLifeCycleProcessorTest.java
├── gradle.properties
├── maven_3rd_party
│ ├── com
│ │ └── android
│ │ │ └── support
│ │ │ └── support-v4
│ │ │ └── 19.0.1
│ │ │ └── support-v4-19.0.1.jar
│ └── org
│ │ └── robolectric
│ │ └── robolectric
│ │ └── 2.4.SNI
│ │ ├── robolectric-2.4.SNI.jar
│ │ └── robolectric-2.4.SNI.pom
└── build.gradle
├── .gitignore
├── loglifecycle-annotations
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── stephanenicolas
│ │ └── loglifecycle
│ │ └── LogLifeCycle.java
└── build.gradle
├── gradle.properties
├── CHANGELOG.md
├── .travis.yml
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/example:
--------------------------------------------------------------------------------
1 | loglifecycle-example/
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':loglifecycle-annotations'
2 | include ':loglifecycle-plugin'
3 |
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stephanenicolas/loglifecycle/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/loglifecycle-plugin/src/main/resources/META-INF/gradle-plugins/loglifecycle.properties:
--------------------------------------------------------------------------------
1 | implementation-class=com.github.stephanenicolas.loglifecycle.LogLifeCyclePlugin
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stephanenicolas/loglifecycle/HEAD/loglifecycle-example/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stephanenicolas/loglifecycle/HEAD/loglifecycle-example/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stephanenicolas/loglifecycle/HEAD/loglifecycle-example/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loglifecycle-plugin/src/main/resources/META-INF/gradle-plugins/com.github.stephanenicolas.loglifecycle.properties:
--------------------------------------------------------------------------------
1 | implementation-class=com.github.stephanenicolas.loglifecycle.LogLifeCyclePlugin
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stephanenicolas/loglifecycle/HEAD/loglifecycle-example/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loglifecycle-plugin/gradle.properties:
--------------------------------------------------------------------------------
1 | ROBOLECTRIC_VERSION=2.4.SNI
2 | JUNIT_VERSION=4.11
3 | ANDROID_VERSION=4.1.1.4
4 | EASY_MOCK_VERSION=3.0
5 | BOUNCYCASTLE_VERSION=1.46
6 | HTTP_CLIENT_VERSION=4.1.1
7 | COMMONS_LOGGING_VERSION=1.1.1
--------------------------------------------------------------------------------
/loglifecycle-plugin/maven_3rd_party/com/android/support/support-v4/19.0.1/support-v4-19.0.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stephanenicolas/loglifecycle/HEAD/loglifecycle-plugin/maven_3rd_party/com/android/support/support-v4/19.0.1/support-v4-19.0.1.jar
--------------------------------------------------------------------------------
/loglifecycle-plugin/maven_3rd_party/org/robolectric/robolectric/2.4.SNI/robolectric-2.4.SNI.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stephanenicolas/loglifecycle/HEAD/loglifecycle-plugin/maven_3rd_party/org/robolectric/robolectric/2.4.SNI/robolectric-2.4.SNI.jar
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Aug 19 21:17:01 EDT 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip
7 |
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | LogLifeCycle Sample
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/loglifecycle-plugin/src/main/groovy/com/github/stephanenicolas/loglifecycle/LogLifeCyclePluginExtension.groovy:
--------------------------------------------------------------------------------
1 | package com.github.stephanenicolas.loglifecycle
2 |
3 | /**
4 | * @author SNI
5 | */
6 | public class LogLifeCyclePluginExtension {
7 | /** Enable to debug the lib's errors. */
8 | boolean debug;
9 | }
10 |
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.war
8 | *.ear
9 |
10 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
11 | hs_err_pid*
12 |
13 | #Android Studio
14 | .idea/
15 | *.iml
16 | local.properties
17 |
18 | #gradle
19 | .gradle
20 | build/
21 |
22 | #personal aliases
23 | annotations
24 |
25 |
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/loglifecycle-annotations/src/main/java/com/github/stephanenicolas/loglifecycle/LogLifeCycle.java:
--------------------------------------------------------------------------------
1 | package com.github.stephanenicolas.loglifecycle;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Target(ElementType.TYPE)
9 | @Retention(RetentionPolicy.CLASS)
10 | public @interface LogLifeCycle {
11 | }
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/java/com/example/loglifecycle/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.loglifecycle;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import android.support.v4.app.FragmentActivity;
7 |
8 | import com.github.stephanenicolas.loglifecycle.LogLifeCycle;
9 |
10 | @LogLifeCycle
11 | public class MainActivity extends FragmentActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 |
16 | super.onCreate(savedInstanceState);
17 |
18 | setContentView(R.layout.activity_main);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | version=1.0.4-SNAPSHOT
2 | GROUP=com.github.stephanenicolas.loglifecycle
3 |
4 | POM_DESCRIPTION=Logs all life cycle methods of an Activity on Android
5 | POM_URL=https://github.com/stephannicolas/loglifecycle/
6 | POM_SCM_URL=https://github.com/stephannicolas/loglifecycle/
7 | POM_SCM_CONNECTION=scm:git@github.com/stephannicolas/loglifecycle.git
8 | POM_SCM_DEV_CONNECTION=scm:git@github.com:stephannicolas/loglifecycle.git
9 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
10 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
11 | POM_LICENCE_DIST=repo
12 | POM_DEVELOPER_ID=SNI
13 | POM_DEVELOPER_NAME=Stéphane NICOLAS
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/java/com/example/loglifecycle/MainFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.loglifecycle;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import android.support.v4.app.Fragment;
9 |
10 | import com.github.stephanenicolas.loglifecycle.LogLifeCycle;
11 |
12 | @LogLifeCycle
13 | public class MainFragment extends Fragment {
14 |
15 | @Override
16 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
17 | Bundle savedInstanceState) {
18 | return inflater.inflate(R.layout.fragment_main, container);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Version 1.0.3 (released on August 30th 2014)
2 | -------------
3 |
4 | * Thx to Riccardo Ciovati for helping make the plugin work out of the box.
5 | * minor fixes and better logs.
6 | * LogLifeCycle now check if methods can be overriden.
7 | * CI
8 | * Added tests and coverage
9 |
10 | Version 1.0.2 (Failed release)
11 | -------------
12 |
13 | Version 1.0.1 (released on August 23rd 2014)
14 | -------------
15 |
16 | Support for
17 | * fragments (native and support)
18 | * activities
19 | * services
20 | * application
21 | * views
22 | * broadcast receivers
23 |
24 | Also automatically skip release variant.
25 |
26 | Version 1.0.0 (released on August 21th 2014)
27 |
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/java/com/example/loglifecycle/CustomTextView.java:
--------------------------------------------------------------------------------
1 | package com.example.loglifecycle;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.TextView;
6 |
7 | import com.github.stephanenicolas.loglifecycle.LogLifeCycle;
8 |
9 | @LogLifeCycle
10 | public class CustomTextView extends TextView {
11 |
12 | public CustomTextView(Context context) {
13 |
14 | super(context);
15 | }
16 |
17 | public CustomTextView(Context context, AttributeSet attrs) {
18 |
19 | super(context, attrs);
20 | }
21 |
22 | public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
23 |
24 | super(context, attrs, defStyle);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/loglifecycle-example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/loglifecycle-annotations/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'nexus'
3 |
4 | targetCompatibility = JavaVersion.VERSION_1_6
5 | sourceCompatibility = JavaVersion.VERSION_1_6
6 |
7 | modifyPom {
8 | project {
9 | name "Loglifecycle Annotations"
10 | description POM_DESCRIPTION
11 | url POM_URL
12 |
13 | scm {
14 | url POM_SCM_URL
15 | connection POM_SCM_CONNECTION
16 | developerConnection POM_SCM_DEV_CONNECTION
17 | }
18 |
19 | licenses {
20 | license {
21 | name POM_LICENCE_NAME
22 | url POM_LICENCE_URL
23 | distribution POM_LICENCE_DIST
24 | }
25 | }
26 |
27 | developers {
28 | developer {
29 | id POM_DEVELOPER_ID
30 | name POM_DEVELOPER_NAME
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/loglifecycle-example/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 |
5 | // NOTE: This is only needed when developing the plugin!
6 | mavenLocal()
7 | }
8 |
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:0.12.2'
11 | classpath 'com.github.stephanenicolas.loglifecycle:loglifecycle-plugin:1.0.2-SNAPSHOT'
12 | }
13 | }
14 |
15 | apply plugin: 'android'
16 | apply plugin: 'loglifecycle'
17 |
18 | repositories {
19 | mavenCentral()
20 | }
21 |
22 | dependencies{
23 | compile 'com.android.support:support-v4:19.1.+'
24 | }
25 |
26 | android {
27 | compileSdkVersion 19
28 | buildToolsVersion '19.1.0'
29 |
30 | compileOptions {
31 | sourceCompatibility JavaVersion.VERSION_1_7
32 | targetCompatibility JavaVersion.VERSION_1_7
33 | }
34 | }
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk: oraclejdk7
3 | branches:
4 | only:
5 | - master
6 | before_install:
7 | # Install base Android SDK and components
8 | - sudo apt-get update -qq
9 | - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect
10 | - export COMPONENTS=build-tools-19.0.3,android-19,extra-android-support,extra-android-m2repository,extra-google-m2repository
11 | - export LICENSES=android-sdk-license-bcbbd656
12 | - curl -3L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS --accept=$LICENSES
13 | - source ~/.android-sdk-installer/env
14 |
15 | install:
16 | # Without TERM=dumb, we get mangled output in the Travis console
17 | - TERM=dumb ./gradlew clean assemble
18 |
19 | script:
20 | - TERM=dumb ./gradlew check
21 |
22 | env:
23 | global:
24 | - TERM=dumb
25 |
26 | notifications:
27 | email: false
28 |
29 | #from http://blog.ansuz.nl/index.php/2014/06/01/robolectric-and-cobertura-with-gradle/
30 | after_success:
31 | - ./gradlew clean cobertura coveralls -d
32 |
--------------------------------------------------------------------------------
/loglifecycle-plugin/src/main/groovy/com/github/stephanenicolas/loglifecycle/LogLifeCyclePlugin.groovy:
--------------------------------------------------------------------------------
1 | package com.github.stephanenicolas.loglifecycle
2 |
3 | import com.github.stephanenicolas.morpheus.AbstractMorpheusPlugin;
4 | import javassist.build.IClassTransformer;
5 | import org.gradle.api.Project;
6 |
7 | /**
8 | * @author SNI
9 | */
10 | public class LogLifeCyclePlugin extends AbstractMorpheusPlugin {
11 |
12 | @Override
13 | public IClassTransformer[] getTransformers(Project project) {
14 | return new LogLifeCycleProcessor(project.loglifecycle.debug);
15 | }
16 |
17 | @Override
18 | protected void configure(Project project) {
19 | project.dependencies {
20 | provided 'com.github.stephanenicolas.loglifecycle:loglifecycle-annotations:1.0.1'
21 | }
22 | }
23 |
24 | @Override
25 | protected Class getPluginExtension() {
26 | LogLifeCyclePluginExtension
27 | }
28 |
29 | @Override
30 | protected String getExtension() {
31 | "loglifecycle"
32 | }
33 |
34 | @Override
35 | public boolean skipVariant(def variant) {
36 | return variant.name.contains('release')
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/loglifecycle-plugin/src/test/java/com/github/stephanenicolas/loglifecycle/LogLifeCycleTestRunner.java:
--------------------------------------------------------------------------------
1 | package com.github.stephanenicolas.loglifecycle;
2 |
3 | import com.github.stephanenicolas.loglifecycle.LogLifeCycleProcessor;
4 | import java.io.FileOutputStream;
5 | import java.net.URL;
6 | import javassist.ClassPool;
7 | import javassist.CtClass;
8 | import lombok.extern.slf4j.Slf4j;
9 | import org.junit.runners.model.InitializationError;
10 | import org.robolectric.AndroidManifest;
11 | import org.robolectric.RobolectricTestRunner;
12 | import org.robolectric.SdkConfig;
13 | import org.robolectric.annotation.Config;
14 | import org.robolectric.bytecode.AsmInstrumentingClassLoader;
15 | import org.robolectric.bytecode.Setup;
16 | import org.robolectric.res.Fs;
17 |
18 |
19 | /**
20 | * Created by administrateur on 2014-08-21.
21 | */
22 | @Slf4j
23 | public class LogLifeCycleTestRunner extends RobolectricTestRunner {
24 | private LogLifeCycleProcessor processor = new LogLifeCycleProcessor(true);
25 |
26 | public LogLifeCycleTestRunner(Class> testClass) throws InitializationError {
27 | super(testClass);
28 | }
29 |
30 | @Override
31 | protected ClassLoader createRobolectricClassLoader(Setup setup, SdkConfig sdkConfig) {
32 | URL[] urls = getJarResolver().getLocalArtifactUrls(sdkConfig.getSdkClasspathDependencies());
33 | return new AsmInstrumentingClassLoader(setup, urls) {
34 | @Override
35 | protected byte[] getByteCode(String className) throws ClassNotFoundException {
36 | if (className.startsWith("com.github.stephanenicolas.loglifecycle")) {
37 | try {
38 | CtClass dummyClass = ClassPool.getDefault().get(className);
39 | if (processor.shouldTransform(dummyClass)) {
40 | log.debug("Intercepting via InjectExtra " + className);
41 | processor.applyTransformations(dummyClass);
42 | byte[] bytes = dummyClass.toBytecode();
43 | System.out.println("Size of weaved byte code :" + bytes.length);
44 | FileOutputStream fileOutputStream =
45 | new FileOutputStream("/tmp/" + className + ".class");
46 | fileOutputStream.write(bytes);
47 | fileOutputStream.close();
48 | return bytes;
49 | }
50 | } catch (Exception e) {
51 | throw new RuntimeException("Impossible to transform class " + className, e);
52 | }
53 | }
54 | return super.getByteCode(className);
55 | }
56 | };
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ⟳ loglifecycle [](https://maven-badges.herokuapp.com/maven-central/com.github.stephanenicolas.loglifecycle/loglifecycle-plugin)
2 | ============
3 |
4 | ***Logs all lifecycle methods of annotated activities, fragments, views, etc. on Android.***
5 |
6 | ###Usage
7 |
8 | Inside your `build.gradle` file, add :
9 |
10 | ```groovy
11 | apply plugin: 'loglifecycle'
12 | ```
13 |
14 | And now, annotate every `Activity` you want to see its life cycle logged in logcat :
15 |
16 | ```java
17 | @LogLifeCycle
18 | public class MainActivity extends Activity {
19 | ...
20 | }
21 | ```
22 |
23 | You will see something like this in logcat :
24 |
25 | ```bash
26 | > adb logcat | grep ⟳
27 |
28 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onCreate
29 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onApplyThemeResource
30 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onWindowAttributesChanged
31 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onWindowAttributesChanged
32 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onWindowAttributesChanged
33 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onContentChanged
34 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onAttachFragment
35 | D/LogLifeCycle( 4640): MainActivity$MainFragment [1384183528] ⟳ onCreate
36 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onStart
37 | D/LogLifeCycle( 4640): MainActivity$MainFragment [1384183528] ⟳ onStart
38 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onTitleChanged
39 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onPostCreate
40 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onResume
41 | D/LogLifeCycle( 4640): MainActivity$MainFragment [1384183528] ⟳ onResume
42 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onPostResume
43 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onAttachedToWindow
44 | D/LogLifeCycle( 4640): MainActivity [1384162984] ⟳ onWindowFocusChanged
45 | ```
46 |
47 | Extra features :
48 | * release builds won't log anything, indeed the app is not modified at all in release builds.
49 | * this plugin will add only a few more bytes to your app : log statements, and the annotation class, nothing more.
50 |
51 | ###Example
52 |
53 | You will find an example app using LogLifeCycle in the repo.
54 |
55 | ###How does it work ?
56 |
57 | Thanks to
58 | * [morpheus](https://github.com/stephanenicolas/morpheus), byte code weaver for android.
59 | * [AfterBurner](https://github.com/stephanenicolas/afterburner), byte code weaving swiss army knife for Android.
60 |
61 | ### Related projects
62 |
63 | On the same principle of byte code weaving :
64 |
65 | * [InjectView](https://github.com/stephanenicolas/injectview)
66 | * [InjectResource](https://github.com/stephanenicolas/injectresource)
67 | * [InjectExtra](https://github.com/stephanenicolas/injectextra)
68 | * [Hugo](https://github.com/jakewharton/hugo)
69 |
70 | ###TODO
71 | * [ ] add tests
72 |
73 | ### CI
74 |
75 | [](https://travis-ci.org/stephanenicolas/loglifecycle)
76 | [](https://coveralls.io/r/stephanenicolas/loglifecycle)
77 |
78 | License
79 | -------
80 |
81 | Copyright (C) 2014 Stéphane NICOLAS
82 |
83 | Licensed under the Apache License, Version 2.0 (the "License");
84 | you may not use this file except in compliance with the License.
85 | You may obtain a copy of the License at
86 |
87 | http://www.apache.org/licenses/LICENSE-2.0
88 |
89 | Unless required by applicable law or agreed to in writing, software
90 | distributed under the License is distributed on an "AS IS" BASIS,
91 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
92 | See the License for the specific language governing permissions and
93 | limitations under the License.
94 |
95 |
--------------------------------------------------------------------------------
/loglifecycle-plugin/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | jcenter()
5 | }
6 |
7 | dependencies {
8 | classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.7'
9 | classpath ("net.saliman:gradle-cobertura-plugin:2.2.4")
10 | classpath ("org.kt3k.gradle.plugin:coveralls-gradle-plugin:1.0.2")
11 | }
12 | }
13 |
14 | apply plugin: 'groovy'
15 | apply plugin: 'java'
16 | apply plugin: 'nexus'
17 | apply plugin: 'cobertura'
18 | apply plugin: 'com.github.kt3k.coveralls'
19 |
20 | repositories {
21 | mavenCentral()
22 |
23 | //only needed to develop the lib
24 | mavenLocal()
25 |
26 | //for robolectric fork and support
27 | maven {
28 | url 'maven_3rd_party'
29 | }
30 |
31 | //to get snapshots
32 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
33 | }
34 |
35 | dependencies {
36 |
37 | //compile 'com.android.tools.build:gradle:0.12.2'
38 | compile 'com.github.stephanenicolas.javassist:javassist-build-plugin-api:1.0.0'
39 | //needed to create a processor based on afterburner
40 | compile 'com.github.stephanenicolas.afterburner:afterburner-library:1.0.1'
41 |
42 | //only needed to create a plugin
43 | compile 'com.github.stephanenicolas.morpheus:morpheus-plugin:1.0.7'
44 | compile 'com.github.stephanenicolas.morpheus:morpheus-commons:1.0.7'
45 | compile gradleApi()
46 | compile localGroovy()
47 |
48 | compile project(':loglifecycle-annotations')
49 |
50 | compile 'org.projectlombok:lombok:1.14.2'
51 | compile "com.google.android:android:${ANDROID_VERSION}"
52 |
53 | //--TESTS
54 | testCompile "junit:junit:$JUNIT_VERSION"
55 | testCompile "org.bouncycastle:bcprov-jdk15:$BOUNCYCASTLE_VERSION"
56 |
57 | testCompile("org.robolectric:robolectric:$ROBOLECTRIC_VERSION") {
58 | exclude module: 'classworlds'
59 | exclude module: 'maven-artifact'
60 | exclude module: 'maven-artifact-manager'
61 | exclude module: 'maven-error-diagnostics'
62 | exclude module: 'maven-model'
63 | exclude module: 'maven-plugin-registry'
64 | exclude module: 'maven-profile'
65 | exclude module: 'maven-project'
66 | exclude module: 'maven-settings'
67 | exclude module: 'nekohtml'
68 | exclude module: 'plexus-container-default'
69 | exclude module: 'plexus-interpolation'
70 | exclude module: 'plexus-utils'
71 | exclude module: 'wagon-file'
72 | exclude module: 'wagon-http-lightweight'
73 | exclude module: 'wagon-http-shared'
74 | exclude module: 'wagon-provider-api'
75 | exclude module: 'commons-logging'
76 | exclude module: 'httpclient'
77 | exclude group: 'com.google.android'
78 | }
79 | testCompile("org.apache.httpcomponents:httpclient:$HTTP_CLIENT_VERSION")
80 | testCompile("commons-logging:commons-logging:$COMMONS_LOGGING_VERSION")
81 | testCompile("com.google.android:android-test:$ANDROID_VERSION")
82 | testCompile "org.easymock:easymock:$EASY_MOCK_VERSION"
83 | }
84 |
85 | modifyPom {
86 | project {
87 | name "Loglifecycle Gradle Plugin"
88 | description POM_DESCRIPTION
89 | url POM_URL
90 |
91 | scm {
92 | url POM_SCM_URL
93 | connection POM_SCM_CONNECTION
94 | developerConnection POM_SCM_DEV_CONNECTION
95 | }
96 |
97 | licenses {
98 | license {
99 | name POM_LICENCE_NAME
100 | url POM_LICENCE_URL
101 | distribution POM_LICENCE_DIST
102 | }
103 | }
104 |
105 | developers {
106 | developer {
107 | id POM_DEVELOPER_ID
108 | name POM_DEVELOPER_NAME
109 | }
110 | }
111 | }
112 | }
113 |
114 | check.dependsOn test
115 | install.dependsOn check
116 |
117 | //as we want to have non test classes in test source tree
118 | //http://stackoverflow.com/a/14947906/693752
119 | tasks.withType(Test) {
120 | scanForTestClasses = false
121 | include "**/*Test.class"
122 | }
123 |
124 | cobertura.coverageFormats = ['html', 'xml'] // coveralls plugin depends on xml format report
125 | cobertura.auxiliaryClasspath += project.files('../loglifecycle-annotations/build/classes/')
126 | cobertura.coverageIncludes = ['.*com.github.stephanenicolas.loglifecycle.LogLifeCycleProcessor']
127 |
--------------------------------------------------------------------------------
/loglifecycle-plugin/src/test/java/com/github/stephanenicolas/loglifecycle/LogLifeCycleProcessorTest.java:
--------------------------------------------------------------------------------
1 | package com.github.stephanenicolas.loglifecycle;
2 |
3 | import java.util.List;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 |
9 | import android.app.Activity;
10 | import android.app.Fragment;
11 | import android.app.Service;
12 | import android.os.Bundle;
13 | import android.os.IBinder;
14 | import android.view.View;
15 | import android.content.Context;
16 | import android.content.Intent;
17 |
18 | import org.robolectric.shadows.ShadowLog;
19 | import org.junit.runner.RunWith;
20 | import org.robolectric.Robolectric;
21 | import org.robolectric.annotation.Config;
22 |
23 | import static org.junit.Assert.assertNotNull;
24 | import static org.junit.Assert.assertTrue;
25 | import static org.junit.Assert.fail;
26 |
27 | /**
28 | * @author SNI
29 | */
30 | @RunWith(LogLifeCycleTestRunner.class)
31 | @Config(shadows = {ShadowLog.class}, manifest = Config.NONE)
32 | public class LogLifeCycleProcessorTest {
33 |
34 | @Before
35 | public void setup() {
36 | ShadowLog.reset();
37 | }
38 |
39 | @Test
40 | public void shouldLog_activity() {
41 | Robolectric.buildActivity(TestActivity.class).create().start().stop().destroy().get();
42 | List logItems = ShadowLog.getLogsForTag("LogLifeCycle");
43 |
44 | assertNotNull(logItems);
45 | assertLogContainsMessage(logItems, "onCreate");
46 | assertLogContainsMessage(logItems, "onStart");
47 | assertLogContainsMessage(logItems, "onStop");
48 | assertLogContainsMessage(logItems, "onDestroy");
49 | }
50 |
51 | @Test
52 | public void shouldLog_fragment() {
53 | Robolectric.buildActivity(TestActivityWitFragment.class).create().start().stop().destroy().get();
54 | List logItems = ShadowLog.getLogsForTag("LogLifeCycle");
55 |
56 | assertNotNull(logItems);
57 | assertLogContainsMessage(logItems, "onStart");
58 | assertLogContainsMessage(logItems, "onStop");
59 | }
60 |
61 | @Test
62 | public void shouldLog_View() {
63 | Robolectric.buildActivity(TestActivityWitView.class).create().start().get();
64 | List logItems = ShadowLog.getLogsForTag("LogLifeCycle");
65 |
66 | assertNotNull(logItems);
67 | assertLogContainsMessage(logItems, "onFinishInflate");
68 | }
69 |
70 | @Test
71 | public void shouldLog_Service() {
72 | Robolectric.buildService(TestService.class).attach().create().withIntent(null).startCommand(0,1).destroy().get();
73 | List logItems = ShadowLog.getLogsForTag("LogLifeCycle");
74 |
75 | assertNotNull(logItems);
76 | assertLogContainsMessage(logItems, "onCreate");
77 | assertLogContainsMessage(logItems, "onStart");
78 | assertLogContainsMessage(logItems, "onDestroy");
79 | }
80 |
81 | @LogLifeCycle
82 | public static class TestActivity extends Activity {
83 | }
84 |
85 | //do not log activity now, only fragment
86 | public static class TestActivityWitFragment extends Activity {
87 |
88 | public void onCreate(Bundle bundle) {
89 | TestFragment testFragment = new TestFragment();
90 | getFragmentManager().beginTransaction().add(testFragment, "TAG").commit();
91 | }
92 | }
93 |
94 | @LogLifeCycle
95 | public static class TestFragment extends Fragment {
96 | }
97 |
98 | //do not log activity now, only fragment
99 | public static class TestActivityWitView extends Activity {
100 |
101 | public void onCreate(Bundle bundle) {
102 | setContentView(new TestView(this));
103 | }
104 | }
105 |
106 | @LogLifeCycle
107 | public static class TestView extends View {
108 |
109 | public TestView(Context context) {
110 | super(context);
111 | onFinishInflate();
112 | }
113 | }
114 |
115 | @LogLifeCycle
116 | public static class TestService extends Service {
117 | @Override
118 | public IBinder onBind(Intent intent) {
119 | return null;
120 | } }
121 |
122 | private void assertLogContainsMessage(List logItems, String logMessage) {
123 | for(ShadowLog.LogItem logItem : logItems ) {
124 | if (logItem.msg.contains(logMessage)) {
125 | return;
126 | }
127 | }
128 | fail("No message " + logMessage + " in log");
129 | }
130 |
131 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/loglifecycle-plugin/src/main/java/com/github/stephanenicolas/loglifecycle/LogLifeCycleProcessor.java:
--------------------------------------------------------------------------------
1 | package com.github.stephanenicolas.loglifecycle;
2 |
3 | import com.github.stephanenicolas.afterburner.AfterBurner;
4 | import com.github.stephanenicolas.afterburner.exception.AfterBurnerImpossibleException;
5 | import java.util.HashSet;
6 | import java.util.Set;
7 | import javassist.CannotCompileException;
8 | import javassist.ClassPool;
9 | import javassist.CtClass;
10 | import javassist.CtMethod;
11 | import javassist.NotFoundException;
12 | import javassist.build.IClassTransformer;
13 | import javassist.build.JavassistBuildException;
14 | import javassist.bytecode.AccessFlag;
15 | import lombok.extern.slf4j.Slf4j;
16 |
17 | import static com.github.stephanenicolas.morpheus.commons.JavassistUtils.isActivity;
18 | import static com.github.stephanenicolas.morpheus.commons.JavassistUtils.isApplication;
19 | import static com.github.stephanenicolas.morpheus.commons.JavassistUtils.isBroadCastReceiver;
20 | import static com.github.stephanenicolas.morpheus.commons.JavassistUtils.isContentProvider;
21 | import static com.github.stephanenicolas.morpheus.commons.JavassistUtils.isFragment;
22 | import static com.github.stephanenicolas.morpheus.commons.JavassistUtils.isService;
23 | import static com.github.stephanenicolas.morpheus.commons.JavassistUtils.isSupportFragment;
24 | import static com.github.stephanenicolas.morpheus.commons.JavassistUtils.isView;
25 |
26 | /**
27 | * A class transformer to inject logging byte code for all life cycle methods.
28 | *
29 | * @author SNI
30 | */
31 | @Slf4j
32 | public class LogLifeCycleProcessor implements IClassTransformer {
33 |
34 | private AfterBurner afterBurner = new AfterBurner();
35 | private boolean debug;
36 |
37 | public LogLifeCycleProcessor(boolean debug) {
38 | this.debug = debug;
39 | }
40 |
41 | @Override
42 | public boolean shouldTransform(CtClass candidateClass) throws JavassistBuildException {
43 | try {
44 | boolean isSupported = isSupported(candidateClass);
45 | return candidateClass.hasAnnotation(LogLifeCycle.class) && isSupported;
46 | } catch (Exception e) {
47 | logMoreIfDebug("Should transform filter failed for class " + candidateClass.getName(), e);
48 | throw new JavassistBuildException(e);
49 | }
50 | }
51 |
52 | private boolean isSupported(CtClass candidateClass) throws NotFoundException {
53 | return isActivity(candidateClass)
54 | || isFragment(candidateClass)
55 | || isSupportFragment(candidateClass)
56 | || isView(candidateClass)
57 | || isService(candidateClass)
58 | || isBroadCastReceiver(candidateClass)
59 | || isContentProvider(candidateClass)
60 | || isApplication(candidateClass);
61 | }
62 |
63 | @Override
64 | public void applyTransformations(CtClass classToTransform) throws JavassistBuildException {
65 | String classToTransformName = classToTransform.getName();
66 | try {
67 | log.info("Transforming " + classToTransformName);
68 | ClassPool pool = classToTransform.getClassPool();
69 | Set methodSet = getAllLifeCycleMethods(pool, classToTransform.getName());
70 | debugLifeCycleMethods(classToTransform, methodSet.toArray(new CtMethod[methodSet.size()]));
71 | } catch (Exception e) {
72 | logMoreIfDebug("Transformation failed for class " + classToTransformName, e);
73 | throw new JavassistBuildException(e);
74 | }
75 | log.info("Transformation successful for " + classToTransformName);
76 | }
77 |
78 | private Set getAllLifeCycleMethods(ClassPool pool, String className)
79 | throws NotFoundException {
80 | Set methodSet = new HashSet();
81 | CtMethod[] inheritedMethods = pool.get(className).getMethods();
82 | CtMethod[] declaredMethods = pool.get(className).getDeclaredMethods();
83 | for (CtMethod method : inheritedMethods) {
84 | methodSet.add(method);
85 | }
86 | for (CtMethod method : declaredMethods) {
87 | methodSet.add(method);
88 | }
89 | return methodSet;
90 | }
91 |
92 | private void debugLifeCycleMethods(CtClass classToTransform, CtMethod[] methods)
93 | throws CannotCompileException, AfterBurnerImpossibleException, NotFoundException {
94 | for (CtMethod lifeCycleHook : methods) {
95 | String methodName = lifeCycleHook.getName();
96 | String className = classToTransform.getName();
97 |
98 | int accessFlags = lifeCycleHook.getMethodInfo().getAccessFlags();
99 | boolean isFinal = (accessFlags & AccessFlag.FINAL) == AccessFlag.FINAL;
100 | boolean canOverride = !isFinal && (AccessFlag.isPublic(accessFlags)
101 | || AccessFlag.isProtected(accessFlags)
102 | || AccessFlag.isPackage(accessFlags));
103 |
104 | if (canOverride && methodName.startsWith("on")) {
105 | log.info("Overriding " + methodName);
106 | try {
107 |
108 | String body = "android.util.Log.d(\"LogLifeCycle\", \""
109 | + className
110 | + " [\" + System.identityHashCode(this) + \"] \u27F3 "
111 | + methodName
112 | + "\");";
113 | afterBurner.afterOverrideMethod(classToTransform, methodName, body);
114 | log.info("Override successful " + methodName);
115 | } catch (Exception e) {
116 | logMoreIfDebug("Override didn't work ", e);
117 | }
118 | } else {
119 | log.info(
120 | "Skipping " + methodName + ". Either it is final, private or doesn't start by 'on...'");
121 | }
122 | }
123 | }
124 |
125 | private void logMoreIfDebug(String message, Exception e) {
126 | if (debug) {
127 | log.debug(message, e);
128 | } else {
129 | log.info(message);
130 | }
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/loglifecycle-plugin/maven_3rd_party/org/robolectric/robolectric/2.4.SNI/robolectric-2.4.SNI.pom:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.sonatype.oss
7 | oss-parent
8 | 7
9 |
10 |
11 | org.robolectric
12 | robolectric
13 | 2.4.SNI
14 | jar
15 | Robolectric
16 | An alternative Android testing framework.
17 | http://robolectric.org/
18 |
19 |
20 | 0.282-3
21 |
22 |
23 |
24 |
25 | junit
26 | junit-dep
27 | 4.8.2
28 | provided
29 |
30 |
31 |
32 | org.objenesis
33 | objenesis
34 | 1.3
35 |
36 |
37 |
38 | com.almworks.sqlite4java
39 | sqlite4java
40 | 0.282
41 |
42 |
43 |
44 |
45 | com.github.axet.litedb
46 | libsqlite
47 | ${libsqlite.version}
48 | natives-windows-x86
49 | provided
50 |
51 |
52 |
53 | com.github.axet.litedb
54 | libsqlite
55 | ${libsqlite.version}
56 | natives-windows-x86_64
57 | provided
58 |
59 |
60 |
61 | com.github.axet.litedb
62 | libsqlite
63 | ${libsqlite.version}
64 | natives-mac-x86_64
65 | provided
66 |
67 |
68 |
69 | com.github.axet.litedb
70 | libsqlite
71 | ${libsqlite.version}
72 | natives-linux-x86
73 | provided
74 |
75 |
76 |
77 | com.github.axet.litedb
78 | libsqlite
79 | natives-linux-x86_64
80 | ${libsqlite.version}
81 | provided
82 |
83 |
84 |
85 | org.ow2.asm
86 | asm
87 | 5.0.1
88 |
89 |
90 |
91 | org.ow2.asm
92 | asm-commons
93 | 5.0.1
94 |
95 |
96 |
97 | org.ow2.asm
98 | asm-util
99 | 5.0.1
100 |
101 |
102 |
103 | org.ow2.asm
104 | asm-analysis
105 | 5.0.1
106 |
107 |
108 |
109 | commons-logging
110 | commons-logging
111 | 1.1.1
112 |
113 |
114 |
115 | commons-codec
116 | commons-codec
117 | 1.3
118 |
119 |
120 |
121 | org.apache.httpcomponents
122 | httpclient
123 | 4.0.3
124 |
125 |
126 |
127 | com.ximpleware
128 | vtd-xml
129 | 2.11
130 |
131 |
132 |
133 | org.robolectric
134 | android-all
135 | 4.3_r2-robolectric-0
136 | provided
137 |
138 |
139 |
140 | com.google.android.maps
141 | maps
142 | 18_r3
143 | provided
144 |
145 |
146 |
147 | com.android.support
148 | support-v4
149 | 19.0.1
150 | compile
151 | true
152 |
153 |
154 |
155 | org.easytesting
156 | fest-util
157 | 1.2.5
158 |
159 |
160 |
161 | org.easytesting
162 | fest-reflect
163 | 1.4.1
164 |
165 |
166 |
167 | org.easytesting
168 | fest-util
169 |
170 |
171 |
172 |
173 |
174 | org.easytesting
175 | fest-assert-core
176 | 2.0M10
177 | test
178 |
179 |
180 |
181 | org.mockito
182 | mockito-core
183 | 1.9.5
184 | test
185 |
186 |
187 |
188 | com.intellij
189 | annotations
190 | 12.0
191 | provided
192 |
193 |
194 |
195 | org.apache.maven
196 | maven-ant-tasks
197 | 2.1.3
198 |
200 |
201 |
202 | *
203 | *
204 |
205 |
206 |
207 |
208 | org.apache.ant
209 | ant
210 | 1.8.0
211 |
212 |
213 |
214 |
215 |
216 |
217 | target/natives
218 |
219 |
220 |
221 |
222 |
223 | maven-compiler-plugin
224 | 2.3.2
225 |
226 | 1.6
227 | 1.6
228 |
229 |
230 |
231 |
232 | org.apache.maven.plugins
233 | maven-surefire-plugin
234 | 2.13
235 |
236 |
237 | **/Test*.java
238 |
239 | -Xms512m -Xmx1024m -XX:MaxPermSize=256m
240 |
241 |
242 |
243 |
244 | maven-assembly-plugin
245 | 2.2
246 |
247 |
248 | jar-with-dependencies
249 |
250 |
251 |
252 |
253 | make-assembly
254 | package
255 |
256 | single
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 | org.apache.maven.plugins
265 | maven-jar-plugin
266 | 2.3.1
267 |
268 |
269 |
270 | test-jar
271 |
272 |
273 |
274 |
275 |
276 |
277 | com.googlecode.mavennatives
278 | maven-nativedependencies-plugin
279 | 0.0.7
280 |
281 |
282 | unpacknatives
283 | generate-resources
284 |
285 | copy
286 |
287 |
288 |
289 |
290 | true
291 |
292 |
293 |
294 |
295 | maven-clean-plugin
296 | 2.4.1
297 |
298 |
299 |
300 | tmp
301 |
302 | *
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 | git@github.com:robolectric/robolectric.git
313 | scm:git:git://github.com/robolectric/robolectric.git
314 | scm:git:https://github.com/robolectric/robolectric.git
315 |
316 |
317 |
318 | Travis CI
319 | http://travis-ci.org/robolectric/robolectric
320 |
321 |
322 |
323 |
324 | xian
325 | Christian Williams
326 | xian@squareup.com
327 | Square, Inc.
328 | http://corner.squareup.com/
329 |
330 | Principal Developer
331 |
332 | PST/PDT
333 |
334 |
335 | tyler
336 | Tyler Schultz
337 | tyler@pivotallabs.com
338 | Pivotal Labs
339 | http://pivotallabs.com/
340 |
341 | Developer
342 |
343 | PST/PDT
344 |
345 |
346 | phil
347 | Phil Goodwin
348 | phil@pivotallabs.com
349 | Pivotal Labs
350 | http://pivotallabs.com/
351 |
352 | Developer
353 |
354 | PST/PDT
355 |
356 |
357 |
358 |
359 |
360 | User List
361 | robolectric@googlegroups.com
362 | http://groups.google.com/group/robolectric
363 |
364 |
365 |
366 |
367 |
368 | MIT license
369 |
370 | The MIT License
371 |
372 | Copyright (c) 2010 Xtreme Labs and Pivotal Labs
373 |
374 | Permission is hereby granted, free of charge, to any person obtaining a copy
375 | of this software and associated documentation files (the "Software"), to deal
376 | in the Software without restriction, including without limitation the rights
377 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
378 | copies of the Software, and to permit persons to whom the Software is
379 | furnished to do so, subject to the following conditions:
380 |
381 | The above copyright notice and this permission notice shall be included in
382 | all copies or substantial portions of the Software.
383 |
384 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
385 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
386 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
387 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
388 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
389 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
390 | THE SOFTWARE.
391 |
392 |
393 |
394 |
395 |
--------------------------------------------------------------------------------