diff --git a/app/build.gradle b/app/build.gradle index 7a4ece4..473eed1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,8 +1,5 @@ -import org.aspectj.bridge.IMessage -import org.aspectj.bridge.MessageHandler -import org.aspectj.tools.ajc.Main - apply plugin: 'com.android.application' +apply plugin: 'uiblock-plugin' android { compileSdkVersion 23 @@ -25,54 +22,10 @@ android { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:23.1.1' - - compile 'com.jakewharton:butterknife:7.0.1' + compile 'com.android.support:appcompat-v7:23.3.0' debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3' compile project(':lib') -} - -final def log = project.logger - -android.applicationVariants.all { variant -> - if (!variant.buildType.isDebuggable()) { - log.debug("Skipping non-debuggable build type '${variant.buildType.name}'.") - return; - } - - JavaCompile javaCompile = variant.javaCompile - javaCompile.doLast { - String[] args = ["-showWeaveInfo", - "-1.5", - "-inpath", javaCompile.destinationDir.toString(), - "-aspectpath", javaCompile.classpath.asPath, - "-d", javaCompile.destinationDir.toString(), - "-classpath", javaCompile.classpath.asPath, - "-bootclasspath", project.android.bootClasspath.join(File.pathSeparator)] - log.debug "ajc args: " + Arrays.toString(args) - - MessageHandler handler = new MessageHandler(true); - new Main().run(args, handler); - for (IMessage message : handler.getMessages(null, true)) { - switch (message.getKind()) { - case IMessage.ABORT: - case IMessage.ERROR: - case IMessage.FAIL: - log.error message.message, message.thrown - break; - case IMessage.WARNING: - log.warn message.message, message.thrown - break; - case IMessage.INFO: - log.info message.message, message.thrown - break; - case IMessage.DEBUG: - log.debug message.message, message.thrown - break; - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/kale/ui/block/DemoTopUiBlock.java b/app/src/main/java/kale/ui/block/DemoTopUiBlock.java index b8c98fd..1443c63 100644 --- a/app/src/main/java/kale/ui/block/DemoTopUiBlock.java +++ b/app/src/main/java/kale/ui/block/DemoTopUiBlock.java @@ -3,8 +3,6 @@ import android.view.View; import android.widget.TextView; -import butterknife.Bind; -import butterknife.ButterKnife; import kale.ui.R; import kale.ui.uiblock.UiBlock; @@ -14,7 +12,6 @@ */ public class DemoTopUiBlock extends UiBlock { - @Bind(R.id.top_tv) TextView mTopTv; @Override @@ -24,7 +21,7 @@ protected int getLayoutResId() { @Override public void bindViews(View rootView) { - ButterKnife.bind(this, getRootView()); + mTopTv = getView(R.id.top_tv); } @Override diff --git a/build.gradle b/build.gradle index 225dfd7..50aba56 100644 --- a/build.gradle +++ b/build.gradle @@ -3,25 +3,35 @@ buildscript { repositories { jcenter() + maven { + url 'plugin' + } } dependencies { classpath 'com.android.tools.build:gradle:2.1.0-alpha5' classpath 'me.tatarka:gradle-retrolambda:3.2.0'//lambda classpath 'org.aspectj:aspectjtools:1.8.1' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' + + classpath 'com.github.tianzhijiexian:uiblock-gradle-plugin:1.0.0' } } allprojects { repositories { jcenter() + maven { + url 'plugin' + } } } -/* task clean(type: Delete) { delete rootProject.buildDir } -*/ + +apply plugin: 'groovy' + +dependencies { + compile localGroovy() +} \ No newline at end of file diff --git a/lib/build.gradle b/lib/build.gradle index 492a4f1..dafdf2d 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -1,8 +1,3 @@ -import com.android.build.gradle.LibraryPlugin -import org.aspectj.bridge.IMessage -import org.aspectj.bridge.MessageHandler -import org.aspectj.tools.ajc.Main - apply plugin: 'com.android.library' apply plugin: 'me.tatarka.retrolambda' @@ -13,10 +8,15 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 23 - versionCode 2 - versionName "1.0.1" } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + compileOptions { encoding "UTF-8" sourceCompatibility JavaVersion.VERSION_1_8 @@ -25,13 +25,19 @@ android { } dependencies { - // compile 'com.android.support:support-annotations:23.1.0' provided 'com.android.support:appcompat-v7:23.1.1' provided "org.projectlombok:lombok:1.12.6" compile 'org.aspectj:aspectjrt:1.8.1' } +import com.android.build.gradle.LibraryPlugin +import org.aspectj.bridge.IMessage +import org.aspectj.bridge.MessageHandler +import org.aspectj.tools.ajc.Main + +final def log = project.logger + android.libraryVariants.all { variant -> LibraryPlugin plugin = project.plugins.getPlugin(LibraryPlugin) JavaCompile javaCompile = variant.javaCompile @@ -46,6 +52,24 @@ android.libraryVariants.all { variant -> File.pathSeparator)] MessageHandler handler = new MessageHandler(true); - new Main().run(args, handler) + new Main().run(args, handler); + for (IMessage message : handler.getMessages(null, true)) { + switch (message.getKind()) { + case IMessage.ABORT: + case IMessage.ERROR: + case IMessage.FAIL: + log.error message.message, message.thrown + break; + case IMessage.WARNING: + log.warn message.message, message.thrown + break; + case IMessage.INFO: + log.info message.message, message.thrown + break; + case IMessage.DEBUG: + log.debug message.message, message.thrown + break; + } + } } } \ No newline at end of file diff --git a/lib/proguard-rules.pro b/lib/proguard-rules.pro new file mode 100644 index 0000000..648d8a5 --- /dev/null +++ b/lib/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in H:\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.jar b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.jar new file mode 100644 index 0000000..248893f Binary files /dev/null and b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.jar differ diff --git a/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.jar.md5 b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.jar.md5 new file mode 100644 index 0000000..94bc3d8 --- /dev/null +++ b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.jar.md5 @@ -0,0 +1 @@ +761b97311948ac9610415ee9d192e932 \ No newline at end of file diff --git a/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.jar.sha1 b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.jar.sha1 new file mode 100644 index 0000000..f4d0ea1 --- /dev/null +++ b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.jar.sha1 @@ -0,0 +1 @@ +a394d8b20af0f169b92b811eef11b35ce5eb4af0 \ No newline at end of file diff --git a/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.pom b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.pom new file mode 100644 index 0000000..0d17b9a --- /dev/null +++ b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.pom @@ -0,0 +1,28 @@ + + + 4.0.0 + com.github.tianzhijiexian + uiblock-gradle-plugin + 1.0.0 + + + com.android.tools.build + gradle + 1.3.1 + compile + + + org.aspectj + aspectjrt + 1.8.6 + compile + + + org.aspectj + aspectjtools + 1.8.6 + compile + + + diff --git a/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.pom.md5 b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.pom.md5 new file mode 100644 index 0000000..317a0e8 --- /dev/null +++ b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.pom.md5 @@ -0,0 +1 @@ +f594416dd96f1b760d4c478422274bff \ No newline at end of file diff --git a/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.pom.sha1 b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.pom.sha1 new file mode 100644 index 0000000..72ebec0 --- /dev/null +++ b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/1.0.0/uiblock-gradle-plugin-1.0.0.pom.sha1 @@ -0,0 +1 @@ +779ad489394ceaf9fbd8cc3a8ad4a10efa1e0580 \ No newline at end of file diff --git a/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/maven-metadata.xml b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/maven-metadata.xml new file mode 100644 index 0000000..133bf5d --- /dev/null +++ b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/maven-metadata.xml @@ -0,0 +1,12 @@ + + + com.github.tianzhijiexian + uiblock-gradle-plugin + + 1.0.0 + + 1.0.0 + + 20160409092959 + + diff --git a/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/maven-metadata.xml.md5 b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/maven-metadata.xml.md5 new file mode 100644 index 0000000..0e3691c --- /dev/null +++ b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/maven-metadata.xml.md5 @@ -0,0 +1 @@ +c0cc2c474f69081c19da3d9b674da176 \ No newline at end of file diff --git a/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/maven-metadata.xml.sha1 b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/maven-metadata.xml.sha1 new file mode 100644 index 0000000..cc2fed4 --- /dev/null +++ b/plugin/com/github/tianzhijiexian/uiblock-gradle-plugin/maven-metadata.xml.sha1 @@ -0,0 +1 @@ +cb013835d336dd535ebd2b4c70835bcd2cda0860 \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 3cbe249..4723490 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':lib' +include ':app', ':lib', ':uiblock-plugin' diff --git a/uiblock-plugin/.gitignore b/uiblock-plugin/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/uiblock-plugin/.gitignore @@ -0,0 +1 @@ +/build diff --git a/uiblock-plugin/build.gradle b/uiblock-plugin/build.gradle new file mode 100644 index 0000000..784fd42 --- /dev/null +++ b/uiblock-plugin/build.gradle @@ -0,0 +1,56 @@ +apply plugin: 'groovy' + +targetCompatibility = JavaVersion.VERSION_1_7 +sourceCompatibility = JavaVersion.VERSION_1_7 + +dependencies { + compile gradleApi() + compile localGroovy() + compile 'com.android.tools.build:gradle:1.3.1' + compile 'org.aspectj:aspectjtools:1.8.6' + compile 'org.aspectj:aspectjrt:1.8.6' + compile files('libs/proguard.jar') +} + +apply plugin: 'maven' + +version = '1.0.0' +group = 'com.github.tianzhijiexian' +archivesBaseName = 'uiblock-gradle-plugin' + +repositories { + mavenCentral() +} + +compileGroovy { + options.encoding = "UTF-8" +} + +uploadArchives { + repositories.mavenDeployer { + repository(url: 'file:../plugin/') + } +} + +/* +apply plugin: 'com.github.dcendents.android-maven' // ADD THIS + +task pluginJavadocs(type: Groovydoc) { + source = sourceSets.main.groovy.srcDirs + classpath = sourceSets.main.compileClasspath +} + +task pluginJavadocsJar(type: Jar, dependsOn: pluginJavadocs) { + classifier = 'javadoc' + from pluginJavadocs.destinationDir +} + +task pluginSourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allGroovy +} + +artifacts { + archives pluginSourcesJar + archives pluginJavadocsJar +}*/ diff --git a/uiblock-plugin/src/main/groovy/kale.ui.uiblock.plugin/AspectPlugin.groovy b/uiblock-plugin/src/main/groovy/kale.ui.uiblock.plugin/AspectPlugin.groovy new file mode 100644 index 0000000..63e801e --- /dev/null +++ b/uiblock-plugin/src/main/groovy/kale.ui.uiblock.plugin/AspectPlugin.groovy @@ -0,0 +1,74 @@ +package kale.ui.uiblock.plugin + +import com.android.build.gradle.AppPlugin +import com.android.build.gradle.LibraryPlugin +import org.aspectj.bridge.IMessage +import org.aspectj.bridge.MessageHandler +import org.aspectj.tools.ajc.Main +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.tasks.compile.JavaCompile + +class AspectPlugin implements Plugin { + + @Override + void apply(Project project) { + def hasApp = project.plugins.withType(AppPlugin) + def hasLib = project.plugins.withType(LibraryPlugin) + + if (!hasApp && !hasLib) { + throw new IllegalStateException("'android' or 'android-library' plugin required.") + } + + final def log = project.logger + final def variants + if (hasApp) { + variants = project.android.applicationVariants + } else { + variants = project.android.libraryVariants + } + + variants.all { variant -> + if (!variant.buildType.isDebuggable()) { + log.debug("Skipping non-debuggable build type '${variant.buildType.name}'.") + return; + } + + JavaCompile javaCompile = variant.javaCompile + javaCompile.doLast { + String[] args = [ + "-showWeaveInfo", + "-1.5", + "-inpath", javaCompile.destinationDir.toString(), + "-aspectpath", javaCompile.classpath.asPath, + "-d", javaCompile.destinationDir.toString(), + "-classpath", javaCompile.classpath.asPath, + "-bootclasspath", project.android.bootClasspath.join(File.pathSeparator) + ] + + log.debug "ajc args: " + Arrays.toString(args) + + MessageHandler handler = new MessageHandler(true); + new Main().run(args, handler); + for (IMessage message : handler.getMessages(null, true)) { + switch (message.getKind()) { + case IMessage.ABORT: + case IMessage.ERROR: + case IMessage.FAIL: + log.error message.message, message.thrown + break; + case IMessage.WARNING: + log.warn message.message, message.thrown + break; + case IMessage.INFO: + log.info message.message, message.thrown + break; + case IMessage.DEBUG: + log.debug message.message, message.thrown + break; + } + } + } + } + } +} \ No newline at end of file diff --git a/uiblock-plugin/src/main/resources/META-INF/gradle-plugins/uiblock-plugin.properties b/uiblock-plugin/src/main/resources/META-INF/gradle-plugins/uiblock-plugin.properties new file mode 100644 index 0000000..9e931e5 --- /dev/null +++ b/uiblock-plugin/src/main/resources/META-INF/gradle-plugins/uiblock-plugin.properties @@ -0,0 +1 @@ +implementation-class = kale.ui.uiblock.plugin.AspectPlugin \ No newline at end of file