Merge "Refactor build logic."
diff --git a/builder-model/build.gradle b/builder-model/build.gradle
index 10032d6..3e780df 100644
--- a/builder-model/build.gradle
+++ b/builder-model/build.gradle
@@ -1,110 +1,16 @@
 apply plugin: 'java'
 apply plugin: 'maven'
-apply plugin: 'signing'
 apply plugin: 'clone-artifacts'
 
 dependencies {
     compile "com.android.tools:common:$project.ext.baseAndroidVersion"
 }
 
-def getVersion() {
-    if (project.has("release")) {
-        return project.ext.baseVersion
-    }
-
-    return project.ext.baseVersion + '-SNAPSHOT'
-}
-
-version = getVersion()
 archivesBaseName = 'builder-model'
+project.ext.pomName = 'Android Builder Model library'
+project.ext.pomDesc = 'Model for the Builder library.'
+
+apply from: '../publish.gradle'
+apply from: '../javadoc.gradle'
 
 jar.manifest.attributes("Model-Version": "$version")
-
-task publishLocal(type: Upload) {
-    configuration = configurations.archives
-    repositories {
-        mavenDeployer {
-            repository(url: uri("$rootProject.ext.androidHostOut/repo"))
-        }
-    }
-}
-
-project.ext.sonatypeUsername = hasProperty('sonatypeUsername') ? sonatypeUsername : ""
-project.ext.sonatypePassword = hasProperty('sonatypePassword') ? sonatypePassword : ""
-
-uploadArchives {
-    repositories {
-        mavenDeployer {
-            beforeDeployment { MavenDeployment deployment ->
-                if (!project.has("release")) {
-                    throw new StopExecutionException("uploadArchives must be called with the release.gradle init script")
-                }
-
-                if (project.ext.sonatypeUsername.length() == 0 || project.ext.sonatypePassword.length() == 0) {
-                    throw new StopExecutionException("uploadArchives cannot be called without sonatype username and password")
-                }
-
-                signing.signPom(deployment)
-            }
-
-            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
-                authentication(userName: project.ext.sonatypeUsername, password: project.ext.sonatypePassword)
-            }
-
-            pom.project {
-                name 'Android Builder Model library'
-                description 'Model for the Builder library.'
-                url 'http://tools.android.com'
-                inceptionYear '2007'
-
-                licenses {
-                    license {
-                        name 'The Apache Software License, Version 2.0'
-                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
-                        distribution 'repo'
-                    }
-                }
-
-                scm {
-                    url "https://android.googlesource.com/platform/tools/build"
-                    connection "git://android.googlesource.com/platform/tools/build.git"
-                }
-                developers {
-                    developer {
-                        name 'The Android Open Source Project'
-                    }
-                }
-            }
-        }
-    }
-}
-
-// custom tasks for creating source/javadoc jars
-task sourcesJar(type: Jar, dependsOn:classes) {
-    classifier = 'sources'
-    from sourceSets.main.allSource
-}
-
-javadoc {
-    exclude               "**/internal/**"
-    options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
-
-    title                 "Android Model"
-}
-
-task javadocJar(type: Jar, dependsOn:javadoc) {
-    classifier         'javadoc'
-    from               javadoc.destinationDir
-}
- 
-// add javadoc/source jar tasks as artifacts
-artifacts {
-    archives jar
-    archives sourcesJar
-    archives javadocJar
-}
-
-signing {
-    required { project.has("release") && gradle.taskGraph.hasTask("uploadArchives") }
-    sign configurations.archives
-}
diff --git a/builder-test-api/build.gradle b/builder-test-api/build.gradle
index 579f4f7..4ba5312 100644
--- a/builder-test-api/build.gradle
+++ b/builder-test-api/build.gradle
@@ -7,102 +7,9 @@
     compile "com.android.tools.ddms:ddmlib:$project.ext.baseAndroidVersion"
 }
 
-def getVersion() {
-    if (project.has("release")) {
-        return project.ext.baseVersion
-    }
-
-    return project.ext.baseVersion + '-SNAPSHOT'
-}
-
-version = getVersion()
 archivesBaseName = 'builder-test-api'
+project.ext.pomName = 'Android Builder Test API library'
+project.ext.pomDesc = 'API for the Test extension point in the Builder library.'
 
