aboutsummaryrefslogtreecommitdiff
path: root/gradle/src
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-11-12 09:46:07 +0100
committerXavier Ducrohet <xav@android.com>2012-11-12 11:00:48 +0100
commitec1ea61b42ba03107a75f524df6e3c06532f196d (patch)
treef9cde8de0c3b17ce586de629c294375c0fb5f627 /gradle/src
parent91f53cd2dd9caef4ffbfd996df2612ee35e5fb21 (diff)
downloadbuild-ec1ea61b42ba03107a75f524df6e3c06532f196d.tar.gz
Add test that builds all the test projects.
Change-Id: I8686052470b71f9f61f83da360a205a2f04d5271
Diffstat (limited to 'gradle/src')
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy1
-rw-r--r--gradle/src/test/groovy/com/android/build/gradle/ProjectTest.groovy154
-rw-r--r--gradle/src/test/groovy/com/android/build/gradle/internal/BaseTest.groovy47
3 files changed, 194 insertions, 8 deletions
diff --git a/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy b/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy
index dc5c249..d777023 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy
@@ -71,7 +71,6 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
extension = project.extensions.create('android', AppExtension,
this, (ProjectInternal) project, instantiator,
buildTypeContainer, productFlavorContainer)
- extension.
setDefaultConfig(extension.defaultConfig, extension.sourceSetsContainer)
buildTypeContainer.whenObjectAdded { BuildType buildType ->
diff --git a/gradle/src/test/groovy/com/android/build/gradle/ProjectTest.groovy b/gradle/src/test/groovy/com/android/build/gradle/ProjectTest.groovy
new file mode 100644
index 0000000..045d50e
--- /dev/null
+++ b/gradle/src/test/groovy/com/android/build/gradle/ProjectTest.groovy
@@ -0,0 +1,154 @@
+/*
+ * 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 com.android.build.gradle
+
+import com.android.build.gradle.internal.BaseTest
+import com.android.sdklib.internal.project.ProjectProperties
+import com.android.sdklib.internal.project.ProjectPropertiesWorkingCopy
+import com.google.common.collect.Sets
+import org.gradle.tooling.GradleConnector
+import org.gradle.tooling.ProjectConnection
+
+/**
+ */
+class ProjectTest extends BaseTest {
+
+ private File testDir
+ private File sdkDir
+ private static Set<String> builtProjects = Sets.newHashSet()
+
+ @Override
+ protected void setUp() throws Exception {
+ testDir = getTestDir()
+ sdkDir = getSdkDir()
+ }
+
+ void testAidl() {
+ buildProject("aidl")
+ }
+
+ void testApi() {
+ buildProject("api")
+ }
+
+ void testAppLibTest() {
+ buildProject("applibtest")
+ }
+
+ void testBasic() {
+ buildProject("basic")
+ }
+
+ void testDependencies() {
+ buildProject("dependencies")
+ }
+
+ void testFlavored() {
+ buildProject("flavored")
+ }
+
+ void testFlavorLib() {
+ buildProject("flavorlib")
+ }
+
+ void testFlavors() {
+ buildProject("flavors")
+ }
+
+ void testlibsTest() {
+ buildProject("libsTest")
+ }
+
+ void testMigrated() {
+ buildProject("migrated")
+ }
+
+ void testMultiProject() {
+ buildProject("multiproject")
+ }
+
+ void testRepo() {
+ // this is not an actual project, but we add it so that the catch-all below doesn't
+ // try to build it again
+ builtProjects.add("repo")
+
+ File repo = new File(testDir, "repo")
+
+ try {
+ buildProject(new File(repo, "util"), "clean", "uploadArchives")
+ buildProject(new File(repo, "baseLibrary"), "clean", "uploadArchives")
+ buildProject(new File(repo, "library"), "clean", "uploadArchives")
+ buildProject(new File(repo, "app"), "clean", "assemble")
+ } finally {
+ // clean up the test repository.
+ File testrepo = new File(repo, "testrepo")
+ testrepo.deleteDir()
+ }
+ }
+
+ void testTicTacToe() {
+ buildProject("tictactoe")
+ }
+
+ void testOtherProjects() {
+ File[] projects = testDir.listFiles()
+ for (File project : projects) {
+ String name = project.name
+ if (!builtProjects.contains(name)) {
+ System.out.println(">>>> " + name)
+ buildProject(name)
+ }
+ }
+ }
+
+ private void buildProject(String name) {
+ File project = new File(testDir, name)
+ builtProjects.add(name)
+ System.out.println("### " + name)
+
+ buildProject(project, "clean", "assemble")
+ }
+
+ private void buildProject(File project, String... tasks) {
+ File localProp = createLocalProp(project)
+
+ try {
+
+ GradleConnector connector = GradleConnector.newConnector()
+
+ ProjectConnection connection = connector
+ .useGradleVersion("1.2")
+ .forProjectDirectory(project)
+ .connect()
+// .useInstallation(new File("/Users/xav/Desktop/gradle-1.2"))
+
+ connection.newBuild().forTasks(tasks).run()
+ } finally {
+ localProp.delete()
+ }
+ }
+
+
+ private File createLocalProp(File project) {
+ ProjectPropertiesWorkingCopy localProp = ProjectProperties.create(
+ project.absolutePath, ProjectProperties.PropertyType.LOCAL)
+ localProp.setProperty(ProjectProperties.PROPERTY_SDK, sdkDir.absolutePath)
+ localProp.save()
+
+ return (File) localProp.file
+ }
+}
diff --git a/gradle/src/test/groovy/com/android/build/gradle/internal/BaseTest.groovy b/gradle/src/test/groovy/com/android/build/gradle/internal/BaseTest.groovy
index 2a97455..c83fc08 100644
--- a/gradle/src/test/groovy/com/android/build/gradle/internal/BaseTest.groovy
+++ b/gradle/src/test/groovy/com/android/build/gradle/internal/BaseTest.groovy
@@ -24,22 +24,19 @@ import java.security.CodeSource
* Base class for tests.
*/
public abstract class BaseTest extends TestCase {
+
/**
- * Returns the Android source tree root dir.
- * @return the root dir or null if it couldn't be computed.
+ * Returns the gradle plugin test folder.
*/
- protected File getTestDir() {
+ protected File getRootDir() {
CodeSource source = getClass().getProtectionDomain().getCodeSource()
if (source != null) {
URL location = source.getLocation();
try {
File dir = new File(location.toURI())
assertTrue(dir.getPath(), dir.exists())
- System.out.println(dir.absolutePath)
-
- File rootDir = dir.getParentFile().getParentFile().getParentFile().getParentFile()
- return new File(rootDir, "tests")
+ return dir.getParentFile().getParentFile().getParentFile().getParentFile()
} catch (URISyntaxException e) {
fail(e.getLocalizedMessage())
}
@@ -47,4 +44,40 @@ public abstract class BaseTest extends TestCase {
fail("Fail to get tests folder")
}
+
+
+ /**
+ * Returns the root folder for the tests projects.
+ */
+ protected File getTestDir() {
+ File rootDir = getRootDir()
+ return new File(rootDir, "tests")
+ }
+
+ /**
+ * Returns the SDK folder as built from the Android source tree.
+ * @return
+ */
+ protected File getSdkDir() {
+ // get the gradle project root dir.
+ File rootDir = getRootDir()
+
+ // go up twice and get the root Android dir.
+ File androidRootDir = rootDir.getParentFile().getParentFile()
+
+ // get the sdk folder
+ File sdk = new File(androidRootDir, "out" + File.separatorChar + "host" + File.separatorChar + "darwin-x86" + File.separatorChar + "sdk")
+
+ File[] files = sdk.listFiles(new FilenameFilter() {
+
+ @Override
+ boolean accept(File file, String s) {
+ return s.startsWith("android-sdk_") && new File(file,s ).isDirectory()
+ }
+ })
+
+ if (files.length == 1) {
+ return files[0]
+ }
+ }
}