Skip to content

Commit

Permalink
#23 add annotation to escape auto register sub component
Browse files Browse the repository at this point in the history
  • Loading branch information
leobert-lan committed May 10, 2018
1 parent a4259f5 commit a613b91
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 28 deletions.
59 changes: 59 additions & 0 deletions jimu-core/bintrayv1.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
apply plugin: 'com.jfrog.bintray'

version = libraryVersion

if (project.hasProperty("android")) { // Android libraries
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
} else { // Java libraries
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives javadocJar
archives sourcesJar
}

// Bintray
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")

configurations = ['archives']
pkg {
repo = bintrayRepo
name = bintrayName
desc = libraryDescription
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = allLicenses
publish = true
publicDownloadNumbers = true
version {
desc = libraryDescription
gpg {
sign = true //Determines whether to GPG sign the files. The default is false
passphrase = properties.getProperty("bintray.gpg.password")
//Optional. The passphrase for GPG signing'
}
}
}
}
6 changes: 3 additions & 3 deletions jimu-core/build-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'groovy'

def MAVEN_LOCAL_PATH = uri('../../local_repo')
def ARTIFACT_ID = 'build-gradle'
def VERSION_NAME = '1.2.1'
def VERSION_NAME = '1.2.5'
def GROUP_ID = 'com.github.jimu'