-task publishLocal(type: Upload) {
-    configuration = configurations.archives
-    repositories {
-        mavenDeployer {
-            repository(url: uri("$rootProject.ext.androidHostOut/repo"))
-        }
-    }
-}
-
-project.ext.sonatypeUsername = hasProperty('sonatypeUsername') ? sonatypeUsername : ""
-project.ext.sonatypePassword = hasProperty('sonatypePassword') ? sonatypePassword : ""
-
-uploadArchives {
-    repositories {
-        mavenDeployer {
-            beforeDeployment { MavenDeployment deployment ->
-                if (!project.has("release")) {
-                    throw new StopExecutionException("uploadArchives must be called with the release.gradle init script")
-                }
-
-                if (project.ext.sonatypeUsername.length() == 0 || project.ext.sonatypePassword.length() == 0) {
-                    throw new StopExecutionException("uploadArchives cannot be called without sonatype username and password")
-                }
-
-                signing.signPom(deployment)
-            }
-
-            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
-                authentication(userName: project.ext.sonatypeUsername, password: project.ext.sonatypePassword)
-            }
-
-            pom.project {
-                name 'Android Builder Test API library'
-                description 'API for the Test extension point in the Builder library.'
-                url 'http://tools.android.com'
-                inceptionYear '2007'
-
-                licenses {
-                    license {
-                        name 'The Apache Software License, Version 2.0'
-                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
-                        distribution 'repo'
-                    }
-                }
-
-                scm {
-                    url "https://android.googlesource.com/platform/tools/build"
-                    connection "git://android.googlesource.com/platform/tools/build.git"
-                }
-                developers {
-                    developer {
-                        name 'The Android Open Source Project'
-                    }
-                }
-            }
-        }
-    }
-}
-
-// custom tasks for creating source/javadoc jars
-task sourcesJar(type: Jar, dependsOn:classes) {
-    classifier = 'sources'
-    from sourceSets.main.allSource
-}
-
-javadoc {
-    exclude               "**/internal/**"
-    options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
-
-    title                 "Android Model"
-}
-
-task javadocJar(type: Jar, dependsOn:javadoc) {
-    classifier         'javadoc'
-    from               javadoc.destinationDir
-}
- 
-// add javadoc/source jar tasks as artifacts
-artifacts {
-    archives jar
-    archives sourcesJar
-    archives javadocJar
-}
-
-signing {
-    required { project.has("release") && gradle.taskGraph.hasTask("uploadArchives") }
-    sign configurations.archives
-}
+apply from: '../publish.gradle'
+apply from: '../javadoc.gradle'
diff --git a/builder/build.gradle b/builder/build.gradle
index c765b0d..6b5fb9b 100644
--- a/builder/build.gradle
+++ b/builder/build.gradle
@@ -22,105 +22,13 @@
     testCompile "com.android.tools:testutils:$project.ext.baseAndroidVersion"
 }
 
-def getVersion() {
-    if (project.has("release")) {
-        return project.ext.baseVersion
-    }
-
-    return project.ext.baseVersion + '-SNAPSHOT'
-}
-
-version = getVersion()
 archivesBaseName = 'builder'
-jar.manifest.attributes("Builder-Version": version)
+project.ext.pomName = 'Android Builder library'
+project.ext.pomDesc = 'Library to build Android applications.'
 
-task publishLocal(type: Upload) {
-    configuration = configurations.archives
-    repositories {
-        mavenDeployer {
-            repository(url: uri(rootProject.ext.localRepo))
-        }
-    }
-}
+apply from: '../publish.gradle'
+apply from: '../javadoc.gradle'
+
+jar.manifest.attributes("Builder-Version": version)
 publishLocal.dependsOn ':builder-model:publishLocal', ':builder-test-api:publishLocal'
 
