Initial prototype of Gradle plugin to build Android applications
Adam Murdoch [Sun, 19 Aug 2012 23:44:51 +0000 (09:44 +1000)]
This is an initial prototype Gradle plugin that can build Android applications.
This is intended to demonstrate how such a plugin would be wired together. Most
of the tasks are placeholders for a real implementation. See the readme for
details.

Change-Id: I8f25493b9656c3919c0635c0e5363cdd9c8c171d

80 files changed:
.gitignore [new file with mode: 0644]
basic/build.gradle [new file with mode: 0644]
basic/src/main/AndroidManifest.xml [new file with mode: 0644]
basic/src/main/java/org/gradle/sample/BuildType.java [new file with mode: 0644]
basic/src/main/java/org/gradle/sample/MainActivity.java [new file with mode: 0644]
basic/src/main/java/org/gradle/sample/Person.java [new file with mode: 0644]
basic/src/main/java/org/gradle/sample/ShowPeopleActivity.java [new file with mode: 0644]
basic/src/main/res/drawable-hdpi/ic_launcher.png [new file with mode: 0644]
basic/src/main/res/drawable-ldpi/ic_launcher.png [new file with mode: 0644]
basic/src/main/res/drawable-mdpi/ic_launcher.png [new file with mode: 0644]
basic/src/main/res/drawable-xhdpi/ic_launcher.png [new file with mode: 0644]
basic/src/main/res/layout/main.xml [new file with mode: 0644]
basic/src/main/res/values/strings.xml [new file with mode: 0644]
build.gradle [new file with mode: 0644]
buildSrc/MODULE_LICENSE_APACHE2 [new file with mode: 0644]
buildSrc/NOTICE [new file with mode: 0644]
buildSrc/build.gradle [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/AndroidExtension.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/AndroidLibraryExtension.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/AndroidLibraryPlugin.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/AndroidPlugin.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/BuildType.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/CrunchResources.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/Dex.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/GenerateManifest.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/InstallApplication.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/PackageApplication.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/ProcessResources.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/ProductFlavor.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/ZipAlign.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/internal/AndroidManifest.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/internal/ApplicationVariant.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/internal/BuildTypeDimension.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/internal/ProductFlavorDimension.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/internal/ProductionAppVariant.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/internal/SourceVariant.groovy [new file with mode: 0644]
buildSrc/src/main/groovy/org/gradle/android/internal/TestAppVariant.groovy [new file with mode: 0644]
buildSrc/src/main/resources/META-INF/gradle-plugins/android-library.properties [new file with mode: 0644]
buildSrc/src/main/resources/META-INF/gradle-plugins/android.properties [new file with mode: 0644]
customized/build.gradle [new file with mode: 0644]
customized/src/custom/java/org/gradle/sample/BuildTypeImpl.java [new file with mode: 0644]
customized/src/debug/java/org/gradle/sample/BuildTypeImpl.java [new file with mode: 0644]
customized/src/free/java/org/gradle/sample/People.java [new file with mode: 0644]
customized/src/free/res/values/strings.xml [new file with mode: 0644]
customized/src/main/AndroidManifest.xml [new file with mode: 0644]
customized/src/main/java/org/gradle/sample/BuildType.java [new file with mode: 0644]
customized/src/main/java/org/gradle/sample/MainActivity.java [new file with mode: 0644]
customized/src/main/java/org/gradle/sample/Person.java [new file with mode: 0644]
customized/src/main/res/drawable-hdpi/ic_launcher.png [new file with mode: 0644]
customized/src/main/res/drawable-ldpi/ic_launcher.png [new file with mode: 0644]
customized/src/main/res/drawable-mdpi/ic_launcher.png [new file with mode: 0644]
customized/src/main/res/drawable-xhdpi/ic_launcher.png [new file with mode: 0644]
customized/src/main/res/layout/main.xml [new file with mode: 0644]
customized/src/main/res/values/strings.xml [new file with mode: 0644]
customized/src/paid/java/org/gradle/sample/People.java [new file with mode: 0644]
customized/src/paid/res/values/strings.xml [new file with mode: 0644]
customized/src/release/java/org/gradle/sample/BuildTypeImpl.java [new file with mode: 0644]
customized/src/test/java/org/gradle/sample/Test.java [new file with mode: 0644]
customized/src/testFree/java/org/gradle/sample/FlavorTest.java [new file with mode: 0644]
customized/src/testPaid/java/org/gradle/sample/FlavorTest.java [new file with mode: 0644]
gradle/wrapper/gradle-wrapper.jar [new file with mode: 0644]
gradle/wrapper/gradle-wrapper.properties [new file with mode: 0644]
gradlew [new file with mode: 0755]
gradlew.bat [new file with mode: 0644]
multiproject/app/build.gradle [new file with mode: 0644]
multiproject/app/src/main/AndroidManifest.xml [new file with mode: 0644]
multiproject/app/src/main/java/org/gradle/sample/MainActivity.java [new file with mode: 0644]
multiproject/app/src/main/java/org/gradle/sample/ShowPeopleActivity.java [new file with mode: 0644]
multiproject/app/src/main/res/drawable-hdpi/ic_launcher.png [new file with mode: 0644]
multiproject/app/src/main/res/drawable-ldpi/ic_launcher.png [new file with mode: 0644]
multiproject/app/src/main/res/drawable-mdpi/ic_launcher.png [new file with mode: 0644]
multiproject/app/src/main/res/drawable-xhdpi/ic_launcher.png [new file with mode: 0644]
multiproject/app/src/main/res/layout/main.xml [new file with mode: 0644]
multiproject/app/src/main/res/values/strings.xml [new file with mode: 0644]
multiproject/library/build.gradle [new file with mode: 0644]
multiproject/util/build.gradle [new file with mode: 0644]
multiproject/util/src/main/java/org/gradle/sample/People.java [new file with mode: 0644]
multiproject/util/src/main/java/org/gradle/sample/Person.java [new file with mode: 0644]
readme.md [new file with mode: 0644]
settings.gradle [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..e96ffab
--- /dev/null
@@ -0,0 +1,6 @@
+local.properties
+*.iml
+*.ipr
+*.iws
+build
+.gradle
diff --git a/basic/build.gradle b/basic/build.gradle
new file mode 100644 (file)
index 0000000..e4a5ce3
--- /dev/null
@@ -0,0 +1,15 @@
+//
+// A basic Android application that follows all the conventions
+//
+
+apply plugin: 'android'
+
+version='1.0'
+
+repositories {
+    mavenCentral()
+}
+
+dependencies {
+    compile 'com.google.guava:guava:11.0.2'
+}
\ No newline at end of file
diff --git a/basic/src/main/AndroidManifest.xml b/basic/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..1f411e0
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      package="org.gradle.sample"
+      android:versionCode="1"
+      android:versionName="1.0">
+    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
+        <activity android:name="MainActivity"
+                  android:label="@string/app_name">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        <activity
+                android:name="ShowPeopleActivity"
+                android:label="@string/title_activity_display_message" >
+                <meta-data
+                    android:name="android.support.PARENT_ACTIVITY"
+                    android:value="org.gradle.sample.MainActivity" />
+            </activity>
+    </application>
+</manifest>
diff --git a/basic/src/main/java/org/gradle/sample/BuildType.java b/basic/src/main/java/org/gradle/sample/BuildType.java
new file mode 100644 (file)
index 0000000..4364026
--- /dev/null
@@ -0,0 +1,5 @@
+package org.gradle.sample;
+
+public interface BuildType {
+    String getBuildType();
+}
diff --git a/basic/src/main/java/org/gradle/sample/MainActivity.java b/basic/src/main/java/org/gradle/sample/MainActivity.java
new file mode 100644 (file)
index 0000000..242c173
--- /dev/null
@@ -0,0 +1,19 @@
+package org.gradle.sample;
+
+import android.app.Activity;
+import android.view.View;
+import android.content.Intent;
+import android.os.Bundle;
+
+public class MainActivity extends Activity {
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.main);
+    }
+
+    public void sendMessage(View view) {
+        Intent intent = new Intent(this, ShowPeopleActivity.class);
+        startActivity(intent);
+    }
+}
diff --git a/basic/src/main/java/org/gradle/sample/Person.java b/basic/src/main/java/org/gradle/sample/Person.java
new file mode 100644 (file)
index 0000000..b6fcb27
--- /dev/null
@@ -0,0 +1,13 @@
+package org.gradle.sample;
+
+public class Person {
+    private final String name;
+
+    public Person(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+}
diff --git a/basic/src/main/java/org/gradle/sample/ShowPeopleActivity.java b/basic/src/main/java/org/gradle/sample/ShowPeopleActivity.java
new file mode 100644 (file)
index 0000000..24a739a
--- /dev/null
@@ -0,0 +1,31 @@
+package org.gradle.sample;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.content.Intent;
+import android.widget.TextView;
+import com.google.common.collect.Lists;
+
+import java.lang.String;
+import java.util.Arrays;
+
+public class ShowPeopleActivity extends Activity {
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        String message = "People:";
+
+        Iterable<Person> people = Lists.newArrayList(new Person("fred"));
+        for (Person person : people) {
+            message += "\n * ";
+            message += person.getName();
+        }
+
+        TextView textView = new TextView(this);
+        textView.setTextSize(20);
+        textView.setText(message);
+
+        setContentView(textView);
+    }
+}
diff --git a/basic/src/main/res/drawable-hdpi/ic_launcher.png b/basic/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..96a442e
Binary files /dev/null and b/basic/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/basic/src/main/res/drawable-ldpi/ic_launcher.png b/basic/src/main/res/drawable-ldpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..9923872
Binary files /dev/null and b/basic/src/main/res/drawable-ldpi/ic_launcher.png differ
diff --git a/basic/src/main/res/drawable-mdpi/ic_launcher.png b/basic/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..359047d
Binary files /dev/null and b/basic/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/basic/src/main/res/drawable-xhdpi/ic_launcher.png b/basic/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..71c6d76
Binary files /dev/null and b/basic/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/basic/src/main/res/layout/main.xml b/basic/src/main/res/layout/main.xml
new file mode 100644 (file)
index 0000000..ccc59fb
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="horizontal"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+    <Button
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/button_send"
+            android:onClick="sendMessage" />
+</LinearLayout>
diff --git a/basic/src/main/res/values/strings.xml b/basic/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..8eda275
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">Basic App</string>
+    <string name="button_send">Go</string>
+    <string name="title_activity_display_message">People</string>
+</resources>
diff --git a/build.gradle b/build.gradle
new file mode 100644 (file)
index 0000000..2b8e3ea
--- /dev/null
@@ -0,0 +1 @@
+allprojects { apply plugin: 'idea' }
diff --git a/buildSrc/MODULE_LICENSE_APACHE2 b/buildSrc/MODULE_LICENSE_APACHE2
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/buildSrc/NOTICE b/buildSrc/NOTICE
new file mode 100644 (file)
index 0000000..c77f135
--- /dev/null
@@ -0,0 +1,190 @@
+
+   Copyright (c) 2012, The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+
+   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.
+
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
new file mode 100644 (file)
index 0000000..35d138b
--- /dev/null
@@ -0,0 +1,7 @@
+apply plugin: 'groovy'
+apply plugin: 'idea'
+
+dependencies {
+    compile gradleApi()
+    groovy localGroovy()
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/AndroidExtension.groovy b/buildSrc/src/main/groovy/org/gradle/android/AndroidExtension.groovy
new file mode 100644 (file)
index 0000000..e14bfb0
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+import org.gradle.api.Action
+import org.gradle.api.NamedDomainObjectContainer
+
+class AndroidExtension {
+    final NamedDomainObjectContainer<BuildType> buildTypes
+    final NamedDomainObjectContainer<ProductFlavor> productFlavors
+    String target = "android-16"
+    String packageName
+    Integer versionCode
+    String versionName
+
+    AndroidExtension(NamedDomainObjectContainer<BuildType> buildTypes, NamedDomainObjectContainer<ProductFlavor> productFlavors) {
+        this.buildTypes = buildTypes
+        this.productFlavors = productFlavors
+    }
+
+    void buildTypes(Action<? super NamedDomainObjectContainer<BuildType>> action) {
+        action.execute(buildTypes)
+    }
+
+    void productFlavors(Action<? super NamedDomainObjectContainer<ProductFlavor>> action) {
+        action.execute(productFlavors)
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/AndroidLibraryExtension.groovy b/buildSrc/src/main/groovy/org/gradle/android/AndroidLibraryExtension.groovy
new file mode 100644 (file)
index 0000000..132fcde
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+import org.gradle.api.Action
+import org.gradle.api.NamedDomainObjectContainer
+
+class AndroidLibraryExtension {
+    final NamedDomainObjectContainer<BuildType> buildTypes
+
+    AndroidLibraryExtension(NamedDomainObjectContainer<BuildType> buildTypes) {
+        this.buildTypes = buildTypes
+    }
+
+    void buildTypes(Action<? super NamedDomainObjectContainer<BuildType>> action) {
+        action.execute(buildTypes)
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/AndroidLibraryPlugin.groovy b/buildSrc/src/main/groovy/org/gradle/android/AndroidLibraryPlugin.groovy
new file mode 100644 (file)
index 0000000..8a6279a
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.plugins.JavaBasePlugin
+
+class AndroidLibraryPlugin implements Plugin<Project> {
+    private Project project
+
+    @Override
+    void apply(Project project) {
+        this.project = project
+
+        project.apply plugin: JavaBasePlugin
+
+        def buildTypes = project.container(BuildType)
+
+        project.extensions.create('android', AndroidLibraryExtension, buildTypes)
+
+        buildTypes.whenObjectAdded { BuildType buildType ->
+            addBuildType(buildType)
+        }
+        buildTypes.whenObjectRemoved {
+            throw new UnsupportedOperationException("Removing build types is not implemented yet.")
+        }
+
+        buildTypes.create('debug')
+        buildTypes.create('release')
+    }
+
+    void addBuildType(BuildType buildType) {
+        def assemble = project.tasks.add("assemble${buildType.name.capitalize()}")
+
+        project.tasks.assemble.dependsOn assemble
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/AndroidPlugin.groovy b/buildSrc/src/main/groovy/org/gradle/android/AndroidPlugin.groovy
new file mode 100644 (file)
index 0000000..c9e858b
--- /dev/null
@@ -0,0 +1,308 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+import org.gradle.android.internal.BuildTypeDimension
+import org.gradle.android.internal.ProductFlavorDimension
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.plugins.JavaBasePlugin
+import org.gradle.api.tasks.SourceSet
+import org.gradle.api.tasks.compile.Compile
+import org.gradle.android.internal.AndroidManifest
+import org.gradle.internal.reflect.Instantiator
+
+import org.gradle.android.internal.ApplicationVariant
+import org.gradle.android.internal.TestAppVariant
+import org.gradle.android.internal.ProductionAppVariant
+
+class AndroidPlugin implements Plugin<Project> {
+    private final Set<ProductionAppVariant> variants = []
+    private final Map<String, BuildTypeDimension> buildTypes = [:]
+    private final Map<String, ProductFlavorDimension> productFlavors = [:]
+    private Project project
+    private SourceSet main
+    private SourceSet test
+    private File sdkDir
+    private AndroidExtension extension
+    private AndroidManifest mainManifest
+
+    @Override
+    void apply(Project project) {
+        this.project = project
+
+        project.apply plugin: JavaBasePlugin
+
+        def buildTypes = project.container(BuildType)
+        // TODO - do the decoration by default
+        def productFlavors = project.container(ProductFlavor) { name ->
+            project.services.get(Instantiator).newInstance(ProductFlavor, name)
+        }
+
+        extension = project.extensions.create('android', AndroidExtension, buildTypes, productFlavors)
+        extension.conventionMapping.packageName = { getMainManifest().packageName }
+        extension.conventionMapping.versionCode = { getMainManifest().versionCode }
+        extension.conventionMapping.versionName = { getMainManifest().versionName }
+
+        findSdk(project)
+
+        project.sourceSets.all { sourceSet ->
+            sourceSet.resources.srcDirs = ["src/$sourceSet.name/res"]
+        }
+
+        main = project.sourceSets.add('main')
+        test = project.sourceSets.add('test')
+
+        buildTypes.whenObjectAdded { BuildType buildType ->
+            addBuildType(buildType)
+        }
+        buildTypes.whenObjectRemoved {
+            throw new UnsupportedOperationException("Removing build types is not implemented yet.")
+        }
+
+        buildTypes.create('debug') {
+            zipAlign = false
+        }
+        buildTypes.create('release')
+
+        productFlavors.whenObjectAdded { ProductFlavor flavor ->
+            addProductFlavor(flavor)
+        }
+        productFlavors.whenObjectRemoved {
+            throw new UnsupportedOperationException("Removing product flavors is not implemented yet.")
+        }
+
+        project.afterEvaluate {
+            if (productFlavors.isEmpty()) {
+                productFlavors.create('main')
+            }
+        }
+
+        project.tasks.assemble.dependsOn { variants.collect { "assemble${it.name}" } }
+    }
+
+    private File getRuntimeJar() {
+        def platformDir = new File(sdkDir, "platforms/${extension.target}")
+        if (!platformDir.exists()) {
+            throw new RuntimeException("Specified target '$extension.target' does not exist.")
+        }
+        new File(platformDir, "android.jar")
+    }
+
+    private AndroidManifest getMainManifest() {
+        if (mainManifest == null) {
+            mainManifest = new AndroidManifest()
+            mainManifest.load(project.file("src/main/AndroidManifest.xml"))
+        }
+        return mainManifest
+    }
+
+    private void findSdk(Project project) {
+        def localProperties = project.file("local.properties")
+        if (!localProperties) {
+            throw new RuntimeException("No local.properties file found at ${localProperties}.")
+        }
+        Properties properties = new Properties()
+        localProperties.withInputStream { instr ->
+            properties.load(instr)
+        }
+        def sdkDirProp = properties.getProperty('sdk.dir')
+        if (!sdkDirProp) {
+            throw new RuntimeException("No sdk.dir property defined in local.properties file.")
+        }
+        sdkDir = new File(sdkDirProp)
+        if (!sdkDir.directory) {
+            throw new RuntimeException("The SDK directory '$sdkDir' specified in local.properties does not exist.")
+        }
+    }
+
+    private void addBuildType(BuildType buildType) {
+        def sourceSet = project.sourceSets.add(buildType.name)
+
+        def buildTypeDimension = new BuildTypeDimension(buildType, sourceSet)
+        buildTypes[buildType.name] = buildTypeDimension
+
+        def assembleBuildType = project.tasks.add(buildTypeDimension.assembleTaskName)
+        assembleBuildType.dependsOn {
+            buildTypeDimension.variants.collect { "assemble$it.name" }
+        }
+        assembleBuildType.description = "Assembles all ${buildType.name} applications"
+        assembleBuildType.group = "Build"
+
+        productFlavors.values().each { flavor ->
+            addVariant(buildTypeDimension, flavor)
+        }
+    }
+
+    private void addProductFlavor(ProductFlavor productFlavor) {
+        def mainSourceSet
+        def testSourceSet
+        if (productFlavor.name == 'main') {
+            mainSourceSet = main
+            testSourceSet = test
+        } else {
+            mainSourceSet = project.sourceSets.add(productFlavor.name)
+            testSourceSet = project.sourceSets.add("test${productFlavor.name.capitalize()}")
+        }
+
+        def productFlavorDimension = new ProductFlavorDimension(productFlavor, mainSourceSet, testSourceSet)
+        productFlavors[productFlavor.name] = productFlavorDimension
+
+        productFlavor.conventionMapping.packageName = { extension.packageName }
+        productFlavor.conventionMapping.versionCode = { extension.versionCode }
+        productFlavor.conventionMapping.versionName = { extension.versionName }
+
+        def assembleFlavour = project.tasks.add(productFlavorDimension.assembleTaskName)
+        assembleFlavour.dependsOn {
+            productFlavorDimension.variants.collect { "assemble${it.name}" }
+        }
+        assembleFlavour.description = "Assembles all ${productFlavor.name} applications"
+        assembleFlavour.group = "Build"
+
+        buildTypes.values().each { buildType ->
+            addVariant(buildType, productFlavorDimension)
+        }
+
+        assert productFlavorDimension.debugVariant != null
+
+        // Add a task to generate the test app manifest
+        def generateManifestTask = project.tasks.add("generate${productFlavor.name.capitalize()}TestManifest", GenerateManifest)
+        generateManifestTask.conventionMapping.outputFile = { project.file("$project.buildDir/manifests/test/$productFlavor.name/AndroidManifest.xml") }
+        generateManifestTask.conventionMapping.packageName = { productFlavor.packageName + '.test' }
+        generateManifestTask.conventionMapping.versionCode = { productFlavor.versionCode }
+        generateManifestTask.conventionMapping.versionName = { productFlavor.versionName }
+
+        // Add a task to compile the test application
+        def testCompile = project.tasks.add("compile${productFlavor.name.capitalize()}Test", Compile)
+        testCompile.source test.java, productFlavorDimension.testSource.java
+        testCompile.classpath = test.compileClasspath + productFlavorDimension.debugVariant.runtimeClasspath
+        testCompile.conventionMapping.destinationDir = { project.file("$project.buildDir/classes/test/$productFlavor.name") }
+        testCompile.options.bootClasspath = getRuntimeJar()
+
+        // Add a task to generate resource package
+        def processResources = project.tasks.add("process${productFlavor.name.capitalize()}TestResources", ProcessResources)
+        processResources.dependsOn generateManifestTask
+        processResources.conventionMapping.packageFile = { project.file("$project.buildDir/libs/test/${project.archivesBaseName}-${productFlavor.name}.ap_") }
+        processResources.sdkDir = sdkDir
+        processResources.conventionMapping.sourceDirectories =  { [] }
+        processResources.conventionMapping.androidManifestFile = { generateManifestTask.outputFile }
+        processResources.conventionMapping.packageName = { generateManifestTask.packageName }
+        processResources.conventionMapping.includeFiles = { [getRuntimeJar()] }
+
+        def testApp = new TestAppVariant(productFlavor)
+        testApp.runtimeClasspath = testCompile.outputs.files + testCompile.classpath
+        testApp.resourcePackage = project.files({processResources.packageFile}) { builtBy processResources }
+        addPackageTasks(testApp)
+
+        project.tasks.check.dependsOn "assemble${testApp.name}"
+    }
+
+    private void addVariant(BuildTypeDimension buildType, ProductFlavorDimension productFlavor) {
+        def variant = new ProductionAppVariant(buildType.buildType, productFlavor.productFlavor)
+        variants << variant
+        buildType.variants << variant
+        productFlavor.variants << variant
+        if (buildType.name == 'debug') {
+            productFlavor.debugVariant = variant
+        }
+
+        // Add a task to generate the manifest
+        def generateManifestTask = project.tasks.add("generate${variant.name}Manifest", GenerateManifest)
+        generateManifestTask.sourceFile = project.file('src/main/AndroidManifest.xml')
+        generateManifestTask.conventionMapping.outputFile = { project.file("$project.buildDir/manifests/main/$variant.dirName/AndroidManifest.xml") }
+        generateManifestTask.conventionMapping.packageName = { getMainManifest().packageName }
+        generateManifestTask.conventionMapping.versionCode = { productFlavor.productFlavor.versionCode }
+        generateManifestTask.conventionMapping.versionName = { productFlavor.productFlavor.versionName }
+
+        // Add a task to crunch resource files
+        def crunchTask = project.tasks.add("crunch${variant.name}Resources", CrunchResources)
+        crunchTask.conventionMapping.outputDir = { project.file("$project.buildDir/resources/main/$variant.dirName") }
+        crunchTask.sdkDir = sdkDir
+        crunchTask.conventionMapping.sourceDirectories =  {
+            (main.resources.srcDirs + productFlavor.mainSource.resources.srcDirs + buildType.mainSource.resources.srcDirs).findAll { it.exists() }
+        }
+
+        // Add a task to generate resource source files
+        def processResources = project.tasks.add("process${variant.name}Resources", ProcessResources)
+        processResources.dependsOn generateManifestTask, crunchTask
+        processResources.conventionMapping.sourceOutputDir = { project.file("$project.buildDir/source/main/$variant.dirName") }
+        processResources.conventionMapping.packageFile = { project.file("$project.buildDir/libs/${project.archivesBaseName}-${variant.baseName}.ap_") }
+        processResources.sdkDir = sdkDir
+        processResources.conventionMapping.sourceDirectories =  {
+            ([crunchTask.outputDir] + main.resources.srcDirs + productFlavor.mainSource.resources.srcDirs + buildType.mainSource.resources.srcDirs).findAll { it.exists() }
+        }
+        processResources.conventionMapping.androidManifestFile = { generateManifestTask.outputFile }
+        processResources.conventionMapping.includeFiles = { [getRuntimeJar()] }
+        processResources.conventionMapping.packageName = { productFlavor.productFlavor.packageName }
+
+        // Add a compile task
+        def compileTaskName = "compile${variant.name}"
+        def compileTask = project.tasks.add(compileTaskName, Compile)
+        compileTask.dependsOn processResources
+        compileTask.source main.java, buildType.mainSource.java, productFlavor.mainSource.java, { processResources.sourceOutputDir }
+        compileTask.classpath = main.compileClasspath
+        compileTask.conventionMapping.destinationDir = { project.file("$project.buildDir/classes/main/$variant.dirName") }
+        compileTask.options.bootClasspath = getRuntimeJar()
+
+        // Wire up the outputs
+        variant.runtimeClasspath = project.files(compileTask.outputs, main.compileClasspath)
+        variant.resourcePackage = project.files({processResources.packageFile}) { builtBy processResources }
+
+        addPackageTasks(variant)
+    }
+
+    private void addPackageTasks(ApplicationVariant variant) {
+        // Add a dex task
+        def dexTaskName = "dex${variant.name}"
+        def dexTask = project.tasks.add(dexTaskName, Dex)
+        dexTask.sdkDir = sdkDir
+        dexTask.conventionMapping.sourceFiles = { variant.runtimeClasspath }
+        dexTask.conventionMapping.outputFile = { project.file("${project.buildDir}/libs/${project.archivesBaseName}-${variant.baseName}.dex") }
+
+        // Add a task to generate application package
+        def packageApp = project.tasks.add("package${variant.name}", PackageApplication)
+        packageApp.dependsOn variant.resourcePackage, dexTask
+        packageApp.conventionMapping.outputFile = { project.file("$project.buildDir/apk/${project.archivesBaseName}-${variant.baseName}-unaligned.apk") }
+        packageApp.sdkDir = sdkDir
+        packageApp.conventionMapping.resourceFile = { variant.resourcePackage.singleFile }
+        packageApp.conventionMapping.dexFile = { dexTask.outputFile }
+
+        def appTask = packageApp
+
+        if (variant.zipAlign) {
+            // Add a task to zip align application package
+            def alignApp = project.tasks.add("zipalign${variant.name}", ZipAlign)
+            alignApp.dependsOn packageApp
+            alignApp.conventionMapping.inputFile = { packageApp.outputFile }
+            alignApp.conventionMapping.outputFile = { project.file("$project.buildDir/apk/${project.archivesBaseName}-${variant.baseName}.apk") }
+            alignApp.sdkDir = sdkDir
+
+            appTask = alignApp
+        }
+
+        // Add an assemble task
+        def assembleTask = project.tasks.add("assemble${variant.name}")
+        assembleTask.dependsOn appTask
+        assembleTask.description = "Assembles the ${variant.description} application"
+        assembleTask.group = "Build"
+
+        // Add a task to install the application package
+        def installApp = project.tasks.add("install${variant.name}", InstallApplication)
+        installApp.dependsOn appTask
+        installApp.conventionMapping.packageFile = { appTask.outputFile }
+        installApp.sdkDir = sdkDir
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/BuildType.groovy b/buildSrc/src/main/groovy/org/gradle/android/BuildType.groovy
new file mode 100644 (file)
index 0000000..e813a85
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+class BuildType {
+    final String name
+
+    boolean zipAlign = true
+
+    BuildType(String name) {
+        this.name = name
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/CrunchResources.groovy b/buildSrc/src/main/groovy/org/gradle/android/CrunchResources.groovy
new file mode 100644 (file)
index 0000000..ea3528d
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.tasks.*
+
+class CrunchResources extends DefaultTask {
+    @OutputDirectory
+    File outputDir
+
+    @Input
+    File sdkDir
+
+    @InputFiles
+    Iterable<File> sourceDirectories
+
+    @TaskAction
+    void generate() {
+        project.exec {
+            executable = new File(getSdkDir(), "platform-tools/aapt")
+            args 'crunch'
+            args '-C', getOutputDir()
+            getSourceDirectories().each {
+                args '-S', it
+            }
+        }
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/Dex.groovy b/buildSrc/src/main/groovy/org/gradle/android/Dex.groovy
new file mode 100644 (file)
index 0000000..1706058
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.tasks.*
+
+class Dex extends DefaultTask {
+    @OutputFile
+    File outputFile
+
+    @Input
+    File sdkDir
+
+    @InputFiles
+    Iterable<File> sourceFiles
+
+    @TaskAction
+    void generate() {
+        project.exec {
+            executable = new File(getSdkDir(), "platform-tools/dx")
+            args '--dex'
+            args '--output', getOutputFile()
+            getSourceFiles().each {
+                args it
+            }
+        }
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/GenerateManifest.groovy b/buildSrc/src/main/groovy/org/gradle/android/GenerateManifest.groovy
new file mode 100644 (file)
index 0000000..9bb5861
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.tasks.InputFile
+import org.gradle.api.tasks.Input
+import org.gradle.api.tasks.TaskAction
+import org.gradle.api.tasks.OutputFile
+import org.gradle.android.internal.AndroidManifest
+import org.gradle.api.tasks.Optional
+
+class GenerateManifest extends DefaultTask {
+    @InputFile @Optional
+    File sourceFile
+
+    @OutputFile
+    File outputFile
+
+    @Input
+    String packageName
+
+    @Input
+    Integer versionCode
+
+    @Input
+    String versionName
+
+    @TaskAction
+    def generate() {
+        AndroidManifest manifest = new AndroidManifest()
+        if (getSourceFile() != null) {
+            manifest.load(getSourceFile())
+        }
+        manifest.packageName = getPackageName()
+        manifest.versionCode = getVersionCode()
+        manifest.versionName = getVersionName()
+        manifest.save(getOutputFile())
+    }
+}
+
diff --git a/buildSrc/src/main/groovy/org/gradle/android/InstallApplication.groovy b/buildSrc/src/main/groovy/org/gradle/android/InstallApplication.groovy
new file mode 100644 (file)
index 0000000..41bf98a
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.tasks.*
+
+class InstallApplication extends DefaultTask {
+    @Input
+    File sdkDir
+
+    @InputFile
+    File packageFile
+
+    @TaskAction
+    void generate() {
+        project.exec {
+            executable = new File(getSdkDir(), "platform-tools/adb")
+            args 'install'
+            args getPackageFile()
+        }
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/PackageApplication.groovy b/buildSrc/src/main/groovy/org/gradle/android/PackageApplication.groovy
new file mode 100644 (file)
index 0000000..e892e2d
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.tasks.*
+
+class PackageApplication extends DefaultTask {
+    @OutputFile
+    File outputFile
+
+    @Input
+    File sdkDir
+
+    @InputFile
+    File resourceFile
+
+    @InputFile
+    File dexFile
+
+    @TaskAction
+    void generate() {
+        def antJar = new File(getSdkDir(), "tools/lib/anttasks.jar")
+        ant.taskdef(resource: "anttasks.properties", classpath: antJar)
+        ant.apkbuilder(apkFilepath: getOutputFile(),
+                resourcefile: project.fileResolver.withBaseDir(getOutputFile().parentFile).resolveAsRelativePath(getResourceFile()),
+                outfolder: getOutputFile().getParentFile(),
+                debugsigning: true) {
+            dex(path: getDexFile())
+        }
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/ProcessResources.groovy b/buildSrc/src/main/groovy/org/gradle/android/ProcessResources.groovy
new file mode 100644 (file)
index 0000000..1111d77
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.tasks.TaskAction
+import org.gradle.api.tasks.OutputDirectory
+import org.gradle.api.tasks.Input
+import org.gradle.api.tasks.InputFiles
+import org.gradle.api.tasks.InputFile
+import org.gradle.api.tasks.OutputFile
+import org.gradle.api.tasks.Optional
+
+class ProcessResources extends DefaultTask {
+    @Input
+    File sdkDir
+
+    @InputFiles
+    Iterable<File> sourceDirectories
+
+    @InputFiles
+    Iterable<File> includeFiles
+
+    @InputFile
+    File androidManifestFile
+
+    @Input
+    String packageName
+
+    @OutputDirectory @Optional
+    File sourceOutputDir
+
+    @OutputFile
+    File packageFile
+
+    @TaskAction
+    void generate() {
+        project.exec {
+            executable = new File(getSdkDir(), "platform-tools/aapt")
+            args 'package'
+            args '-f'
+            args '-m'
+            args '--generate-dependencies'
+            args '--rename-manifest-package', getPackageName()
+            if (getSourceOutputDir() != null) {
+                args '-J', getSourceOutputDir()
+            }
+            args '-F', getPackageFile()
+            args '-M', getAndroidManifestFile()
+            getSourceDirectories().each {
+                args '-S', it
+            }
+            getIncludeFiles().each {
+                args '-I', it
+            }
+        }
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/ProductFlavor.groovy b/buildSrc/src/main/groovy/org/gradle/android/ProductFlavor.groovy
new file mode 100644 (file)
index 0000000..5b724c5
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+class ProductFlavor {
+    final String name
+    String packageName
+    Integer versionCode
+    String versionName
+
+    ProductFlavor(String name) {
+        this.name = name
+    }
+}
+
diff --git a/buildSrc/src/main/groovy/org/gradle/android/ZipAlign.groovy b/buildSrc/src/main/groovy/org/gradle/android/ZipAlign.groovy
new file mode 100644 (file)
index 0000000..94544be
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.tasks.*
+
+class ZipAlign extends DefaultTask {
+    @OutputFile
+    File outputFile
+
+    @Input
+    File sdkDir
+
+    @InputFile
+    File inputFile
+
+    @TaskAction
+    void generate() {
+        project.exec {
+            executable = new File(getSdkDir(), "tools/zipalign")
+            args '-f', '4'
+            args getInputFile()
+            args getOutputFile()
+        }
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/internal/AndroidManifest.groovy b/buildSrc/src/main/groovy/org/gradle/android/internal/AndroidManifest.groovy
new file mode 100644 (file)
index 0000000..b4d0957
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android.internal
+
+import javax.xml.parsers.DocumentBuilderFactory
+import org.w3c.dom.Element
+import javax.xml.transform.TransformerFactory
+import javax.xml.transform.dom.DOMSource
+import javax.xml.transform.stream.StreamResult
+
+class AndroidManifest {
+    private static final String ANDROID_NAME_SPACE = "http://schemas.android.com/apk/res/android"
+    String packageName
+    Integer versionCode
+    String versionName
+    Element manifestXml
+
+    void load(File sourceFile) {
+        def builderFactory = DocumentBuilderFactory.newInstance()
+        builderFactory.setNamespaceAware(true)
+        manifestXml = builderFactory.newDocumentBuilder().parse(sourceFile).documentElement
+
+        packageName = manifestXml.getAttribute("package")
+        versionCode = manifestXml.getAttributeNS(ANDROID_NAME_SPACE, "versionCode").toInteger()
+        versionName = manifestXml.getAttributeNS(ANDROID_NAME_SPACE, "versionName")
+    }
+
+    void save(File destFile) {
+        if (manifestXml == null) {
+            def builderFactory = DocumentBuilderFactory.newInstance()
+            builderFactory.setNamespaceAware(true)
+            def doc = builderFactory.newDocumentBuilder().newDocument()
+            manifestXml = doc.createElement("manifest")
+            manifestXml.setAttributeNS(ANDROID_NAME_SPACE, "versionCode", "")
+            manifestXml.setAttributeNS(ANDROID_NAME_SPACE, "versionName", "")
+        }
+        manifestXml.setAttribute("package", packageName)
+        manifestXml.getAttributeNodeNS(ANDROID_NAME_SPACE, "versionCode").setValue(versionCode.toString())
+        manifestXml.getAttributeNodeNS(ANDROID_NAME_SPACE, "versionName").setValue(versionName)
+
+        TransformerFactory.newInstance().newTransformer().transform(new DOMSource(manifestXml), new StreamResult(destFile))
+    }
+}
+
diff --git a/buildSrc/src/main/groovy/org/gradle/android/internal/ApplicationVariant.groovy b/buildSrc/src/main/groovy/org/gradle/android/internal/ApplicationVariant.groovy
new file mode 100644 (file)
index 0000000..256112d
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android.internal
+
+import org.gradle.api.file.FileCollection
+
+/**
+ * Represents something that can be packaged into an APK and installed.
+ */
+public interface ApplicationVariant {
+    String getName()
+
+    String getDescription()
+
+    String getDirName()
+
+    String getBaseName()
+
+    boolean getZipAlign()
+
+    FileCollection getRuntimeClasspath()
+
+    FileCollection getResourcePackage()
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/internal/BuildTypeDimension.groovy b/buildSrc/src/main/groovy/org/gradle/android/internal/BuildTypeDimension.groovy
new file mode 100644 (file)
index 0000000..251492c
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android.internal
+
+import org.gradle.android.BuildType
+import org.gradle.api.tasks.SourceSet
+
+class BuildTypeDimension {
+    final BuildType buildType
+    final Set<ProductionAppVariant> variants = []
+    final SourceSet mainSource
+
+    BuildTypeDimension(BuildType buildType, SourceSet mainSource) {
+        this.buildType = buildType
+        this.mainSource = mainSource
+    }
+
+    String getName() {
+        return buildType.name
+    }
+
+    String getAssembleTaskName() {
+        return "assemble${buildType.name.capitalize()}"
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/internal/ProductFlavorDimension.groovy b/buildSrc/src/main/groovy/org/gradle/android/internal/ProductFlavorDimension.groovy
new file mode 100644 (file)
index 0000000..22729bd
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android.internal
+
+import org.gradle.android.ProductFlavor
+import org.gradle.api.tasks.SourceSet
+
+class ProductFlavorDimension {
+    final ProductFlavor productFlavor
+    final Set<ProductionAppVariant> variants = []
+    final SourceSet mainSource
+    final SourceSet testSource
+    ProductionAppVariant debugVariant
+
+    ProductFlavorDimension(ProductFlavor productFlavor, SourceSet mainSource, SourceSet testSource) {
+        this.productFlavor = productFlavor
+        this.mainSource = mainSource
+        this.testSource = testSource
+    }
+
+    String getName() {
+        return productFlavor.name
+    }
+
+    String getAssembleTaskName() {
+        return "assemble${productFlavor.name.capitalize()}"
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/internal/ProductionAppVariant.groovy b/buildSrc/src/main/groovy/org/gradle/android/internal/ProductionAppVariant.groovy
new file mode 100644 (file)
index 0000000..95dadb5
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android.internal
+
+import org.gradle.android.BuildType
+import org.gradle.android.ProductFlavor
+import org.gradle.api.file.FileCollection
+
+class ProductionAppVariant implements ApplicationVariant {
+    final String name
+    final BuildType buildType
+    final ProductFlavor productFlavor
+    FileCollection runtimeClasspath
+    FileCollection resourcePackage
+
+    ProductionAppVariant(BuildType buildType, ProductFlavor productFlavor) {
+        this.name = "${productFlavor.name.capitalize()}${buildType.name.capitalize()}"
+        this.buildType = buildType
+        this.productFlavor = productFlavor
+    }
+
+    String getDescription() {
+        return "$productFlavor.name $buildType.name"
+    }
+
+    String getDirName() {
+        return "$productFlavor.name/$buildType.name"
+    }
+
+    String getBaseName() {
+        return "$productFlavor.name-$buildType.name"
+    }
+
+    @Override
+    boolean getZipAlign() {
+        return buildType.zipAlign
+    }
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/internal/SourceVariant.groovy b/buildSrc/src/main/groovy/org/gradle/android/internal/SourceVariant.groovy
new file mode 100644 (file)
index 0000000..6e0b1de
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android.internal
+
+/**
+ * Represents something that contains source and resources.
+ */
+public interface SourceVariant {
+    String getName()
+
+    String getDirName()
+}
diff --git a/buildSrc/src/main/groovy/org/gradle/android/internal/TestAppVariant.groovy b/buildSrc/src/main/groovy/org/gradle/android/internal/TestAppVariant.groovy
new file mode 100644 (file)
index 0000000..8e2908b
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 org.gradle.android.internal
+
+import org.gradle.android.ProductFlavor
+import org.gradle.api.file.FileCollection
+
+class TestAppVariant implements ApplicationVariant {
+    final String name
+    final ProductFlavor productFlavor
+    FileCollection runtimeClasspath
+    FileCollection resourcePackage
+
+    TestAppVariant(ProductFlavor productFlavor) {
+        this.name = "${productFlavor.name.capitalize()}Test"
+        this.productFlavor = productFlavor
+    }
+
+    @Override
+    String getDescription() {
+        return "$productFlavor.name test"
+    }
+
+    String getDirName() {
+        return "${productFlavor.name}/test"
+    }
+
+    String getBaseName() {
+        return "$productFlavor.name-test"
+    }
+
+    @Override
+    boolean getZipAlign() {
+        return false
+    }
+}
diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/android-library.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/android-library.properties
new file mode 100644 (file)
index 0000000..02e3e15
--- /dev/null
@@ -0,0 +1 @@
+implementation-class=org.gradle.android.AndroidLibraryPlugin
\ No newline at end of file
diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/android.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/android.properties
new file mode 100644 (file)
index 0000000..6e679f0
--- /dev/null
@@ -0,0 +1 @@
+implementation-class=org.gradle.android.AndroidPlugin
\ No newline at end of file
diff --git a/customized/build.gradle b/customized/build.gradle
new file mode 100644 (file)
index 0000000..4256381
--- /dev/null
@@ -0,0 +1,31 @@
+apply plugin: 'android'
+
+version='1.0'
+
+android {
+    // Define the target platform
+    target 'android-16'
+
+    // Define the flavors of our product
+    productFlavors {
+        free {
+            packageName = 'org.gradle.sample.free'
+        }
+        paid
+    }
+
+    // Add a custom build type
+    buildTypes {
+        custom
+    }
+}
+
+// You can configure the various source locations
+sourceSets {
+    // Add an additional main source directory and resource directory
+    main.java.srcDir 'some-dir'
+    main.resources.srcDir 'some-resources'
+
+    // A source set for each product flavor and build type is also available for configuration
+    free.java.srcDir 'some-free-dir'
+}
diff --git a/customized/src/custom/java/org/gradle/sample/BuildTypeImpl.java b/customized/src/custom/java/org/gradle/sample/BuildTypeImpl.java
new file mode 100644 (file)
index 0000000..df4425d
--- /dev/null
@@ -0,0 +1,7 @@
+package org.gradle.sample;
+
+public class BuildTypeImpl implements BuildType {
+    public String getBuildType() {
+        return "custom";
+    }
+}
diff --git a/customized/src/debug/java/org/gradle/sample/BuildTypeImpl.java b/customized/src/debug/java/org/gradle/sample/BuildTypeImpl.java
new file mode 100644 (file)
index 0000000..2c3f6bb
--- /dev/null
@@ -0,0 +1,7 @@
+package org.gradle.sample;
+
+public class BuildTypeImpl implements BuildType {
+    public String getBuildType() {
+        return "debug";
+    }
+}
diff --git a/customized/src/free/java/org/gradle/sample/People.java b/customized/src/free/java/org/gradle/sample/People.java
new file mode 100644 (file)
index 0000000..e30708a
--- /dev/null
@@ -0,0 +1,10 @@
+package org.gradle.sample;
+
+import java.util.Iterator;
+import java.util.Arrays;
+
+public class People implements Iterable<Person> {
+    public Iterator<Person> iterator() {
+        return Arrays.asList(new Person("free person")).iterator();
+    }
+}
diff --git a/customized/src/free/res/values/strings.xml b/customized/src/free/res/values/strings.xml
new file mode 100644 (file)
index 0000000..fcb839d
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">Customized Free App</string>
+    <string name="greeting">Hello world! Please upgrade to the paid version!</string>
+</resources>
diff --git a/customized/src/main/AndroidManifest.xml b/customized/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..465282e
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      package="org.gradle.sample"
+      android:versionCode="1"
+      android:versionName="1.0">
+    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
+        <activity android:name="MainActivity"
+                  android:label="@string/app_name">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+</manifest>
diff --git a/customized/src/main/java/org/gradle/sample/BuildType.java b/customized/src/main/java/org/gradle/sample/BuildType.java
new file mode 100644 (file)
index 0000000..4364026
--- /dev/null
@@ -0,0 +1,5 @@
+package org.gradle.sample;
+
+public interface BuildType {
+    String getBuildType();
+}
diff --git a/customized/src/main/java/org/gradle/sample/MainActivity.java b/customized/src/main/java/org/gradle/sample/MainActivity.java
new file mode 100644 (file)
index 0000000..af41e10
--- /dev/null
@@ -0,0 +1,28 @@
+package org.gradle.sample;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.TextView;
+
+public class MainActivity extends Activity
+{
+    /** Called when the activity is first created. */
+    @Override
+    public void onCreate(Bundle savedInstanceState)
+    {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.main);
+
+        String message = "People:";
+
+        Iterable<Person> people = new People();
+        for (Person person : people) {
+            message += "\n * ";
+            message += person.getName();
+        }
+
+        TextView textView = (TextView)findViewById(R.id.people);
+        textView.setTextSize(20);
+        textView.setText(message);
+    }
+}
diff --git a/customized/src/main/java/org/gradle/sample/Person.java b/customized/src/main/java/org/gradle/sample/Person.java
new file mode 100644 (file)
index 0000000..b6fcb27
--- /dev/null
@@ -0,0 +1,13 @@
+package org.gradle.sample;
+
+public class Person {
+    private final String name;
+
+    public Person(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+}
diff --git a/customized/src/main/res/drawable-hdpi/ic_launcher.png b/customized/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..96a442e
Binary files /dev/null and b/customized/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/customized/src/main/res/drawable-ldpi/ic_launcher.png b/customized/src/main/res/drawable-ldpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..9923872
Binary files /dev/null and b/customized/src/main/res/drawable-ldpi/ic_launcher.png differ
diff --git a/customized/src/main/res/drawable-mdpi/ic_launcher.png b/customized/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..359047d
Binary files /dev/null and b/customized/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/customized/src/main/res/drawable-xhdpi/ic_launcher.png b/customized/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..71c6d76
Binary files /dev/null and b/customized/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/customized/src/main/res/layout/main.xml b/customized/src/main/res/layout/main.xml
new file mode 100644 (file)
index 0000000..a896905
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+<TextView
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:text="@string/greeting"
+    />
+<TextView
+    android:id="@+id/people"
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    />
+</LinearLayout>
+
diff --git a/customized/src/main/res/values/strings.xml b/customized/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..045e125
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+</resources>
diff --git a/customized/src/paid/java/org/gradle/sample/People.java b/customized/src/paid/java/org/gradle/sample/People.java
new file mode 100644 (file)
index 0000000..535da1a
--- /dev/null
@@ -0,0 +1,10 @@
+package org.gradle.sample;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+public class People implements Iterable<Person> {
+    public Iterator<Person> iterator() {
+        return Arrays.asList(new Person("paid for person")).iterator();
+    }
+}
diff --git a/customized/src/paid/res/values/strings.xml b/customized/src/paid/res/values/strings.xml
new file mode 100644 (file)
index 0000000..5bdd677
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">Customized Paid App</string>
+    <string name="greeting">Hello world! Thanks for upgrading.</string>
+</resources>
diff --git a/customized/src/release/java/org/gradle/sample/BuildTypeImpl.java b/customized/src/release/java/org/gradle/sample/BuildTypeImpl.java
new file mode 100644 (file)
index 0000000..8afa955
--- /dev/null
@@ -0,0 +1,7 @@
+package org.gradle.sample;
+
+public class BuildTypeImpl implements BuildType {
+    public String getBuildType() {
+        return "release";
+    }
+}
diff --git a/customized/src/test/java/org/gradle/sample/Test.java b/customized/src/test/java/org/gradle/sample/Test.java
new file mode 100644 (file)
index 0000000..17e7bdd
--- /dev/null
@@ -0,0 +1,5 @@
+package org.gradle.sample;
+
+public class Test extends FlavorTest {
+    MainActivity activity = new MainActivity();
+}
diff --git a/customized/src/testFree/java/org/gradle/sample/FlavorTest.java b/customized/src/testFree/java/org/gradle/sample/FlavorTest.java
new file mode 100644 (file)
index 0000000..a72f16d
--- /dev/null
@@ -0,0 +1,4 @@
+package org.gradle.sample;
+
+public class FlavorTest {
+}
diff --git a/customized/src/testPaid/java/org/gradle/sample/FlavorTest.java b/customized/src/testPaid/java/org/gradle/sample/FlavorTest.java
new file mode 100644 (file)
index 0000000..a72f16d
--- /dev/null
@@ -0,0 +1,4 @@
+package org.gradle.sample;
+
+public class FlavorTest {
+}
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644 (file)
index 0000000..9799fd0
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644 (file)
index 0000000..0cf3f16
--- /dev/null
@@ -0,0 +1,6 @@
+#Tue Jul 31 07:31:01 EST 2012
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.1-rc-2-bin.zip
diff --git a/gradlew b/gradlew
new file mode 100755 (executable)
index 0000000..e61422d
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,164 @@
+#!/bin/bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/"
+APP_HOME="`pwd -P`"
+cd "$SAVED"
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644 (file)
index 0000000..8a0b282
--- /dev/null
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/multiproject/app/build.gradle b/multiproject/app/build.gradle
new file mode 100644 (file)
index 0000000..0b715e3
--- /dev/null
@@ -0,0 +1,15 @@
+//
+// A basic Android application split over a couple of Gradle projects.
+//
+
+apply plugin: 'android'
+
+version='1.0'
+
+repositories {
+    mavenCentral()
+}
+
+dependencies {
+    compile project(':util')
+}
diff --git a/multiproject/app/src/main/AndroidManifest.xml b/multiproject/app/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..1f411e0
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      package="org.gradle.sample"
+      android:versionCode="1"
+      android:versionName="1.0">
+    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
+        <activity android:name="MainActivity"
+                  android:label="@string/app_name">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        <activity
+                android:name="ShowPeopleActivity"
+                android:label="@string/title_activity_display_message" >
+                <meta-data
+                    android:name="android.support.PARENT_ACTIVITY"
+                    android:value="org.gradle.sample.MainActivity" />
+            </activity>
+    </application>
+</manifest>
diff --git a/multiproject/app/src/main/java/org/gradle/sample/MainActivity.java b/multiproject/app/src/main/java/org/gradle/sample/MainActivity.java
new file mode 100644 (file)
index 0000000..242c173
--- /dev/null
@@ -0,0 +1,19 @@
+package org.gradle.sample;
+
+import android.app.Activity;
+import android.view.View;
+import android.content.Intent;
+import android.os.Bundle;
+
+public class MainActivity extends Activity {
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.main);
+    }
+
+    public void sendMessage(View view) {
+        Intent intent = new Intent(this, ShowPeopleActivity.class);
+        startActivity(intent);
+    }
+}
diff --git a/multiproject/app/src/main/java/org/gradle/sample/ShowPeopleActivity.java b/multiproject/app/src/main/java/org/gradle/sample/ShowPeopleActivity.java
new file mode 100644 (file)
index 0000000..e2774d7
--- /dev/null
@@ -0,0 +1,30 @@
+package org.gradle.sample;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.content.Intent;
+import android.widget.TextView;
+
+import java.lang.String;
+import java.util.Arrays;
+
+public class ShowPeopleActivity extends Activity {
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        String message = "People:";
+
+        Iterable<Person> people = new People();
+        for (Person person : people) {
+            message += "\n * ";
+            message += person.getName();
+        }
+
+        TextView textView = new TextView(this);
+        textView.setTextSize(20);
+        textView.setText(message);
+
+        setContentView(textView);
+    }
+}
diff --git a/multiproject/app/src/main/res/drawable-hdpi/ic_launcher.png b/multiproject/app/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..96a442e
Binary files /dev/null and b/multiproject/app/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/multiproject/app/src/main/res/drawable-ldpi/ic_launcher.png b/multiproject/app/src/main/res/drawable-ldpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..9923872
Binary files /dev/null and b/multiproject/app/src/main/res/drawable-ldpi/ic_launcher.png differ
diff --git a/multiproject/app/src/main/res/drawable-mdpi/ic_launcher.png b/multiproject/app/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..359047d
Binary files /dev/null and b/multiproject/app/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/multiproject/app/src/main/res/drawable-xhdpi/ic_launcher.png b/multiproject/app/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..71c6d76
Binary files /dev/null and b/multiproject/app/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/multiproject/app/src/main/res/layout/main.xml b/multiproject/app/src/main/res/layout/main.xml
new file mode 100644 (file)
index 0000000..ccc59fb
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="horizontal"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+    <Button
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/button_send"
+            android:onClick="sendMessage" />
+</LinearLayout>
diff --git a/multiproject/app/src/main/res/values/strings.xml b/multiproject/app/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..9c00d14
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">Composite App</string>
+    <string name="button_send">Go</string>
+    <string name="title_activity_display_message">People</string>
+</resources>
diff --git a/multiproject/library/build.gradle b/multiproject/library/build.gradle
new file mode 100644 (file)
index 0000000..48c76ec
--- /dev/null
@@ -0,0 +1 @@
+apply plugin: 'android-library'
diff --git a/multiproject/util/build.gradle b/multiproject/util/build.gradle
new file mode 100644 (file)
index 0000000..f4a999a
--- /dev/null
@@ -0,0 +1,11 @@
+apply plugin: 'java'
+
+version='1.0'
+
+repositories {
+    mavenCentral()
+}
+
+dependencies {
+    compile 'com.google.guava:guava:11.0.2'
+}
diff --git a/multiproject/util/src/main/java/org/gradle/sample/People.java b/multiproject/util/src/main/java/org/gradle/sample/People.java
new file mode 100644 (file)
index 0000000..012dfa1
--- /dev/null
@@ -0,0 +1,10 @@
+package org.gradle.sample;
+
+import java.util.Iterator;
+import com.google.common.collect.Lists;
+
+public class People implements Iterable<Person> {
+    public Iterator<Person> iterator() {
+        return Lists.newArrayList(new Person("fred")).iterator();
+    }
+}
diff --git a/multiproject/util/src/main/java/org/gradle/sample/Person.java b/multiproject/util/src/main/java/org/gradle/sample/Person.java
new file mode 100644 (file)
index 0000000..b6fcb27
--- /dev/null
@@ -0,0 +1,13 @@
+package org.gradle.sample;
+
+public class Person {
+    private final String name;
+
+    public Person(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+}
diff --git a/readme.md b/readme.md
new file mode 100644 (file)
index 0000000..f529599
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,99 @@
+## What is this?
+
+A prototype Gradle plugin to build Android applications. This is intended to be used to explore how such a plugin
+would look and to develop some ideas about how such a plugin would be implemented.
+
+The plugin is functional, if a bit rough, and can generate packaged applications ready to install.
+
+## DSL
+
+The plugin adds 2 concepts to the Gradle DSL:
+
+* A _build type_. There are 2 predefined build types, called `release` and `debug`. You can add additional build types.
+* A _product flavor_. For example, a free or a paid-for flavour.
+
+If you do not define any flavors for your product, a default flavor called `main` is added.
+
+From this, the plugin will add the appropriate tasks to build each combination of build type and product flavor. The
+plugin will also define the following source directories:
+
+* `src/main/java` - Java source to be included in all application variants.
+* `src/main/res` - Resources to be included in all application variants.
+* `src/main/AndroidManifest.xml' - The application manifest (currently shared by all application variants).
+* `src/$BuildType/java` - Java source to be included in all application variants with the given build type.
+* `src/$BuildType/res` - Java source to be included in all application variants with the given build type.
+* `src/$ProductFlavor/java` - Resources to be included in all application variants with the given product flavor.
+* `src/$ProductFlavor/res` - Resources to be included in all application variants with the given product flavor.
+* `src/test/java` - Test source to be included in all test applications.
+* `src/test$ProductFlavor/java` - Test source to be include for the test application for the given product flavor.
+
+You can configure these locations by configuring the associated source set.
+
+Compile time dependencies are declared in the usual way.
+
+Have a look at the `basic/build.gradle` and `customized/build.gradle` build files to see the DSL in action.
+
+### Configuration options
+
+* `android.packageName` - defaults to that specified in `src/main/AndroidManifest.xml`
+* `android.versionCode` - defaults to that specified in `src/main/AndroidManifest.xml`
+* `android.versionName` - defaults to that specified in `src/main/AndroidManifest.xml`
+* `android.target` - defaults to `android-16`.
+* `android.productFlavors.$flavor.packageName` - defaults to `${android.packageName}`
+* `android.productFlavors.$flavor.versionCode` - defaults to `${android.versionCode}`
+* `android.productFlavors.$flavor.versionName` - defaults to `${android.versionName}`
+* `android.buildTypes.$type.zipAlign` - defaults to `true` for `release` and `false` for `debug`
+* `sourceSets.main.java.srcDirs` - defaults to `src/main/java`
+* `sourceSets.main.resources.srcDirs` - defaults to `src/main/res`
+* `sourceSets.$flavor.java.srcDirs` - defaults to `src/$flavor/java`
+* `sourceSets.$flavor.resources.srcDirs` - defaults to `src/$flavor/res`
+* `sourceSets.$buildType.java.srcDirs` - defaults to `src/$buildType/java`
+* `sourceSets.$buildType.resources.srcDirs` - defaults to `src/$buildType/res`
+* `sourceSets.test.java.srcDirs` - defaults to `src/test/java`
+* `sourceSets.test$Flavor.java.srcDirs` - defaults to `src/test$Flavor/java`
+* `dependencies.compile` - compile time dependencies for all applications.
+
+## Contents
+
+The source tree contains the following:
+
+* The `buildSrc` directory contains the plugin implementation.
+* The `basic` directory contains a simple application that follows the conventions
+* The `customized` directory contains an application with some custom build types, product flavors and other
+customizations.
+* The `multiproject` directory contains an application composed from several Gradle projects.
+
+## Usage
+
+Before you start, edit the `basic/local.properties` and `customized/local.properties` files to point at your local install
+of the Android SDK. Normally, these files would not be checked into source control, but would be generated when the
+project is bootstrapped.
+
+Try `./gradlew basic:tasks` in the root directory.
+
+You can also run:
+
+* `assemble` - builds all combinations of build type and product flavor
+* `assemble$BuildType` - build all flavors for the given build type.
+* `assemble$ProductFlavor` - build all build types for the given product flavor.
+* `assemble$ProductFlavor$BuildType` - build the given application variant.
+* `install$ProductFlavor$BuildType` - build and install the given application variant.
+
+## Implementation
+
+For each variant (product-flavor, build-type):
+
+* Generates resource source files into `build/source` from resource directories (main-source-set, product-flavor-source-set, build-type-source-set)
+* Compile source files (main-source-set, product-flavor-source-set, build-type-source-set, generated-source).
+* Converts the bytecode into `build/libs`
+* Crunches resources in `build/resources`
+* Packages the resource into `build/libs`
+* Assembles the application package into `build/libs`.
+
+Some other notes:
+* Uses `sourceSets.main.compileClasspath` as the compile classpath for each variant. Could potentially also include
+`sourceSets.$BuildType.compileClasspath` and `sourceSets.$ProductFlavor.compileClasspath` as well.
+* Currently, the plugin signs all applications using the debug key.
+* No support for building test applications.
+* No support for building library projects.
+* No support for running ProGuard.
diff --git a/settings.gradle b/settings.gradle
new file mode 100644 (file)
index 0000000..a93691f
--- /dev/null
@@ -0,0 +1,9 @@
+include 'basic'
+include 'customized'
+
+include 'app'
+include 'util'
+include 'library'
+project(':app').projectDir = new File(rootDir, 'multiproject/app')
+project(':util').projectDir = new File(rootDir, 'multiproject/util')
+project(':library').projectDir = new File(rootDir, 'multiproject/library')