Skip to content

Commit

Permalink
Merge pull request #52 from chenenyu/dev
Browse files Browse the repository at this point in the history
1.2.5.1
  • Loading branch information
chenenyu committed Sep 12, 2017
2 parents 897444e + a36f585 commit 290b92c
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 49 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2017.09.12

`router-gradle-plugin: 1.2.5.1`:

Bug fix for [issues51](https://github.com/chenenyu/Router/issues/51) in `1.2.5`.

## 2017.09.08

`router: 1.2.5`:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Router

建议浏览[中文wiki](https://github.com/chenenyu/Router/wiki).
建议浏览[中文wiki](https://github.com/chenenyu/Router/wiki). It's better than you think.

![screenshot](static/screenshot.gif)

Expand Down
5 changes: 5 additions & 0 deletions Sample/app/src/main/java/com/chenenyu/router/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ public void onCreate() {
if (BuildConfig.DEBUG) {
Router.setDebuggable(true);
}

// The next comment line show how to process aar module.
// AptHub.registerModules("your-aar-module-name");

// init
Router.initialize(this);

Router.addGlobalInterceptor(new GlobalInterceptor());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.chenenyu.router.app;

import android.content.Context;
import android.util.Log;

import com.chenenyu.router.RouteInterceptor;
import com.chenenyu.router.RouteRequest;

/**
* Global interceptor.
* <p>
* Created by chenenyu on 2017/9/11.
*/
public class GlobalInterceptor implements RouteInterceptor {
@Override
public boolean intercept(Context context, RouteRequest routeRequest) {
Log.d("GlobalInterceptor", String.format("Intercepted: {uri: %s, interceptor: %s}",
routeRequest.getUri().toString(), GlobalInterceptor.class.getName()));
return false;
}
}
2 changes: 1 addition & 1 deletion VERSION.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# router gradle plugin version
GRADLE_PLUGIN_VERSION=1.2.5
GRADLE_PLUGIN_VERSION=1.2.5.1
# router library version
ROUTER_VERSION=1.2.5
# compiler library version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@ import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

/**
* Generate a java file to record all the modules.
* <p>
* Created by Cheney on 2017/3/1.
* Created by chenenyu on 2017/3/1.
*/
class GenerateBuildInfoTask extends DefaultTask {
static final String BUILD_INFO_NAME = "RouterBuildInfo.java"

File routerFolder
File buildInfoFile
String buildInfoContent
final String buildInfoName = "RouterBuildInfo.java"

GenerateBuildInfoTask() {
group = 'router'
}

@TaskAction
void generate() {
project.logger.error(">>> ${project.name}: Generate ${BUILD_INFO_NAME} begin...")

if (!routerFolder.exists()) {
routerFolder.mkdirs()
}
routerFolder = new File(routerFolder, "com" + File.separator + "chenenyu" + File.separator + "router")
routerFolder.mkdirs()
buildInfoFile = new File(routerFolder, buildInfoName)
buildInfoFile = new File(routerFolder, BUILD_INFO_NAME)
if (!buildInfoFile.exists()) {
buildInfoFile.createNewFile()
}
Expand All @@ -33,6 +37,10 @@ class GenerateBuildInfoTask extends DefaultTask {
pw.print(buildInfoContent)
pw.flush()
pw.close()

println(buildInfoContent)

project.logger.error("${project.name}: Generate ${BUILD_INFO_NAME} end. <<<")
}

}
83 changes: 39 additions & 44 deletions buildSrc/src/main/groovy/com/chenenyu/router/RouterPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import org.gradle.api.Task
import org.gradle.api.plugins.ExtraPropertiesExtension

/**
* Router gradle plugin.
* <p>
* Created by Cheney on 2017/1/10.
* Created by chenenyu on 2017/1/10.
*/
class RouterPlugin implements Plugin<Project> {
static final String APP = "com.android.application"
Expand All @@ -21,20 +22,21 @@ class RouterPlugin implements Plugin<Project> {
'Router gradle plugin can only be applied to android projects.')
}

def isKotlinProject = project.plugins.hasPlugin('kotlin-android')
if (isKotlinProject) {
if (!project.plugins.hasPlugin('kotlin-kapt')) {
project.plugins.apply('kotlin-kapt')
}
}

// Add annotationProcessorOptions
def android = project.extensions.android // BaseExtension
android.defaultConfig.javaCompileOptions.annotationProcessorOptions.argument(APT_OPTION_NAME, project.name)
android.productFlavors.all {
it.javaCompileOptions.annotationProcessorOptions.argument(APT_OPTION_NAME, project.name)
}

// Kotlin project ?
def isKotlinProject = project.plugins.hasPlugin('kotlin-android')
if (isKotlinProject) {
if (!project.plugins.hasPlugin('kotlin-kapt')) {
project.plugins.apply('kotlin-kapt')
}
}

// Add dependencies
Project router = project.rootProject.findProject("router")
Project routerCompiler = project.rootProject.findProject("compiler")
Expand Down Expand Up @@ -71,47 +73,40 @@ class RouterPlugin implements Plugin<Project> {
project.dependencies.add(apt, "com.chenenyu.router:compiler:${compilerVersion}")
}

project.afterEvaluate {
project.rootProject.subprojects.each {
if (it.plugins.hasPlugin(APP) && !it.plugins.hasPlugin(RouterPlugin)) {
project.logger.error("Have you forgotten to apply plugin: 'com.chenenyu.router'" +
" in module: '${it.name}'?")
}
}

if (project.plugins.hasPlugin(APP)) {
if (project.plugins.hasPlugin(APP)) {
// Read template in advance, it can't be read in GenerateBuildInfoTask.
InputStream is = RouterPlugin.class.getResourceAsStream("/RouterBuildInfo.template")
String template
new Scanner(is).with {
template = it.useDelimiter("\\A").next()
}
File routerFolder = new File(project.buildDir,
"generated" + File.separator + "source" + File.separator + "router")

// Read template in advance, it can't be read in GenerateBuildInfoTask.
InputStream is = RouterPlugin.class.getResourceAsStream("/RouterBuildInfo.template")
String template
new Scanner(is).with {
template = it.useDelimiter("\\A").next()
project.afterEvaluate {
// Record router modules' name, include library and app modules.
StringBuilder sb = new StringBuilder()
Set<Project> subs = project.rootProject.subprojects
subs.findAll {
it.plugins.hasPlugin(LIBRARY) && it.plugins.hasPlugin(RouterPlugin)
}.each {
sb.append(validateName(it.name)).append(",") // library
}
File routerFolder = new File(project.buildDir,
"generated" + File.separator + "source" + File.separator + "router")

project.gradle.projectsEvaluated {
// Record router modules' name, include library and app modules.
StringBuilder sb = new StringBuilder()
Set<Project> subs = project.rootProject.subprojects
subs.findAll {
it.plugins.hasPlugin(LIBRARY) && it.plugins.hasPlugin(RouterPlugin)
}.each {
sb.append(validateName(it.name)).append(",") // library
}
sb.append(validateName(project.name)) // app
sb.append(validateName(project.name)) // app

project.android.applicationVariants.all { variant ->
// Create task
Task generateTask = project.tasks.create(
"generate${variant.name.capitalize()}BuildInfo", GenerateBuildInfoTask) {
it.routerFolder = routerFolder
it.buildInfoContent = template.replaceAll("%ALL_MODULES%", sb.toString())
}
// Add generated file to javac source
variant.javaCompile.source(routerFolder)
variant.javaCompile.dependsOn generateTask
android.applicationVariants.all { variant ->
// Create task
Task generateTask = project.tasks.create(
"generate${variant.name.capitalize()}BuildInfo", GenerateBuildInfoTask) {
it.routerFolder = routerFolder
it.buildInfoContent = template.replaceAll("%ALL_MODULES%", sb.toString())
}
// Add generated file to javac source
Task javac = variant.javaCompile
javac.source(routerFolder)
generateTask.dependsOn javac.taskDependencies.getDependencies(javac)
javac.dependsOn generateTask
}
}
}
Expand Down

0 comments on commit 290b92c

Please sign in to comment.