-project.ext.sonatypeUsername = hasProperty('sonatypeUsername') ? sonatypeUsername : ""
-project.ext.sonatypePassword = hasProperty('sonatypePassword') ? sonatypePassword : ""
-
-uploadArchives {
-    repositories {
-        mavenDeployer {
-            beforeDeployment { MavenDeployment deployment ->
-                if (!project.has("release")) {
-                    throw new StopExecutionException("uploadArchives must be called with the release.gradle init script")
-                }
-
-                if (project.ext.sonatypeUsername.length() == 0 || project.ext.sonatypePassword.length() == 0) {
-                    throw new StopExecutionException("uploadArchives cannot be called without sonatype username and password")
-                }
-
-                signing.signPom(deployment)
-            }
-
-            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
-                authentication(userName: project.ext.sonatypeUsername, password: project.ext.sonatypePassword)
-            }
-
-            pom.project {
-                name 'Android Builder library'
-                description 'library to build Android applications.'
-                url 'http://tools.android.com'
-                inceptionYear '2007'
-
-                licenses {
-                    license {
-                        name 'The Apache Software License, Version 2.0'
-                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
-                        distribution 'repo'
-                    }
-                }
-
-                scm {
-                    url "https://android.googlesource.com/platform/tools/build"
-                    connection "git://android.googlesource.com/platform/tools/build.git"
-                }
-                developers {
-                    developer {
-                        name 'The Android Open Source Project'
-                    }
-                }
-            }
-        }
-    }
-}
-
-
-// custom tasks for creating source/javadoc jars
-task sourcesJar(type: Jar, dependsOn:classes) {
-    classifier = 'sources'
-    from sourceSets.main.allSource
-}
-
-javadoc {
-    exclude               "**/internal/**"
-    options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
-
-    title                 "Android Builder"
-}
-
-task javadocJar(type: Jar, dependsOn:javadoc) {
-    classifier         'javadoc'
-    from               javadoc.destinationDir
-}
- 
-// add javadoc/source jar tasks as artifacts
-artifacts {
-    archives jar
-    archives sourcesJar
-    archives javadocJar
-}
-
-signing {
-    required { project.has("release") && gradle.taskGraph.hasTask("uploadArchives") }
-    sign configurations.archives
-}
diff --git a/gradle-model/build.gradle b/gradle-model/build.gradle
index f4a8458..929eaeb 100644
--- a/gradle-model/build.gradle
+++ b/gradle-model/build.gradle
@@ -30,14 +30,6 @@
 sourceSets.test.compileClasspath += configurations.gradleRepo
 sourceSets.test.runtimeClasspath += configurations.gradleRepo
 
-def getVersion() {
-    if (project.has("release")) {
-        return project.ext.baseVersion
-    }
-
-    return project.ext.baseVersion + '-SNAPSHOT'
-}
-
 test.dependsOn ':gradle:publishLocal'
 
 idea {
diff --git a/gradle/build.gradle b/gradle/build.gradle
index f83bc7a..fefe868 100644
--- a/gradle/build.gradle
+++ b/gradle/build.gradle
@@ -72,26 +72,13 @@
     }
 }
 
-def getVersion() {
-    if (project.has("release")) {
-        return project.ext.baseVersion
-    }
-
-    return project.ext.baseVersion + '-SNAPSHOT'
-}
-
-version = getVersion()
 archivesBaseName = 'gradle'
-jar.manifest.attributes("Plugin-Version": version)
+project.ext.pomName = 'Gradle Plug-in for Android'
+project.ext.pomDesc = 'Gradle plug-in to build Android applications.'
 
-task publishLocal(type: Upload) {
-    configuration = configurations.archives
-    repositories {
-        mavenDeployer {
-            repository(url: uri(rootProject.ext.localRepo))
-        }
-    }
-}
+apply from: '../publish.gradle'
+
+jar.manifest.attributes("Plugin-Version": version)
 publishLocal.dependsOn ':builder:publishLocal'
 
 task buildTest(type: Test, dependsOn: publishLocal) {
@@ -112,62 +99,6 @@
 
 check.dependsOn buildTest
 
-project.ext.sonatypeUsername = project.hasProperty('sonatypeUsername') ? sonatypeUsername : ""
-project.ext.sonatypePassword = project.hasProperty('sonatypePassword') ? sonatypePassword : ""
-
-uploadArchives {
-    repositories {
-        mavenDeployer {
-            beforeDeployment { MavenDeployment deployment ->
-                if (!project.has("release")) {
-                    throw new StopExecutionException("uploadArchives must be called with the release.gradle init script")
-                }
-
-                if (project.ext.sonatypeUsername.length() == 0 || project.ext.sonatypePassword.length() == 0) {
-                    throw new StopExecutionException("uploadArchives cannot be called without sonatype username and password")
-                }
-
-                signing.signPom(deployment)
-            }
-
-            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
-                authentication(userName: project.ext.sonatypeUsername, password: project.ext.sonatypePassword)
-            }
-
-            pom.project {
-                name 'Gradle Plug-in for Android'
-                description 'Gradle plug-in to build Android applications.'
-                url 'http://tools.android.com'
-                inceptionYear '2007'
-
-                licenses {
-                    license {
-                        name 'The Apache Software License, Version 2.0'
-                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
-                        distribution 'repo'
-                    }
-                }
-
-                scm {
-                    url "https://android.googlesource.com/platform/tools/build"
-                    connection "git://android.googlesource.com/platform/tools/build.git"
-                }
-
-                developers {
-                    developer {
-                        name 'The Android Open Source Project'
-                    }
-                }
-            }
-        }
-    }
-}
-
-// custom tasks for creating source/javadoc jars
-task sourcesJar(type: Jar, dependsOn:classes) {
-    classifier = 'sources'
-    from sourceSets.main.allSource
-}
 
 groovydoc {
     exclude     "**/internal/**"
@@ -183,15 +114,9 @@
     classifier  'javadoc'
     from        groovydoc.destinationDir
 }
