aboutsummaryrefslogtreecommitdiff
path: root/build.gradle
diff options
context:
space:
mode:
authorBeau Collins <beaucollins@gmail.com>2014-07-02 15:43:49 -0400
committerBeau Collins <beaucollins@gmail.com>2014-07-07 11:41:22 -0700
commit6300948a5c1b1993b3aa516032074b9555fa5403 (patch)
treefbf58678e5dc438290036ef38bc2f79283768517 /build.gradle
parent54e15ba3dda2607bf2fb480f5aac5f9505cdd88d (diff)
downloadgradle-perf-android-medium-6300948a5c1b1993b3aa516032074b9555fa5403.tar.gz
Gradle plugin for setting up WordPress libraries
Potential way to manage libraries via artifacts or from source.
Diffstat (limited to 'build.gradle')
-rw-r--r--build.gradle117
1 files changed, 117 insertions, 0 deletions
diff --git a/build.gradle b/build.gradle
index 495c5038e..fc1760a43 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1 +1,118 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'org.ajoberstar:grgit:0.2.1'
+ }
+}
+
+project(':WordPress') {
+ apply plugin: WordPressLibraries
+}
+
+import org.ajoberstar.grgit.Grgit
+
+class WordPressLibraries implements Plugin<Project> {
+
+ def File libDir
+
+ void apply(Project prj) {
+
+ libDir = new File("${prj.rootDir}/libs")
+ def libraries = prj.container(Library)
+
+ prj.afterEvaluate {
+ libraries.each { lib ->
+ if (isLocal(lib)) {
+ // set the source dependencies
+ def dep = ":libs:$lib.name:$lib.subproject"
+ prj.logger.info "Using local src for $dep"
+ prj.dependencies {
+ debugCompile project(path:dep)
+ releaseCompile lib.artifact
+ }
+ } else {
+ // set the artifact dependency sine the source is not local
+ prj.logger.info "Using artifact for $lib.name"
+ prj.dependencies {
+ compile lib.artifact
+ }
+ }
+ }
+ }
+
+ prj.task('wordpressCreateLibDir') << {
+ libDir.mkdirs()
+ }
+
+ prj.task('devSetup', dependsOn:'wordpressCreateLibDir') {
+ doLast {
+ libraries.each { library ->
+ def dir = localDirectory(library)
+ def uri = library.repo
+ if (!isLocal(library)) {
+ prj.logger.info "Setting up WordPress library $library.name from $uri"
+ def repo = Grgit.clone(dir:dir, uri:uri)
+ } else {
+ prj.logger.info "WordPress library $library.name building from source at $dir"
+ }
+ }
+ }
+ }
+
+ prj.extensions.wordpress = libraries
+ }
+
+ def boolean isLocal(Library library) {
+ return localDirectory(library).isDirectory()
+ }
+
+ def File localDirectory(Library library) {
+ return new File("$libDir/$library.name")
+ }
+
+}
+
+class Library {
+ final String name
+ String repo
+ String subproject
+ String artifact
+
+ Library(String name) {
+ this.name = name
+ }
+
+ def boolean isLocal() {
+ }
+
+ def subproject(String name) {
+ subproject = name
+ }
+
+ def artifact(String name) {
+ artifact = name
+ }
+
+ def repo(String name) {
+
+ // if no "/" then assume in WordPres-Mobile
+ if (!name.contains("/")) {
+ name = "WordPress-Mobile/$name"
+ }
+
+ if (!name.endsWith(".git")) {
+ name = "${name}.git"
+ }
+
+ if (!name.startsWith("https://github.com/")) {
+ name = "https://github.com/$name"
+ }
+
+ this.repo = name
+ }
+
+}