diff --git a/plugin/greenbean-pods-plugin/.gitignore b/plugin/PeaPod/.gitignore similarity index 100% rename from plugin/greenbean-pods-plugin/.gitignore rename to plugin/PeaPod/.gitignore diff --git a/plugin/PeaPod/build.gradle b/plugin/PeaPod/build.gradle new file mode 100644 index 0000000..9598ea2 --- /dev/null +++ b/plugin/PeaPod/build.gradle @@ -0,0 +1,16 @@ +apply plugin: 'groovy' + +dependencies { + compile gradleApi() + compile localGroovy() + compile fileTree(dir: 'libs', include: ['*.jar']) +} + +buildscript { + repositories { + jcenter() + } + dependencies { + + } +} \ No newline at end of file diff --git a/plugin/greenbean-pods-plugin/proguard-rules.pro b/plugin/PeaPod/proguard-rules.pro similarity index 100% rename from plugin/greenbean-pods-plugin/proguard-rules.pro rename to plugin/PeaPod/proguard-rules.pro diff --git a/plugin/PeaPod/src/main/groovy/pea/pod/Log.java b/plugin/PeaPod/src/main/groovy/pea/pod/Log.java new file mode 100644 index 0000000..5f40543 --- /dev/null +++ b/plugin/PeaPod/src/main/groovy/pea/pod/Log.java @@ -0,0 +1,118 @@ +package pea.pod; + +import java.io.PrintWriter; +import java.io.StringWriter; + +public class Log { + + private static LogImp debugLog = new LogImp() { + + @Override + public void v(final String tag, final String msg, final Object... obj) { + String log = obj == null ? msg : String.format(msg, obj); + System.out.println(String.format("[VERBOSE][%s]%s", tag, log)); + } + + @Override + public void i(final String tag, final String msg, final Object... obj) { + String log = obj == null ? msg : String.format(msg, obj); + System.out.println(String.format("[INFO][%s]%s", tag, log)); + } + + @Override + public void d(final String tag, final String msg, final Object... obj) { + String log = obj == null ? msg : String.format(msg, obj); + System.out.println(String.format("[DEBUG][%s]%s", tag, log)); + } + + @Override + public void w(final String tag, final String msg, final Object... obj) { + String log = obj == null ? msg : String.format(msg, obj); + System.out.println(String.format("[WARN][%s]%s", tag, log)); + } + + @Override + public void e(final String tag, final String msg, final Object... obj) { + String log = obj == null ? msg : String.format(msg, obj); + System.out.println(String.format("[ERROR][%s]%s", tag, log)); + } + + @Override + public void printErrStackTrace(String tag, Throwable tr, String format, Object... obj) { + String log = obj == null ? format : String.format(format, obj); + if (log == null) { + log = ""; + } + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + tr.printStackTrace(pw); + log += " " + sw.toString(); + System.out.println(String.format("[ERROR][%s]%s", tag, log)); + } + }; + + private static LogImp logImp = debugLog; + + private Log() { + } + + public static void setLogImp(LogImp imp) { + logImp = imp; + } + + public static LogImp getImpl() { + return logImp; + } + + public static void v(final String tag, final String msg, final Object... obj) { + if (logImp != null) { + logImp.v(tag, msg, obj); + } + } + + public static void e(final String tag, final String msg, final Object... obj) { + if (logImp != null) { + logImp.e(tag, msg, obj); + } + } + + public static void w(final String tag, final String msg, final Object... obj) { + if (logImp != null) { + logImp.w(tag, msg, obj); + } + } + + public static void i(final String tag, final String msg, final Object... obj) { + if (logImp != null) { + logImp.i(tag, msg, obj); + } + } + + public static void d(final String tag, final String msg, final Object... obj) { + if (logImp != null) { + logImp.d(tag, msg, obj); + } + } + + public static void printErrStackTrace(String tag, Throwable tr, final String format, final Object... obj) { + if (logImp != null) { + logImp.printErrStackTrace(tag, tr, format, obj); + } + } + + public interface LogImp { + + void v(final String tag, final String msg, final Object... obj); + + void i(final String tag, final String msg, final Object... obj); + + void w(final String tag, final String msg, final Object... obj); + + void d(final String tag, final String msg, final Object... obj); + + void e(final String tag, final String msg, final Object... obj); + + void printErrStackTrace(String tag, Throwable tr, final String format, final Object... obj); + + } +} diff --git a/plugin/greenbean-pods-plugin/src/main/groovy/greenbean/pods/GreenBean.groovy b/plugin/PeaPod/src/main/groovy/pea/pod/Pea.groovy similarity index 98% rename from plugin/greenbean-pods-plugin/src/main/groovy/greenbean/pods/GreenBean.groovy rename to plugin/PeaPod/src/main/groovy/pea/pod/Pea.groovy index a302bd7..52b67e6 100644 --- a/plugin/greenbean-pods-plugin/src/main/groovy/greenbean/pods/GreenBean.groovy +++ b/plugin/PeaPod/src/main/groovy/pea/pod/Pea.groovy @@ -1,4 +1,4 @@ -package greenbean.pods +package pea.pod /** * DSL 基础脚本 @@ -7,7 +7,7 @@ package greenbean.pods * @description Basic Script * @since 2018.11.7 */ -abstract class GreenBean extends Script { +abstract class Pea extends Script { public static ArrayList pods = new ArrayList<>() diff --git a/plugin/greenbean-pods-plugin/src/main/groovy/greenbean/pods/GreenBeanPods.groovy b/plugin/PeaPod/src/main/groovy/pea/pod/PeaPodPlugin.groovy similarity index 66% rename from plugin/greenbean-pods-plugin/src/main/groovy/greenbean/pods/GreenBeanPods.groovy rename to plugin/PeaPod/src/main/groovy/pea/pod/PeaPodPlugin.groovy index 8641929..ae3d4cd 100644 --- a/plugin/greenbean-pods-plugin/src/main/groovy/greenbean/pods/GreenBeanPods.groovy +++ b/plugin/PeaPod/src/main/groovy/pea/pod/PeaPodPlugin.groovy @@ -1,34 +1,32 @@ -package greenbean.pods +package pea.pod import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.initialization.Settings import org.gradle.api.plugins.PluginAware +import pea.pod.extension.PeaPodExt /** - * Green Bean Pods + * PeaPodPlugin * - * @since 2018.11.7 - * @author jacky + * @author JackyWang since 2018.11.7 */ -class GreenBeanPods implements Plugin { +class PeaPodPlugin implements Plugin { - private String dslPath = "greenbean.pods/PodsSpec.groovy" + def TAG = "PeaPodPlugin" + def dslPath = "gradle/pea_pod.gradle" + PeaPodExt peaPodExtension @Override void apply(PluginAware pluginAware) { - def isInclude = pluginAware instanceof Settings - def isReplace = pluginAware instanceof Project - if (isInclude) { - includePods(pluginAware) - } else if (isReplace) { - replacePods(pluginAware) + peaPodExtension = project.getExtensions().create("PeaPod", PeaPodExt) + if (pluginAware instanceof Settings) { + includeStage(pluginAware) + } else if (pluginAware instanceof Project) { + projectStage(pluginAware) } } - /** - * 加载依赖描述 - */ private void evaluateDSL(String path) { def shell = new GroovyShell(this.getClass().getClassLoader()) // 加载内部DSL @@ -47,11 +45,11 @@ class GreenBeanPods implements Plugin { * @param pluginAware * @return */ - void includePods(PluginAware pluginAware) { + def includeStage(PluginAware pluginAware) { def settings = (Settings) pluginAware def rootDir = settings.rootDir - evaluateDSL(rootDir.path + File.separator + dslPath) - GreenBean.pods.each { pod -> +// evaluateDSL(rootDir.path + File.separator + dslPath) + peaPodExtension.peaPods.each { pod -> if (pod.on_off) { if (pod.path == null && pod.absPath == null) { return @@ -67,44 +65,40 @@ class GreenBeanPods implements Plugin { def proc = pod.cmd.execute() def outputStream = new StringBuffer() proc.waitForProcessOutput(outputStream, System.err) - println "执行Hook命令:" + pod.cmd + " 结果:" + outputStream.toString() + Log.i(TAG, "exec hook cmd:" + pod.cmd + " result:" + outputStream.toString()) } - // 切换分支 + // checkout branch. if (pod.branch != null && !pod.branch.isEmpty()) { String cmd = "git -C " + path + " checkout " + pod.branch def proc = cmd.execute() def outputStream = new StringBuffer() proc.waitForProcessOutput(outputStream, System.err) - println "模块:" + pod.name + " 检出分支:" + pod.branch + " 结果:" + outputStream.toString() + Log.i(TAG, "module:" + pod.name + " checkout:" + pod.branch + " result:" + outputStream.toString()) } def projectName = ":" + pod.name settings.include(projectName) settings.project(projectName).projectDir = new File(path) - println("被包含的模块 名字:" + pod.name + " 路径:" + path) + Log.i(TAG, "included module name:" + pod.name + " path:" + path) } } } - /** - * 动态替换依赖 - * @param pluginAware - * @return - */ - void replacePods(PluginAware pluginAware) { + def projectStage(PluginAware pluginAware) { def project = (Project) pluginAware - evaluateDSL(project.rootDir.path + File.separator + dslPath) +// evaluateDSL(project.rootDir.path + File.separator + dslPath) + def peaPods = peaPodExtension.peaPods project.afterEvaluate { //寻找当前节点 - def currentItem = GreenBean.pods.find { + def currentNode = peaPods.find { project.name == it.name } - if (currentItem == null) return + if (currentNode == null) return // 寻找子节点 - List seeds = currentItem.seeds + List seeds = currentNode.seeds if (seeds == null) return seeds.each { seedName -> // 寻找子节点 - def seed = GreenBean.pods.find { + def seed = peaPods.find { it.name == seedName } if (seed == null) return @@ -120,18 +114,23 @@ class GreenBeanPods implements Plugin { excludeModule = seed.name map.put("module", excludeModule) map.put("group", excludeGroup) - project.configurations.compile.exclude(map) +// project.configurations.compile.exclude(map) + project.configurations.each { + it.exclude(map) + } } else { seed.excludes.each { Map map = new HashMap<>() excludeModule = it map.put("module", excludeModule) map.put("group", excludeGroup) - project.configurations.compile.exclude(map) + project.configurations.each { + it.exclude(map) + } } } - println("Project:" + currentItem.name + " exclude online dependence,group:" + excludeGroup + " module:" + excludeModule) - // 添加本地依赖 + Log.i(TAG, "Project:" + currentNode.name + " exclude online dependence, group:" + excludeGroup + " module:" + excludeModule) + // add local module. StringBuilder buildTypes = new StringBuilder() if (seed.buildTypes == null || seed.buildTypes.size() == 0) { buildTypes.append("api") @@ -142,11 +141,11 @@ class GreenBeanPods implements Plugin { if (project.configurations.findByName(buildType) != null) { project.dependencies.add(buildType, project.dependencies.project([path: ":" + seed.name])) } else { - System.err.println "Replace dependency error , build type " + buildType + " not exists." + Log.e(TAG, "Replace dependency error , build type " + buildType + " not exists.") } } } - println("Project:" + currentItem.name + " add local dependence,config name:" + buildTypes.toString() + " path:" + seed.name) + Log.i(TAG, "Project:" + currentNode.name + " add local dependence, build type:" + buildTypes.toString() + " path:" + seed.name) } } } diff --git a/plugin/PeaPod/src/main/groovy/pea/pod/extension/PeaPodExt.groovy b/plugin/PeaPod/src/main/groovy/pea/pod/extension/PeaPodExt.groovy new file mode 100644 index 0000000..83827f5 --- /dev/null +++ b/plugin/PeaPod/src/main/groovy/pea/pod/extension/PeaPodExt.groovy @@ -0,0 +1,95 @@ +package pea.pod.extension; + +public class PeaPodExt { + + def peaPods = new ArrayList() + + PeaPodExt() {} + + def peaPods(peaPods) { + this.peaPods = peaPods + } + + def getPeaPods() { + return peaPods + } + + @Override + public String toString() { + return "PeaPodExt{" + + "peaPods=" + peaPods + + '}'; + } + + class PeaPod { + + def on_off + def name + def group + def path + def absPath + def branch + def cmd + def excludes = new ArrayList<>() + def buildTypes = new ArrayList<>() + def seeds = new ArrayList<>() + + void on_off(boolean on_off) { + this.on_off = on_off + } + + void name(String name) { + this.name = name + } + + void group(String group) { + this.group = group + } + + void path(String path) { + this.path = path + } + + void absPath(String absPath) { + this.absPath = absPath + } + + void branch(String branch) { + this.branch = branch + } + + void cmd(String cmd) { + this.cmd = cmd + } + + void excludes(ArrayList excludes) { + this.excludes = excludes + } + + void buildTypes(ArrayList buildTypes) { + this.buildTypes = buildTypes + } + + void seeds(ArrayList seeds) { + this.seeds = seeds + } + + @Override + public String toString() { + return "PeaPodExtension{" + + "on_off=" + on_off + + ", name='" + name + '\'' + + ", group='" + group + '\'' + + ", path='" + path + '\'' + + ", absPath='" + absPath + '\'' + + ", branch='" + branch + '\'' + + ", cmd='" + cmd + '\'' + + ", excludes=" + excludes + + ", buildTypes=" + buildTypes + + ", seeds=" + seeds + + '}'; + } + } + + +} diff --git a/plugin/PeaPod/src/main/resources/META-INF/gradle-plugins/pea-pod-plugin.properties b/plugin/PeaPod/src/main/resources/META-INF/gradle-plugins/pea-pod-plugin.properties new file mode 100644 index 0000000..692eecd --- /dev/null +++ b/plugin/PeaPod/src/main/resources/META-INF/gradle-plugins/pea-pod-plugin.properties @@ -0,0 +1 @@ +implementation-class=pea.pod.PeaPodPlugin \ No newline at end of file diff --git a/plugin/build.gradle b/plugin/build.gradle index a4d2569..8c063e7 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -1,5 +1,3 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { repositories { @@ -8,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.1.2' + classpath 'com.android.tools.build:gradle:3.5.0' } } diff --git a/plugin/gradle/wrapper/gradle-wrapper.jar b/plugin/gradle/wrapper/gradle-wrapper.jar index 7a3265e..758de96 100644 Binary files a/plugin/gradle/wrapper/gradle-wrapper.jar and b/plugin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/plugin/gradle/wrapper/gradle-wrapper.properties b/plugin/gradle/wrapper/gradle-wrapper.properties index 7176a26..2d80b69 100644 --- a/plugin/gradle/wrapper/gradle-wrapper.properties +++ b/plugin/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sun Jun 03 15:57:47 CST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/plugin/greenbean-pods-plugin/build.gradle b/plugin/greenbean-pods-plugin/build.gradle deleted file mode 100644 index bc0b938..0000000 --- a/plugin/greenbean-pods-plugin/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -apply plugin: 'groovy' - -dependencies { - compile gradleApi() - compile localGroovy() - compile fileTree(dir: 'libs', include: ['*.jar']) -} - -apply plugin: 'com.novoda.bintray-release' - -buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.novoda:bintray-release:0.9' - } -} - -// upload cmd: ./gradlew clean build bintrayUpload -publish { - userOrg = 'jackyjacky' - groupId = 'tech.jackywang' - artifactId = 'greenbean-pods-plugin' - publishVersion = '0.0.3' - licences = ["GPL-3.0"] - desc = 'https://github.com/JackyAndroid/GreenBeanPods' - website = 'https://github.com/JackyAndroid/GreenBeanPods' -} \ No newline at end of file diff --git a/plugin/greenbean-pods-plugin/src/main/groovy/greenbean/pods/SpecInternal.groovy b/plugin/greenbean-pods-plugin/src/main/groovy/greenbean/pods/SpecInternal.groovy deleted file mode 100644 index bcd4a03..0000000 --- a/plugin/greenbean-pods-plugin/src/main/groovy/greenbean/pods/SpecInternal.groovy +++ /dev/null @@ -1,19 +0,0 @@ -package greenbean.pods - -/** - * 内部依赖描述文件,减少外部描述复杂度 - */ -class SpecInternal { - - static String text = ''' - - import xx - @groovy.transform.BaseScript xx xx - - pod { - on_off false - name "sample" - path "sample/path" - } - ''' -} \ No newline at end of file diff --git a/plugin/greenbean-pods-plugin/src/main/resources/META-INF/gradle-plugins/greenbean-pods-plugin.properties b/plugin/greenbean-pods-plugin/src/main/resources/META-INF/gradle-plugins/greenbean-pods-plugin.properties deleted file mode 100644 index a3b9f28..0000000 --- a/plugin/greenbean-pods-plugin/src/main/resources/META-INF/gradle-plugins/greenbean-pods-plugin.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=greenbean.pods.GreenBeanPods \ No newline at end of file diff --git a/plugin/settings.gradle b/plugin/settings.gradle index 077edec..392caa6 100644 --- a/plugin/settings.gradle +++ b/plugin/settings.gradle @@ -1 +1 @@ -include ':greenbean-pods-plugin' \ No newline at end of file +include ':PeaPod' \ No newline at end of file