ext {
Expand All @@ -17,8 +17,8 @@ ext {
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
apply from: '../installv1.gradle'
apply from: '../bintrayv1.gradle'

dependencies {
compile 'com.android.tools.build:gradle:2.3.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class ComCodeTransform extends Transform {
}
}
for (CtClass ctClass : applications) {
System.out.println("application is " + ctClass.getName())
System.out.println("Application is " + ctClass.getName())
}
for (CtClass ctClass : activators) {
System.out.println("applicationlike is " + ctClass.getName())
System.out.println("ApplicationLike will be auto register: " + ctClass.getName())
}

transformInvocation.inputs.each { TransformInput input ->
Expand All @@ -67,6 +67,18 @@ class ComCodeTransform extends Transform {
//对类型为“文件夹”的input进行遍历
input.directoryInputs.each { DirectoryInput directoryInput ->
boolean isRegisterCompoAuto = project.extensions.combuild.isRegisterCompoAuto

System.out.println(">>>")
System.out.println(">>>")
System.out.println(">>>")
System.out.println(">>>")

System.out.println("check isRegisterCompoAuto: "
+ directoryInput.file.getPath()
+ " ; isRegisterCompoAuto:"
+ isRegisterCompoAuto)


if (isRegisterCompoAuto) {
String fileName = directoryInput.file.absolutePath
File dir = new File(fileName)
Expand All @@ -83,6 +95,7 @@ class ComCodeTransform extends Transform {
}
}
}

def dest = transformInvocation.outputProvider.getContentLocation(directoryInput.name,
directoryInput.contentTypes,
directoryInput.scopes, Format.DIRECTORY)
Expand All @@ -108,15 +121,17 @@ class ComCodeTransform extends Transform {
CtMethod attachBaseContextMethod = ctClassApplication.getDeclaredMethod("onCreate", null)
attachBaseContextMethod.insertAfter(getAutoLoadComCode(activators))
} catch (CannotCompileException | NotFoundException e) {

System.out.println("could not found onCreate in Application; " + e.toString())

StringBuilder methodBody = new StringBuilder()
methodBody.append("protected void onCreate() {")
methodBody.append("super.onCreate();")
methodBody.
append(getAutoLoadComCode(activators))
methodBody.append(getAutoLoadComCode(activators))
methodBody.append("}")
ctClassApplication.addMethod(CtMethod.make(methodBody.toString(), ctClassApplication))
} catch (Exception e) {

System.out.println("could not create onCreate() in Application; " + e.toString())
}
ctClassApplication.writeFile(patch)
ctClassApplication.detach()
Expand Down Expand Up @@ -145,15 +160,24 @@ class ComCodeTransform extends Transform {
return false
}

/**
* check if the class is implement of IApplication and isRegisterCompoAuto
* @param ctClass target class to be checked
* @return true if impl& isRegisterCompoAuto
*/
private boolean isActivator(CtClass ctClass) {
try {
for (CtClass ctClassInter : ctClass.getInterfaces()) {
if ("com.luojilab.component.componentlib.applicationlike.IApplicationLike".equals(ctClassInter.name)) {
return true
// todo judge isRegisterCompoAuto
boolean hasManualNotation = ctClass.hasAnnotation(Class.forName("com.luojilab.component.componentlib.applicationlike.RegisterCompManual"))
// return true
System.out.println(">>>> " + ctClass + " manual register?" + hasManualNotation)
return !hasManualNotation
}
}
} catch (Exception e) {
println "class not found exception class name: " + ctClass.getName()
println "isActivator got exception :" + ctClass.getName() + " ; " + e.toString()
}

return false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.luojilab.component.componentlib.applicationlike;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* <p><b>Package:</b> com.dd.buildgradle.exten </p>
* <p><b>Project:</b> jimu-core </p>
* <p><b>Classname:</b> RegisterCompManual </p>
* <p><b>Description:</b> annotate the Applike with this annotation
* represent to register it manual.
* it will never auto register </p>
* Created by leobert on 2018/5/10.
*/
@Retention(RetentionPolicy.CLASS)
public @interface RegisterCompManual {
}
6 changes: 3 additions & 3 deletions jimu-core/componentlib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ targetCompatibility = "1.7"

def MAVEN_LOCAL_PATH = uri('../../local_repo')
def ARTIFACT_ID = 'componentlib'
def VERSION_NAME = '1.3.1'
def VERSION_NAME = '1.3.2'
def GROUP_ID = 'com.github.jimu'

ext {
Expand Down Expand Up @@ -57,8 +57,8 @@ dependencies {
}


apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
apply from: '../installv1.gradle'
apply from: '../bintrayv1.gradle'

uploadArchives() {
repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.luojilab.component.componentlib.applicationlike;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* <p><b>Package:</b> com.dd.buildgradle.exten </p>
* <p><b>Project:</b> jimu-core </p>
* <p><b>Classname:</b> RegisterCompManual </p>
* <p><b>Description:</b> annotate the Applike with this annotation
* represent to register it manual.
* it will never auto register </p>
* Created by leobert on 2018/5/10.
*/
@Retention(RetentionPolicy.CLASS)
public @interface RegisterCompManual {
}
42 changes: 42 additions & 0 deletions jimu-core/installv1.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apply plugin: 'com.github.dcendents.android-maven'

group = publishedGroupId // Maven Group ID for the artifact

install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'
groupId publishedGroupId
artifactId artifact

// Add your description here
name libraryName
description libraryDescription
url siteUrl

// Set your license
licenses {
license {
name licenseName
url licenseUrl
}
}
developers {
developer {
id developerId
name developerName
email developerEmail
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl

}
}
}
}
}
4 changes: 2 additions & 2 deletions jimu-core/router-anno-compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ ext {
allLicenses = ["Apache-2.0"]
}

apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
apply from: '../installv1.gradle'
apply from: '../bintrayv1.gradle'

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
Expand Down
4 changes: 2 additions & 2 deletions jimu-core/router-annotation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ compileJava {
targetCompatibility = '1.7'
}

apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
apply from: '../installv1.gradle'
apply from: '../bintrayv1.gradle'

uploadArchives() {
repositories {
Expand Down
20 changes: 10 additions & 10 deletions jimu-sample-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ buildscript {
],

jimu : [
'componentLib' : 'com.github.jimu:componentlib:1.3.1',
'componentLib' : 'com.github.jimu:componentlib:1.3.2',
'router_anno' : 'com.github.jimu:router-annotation:1.0.1',
'router_anno_compiler': 'com.github.jimu:router-anno-compiler:1.0.1',
'gradle_plugin' : 'com.github.jimu:build-gradle:1.2.1'
'gradle_plugin' : 'com.github.jimu:build-gradle:1.2.5'
],

gson : 'com.google.code.gson:gson:2.8.2',
Expand All @@ -74,17 +74,17 @@ buildscript {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven {
url 'https://maven.google.com/'
name 'Google'
}
maven {
url 'https://dl.bintray.com/leobert-lan-oss/maven/'
}
maven {
url uri('../local_repo')
name 'local-repo'
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
Expand All @@ -105,12 +105,12 @@ allprojects {
url 'https://dl.bintray.com/leobert-lan-oss/maven/'
}
maven {
url 'https://maven.google.com/'
name 'Google'
url uri('../../local_repo')
name 'local-repo'
}
maven {
url uri('../local_repo')
name 'local-repo'
url 'https://maven.google.com/'
name 'Google'
}
}
}
Empty file modified jimu-sample-project/gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.luojilab.reader.applike;

import com.luojilab.component.componentlib.applicationlike.IApplicationLike;
import com.luojilab.component.componentlib.applicationlike.RegisterCompManual;
import com.luojilab.component.componentlib.router.Router;
import com.luojilab.component.componentlib.router.ui.UIRouter;
import com.luojilab.componentservice.readerbook.ReadBookService;
Expand All @@ -9,7 +10,7 @@
/**
* Created by mrzhang on 2017/6/15.
*/

@RegisterCompManual
public class ReaderAppLike implements IApplicationLike {

Router router = Router.getInstance();
Expand Down

0 comments on commit a613b91

Please sign in to comment.