Skip to content

Commit

Permalink
完成了UiBlock的gradle插件
Browse files Browse the repository at this point in the history
  • Loading branch information
kale committed Apr 9, 2016
1 parent feae1de commit f2c4072
Show file tree
Hide file tree
Showing 19 changed files with 247 additions and 68 deletions.
51 changes: 2 additions & 49 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
}
}
}
5 changes: 1 addition & 4 deletions app/src/main/java/kale/ui/block/DemoTopUiBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,7 +12,6 @@
*/
public class DemoTopUiBlock extends UiBlock {

@Bind(R.id.top_tv)
TextView mTopTv;

@Override
Expand All @@ -24,7 +21,7 @@ protected int getLayoutResId() {

@Override
public void bindViews(View rootView) {
ButterKnife.bind(this, getRootView());
mTopTv = getView(R.id.top_tv);
}

@Override
Expand Down
20 changes: 15 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
42 changes: 33 additions & 9 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
}
}
}
}
17 changes: 17 additions & 0 deletions lib/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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 *;
#}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
761b97311948ac9610415ee9d192e932
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a394d8b20af0f169b92b811eef11b35ce5eb4af0
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.tianzhijiexian</groupId>
<artifactId>uiblock-gradle-plugin</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>gradle</artifactId>
<version>1.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.6</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f594416dd96f1b760d4c478422274bff
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
779ad489394ceaf9fbd8cc3a8ad4a10efa1e0580
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.github.tianzhijiexian</groupId>
<artifactId>uiblock-gradle-plugin</artifactId>
<versioning>
<release>1.0.0</release>
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20160409092959</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c0cc2c474f69081c19da3d9b674da176
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cb013835d336dd535ebd2b4c70835bcd2cda0860
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':lib'
include ':app', ':lib', ':uiblock-plugin'
1 change: 1 addition & 0 deletions uiblock-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
56 changes: 56 additions & 0 deletions uiblock-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}*/
Loading

0 comments on commit f2c4072

Please sign in to comment.