- 
-// add javadoc/source jar tasks as artifacts
+
+// add javadoc jar tasks as artifacts
 artifacts {
-    archives jar
-    archives sourcesJar
     archives javadocJar
 }
 
-signing {
-    required { project.has("release") && gradle.taskGraph.hasTask("uploadArchives") }
-    sign configurations.archives
-}
diff --git a/javadoc.gradle b/javadoc.gradle
new file mode 100644
index 0000000..720844a
--- /dev/null
+++ b/javadoc.gradle
@@ -0,0 +1,16 @@
+javadoc {
+    exclude               "**/internal/**"
+    options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
+
+    title                 project.ext.pomName
+}
+
+task javadocJar(type: Jar, dependsOn:javadoc) {
+    classifier         'javadoc'
+    from               javadoc.destinationDir
+}
+
+// add javadoc jar tasks as artifacts
+artifacts {
+    archives javadocJar
+}
diff --git a/publish.gradle b/publish.gradle
new file mode 100644
index 0000000..7d8a319
--- /dev/null
+++ b/publish.gradle
@@ -0,0 +1,87 @@
+apply plugin: 'signing'
+
+def getVersion() {
+    if (project.has("release")) {
+        return project.ext.baseVersion
+    }
+
+    return project.ext.baseVersion + '-SNAPSHOT'
+}
+
+version = getVersion()
+
+task publishLocal(type: Upload) {
+    configuration = configurations.archives
+    repositories {
+        mavenDeployer {
+            repository(url: uri("$rootProject.ext.androidHostOut/repo"))
+        }
+    }
+}
+
+project.ext.sonatypeUsername = hasProperty('sonatypeUsername') ? sonatypeUsername : ""
+project.ext.sonatypePassword = hasProperty('sonatypePassword') ? sonatypePassword : ""
+
+uploadArchives {
+    repositories {
+        mavenDeployer {
+            beforeDeployment { MavenDeployment deployment ->
+                if (!project.has("release")) {
+                    throw new StopExecutionException("uploadArchives must be called with the release.gradle init script")
+                }
+
+                if (project.ext.sonatypeUsername.length() == 0 || project.ext.sonatypePassword.length() == 0) {
+                    throw new StopExecutionException("uploadArchives cannot be called without sonatype username and password")
+                }
+
+                signing.signPom(deployment)
+            }
+
+            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
+                authentication(userName: project.ext.sonatypeUsername, password: project.ext.sonatypePassword)
+            }
+
+            pom.project {
+                name project.ext.pomName
+                description project.ext.pomDesc
+                url 'http://tools.android.com'
+                inceptionYear '2007'
+
+                licenses {
+                    license {
+                        name 'The Apache Software License, Version 2.0'
+                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+                        distribution 'repo'
+                    }
+                }
+
+                scm {
+                    url 'https://android.googlesource.com/platform/tools/build'
+                    connection 'git://android.googlesource.com/platform/tools/build.git'
+                }
+                developers {
+                    developer {
+                        name 'The Android Open Source Project'
+                    }
+                }
+            }
+        }
+    }
+}
+
+// custom tasks for creating source/javadoc jars
+task sourcesJar(type: Jar, dependsOn:classes) {
+    classifier = 'sources'
+    from sourceSets.main.allSource
+}
+
+// add source jar tasks as artifacts
+artifacts {
+    archives jar
+    archives sourcesJar
+}
+
+signing {
+    required { project.has("release") && gradle.taskGraph.hasTask("uploadArchives") }
+    sign configurations.archives
+}