Skip to content

Commit

Permalink
Add the gradle plugin to generate the product into the package corres…
Browse files Browse the repository at this point in the history
…ponding to the ApplicationId.
  • Loading branch information
yanzhenjie committed Apr 12, 2020
1 parent c7636d2 commit 12d24f4
Show file tree
Hide file tree
Showing 22 changed files with 629 additions and 177 deletions.
18 changes: 15 additions & 3 deletions annotation/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
apply plugin: rootProject.ext.plugins.javaLibrary
apply plugin: plugin.javaLibrary
apply from: '../publish.gradle'

compileJava {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

version = bintray.version

uploadArchives {
repositories {
mavenDeployer {
pom.groupId = bintray.group
pom.artifactId = 'annotation'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2020 Zhenjie Yan.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.yanzhenjie.andserver.annotation;

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

/**
* Created by Zhenjie Yan on 4/11/20.
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
public @interface AppInfo {

/**
* Application Id.
*/
String value() default "";

}
34 changes: 23 additions & 11 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
apply plugin: rootProject.ext.plugins.androidLibrary
apply plugin: plugin.androidLibrary
apply from: '../publish.gradle'

version = bintray.version

uploadArchives {
repositories {
mavenDeployer {
pom.groupId = bintray.group
pom.artifactId = 'api'
}
}
}

android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
compileSdkVersion androidBuild.compileSdkVersion
buildToolsVersion androidBuild.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.ext.android.libraryMinSdkVersion
targetSdkVersion rootProject.ext.android.libraryTargetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
minSdkVersion androidBuild.libraryMinSdkVersion
targetSdkVersion androidBuild.libraryTargetSdkVersion
versionCode androidBuild.versionCode
versionName androidBuild.versionName
consumerProguardFiles 'proguard-rules.txt'
}

Expand All @@ -19,9 +31,9 @@ android {
}

dependencies {
api project(':annotation')
api deps.project.annotation

implementation rootProject.ext.dependencies.httpcore
implementation rootProject.ext.dependencies.fileupload
compileOnly rootProject.ext.dependencies.annotation
implementation deps.apache.httpcore
implementation deps.apache.fileupload
compileOnly deps.android.annotation
}
42 changes: 6 additions & 36 deletions api/src/main/java/com/yanzhenjie/andserver/ComponentRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,7 @@
*/
public class ComponentRegister {

private static final String COMPONENT_PACKAGE_NAME = "com.yanzhenjie.andserver.register";
private static final String COMPONENT_INTERFACE_NAME = OnRegister.class.getName();
private static final String[] COMPONENTS = {
COMPONENT_PACKAGE_NAME + ".ConfigRegister",
COMPONENT_PACKAGE_NAME + ".InterceptorRegister",
COMPONENT_PACKAGE_NAME + ".ResolverRegister",
COMPONENT_PACKAGE_NAME + ".ConverterRegister",
COMPONENT_PACKAGE_NAME + ".AdapterRegister"
};
private static final String PROCESSOR_PACKAGE = ".andserver.processor.generator.";

private static final String CODE_CACHE_SECONDARY_DIRECTORY = "code_cache/secondary-dexes";
private static final String EXTRACTED_NAME_EXT = ".classes";
Expand All @@ -67,24 +59,6 @@ public ComponentRegister(Context context) {
}

public void register(Register register, String group) {
List<String> classList = new ArrayList<>();
registerFromArray(register, group, classList);
if (classList.size() < COMPONENTS.length) {
registerFromApk(register, group, classList);
}
}

public void registerFromArray(Register register, String group, List<String> classList) {
for (String component : COMPONENTS) {
try {
registerClass(register, group, component);
classList.add(component);
} catch (Exception ignored) {
}
}
}

public void registerFromApk(Register register, String group, List<String> classList) {
List<String> paths = getDexFilePaths(mContext);

for (final String path : paths) {
Expand All @@ -100,7 +74,7 @@ public void registerFromApk(Register register, String group, List<String> classL
Enumeration<String> dexEntries = dexfile.entries();
while (dexEntries.hasMoreElements()) {
String className = dexEntries.nextElement();
if (className.startsWith(COMPONENT_PACKAGE_NAME) && !classList.contains(className)) {
if (className.contains(PROCESSOR_PACKAGE)) {
try {
registerClass(register, group, className);
} catch (Exception ignored) {
Expand All @@ -120,21 +94,17 @@ public void registerFromApk(Register register, String group, List<String> classL
}
}

private void registerClass(Register register, String group, String className)
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
private void registerClass(Register register, String group, String className) throws Exception {
Class clazz = Class.forName(className);
if (clazz.isInterface()) {
return;
}

Class<?>[] interfaces = clazz.getInterfaces();
for (Class<?> anInterface : interfaces) {
if (COMPONENT_INTERFACE_NAME.equals(anInterface.getName())) {
Object obj = clazz.newInstance();
if (obj instanceof OnRegister) {
OnRegister onRegister = (OnRegister) obj;
onRegister.onRegister(mContext, group, register);
}
if (anInterface.isAssignableFrom(OnRegister.class)) {
OnRegister load = (OnRegister) clazz.newInstance();
load.onRegister(mContext, group, register);
break;
}
}
Expand Down
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ apply from: "config.gradle"

buildscript {
repositories {
google()
mavenLocal()
google { url 'https://maven.aliyun.com/repository/google' }
jcenter { url 'https://maven.aliyun.com/repository/jcenter' }
mavenCentral { url 'https://maven.aliyun.com/repository/central' }
}

dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.yanzhenjie.andserver:plugin:2.1.1'
}
}

allprojects {
repositories {
google()
mavenLocal()
google { url 'https://maven.aliyun.com/repository/google' }
jcenter { url 'https://maven.aliyun.com/repository/jcenter' }
mavenCentral { url 'https://maven.aliyun.com/repository/central' }
}
Expand Down
130 changes: 75 additions & 55 deletions config.gradle
Original file line number Diff line number Diff line change
@@ -1,57 +1,77 @@
ext {
plugins = [java : 'java',
javaLibrary : 'java-library',
android : 'com.android.application',
androidLibrary: 'com.android.library',
maven : 'com.github.dcendents.android-maven',
bintray : 'com.jfrog.bintray']

android = [applicationId : 'com.yanzhenjie.andserver.sample',
compileSdkVersion : 29,
buildToolsVersion : '29.0.3',

libraryMinSdkVersion : 9,
libraryTargetSdkVersion: 29,
sampleMinSdkVersion : 14,
sampleTargetSdkVersion : 22,

versionCode : 24,
versionName : '2.1.0',]

bintray = [version : '2.1.0',
group : 'com.yanzhenjie.andserver',

siteUrl : 'https://github.com/yanzhenjie/AndServer',
gitUrl : '[email protected]:yanzhenjie/AndServer.git',

packaging : 'aar',
name : 'AndServer',
description : 'Android web server',

licenseName : 'The Apache Software License, Version 2.0',
licenseUrl : 'http://www.apache.org/licenses/LICENSE-2.0.txt',

developerId : 'yanzhenjie',
developerName : 'yanzhenjie',
developerEmail: '[email protected]',

binrayLibrary : "",
bintrayRepo : "maven",
bintrayUser : 'yolanda',
bintrayLicense: "Apache-2.0"]

dependencies = [autoService : 'com.google.auto.service:auto-service:1.0-rc6',
javaPoet : 'com.squareup:javapoet:1.12.1',
activation : 'javax.activation:activation:1.1.1',
commonsLang : 'org.apache.commons:commons-lang3:3.9',
commonsCollections: 'org.apache.commons:commons-collections4:4.4',
httpcore : "com.yanzhenjie.apache:httpcore:4.4.13.01",
fileupload : "com.yanzhenjie.apache:fileupload:1.4",

annotation : 'androidx.annotation:annotation:1.1.0',
appCompat : 'androidx.appcompat:appcompat:1.1.0',
design : 'com.google.android.material:material:1.1.0',

loading : 'com.yanzhenjie:loading:1.0.0',
json : 'com.alibaba:fastjson:1.1.71.android']
plugin = [
java : 'java',
javaLibrary : 'java-library',
javaPlugin : 'java-gradle-plugin',
android : 'com.android.application',
androidLibrary: 'com.android.library',
androidMaven : 'com.github.dcendents.android-maven',
bintray : 'com.jfrog.bintray',
andServer : 'com.yanzhenjie.andserver'
]

androidBuild = [
applicationId : 'com.yanzhenjie.andserver.sample',
compileSdkVersion : 29,
buildToolsVersion : '29.0.3',

libraryMinSdkVersion : 9,
libraryTargetSdkVersion: 29,
sampleMinSdkVersion : 14,
sampleTargetSdkVersion : 22,

versionCode : 25,
versionName : '2.1.1'
]

bintray = [
version : '2.1.1',
group : 'com.yanzhenjie.andserver',

siteUrl : 'https://github.com/yanzhenjie/AndServer',
gitUrl : '[email protected]:yanzhenjie/AndServer.git',

packaging : 'aar',
name : 'AndServer',
description : 'Android web server',

licenseName : 'The Apache Software License, Version 2.0',
licenseUrl : 'http://www.apache.org/licenses/LICENSE-2.0.txt',

developerId : 'yanzhenjie',
developerName : 'yanzhenjie',
developerEmail: '[email protected]',

binrayLibrary : "",
bintrayRepo : "maven",
bintrayUser : 'yolanda',
bintrayLicense: "Apache-2.0"
]

deps = [
android: [
plugin : 'com.android.tools.build:gradle:3.6.2',
annotation: 'androidx.annotation:annotation:1.1.0',
compat : 'androidx.appcompat:appcompat:1.1.0',
material : 'com.google.android.material:material:1.1.0',
],

project: [
annotation: "${bintray.group}:annotation:${bintray.version}",
api : "${bintray.group}:api:${bintray.version}",
processor : "${bintray.group}:processor:${bintray.version}",
plugin : "${bintray.group}:plugin:${bintray.version}"
],

apache : [
lang : 'org.apache.commons:commons-lang3:3.9',
collections: 'org.apache.commons:commons-collections4:4.4',
httpcore : "com.yanzhenjie.apache:httpcore:4.4.13.01",
fileupload : "com.yanzhenjie.apache:fileupload:1.4",
],

poet : 'com.squareup:javapoet:1.12.1',
loading: 'com.yanzhenjie:loading:1.0.0',
json : 'com.alibaba:fastjson:1.1.71.android'
]
}
1 change: 1 addition & 0 deletions plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
28 changes: 28 additions & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apply plugin: plugin.javaLibrary
apply plugin: plugin.javaPlugin
apply from: '../publish.gradle'

compileJava {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

version = bintray.version

uploadArchives {
repositories {
mavenDeployer {
pom.groupId = bintray.group
pom.artifactId = 'plugin'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

compileOnly gradleApi()
implementation deps.project.annotation
implementation deps.android.plugin
implementation deps.poet
}
Loading

0 comments on commit 12d24f4

Please sign in to comment.