configClosure
46 |
47 | GroovyAndroidExtension(Project project, Instantiator instantiator) {
48 | sourceSetsContainer = project.container(GroovySourceSet, new AndroidGroovySourceSetFactory(instantiator, project.objects))
49 |
50 | sourceSetsContainer.whenObjectAdded { GroovySourceSet sourceSet ->
51 | sourceSet.groovy
52 | }
53 | }
54 |
55 | /**
56 | * Configure {@link GroovyCompile} options
57 | *
58 | * Here is an example of setting compiler customizers for compilation, turning on the
59 | * annotation processing, and setting the source and target compilation to java 1.7:
60 | *
61 | * androidGroovy {
62 | * options {
63 | * configure(groovyOptions) {
64 | * javaAnnotationProcessing = true
65 | * configurationScript = file("$projectDir/config/groovy-compile-options.groovy")
66 | * }
67 | * sourceCompatibility = '1.7'
68 | * targetCompatibility = '1.7'
69 | * }
70 | * }
71 | *
72 | *
73 | * Please see GroovyCompile
74 | * for more information.
75 | *
76 | * @param config configuration closure that will be applied to all {@link GroovyCompile} tasks for the
77 | * android project.
78 | */
79 |
80 | void options(Closure config) {
81 | configClosure = config
82 | }
83 |
84 | /**
85 | * Configure the sources for Groovy in the same way Java sources can be configured for Android.
86 | *
87 | * For example:
88 | *
89 | * androidGroovy {
90 | * sourceSets {
91 | * main {
92 | * groovy {
93 | * srcDirs = ['src/main/groovy', 'src/main/java', 'src/shared/groovy']
94 | * }
95 | * }
96 | * }
97 | * }
98 | *
99 | * Would include both Groovy and Java source to be compiled by groovyc as well as included
100 | * the shared sources in 'src/shared/groovy'
101 | *
102 | * @param configClosure the configuration block that configures
103 | */
104 | void sourceSets(Action> configClosure) {
105 | configClosure.execute(sourceSetsContainer)
106 | }
107 |
108 | void configure(GroovyCompile task) {
109 | if (configClosure != null) {
110 | ConfigureUtil.configure(configClosure, task)
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/groovy-android-gradle-plugin/src/test/groovy/groovyx/GroovyAndroidExtensionSpec.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovyx
18 |
19 | import groovyx.internal.AndroidFileHelper
20 | import groovyx.internal.AndroidPluginHelper
21 | import groovyx.internal.TestProperties
22 | import org.gradle.api.JavaVersion
23 | import org.gradle.api.Project
24 | import org.gradle.api.tasks.compile.GroovyCompile
25 | import org.gradle.testfixtures.ProjectBuilder
26 | import org.junit.Rule
27 | import org.junit.rules.TemporaryFolder
28 | import spock.lang.Specification
29 |
30 | import java.lang.Void as Should
31 |
32 | class GroovyAndroidExtensionSpec extends Specification implements AndroidPluginHelper, AndroidFileHelper {
33 |
34 | @Rule TemporaryFolder dir
35 |
36 | Project project
37 |
38 | def setup() {
39 | project = ProjectBuilder.builder().withProjectDir(dir.root).build()
40 | applyAppPlugin()
41 | }
42 |
43 | Should "set options on groovy compile"() {
44 | given:
45 | def groovyTask = project.tasks.create('TestGroovyCompile', GroovyCompile)
46 |
47 | project.androidGroovy {
48 | options { // must be explicit here as spock does not resolve like gradle
49 | project.configure(groovyTask.groovyOptions) {
50 | encoding = 'UTF-8'
51 | forkOptions.jvmArgs = ['-noverify']
52 | }
53 | sourceCompatibility = JavaVersion.VERSION_1_7
54 | targetCompatibility = '1.7'
55 | }
56 | }
57 |
58 | when:
59 | extension.configure(groovyTask)
60 |
61 | then:
62 | groovyTask.sourceCompatibility == '1.7'
63 | groovyTask.targetCompatibility == '1.7'
64 | groovyTask.groovyOptions.encoding == 'UTF-8'
65 | groovyTask.groovyOptions.forkOptions.jvmArgs == ['-noverify']
66 | }
67 |
68 | Should "add groovy source directories to groovy extension"() {
69 | given:
70 | def expectedSourceDirs = ['test/groovy/test', 'src/main/groovy']
71 |
72 | when:
73 | project.androidGroovy {
74 | sourceSets {
75 | main {
76 | groovy {
77 | srcDirs = expectedSourceDirs
78 | }
79 | }
80 | }
81 | }
82 |
83 | def srcDirs = extension.sourceSetsContainer.getByName('main').groovy.srcDirs
84 |
85 | // paths on Windows use backslashes instead of slashes
86 | def sourcesDirStrings = srcDirs.collect{ it.path.replaceAll("\\\\", '/') }
87 | // this is to get around a weird bug where absolute path of dir.root does not actually
88 | // return the fill path missing the /private folder at the beginning (OSX).
89 | sourcesDirStrings = sourcesDirStrings.collect{ it.split('/')[-3..-1].join('/') }
90 |
91 | then:
92 | noExceptionThrown()
93 | sourcesDirStrings == expectedSourceDirs
94 | }
95 |
96 | Should "add all sources to groovyCompile"() {
97 | given:
98 | // Android Plugin Requires this file to exist with parsable XML
99 | createSimpleAndroidManifest()
100 | file('src/main/java/Java.java') << ''
101 | file('src/main/groovy/Groovy.groovy') << ''
102 | file('src/test/java/TestJava.java') << ''
103 | file('src/test/groovy/TestGroovy.groovy') << ''
104 | file('src/androidTest/java/AndroidTestJava.java') << ''
105 | file('src/androidTest/groovy/AndroidTestGroovy.groovy') << ''
106 |
107 | project.android {
108 | buildToolsVersion TestProperties.getBuildToolsVersion()
109 | compileSdkVersion TestProperties.getCompileSdkVersion()
110 | }
111 |
112 | project.androidGroovy {
113 | skipJavaC = true
114 | }
115 |
116 | when:
117 | project.evaluate()
118 | def groovyTasks = project.tasks.findAll { it.name.contains('Groovyc') }
119 | def javaTasks = project.tasks.findAll { it.name.contains('Javac') }
120 |
121 | then:
122 | javaTasks.each { assert it.source.empty }
123 | groovyTasks.each { assert !it.source.empty }
124 | extension.skipJavaC
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/groovy-android-gradle-plugin/src/test/groovy/groovyx/functional/AnnotationProcessingSpec.groovy:
--------------------------------------------------------------------------------
1 | package groovyx.functional
2 |
3 | import groovyx.functional.internal.AndroidFunctionalSpec
4 |
5 | class AnnotationProcessingSpec extends AndroidFunctionalSpec {
6 | def "should compile android app with annotation processing"() {
7 | given:
8 | file("settings.gradle") << "rootProject.name = 'test-app'"
9 |
10 | createBuildFileForApplication()
11 | createAndroidManifest()
12 | createMainActivityLayoutFile()
13 |
14 | file('src/main/groovy/groovyx/test/MainActivity.groovy') << """
15 | package groovyx.test
16 |
17 | import android.app.Activity
18 | import android.os.Bundle
19 | import groovy.transform.CompileStatic
20 | import com.google.auto.value.AutoValue
21 |
22 | @CompileStatic
23 | class MainActivity extends Activity {
24 | @Override void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState)
26 | contentView = R.layout.activity_main
27 |
28 | def dog = Animal.create 'dog', 4
29 | println dog
30 |
31 | def car = Automobile.create 'car', 4
32 | println car
33 | }
34 | }
35 |
36 | @AutoValue
37 | @CompileStatic
38 | abstract class Temp {
39 |
40 | static Temp create(String name) {
41 | new AutoValue_Temp(name)
42 | }
43 |
44 | abstract String name()
45 | }
46 | """
47 |
48 | file('src/main/groovy/groovyx/test/Automobile.java') << """
49 | package groovyx.test;
50 |
51 | import com.google.auto.value.AutoValue;
52 |
53 | @AutoValue
54 | abstract class Automobile {
55 | static Automobile create(String name, int numberOfWheels) {
56 | return new AutoValue_Automobile(name, numberOfWheels);
57 | }
58 | abstract String name();
59 | abstract int numberOfWheels();
60 | }
61 | """
62 |
63 | file('src/main/java/groovyx/test/Animal.java') << """
64 | package groovyx.test;
65 |
66 | import com.google.auto.value.AutoValue;
67 |
68 | @AutoValue
69 | abstract class Animal {
70 | static Animal create(String name, int numberOfLegs) {
71 | return new AutoValue_Animal(name, numberOfLegs);
72 | }
73 |
74 | abstract String name();
75 | abstract int numberOfLegs();
76 | }
77 | """
78 |
79 | file('src/test/groovy/groovyx/test/JvmTest.groovy') << """
80 | package groovyx.test
81 |
82 | import org.junit.Test
83 |
84 | class JvmTest {
85 | @Test void shouldCompile() {
86 | assert 10 * 2 == 20
87 | }
88 | }
89 | """
90 |
91 | file('src/androidTest/groovy/groovyx/test/AndroidTest.groovy') << """
92 | package groovyx.test
93 |
94 | import android.support.test.runner.AndroidJUnit4
95 | import android.support.test.filters.SmallTest
96 | import groovy.transform.CompileStatic
97 | import org.junit.Before
98 | import org.junit.Test
99 | import org.junit.runner.RunWith
100 |
101 | @RunWith(AndroidJUnit4)
102 | @SmallTest
103 | @CompileStatic
104 | class AndroidTest {
105 | @Test void shouldCompile() {
106 | assert 5 * 2 == 10
107 | }
108 | }
109 | """
110 |
111 | when:\
112 | run 'assemble', 'test'
113 |
114 | then:
115 | noExceptionThrown()
116 | file('build/outputs/apk/debug/test-app-debug.apk').exists()
117 | file('build/intermediates/javac/debug/classes/groovyx/test/MainActivity.class').exists()
118 |
119 | file('build/intermediates/javac/debug/classes/groovyx/test/Animal.class').exists()
120 | file('build/intermediates/javac/debug/classes/groovyx/test/AutoValue_Animal.java').exists()//build/generated/source/apt
121 | file('build/intermediates/javac/release/classes/groovyx/test/AutoValue_Animal.java').exists()
122 | file('build/intermediates/javac/debug/classes/groovyx/test/AutoValue_Animal.class').exists()
123 |
124 | file('build/intermediates/javac/release/classes/groovyx/test/AutoValue_Animal.class').exists()
125 | file('build/intermediates/javac/debug/classes/groovyx/test/AutoValue_Automobile.java').exists()
126 | file('build/intermediates/javac/release/classes/groovyx/test/AutoValue_Automobile.java').exists()
127 | file('build/intermediates/javac/debug/classes/groovyx/test/AutoValue_Automobile.class').exists()
128 |
129 | file('build/intermediates/javac/debug/classes/groovyx/test/Temp.class').exists()
130 | file('build/intermediates/javac/debug/classes/groovyx/test/AutoValue_Temp.java').exists()
131 | file('build/intermediates/javac/release/classes/groovyx/test/AutoValue_Temp.java').exists()
132 | file('build/intermediates/javac/debug/classes/groovyx/test/AutoValue_Temp.class').exists()
133 |
134 | file('build/intermediates/javac/debugAndroidTest/classes/groovyx/test/AndroidTest.class').exists()
135 | file('build/intermediates/javac/debugUnitTest/classes/groovyx/test/JvmTest.class').exists()
136 | file('build/intermediates/javac/releaseUnitTest/classes/groovyx/test/JvmTest.class').exists()
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/groovy-android-gradle-plugin/src/test/groovy/groovyx/GroovyAndroidPluginSpec.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovyx
18 |
19 | import com.android.build.gradle.AppPlugin
20 | import com.android.build.gradle.api.AndroidSourceSet
21 | import groovyx.internal.AndroidFileHelper
22 | import groovyx.internal.AndroidPluginHelper
23 | import groovyx.internal.TestProperties
24 | import org.gradle.api.Project
25 | import org.gradle.api.tasks.GroovySourceSet
26 | import org.gradle.api.tasks.compile.GroovyCompile
27 | import org.gradle.testfixtures.ProjectBuilder
28 | import org.junit.Rule
29 | import org.junit.rules.TemporaryFolder
30 | import spock.lang.Specification
31 | import spock.lang.Unroll
32 |
33 | import java.lang.Void as Should
34 |
35 | import static groovyx.GroovyAndroidPlugin.ANDROID_GROOVY_EXTENSION_NAME
36 |
37 | class GroovyAndroidPluginSpec extends Specification implements AndroidFileHelper, AndroidPluginHelper {
38 |
39 | @Rule TemporaryFolder dir
40 |
41 | Project project
42 |
43 | void setup() {
44 | project = ProjectBuilder.builder().withProjectDir(dir.root).build()
45 | }
46 |
47 | @Unroll
48 | Should "apply groovy plugin on top of #projectPlugin"() {
49 | given:
50 | project.apply plugin: projectPlugin
51 |
52 | when:
53 | project.apply plugin: 'groovyx.android'
54 |
55 | then:
56 | noExceptionThrown()
57 | project.plugins.hasPlugin(GroovyAndroidPlugin)
58 |
59 | where:
60 | projectPlugin << ['android', 'com.android.application', 'android-library', 'com.android.library', 'com.android.test']
61 | }
62 |
63 | Should "add groovy extension"() {
64 | given:
65 | applyAppPlugin()
66 |
67 | expect:
68 | project.extensions.getByName(ANDROID_GROOVY_EXTENSION_NAME) != null
69 | }
70 |
71 | Should "add groovy source sets"() {
72 | given:
73 | applyAppPlugin()
74 | def extension = project.extensions.getByName('android')
75 |
76 | expect:
77 | extension.sourceSets.all { AndroidSourceSet sourceSet ->
78 | def groovySourceSet = sourceSet.convention.plugins.get('groovy')
79 |
80 | assert groovySourceSet != null
81 | assert groovySourceSet instanceof GroovySourceSet
82 | assert groovySourceSet.groovy.srcDirs.contains(project.file("src/$sourceSet.name/groovy"))
83 | }
84 | }
85 |
86 | Should "add groovy compile tasks"() {
87 | given:
88 | applyAppPlugin()
89 | project.android {
90 | buildToolsVersion TestProperties.getBuildToolsVersion()
91 | compileSdkVersion TestProperties.getCompileSdkVersion()
92 | }
93 |
94 | // Android Plugin Requires this file to exist with parsable XML
95 | createSimpleAndroidManifest()
96 | createSimpleGroovyFile()
97 | file('src/androidTest/groovy/groovyx/SimpleAndroidTest.groovy') << """
98 | package groovyx
99 | class SimpleAndroidTest { }
100 | """
101 | file('src/test/groovy/groovyx/SimpleTest.groovy') << """
102 | package groovyx
103 | class SimpleTest { }
104 | """
105 |
106 | when:
107 | project.evaluate()
108 | def groovyTasks = project.tasks.withType(GroovyCompile)
109 | def taskNames = groovyTasks.collect { it.name }
110 |
111 | then:
112 | groovyTasks.size() == 5
113 | taskNames.contains('compileDebugAndroidTestGroovyWithGroovyc')
114 | taskNames.contains('compileDebugGroovyWithGroovyc')
115 | taskNames.contains('compileDebugUnitTestGroovyWithGroovyc')
116 | taskNames.contains('compileReleaseGroovyWithGroovyc')
117 | taskNames.contains('compileReleaseUnitTestGroovyWithGroovyc')
118 | }
119 |
120 | @Unroll
121 | Should "add groovy sourceCompatibility=#version and targetCompatibility=#version automatically"() {
122 | given:
123 | applyAppPlugin()
124 | project.android {
125 | buildToolsVersion TestProperties.getBuildToolsVersion()
126 | compileSdkVersion TestProperties.getCompileSdkVersion()
127 |
128 | compileOptions {
129 | sourceCompatibility version
130 | targetCompatibility version
131 | }
132 | }
133 |
134 | // Android Plugin Requires this file to exist with parsable XML
135 | createSimpleAndroidManifest()
136 | createSimpleGroovyFile()
137 |
138 | when:
139 | project.evaluate()
140 | def groovyTasks = project.tasks.withType(GroovyCompile)
141 |
142 | then:
143 | groovyTasks.count { it.enabled } == 2
144 | groovyTasks.each { task ->
145 | assert task.sourceCompatibility == version
146 | assert task.targetCompatibility == version
147 | }
148 |
149 | where:
150 | version | _
151 | '1.6' | _
152 | '1.7' | _
153 | '1.8' | _
154 | }
155 |
156 | Should "not enable groovy tasks if no source set"() {
157 | given:
158 | project.with {
159 | pluginManager.apply(AppPlugin)
160 | pluginManager.apply(GroovyAndroidPlugin)
161 | android {
162 | buildToolsVersion TestProperties.getBuildToolsVersion()
163 | compileSdkVersion TestProperties.getCompileSdkVersion()
164 | }
165 | }
166 |
167 | // Android Plugin Requires this file to exist with parsable XML
168 | createSimpleAndroidManifest()
169 |
170 | when:
171 | project.evaluate()
172 |
173 | then: 'all tasks are disabled'
174 | assert project.tasks.withType(GroovyCompile).count { it.enabled } == 0
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/groovy-android-gradle-plugin/src/test/groovy/groovyx/functional/SkipJavaCSpec.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovyx.functional
18 |
19 | import groovyx.functional.internal.AndroidFunctionalSpec
20 | import spock.lang.IgnoreIf
21 |
22 | import java.lang.Void as Should
23 |
24 | import static groovyx.internal.TestProperties.allTests
25 | import static groovyx.internal.TestProperties.androidPluginVersion
26 | import static groovyx.internal.TestProperties.compileSdkVersion
27 | import static groovyx.internal.TestProperties.groovyVersion
28 |
29 | @IgnoreIf({ !allTests })
30 | class SkipJavaCSpec extends AndroidFunctionalSpec {
31 |
32 | Should "joint compile java files added to groovy sourceDirs"() {
33 | file("settings.gradle") << "rootProject.name = 'test-app'"
34 |
35 | createProguardRules()
36 |
37 | buildFile << """
38 | buildscript {
39 | repositories {
40 | maven { url "${localRepo.toURI()}" }
41 | jcenter()
42 | google()
43 | }
44 | dependencies {
45 | classpath 'com.android.tools.build:gradle:$androidPluginVersion'
46 | classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:$PLUGIN_VERSION'
47 | }
48 | }
49 |
50 | apply plugin: 'com.android.application'
51 | apply plugin: 'groovyx.android'
52 |
53 | repositories {
54 | jcenter()
55 | google()
56 | }
57 |
58 | android {
59 | compileSdkVersion $compileSdkVersion
60 |
61 | defaultConfig {
62 | minSdkVersion 16
63 | targetSdkVersion $compileSdkVersion
64 |
65 | versionCode 1
66 | versionName '1.0.0'
67 |
68 | testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
69 | }
70 |
71 | buildTypes {
72 | debug {
73 | applicationIdSuffix '.dev'
74 | }
75 | }
76 |
77 | compileOptions {
78 | sourceCompatibility '1.8'
79 | targetCompatibility '1.8'
80 | }
81 |
82 | buildTypes {
83 | debug {
84 | minifyEnabled true
85 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
86 | testProguardFile 'proguard-rules.txt'
87 | }
88 | release {
89 | minifyEnabled true
90 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
91 | }
92 | }
93 | }
94 |
95 | androidGroovy {
96 | skipJavaC = true
97 | }
98 |
99 | dependencies {
100 | implementation 'org.codehaus.groovy:groovy:$groovyVersion:grooid'
101 | }
102 | """
103 |
104 | file('src/main/AndroidManifest.xml') << """
105 |
106 |
108 |
109 |
112 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 | """.trim()
124 |
125 | file('src/main/res/layout/activity_main.xml') << """
126 |
127 |
131 |
132 |
139 |
140 |
141 | """.trim()
142 |
143 | file('src/main/java/groovyx/test/ExampleJava.java') << """
144 | package groovyx.test;
145 |
146 | class ExampleJava {
147 | String getCoolString() {
148 | return "this is a cool string";
149 | }
150 |
151 | // proof that join compilation can work
152 | // from java sources
153 | String getGroovyString() {
154 | return MainActivity.getCoolString();
155 | }
156 | }
157 | """
158 |
159 | file('src/main/groovy/groovyx/test/MainActivity.groovy') << """
160 | package groovyx.test
161 |
162 | import android.app.Activity
163 | import android.os.Bundle
164 | import groovy.transform.CompileStatic
165 |
166 | @CompileStatic
167 | class MainActivity extends Activity {
168 |
169 | static String getCoolString() {
170 | 'cool string from groovy'
171 | }
172 |
173 | @Override void onCreate(Bundle savedInstanceState) {
174 | super.onCreate(savedInstanceState)
175 | contentView = R.layout.activity_main
176 |
177 | new ExampleJava().coolString
178 | }
179 | }
180 | """
181 |
182 | when:
183 | run 'assemble'
184 |
185 | then:
186 | noExceptionThrown()
187 | file('build/outputs/apk/debug/test-app-debug.apk').exists()
188 | file('build/intermediates/javac/debug/classes/groovyx/test/MainActivity.class').exists()
189 | file('build/intermediates/javac/debug/classes/groovyx/test/ExampleJava.class').exists()
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/groovy-android-gradle-plugin/src/test/groovy/groovyx/functional/internal/AndroidFunctionalSpec.groovy:
--------------------------------------------------------------------------------
1 | package groovyx.functional.internal
2 |
3 | import groovyx.internal.TestProperties
4 |
5 | import static groovyx.internal.TestProperties.compileSdkVersion
6 | import static groovyx.internal.TestProperties.groovyVersion
7 |
8 | abstract class AndroidFunctionalSpec extends FunctionalSpec {
9 |
10 | enum AndroidPlugin {
11 | LIBRARY('com.android.library'),
12 | APP('com.android.application')
13 |
14 | private final String value
15 |
16 | AndroidPlugin(String value) {
17 | this.value = value
18 | }
19 | }
20 |
21 | void createBuildFileForApplication(String androidPluginVersion = TestProperties.androidPluginVersion,
22 | String javaVersion = 'JavaVersion.VERSION_1_7') {
23 | createBuildFile(AndroidPlugin.APP, androidPluginVersion, javaVersion)
24 | }
25 |
26 | void createBuildFileForLibrary(String androidPluginVersion = TestProperties.androidPluginVersion,
27 | String javaVersion = 'JavaVersion.VERSION_1_7') {
28 | createBuildFile(AndroidPlugin.LIBRARY, androidPluginVersion, javaVersion)
29 | }
30 |
31 | void createBuildFile(AndroidPlugin plugin, String androidPluginVersion = TestProperties.androidPluginVersion,
32 | String javaVersion = 'JavaVersion.VERSION_1_7') {
33 | createProguardRules()
34 |
35 | buildFile << """
36 | buildscript {
37 | repositories {
38 | jcenter()
39 | google()
40 | maven { url "${localRepo.toURI()}" }
41 | }
42 | dependencies {
43 | classpath 'com.android.tools.build:gradle:$androidPluginVersion'
44 | classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:$PLUGIN_VERSION'
45 | }
46 | }
47 |
48 | apply plugin: '$plugin.value'
49 | apply plugin: 'groovyx.android'
50 |
51 | repositories {
52 | jcenter()
53 | google()
54 | }
55 |
56 | android {
57 | compileSdkVersion $compileSdkVersion
58 |
59 | defaultConfig {
60 | minSdkVersion ${plugin == AndroidPlugin.LIBRARY ? '28' : '16' }
61 | targetSdkVersion $compileSdkVersion
62 |
63 | versionCode 1
64 | versionName '1.0.0'
65 |
66 | testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
67 | }
68 |
69 | buildTypes {
70 | debug {
71 | minifyEnabled true
72 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
73 | testProguardFile 'proguard-rules.txt'
74 | }
75 | release {
76 | minifyEnabled true
77 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
78 | }
79 | }
80 |
81 | compileOptions {
82 | sourceCompatibility $javaVersion
83 | targetCompatibility $javaVersion
84 | }
85 | }
86 |
87 | dependencies {
88 | implementation 'org.codehaus.groovy:groovy:$groovyVersion:grooid'
89 |
90 | annotationProcessor 'com.google.auto.value:auto-value:1.6.3'
91 | compileOnly 'com.google.auto.value:auto-value-annotations:1.6.3'
92 |
93 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
94 | androidTestImplementation 'com.android.support.test:rules:1.0.2'
95 |
96 | testImplementation 'junit:junit:4.12'
97 | }
98 |
99 | configurations.all {
100 | resolutionStrategy.force 'com.android.support:support-annotations:28.0.0'
101 | }
102 |
103 | // force unit test types to be assembled too
104 | android.testVariants.all { variant ->
105 | tasks.getByName('assemble').dependsOn variant.assemble
106 | }
107 | """
108 | }
109 |
110 | void createProguardRules() {
111 | file('proguard-rules.txt') <<
112 | """
113 | -dontobfuscate
114 |
115 | -keep class org.codehaus.groovy.vmplugin.**
116 | -keep class org.codehaus.groovy.runtime.dgm*
117 |
118 | -keepclassmembers class org.codehaus.groovy.runtime.dgm* {*;}
119 | -keepclassmembers class ** implements org.codehaus.groovy.runtime.GeneratedClosure {*;}
120 | -keepclassmembers class org.codehaus.groovy.reflection.GroovyClassValue* {*;}
121 | -keepclassmembers class groovyx.example.** {*;}
122 | -keepclassmembers class com.arasthel.swissknife.utils.Finder {*;}
123 |
124 | -dontwarn org.codehaus.groovy.**
125 | -dontwarn groovy**
126 | -dontnote org.codehaus.groovy.**
127 | -dontnote groovy**
128 |
129 | -keep class org.xmlpull.v1.**
130 | -dontwarn org.xmlpull.v1.**
131 |
132 | -keep class com.squareup.**
133 | -keep class okio.**
134 | -dontwarn com.squareup.**
135 | -dontwarn okio.**
136 | """
137 | }
138 |
139 | void createAndroidManifest() {
140 | file('src/main/AndroidManifest.xml') << """
141 |
142 |
144 |
145 |
148 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 | """.trim()
160 | }
161 |
162 | void createMainActivityLayoutFile() {
163 | file('src/main/res/layout/activity_main.xml') << """
164 |
165 |
169 |
170 |
177 |
178 |
179 | """.trim()
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/groovy-android-gradle-plugin/src/test/groovy/groovyx/functional/CompilationSpec.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovyx.functional
18 |
19 | import groovyx.functional.internal.AndroidFunctionalSpec
20 | import groovyx.internal.AndroidFileHelper
21 |
22 | import java.lang.Void as Should
23 |
24 | /**
25 | * These tests are intended to test all standard functionality of the groovy android plugin.
26 | */
27 | class CompilationSpec extends AndroidFunctionalSpec implements AndroidFileHelper {
28 |
29 | Should "compile android app"() {
30 | given:
31 | file("settings.gradle") << "rootProject.name = 'test-app'"
32 |
33 | createBuildFileForApplication()
34 | createAndroidManifest()
35 | createMainActivityLayoutFile()
36 |
37 | // create Java class to ensure this compile correctly along with groovy classes
38 | file('src/main/java/groovyx/test/SimpleJava.java') << """
39 | package groovyx.test;
40 |
41 | public class SimpleJava {
42 | public static int getInt() {
43 | return 1337;
44 | }
45 | }
46 | """
47 |
48 | // create Java class in groovy folder to ensure this compile correctly along with groovy classes
49 | file('src/main/groovy/groovyx/test/SimpleJavaGroovy.java') << """
50 | package groovyx.test;
51 |
52 | public class SimpleJavaGroovy {
53 | public static int getInt() {
54 | return 2;
55 | }
56 | }
57 | """
58 |
59 | file('src/main/groovy/groovyx/test/MainActivity.groovy') << """
60 | package groovyx.test
61 |
62 | import android.app.Activity
63 | import android.os.Bundle
64 | import groovy.transform.CompileStatic
65 |
66 | @CompileStatic
67 | class MainActivity extends Activity {
68 | @Override void onCreate(Bundle savedInstanceState) {
69 | super.onCreate(savedInstanceState)
70 | contentView = R.layout.activity_main
71 |
72 | def someValue = SimpleJava.int
73 | def result = someValue * SimpleJavaGroovy.int
74 | }
75 | }
76 | """
77 |
78 | file('src/androidTest/groovy/groovyx/test/AndroidTest.groovy') << """
79 | package groovyx.test
80 |
81 | import android.support.test.runner.AndroidJUnit4
82 | import android.support.test.filters.SmallTest
83 | import groovy.transform.CompileStatic
84 | import org.junit.Before
85 | import org.junit.Test
86 | import org.junit.runner.RunWith
87 |
88 | @RunWith(AndroidJUnit4)
89 | @SmallTest
90 | @CompileStatic
91 | class AndroidTest {
92 | @Test void shouldCompile() {
93 | assert 5 * 2 == 10
94 | }
95 | }
96 | """
97 |
98 | file('src/test/groovy/groovyx/test/JvmTest.groovy') << """
99 | package groovyx.test
100 |
101 | import org.junit.Test
102 |
103 | class JvmTest {
104 | @Test void shouldCompile() {
105 | assert 10 * 2 == 20
106 | }
107 | }
108 | """
109 |
110 | when:
111 | run 'assemble', 'test'
112 |
113 | then:
114 | noExceptionThrown()
115 | file('build/outputs/apk/androidTest/debug/test-app-debug-androidTest.apk').exists()
116 | file('build/intermediates/javac/debug/classes/groovyx/test/MainActivity.class').exists()
117 | file('build/intermediates/javac/debugAndroidTest/classes/groovyx/test/AndroidTest.class').exists()
118 | file('build/intermediates/javac/debugUnitTest/classes/groovyx/test/JvmTest.class').exists()
119 | file('build/intermediates/javac/releaseUnitTest/classes/groovyx/test/JvmTest.class').exists()
120 | }
121 |
122 | Should "should compile android library"() {
123 | given:
124 | file("settings.gradle") << "rootProject.name = 'test-lib'"
125 |
126 | createBuildFileForLibrary()
127 | createSimpleAndroidManifest()
128 |
129 | // create Java class to ensure this compiles correctly along with groovy classes
130 | file('src/main/java/groovyx/test/SimpleJava.java') << """
131 | package groovyx.test;
132 |
133 | public class SimpleJava {
134 | public static int getInt() {
135 | return 1;
136 | }
137 | }
138 | """
139 |
140 | // create Java class in groovy folder to ensure this compile correctly along with groovy classes
141 | file('src/main/groovy/groovyx/test/SimpleJavaGroovy.java') << """
142 | package groovyx.test;
143 |
144 | public class SimpleJavaGroovy {
145 | public static int getInt() {
146 | return 2;
147 | }
148 | }
149 | """
150 |
151 | file('src/main/groovy/groovyx/test/Test.groovy') << """
152 | package groovyx.test
153 |
154 | import android.util.Log
155 | import groovy.transform.CompileStatic
156 |
157 | @CompileStatic
158 | class Test {
159 | static void testMethod() {
160 | Log.d(Test.name, "Testing \${SimpleJava.int} \${SimpleJavaGroovy.int}")
161 | }
162 | }
163 | """
164 |
165 | file('src/androidTest/groovy/groovyx/test/AndroidTest.groovy') << """
166 | package groovyx.test
167 |
168 | import android.support.test.runner.AndroidJUnit4
169 | import android.support.test.filters.SmallTest
170 | import groovy.transform.CompileStatic
171 | import org.junit.Before
172 | import org.junit.Test
173 | import org.junit.runner.RunWith
174 |
175 | @RunWith(AndroidJUnit4)
176 | @SmallTest
177 | @CompileStatic
178 | class AndroidTest {
179 | @Test
180 | void shouldCompile() {
181 | assert 5 == 5
182 | }
183 | }
184 | """
185 |
186 | file('src/test/groovy/groovyx/test/JvmTest.groovy') << """
187 | package groovyx.test
188 |
189 | import org.junit.Test
190 |
191 | class JvmTest {
192 | @Test void shouldCompile() {
193 | assert 10 * 2 == 20
194 | }
195 | }
196 | """
197 |
198 | when:
199 | run 'assemble', 'test'
200 |
201 | then:
202 | noExceptionThrown()
203 | file('build/outputs/aar/test-lib-debug.aar').exists()
204 | file('build/outputs/aar/test-lib-release.aar').exists()
205 | file('build/intermediates/javac/debug/classes/groovyx/test/Test.class').exists()
206 | file('build/intermediates/javac/release/classes/groovyx/test/Test.class').exists()
207 | file('build/intermediates/javac/debugAndroidTest/classes/groovyx/test/AndroidTest.class').exists()
208 | file('build/intermediates/javac/debugUnitTest/classes/groovyx/test/JvmTest.class').exists()
209 | file('build/intermediates/javac/releaseUnitTest/classes/groovyx/test/JvmTest.class').exists()
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/groovy-android-gradle-plugin/src/test/groovy/groovyx/functional/RenderScriptCompilationSpec.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovyx.functional
18 |
19 | import groovyx.functional.internal.AndroidFunctionalSpec
20 | import spock.lang.IgnoreIf
21 |
22 | import javax.imageio.ImageIO
23 | import java.awt.image.BufferedImage
24 |
25 | import java.lang.Void as Should
26 |
27 | import static groovyx.internal.TestProperties.allTests
28 | import static groovyx.internal.TestProperties.androidPluginVersion
29 | import static groovyx.internal.TestProperties.buildToolsVersion
30 | import static groovyx.internal.TestProperties.compileSdkVersion
31 | import static groovyx.internal.TestProperties.groovyVersion
32 |
33 | /**
34 | * Ensure that projects with renderscript compile properly.
35 | */
36 | @IgnoreIf({!allTests})
37 | class RenderScriptCompilationSpec extends AndroidFunctionalSpec {
38 |
39 | Should "compile with renderscript"() {
40 | file("settings.gradle") << "rootProject.name = 'test-app'"
41 |
42 | createProguardRules()
43 |
44 | buildFile << """
45 | buildscript {
46 | repositories {
47 | maven { url "${localRepo.toURI()}" }
48 | jcenter()
49 | google()
50 | }
51 | dependencies {
52 | classpath 'com.android.tools.build:gradle:$androidPluginVersion'
53 | classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:$PLUGIN_VERSION'
54 | }
55 | }
56 |
57 | apply plugin: 'com.android.application'
58 | apply plugin: 'groovyx.android'
59 |
60 | repositories {
61 | jcenter()
62 | google()
63 | }
64 |
65 | android {
66 | compileSdkVersion $compileSdkVersion
67 | buildToolsVersion '$buildToolsVersion'
68 |
69 | defaultConfig {
70 | minSdkVersion 16
71 | targetSdkVersion $compileSdkVersion
72 |
73 | versionCode 1
74 | versionName '1.0.0'
75 |
76 | renderscriptTargetApi 22
77 | renderscriptSupportModeEnabled true
78 | }
79 |
80 | buildTypes {
81 | debug {
82 | applicationIdSuffix '.dev'
83 | }
84 | }
85 |
86 | compileOptions {
87 | sourceCompatibility JavaVersion.VERSION_1_8
88 | targetCompatibility JavaVersion.VERSION_1_8
89 | }
90 |
91 | buildTypes {
92 | debug {
93 | minifyEnabled true
94 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
95 | testProguardFile 'proguard-rules.txt'
96 | }
97 | release {
98 | minifyEnabled true
99 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
100 | }
101 | }
102 | }
103 |
104 | dependencies {
105 | implementation 'org.codehaus.groovy:groovy:$groovyVersion:grooid'
106 | }
107 | """
108 |
109 | def image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB)
110 | for (x in 0..99) {
111 | for (y in 0..99) {
112 | int color = (x + y) % 2 == 0 ? 0x000000 : 0xffffff
113 | image.setRGB(x, y, color)
114 | }
115 | }
116 |
117 | def testImage = file('src/main/res/drawable-xhdpi/test.png')
118 | ImageIO.write(image, 'png', testImage)
119 |
120 | file('src/main/AndroidManifest.xml') << """
121 |
122 |
124 |
125 |
128 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 | """.trim()
140 |
141 | file('src/main/res/layout/activity_main.xml') << """
142 |
143 |
147 |
148 |
155 |
156 |
157 | """.trim()
158 |
159 | file('src/main/groovy/groovyx/test/MainActivity.groovy') << """
160 | package groovyx.test
161 |
162 | import android.app.Activity
163 | import android.graphics.Bitmap
164 | import android.graphics.BitmapFactory
165 | import android.os.Bundle
166 | import android.support.v8.renderscript.Allocation
167 | import android.support.v8.renderscript.Element
168 | import android.support.v8.renderscript.RenderScript
169 | import android.support.v8.renderscript.ScriptIntrinsicBlur
170 | import groovy.transform.CompileStatic
171 |
172 | @CompileStatic
173 | class MainActivity extends Activity {
174 | @Override void onCreate(Bundle savedInstanceState) {
175 | super.onCreate(savedInstanceState)
176 | contentView = R.layout.activity_main
177 |
178 | def renderScript = RenderScript.create(this);
179 | def source = BitmapFactory.decodeResource(resources, R.drawable.test)
180 |
181 | def input = Allocation.createFromBitmap(
182 | renderScript, source, Allocation.MipmapControl.MIPMAP_NONE,
183 | Allocation.USAGE_SCRIPT)
184 |
185 | def output = Allocation.createTyped(renderScript, input.type)
186 |
187 | def script = ScriptIntrinsicBlur.create(renderScript,
188 | Element.U8_4(renderScript))
189 | script.setRadius(25)
190 | script.setInput(input)
191 | script.forEach(output)
192 |
193 | def bitmap = Bitmap.createBitmap(source.width, source.height, source.config)
194 | output.copyTo(bitmap)
195 | }
196 | }
197 | """
198 |
199 | when:
200 | run 'assemble'
201 |
202 | then:
203 | noExceptionThrown()
204 | file('build/outputs/apk/debug/test-app-debug.apk').exists()
205 | file('build/intermediates/javac/debug/classes/groovyx/test/MainActivity.class').exists()
206 | }
207 | }
208 |
--------------------------------------------------------------------------------
/groovy-android-gradle-plugin/src/test/groovy/groovyx/functional/KotlinSupportSpec.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package groovyx.functional
17 |
18 | import groovyx.functional.internal.AndroidFunctionalSpec
19 |
20 | import java.lang.Void as Should
21 |
22 | import static groovyx.internal.TestProperties.androidPluginVersion
23 | import static groovyx.internal.TestProperties.buildToolsVersion
24 | import static groovyx.internal.TestProperties.compileSdkVersion
25 | import static groovyx.internal.TestProperties.kotlinVersion
26 | import static groovyx.internal.TestProperties.groovyVersion
27 |
28 | /**
29 | * Allows Kotlin and Groovy to play nicely with each other.
30 | * https://github.com/groovy/groovy-android-gradle-plugin/issues/139
31 | */
32 | class KotlinSupportSpec extends AndroidFunctionalSpec {
33 |
34 | Should "compile with kotlin dependencies"() {
35 | given:
36 | file("settings.gradle") << "rootProject.name = 'test-app'"
37 |
38 | createProguardRules()
39 |
40 | buildFile << """
41 | buildscript {
42 | repositories {
43 | maven { url "${localRepo.toURI()}" }
44 | jcenter()
45 | google()
46 | }
47 | dependencies {
48 | classpath 'com.android.tools.build:gradle:$androidPluginVersion'
49 | classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:$PLUGIN_VERSION'
50 | classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion'
51 | }
52 | }
53 |
54 | apply plugin: 'com.android.application'
55 | apply plugin: 'kotlin-android' // must be applied before groovy
56 | apply plugin: 'kotlin-kapt'
57 | apply plugin: 'groovyx.android'
58 |
59 | repositories {
60 | google()
61 | jcenter()
62 | }
63 |
64 | android {
65 | compileSdkVersion $compileSdkVersion
66 | buildToolsVersion '$buildToolsVersion'
67 |
68 | defaultConfig {
69 | minSdkVersion 16
70 | targetSdkVersion $compileSdkVersion
71 |
72 | versionCode 1
73 | versionName '1.0.0'
74 |
75 | testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
76 | }
77 |
78 | buildTypes {
79 | debug {
80 | applicationIdSuffix '.dev'
81 | }
82 | }
83 |
84 | compileOptions {
85 | sourceCompatibility '1.8'
86 | targetCompatibility '1.8'
87 | }
88 |
89 | buildTypes {
90 | debug {
91 | minifyEnabled true
92 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
93 | testProguardFile 'proguard-rules.txt'
94 | }
95 | release {
96 | minifyEnabled true
97 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
98 | }
99 | }
100 | }
101 |
102 | dependencies {
103 | implementation 'org.codehaus.groovy:groovy:$groovyVersion:grooid'
104 | implementation 'org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion'
105 |
106 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
107 | androidTestImplementation 'com.android.support.test:rules:1.0.2'
108 |
109 | testImplementation 'junit:junit:4.12'
110 | }
111 |
112 | // force unit test types to be assembled too
113 | android.testVariants.all { variant ->
114 | tasks.getByName('assemble').dependsOn variant.assemble
115 | }
116 | """
117 |
118 | file('src/main/AndroidManifest.xml') << """
119 |
120 |
122 |
123 |
126 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 | """.trim()
138 |
139 | file('src/main/res/layout/activity_main.xml') << """
140 |
141 |
145 |
146 |
153 |
154 |
155 | """.trim()
156 |
157 | file('src/main/groovy/groovyx/test/MainActivity.groovy') << """
158 | package groovyx.test
159 |
160 | import android.app.Activity
161 | import android.os.Bundle
162 | import groovy.transform.CompileStatic
163 |
164 | @CompileStatic
165 | class MainActivity extends Activity {
166 | @Override void onCreate(Bundle savedInstanceState) {
167 | super.onCreate(savedInstanceState)
168 | contentView = R.layout.activity_main
169 |
170 | def value = new SimpleTest().getValue()
171 | }
172 | }
173 | """
174 |
175 | file('src/main/java/groovyx/test/SimpleTest.kt') << """
176 | package groovyx.test
177 |
178 | class SimpleTest {
179 | val value: String get() = "Hello World"
180 | }
181 | """
182 |
183 | file('src/test/groovy/groovyx/test/JvmTest.groovy') << """
184 | package groovyx.test
185 |
186 | import org.junit.Test
187 |
188 | class JvmTest {
189 | @Test void shouldCompile() {
190 | assert 10 * 2 == 20
191 | }
192 | }
193 | """
194 |
195 | file('src/androidTest/groovy/groovyx/test/AndroidTest.groovy') << """
196 | package groovyx.test
197 |
198 | import android.support.test.runner.AndroidJUnit4
199 | import android.support.test.filters.SmallTest
200 | import groovy.transform.CompileStatic
201 | import org.junit.Before
202 | import org.junit.Test
203 | import org.junit.runner.RunWith
204 |
205 | @RunWith(AndroidJUnit4)
206 | @SmallTest
207 | @CompileStatic
208 | class AndroidTest {
209 | @Test void shouldCompile() {
210 | assert 5 * 2 == 10
211 | }
212 | }
213 | """
214 |
215 | when:
216 | run 'assemble', 'test'
217 |
218 | then:
219 | noExceptionThrown()
220 | file('build/outputs/apk/debug/test-app-debug.apk').exists()
221 | file('build/intermediates/javac/debug/classes/groovyx/test/MainActivity.class').exists()
222 | file('build/tmp/kotlin-classes/debug/groovyx/test/SimpleTest.class').exists()
223 | file('build/tmp/kotlin-classes/release/groovyx/test/SimpleTest.class').exists()
224 | file('build/intermediates/javac/debugAndroidTest/classes/groovyx/test/AndroidTest.class').exists()
225 | file('build/intermediates/javac/debugUnitTest/classes/groovyx/test/JvmTest.class').exists()
226 | file('build/intermediates/javac/releaseUnitTest/classes/groovyx/test/JvmTest.class').exists()
227 | }
228 | }
229 |
--------------------------------------------------------------------------------
/groovy-android-gradle-plugin/src/test/groovy/groovyx/functional/FullCompilationSpec.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovyx.functional
18 |
19 | import org.gradle.util.VersionNumber
20 | import groovyx.functional.internal.AndroidFunctionalSpec
21 | import groovyx.internal.AndroidFileHelper
22 | import spock.lang.IgnoreIf
23 | import spock.lang.Unroll
24 |
25 | import java.lang.Void as Should
26 |
27 | import static groovyx.internal.TestProperties.allTests
28 |
29 | /**
30 | * Complete test suite to ensure the plugin works with the different versions of android gradle plugin.
31 | * This will only be run if the system property of 'allTests' is set to true
32 | */
33 | @IgnoreIf({ !allTests })
34 | class FullCompilationSpec extends AndroidFunctionalSpec implements AndroidFileHelper {
35 |
36 | @Unroll
37 | Should "compile android app with java:#javaVersion, android plugin:#_androidPluginVersion, gradle version: #gradleVersion"() {
38 | given:
39 | file("settings.gradle") << "rootProject.name = 'test-app'"
40 |
41 | createBuildFileForApplication(_androidPluginVersion, javaVersion)
42 | createAndroidManifest()
43 | createMainActivityLayoutFile()
44 |
45 | // create Java class to ensure this compile correctly along with groovy classes
46 | file('src/main/java/groovyx/test/SimpleJava.java') << """
47 | package groovyx.test;
48 |
49 | public class SimpleJava {
50 | public static int getInt() {
51 | return 1337;
52 | }
53 | }
54 | """
55 |
56 | // create Java class in groovy folder to ensure this compile correctly along with groovy classes
57 | file('src/main/groovy/groovyx/test/SimpleJavaGroovy.java') << """
58 | package groovyx.test;
59 |
60 | public class SimpleJavaGroovy {
61 | public static int getInt() {
62 | return 2;
63 | }
64 | }
65 | """
66 |
67 | file('src/main/groovy/groovyx/test/MainActivity.groovy') << """
68 | package groovyx.test
69 |
70 | import android.app.Activity
71 | import android.os.Bundle
72 | import groovy.transform.CompileStatic
73 |
74 | @CompileStatic
75 | class MainActivity extends Activity {
76 | @Override void onCreate(Bundle savedInstanceState) {
77 | super.onCreate(savedInstanceState)
78 | contentView = R.layout.activity_main
79 |
80 | def someValue = SimpleJava.int
81 | def result = someValue * SimpleJavaGroovy.int
82 | }
83 | }
84 | """
85 |
86 | file('src/androidTest/groovy/groovyx/test/AndroidTest.groovy') << """
87 | package groovyx.test
88 |
89 | import android.support.test.runner.AndroidJUnit4
90 | import android.support.test.filters.SmallTest
91 | import groovy.transform.CompileStatic
92 | import org.junit.Before
93 | import org.junit.Test
94 | import org.junit.runner.RunWith
95 |
96 | @RunWith(AndroidJUnit4)
97 | @SmallTest
98 | @CompileStatic
99 | class AndroidTest {
100 | @Test void shouldCompile() {
101 | assert 5 * 2 == 10
102 | }
103 | }
104 | """
105 |
106 | file('src/test/groovy/groovyx/test/JvmTest.groovy') << """
107 | package groovyx.test
108 |
109 | import org.junit.Test
110 |
111 | class JvmTest {
112 | @Test void shouldCompile() {
113 | assert 10 * 2 == 20
114 | }
115 | }
116 | """
117 |
118 | when:
119 | runWithVersion(gradleVersion, *args)
120 |
121 | then:
122 | noExceptionThrown()
123 | file('build/outputs/apk/debug/test-app-debug.apk').exists()
124 | file("build/intermediates/javac/debug/classes/groovyx/test/MainActivity.class").exists()
125 | file("build/intermediates/javac/debugAndroidTest/classes/groovyx/test/AndroidTest.class").exists()
126 | if (args.contains('test')) {
127 | assert file("build/intermediates/javac/debugUnitTest/classes/groovyx/test/JvmTest.class").exists()
128 | assert file("build/intermediates/javac/releaseUnitTest/classes/groovyx/test/JvmTest.class").exists()
129 | }
130 |
131 | where:
132 | javaVersion | _androidPluginVersion | gradleVersion | args
133 | 'JavaVersion.VERSION_1_8' | '3.6.1' | '6.2.2' | ['assemble', 'test']
134 | }
135 |
136 | @Unroll
137 | Should "compile android library with java:#javaVersion and android plugin:#_androidPluginVersion, gradle version:#gradleVersion"() {
138 | given:
139 | def isGradle5 = VersionNumber.parse(gradleVersion).major == 5
140 |
141 | file("settings.gradle") << "rootProject.name = 'test-lib'"
142 |
143 | createBuildFileForLibrary()
144 | createSimpleAndroidManifest()
145 |
146 | // create Java class to ensure this compiles correctly along with groovy classes
147 | file('src/main/java/groovyx/test/SimpleJava.java') << """
148 | package groovyx.test;
149 |
150 | public class SimpleJava {
151 | public static int getInt() {
152 | return 1;
153 | }
154 | }
155 | """
156 |
157 | // create Java class in groovy folder to ensure this compile correctly along with groovy classes
158 | file('src/main/groovy/groovyx/test/SimpleJavaGroovy.java') << """
159 | package groovyx.test;
160 |
161 | public class SimpleJavaGroovy {
162 | public static int getInt() {
163 | return 2;
164 | }
165 | }
166 | """
167 |
168 | file('src/main/groovy/groovyx/test/Test.groovy') << """
169 | package groovyx.test
170 |
171 | import android.util.Log
172 | import groovy.transform.CompileStatic
173 |
174 | @CompileStatic
175 | class Test {
176 | static void testMethod() {
177 | Log.d(Test.name, "Testing \${SimpleJava.int} \${SimpleJavaGroovy.int}")
178 | }
179 | }
180 | """
181 |
182 | file('src/androidTest/groovy/groovyx/test/AndroidTest.groovy') << """
183 | package groovyx.test
184 |
185 | import android.support.test.runner.AndroidJUnit4
186 | import android.support.test.filters.SmallTest
187 | import groovy.transform.CompileStatic
188 | import org.junit.Before
189 | import org.junit.Test
190 | import org.junit.runner.RunWith
191 |
192 | @RunWith(AndroidJUnit4)
193 | @SmallTest
194 | @CompileStatic
195 | class AndroidTest {
196 | @Test
197 | void shouldCompile() {
198 | assert 5 == 5
199 | }
200 | }
201 | """
202 |
203 | file('src/test/groovy/groovyx/test/JvmTest.groovy') << """
204 | package groovyx.test
205 |
206 | import org.junit.Test
207 |
208 | class JvmTest {
209 | @Test void shouldCompile() {
210 | assert 10 * 2 == 20
211 | }
212 | }
213 | """
214 |
215 | when:
216 | runWithVersion(gradleVersion, *args)
217 |
218 | then:
219 | noExceptionThrown()
220 | file("build/outputs/aar/test-lib${isGradle5 ? '' : '-debug'}.aar").exists()
221 | isGradle5 ? true : file('build/outputs/aar/test-lib-release.aar').exists()
222 | file('build/outputs/apk/androidTest/debug/test-lib-debug-androidTest.apk').exists()
223 | file("build/intermediates/javac/debug/classes/groovyx/test/Test.class").exists()
224 | file("build/intermediates/javac/release/classes/groovyx/test/Test.class").exists()
225 | file("build/intermediates/javac/debugAndroidTest/classes/groovyx/test/AndroidTest.class").exists()
226 | if (args.contains('test')) {
227 | assert file("build/intermediates/javac/debugUnitTest/classes/groovyx/test/JvmTest.class").exists()
228 | assert file("build/intermediates/javac/releaseUnitTest/classes/groovyx/test/JvmTest.class").exists()
229 | }
230 |
231 | where:
232 | javaVersion | _androidPluginVersion | gradleVersion | args
233 | 'JavaVersion.VERSION_1_8' | '3.6.1' | '6.2.2' | ['assemble', 'test']
234 | }
235 |
236 | Should "not resolve dependencies during configuration with --debug"() {
237 | given: 'a multi-module project'
238 | file("settings.gradle") << """
239 | rootProject.name = 'test-lib'
240 |
241 | include ":java-lib"
242 | """
243 |
244 | and: 'an Android library module that depends on a Java library module'
245 | createBuildFileForLibrary()
246 | createSimpleAndroidManifest()
247 |
248 | buildFile << """
249 | dependencies {
250 | implementation project(":java-lib")
251 | }
252 | """
253 |
254 | and: 'a trivial class to trigger Groovy compilation'
255 | file('src/test/groovy/groovyx/test/TrivialClass.groovy') << """
256 | package groovyx.test
257 |
258 | class TrivialClass {
259 | }
260 | """
261 |
262 | and: 'a trivial Java library module'
263 | file("java-lib/build.gradle") << """
264 | plugins {
265 | id 'java-library'
266 | }
267 | """
268 |
269 | when: ''
270 | runDebug()
271 |
272 | then:
273 | noExceptionThrown()
274 | }
275 | }
276 |
--------------------------------------------------------------------------------
/groovy-android-gradle-plugin/src/main/groovy/groovyx/GroovyAndroidPlugin.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovyx
18 |
19 | import com.android.build.gradle.AppExtension
20 | import com.android.build.gradle.BaseExtension
21 | import com.android.build.gradle.BasePlugin
22 | import com.android.build.gradle.FeatureExtension
23 | import com.android.build.gradle.LibraryExtension
24 | import com.android.build.gradle.TestExtension
25 | import com.android.build.gradle.TestedExtension
26 | import com.android.build.gradle.api.AndroidSourceSet
27 | import com.android.build.gradle.api.BaseVariant
28 | import com.android.build.gradle.api.SourceKind
29 | import com.android.builder.model.SourceProvider
30 | import groovy.util.logging.Slf4j
31 | import org.gradle.api.GradleException
32 | import org.gradle.api.Plugin
33 | import org.gradle.api.Project
34 | import org.gradle.api.internal.HasConvention
35 | import org.gradle.api.tasks.GroovySourceSet
36 | import org.gradle.api.tasks.TaskProvider
37 | import org.gradle.api.tasks.compile.GroovyCompile
38 | import org.gradle.api.tasks.compile.JavaCompile
39 | import org.gradle.internal.reflect.Instantiator
40 |
41 | import javax.inject.Inject
42 |
43 | /**
44 | * Adds support for building Android applications using the Groovy language.
45 | */
46 | @Slf4j
47 | class GroovyAndroidPlugin implements Plugin {
48 |
49 | public static final String ANDROID_GROOVY_EXTENSION_NAME = 'androidGroovy'
50 |
51 | private final Instantiator instantiator
52 |
53 | @Inject
54 | GroovyAndroidPlugin(Instantiator instantiator) {
55 | this.instantiator = instantiator
56 | }
57 |
58 | void apply(Project project) {
59 | project.extensions.create(ANDROID_GROOVY_EXTENSION_NAME, GroovyAndroidExtension, project, instantiator)
60 | handleProject(project)
61 | }
62 |
63 | static void handleProject(Project project) {
64 | def androidPlugin = ['android', 'com.android.application', 'android-library', 'com.android.library',
65 | 'com.android.test', 'com.android.feature']
66 | .collect { project.plugins.findPlugin(it) as BasePlugin }
67 | .find { it != null }
68 |
69 | log.debug('Found Plugin: {}', androidPlugin)
70 |
71 | if (androidPlugin == null) {
72 | throw new GradleException('You must apply the Android plugin or the Android library plugin before using the groovy-android plugin')
73 | }
74 |
75 | def extension = project.extensions.getByType(GroovyAndroidExtension)
76 |
77 | def androidExtension = project.extensions.getByName("android") as BaseExtension
78 |
79 | androidExtension.sourceSets.all { AndroidSourceSet sourceSet ->
80 | if (!(sourceSet instanceof HasConvention)) {
81 | return
82 | }
83 |
84 | def sourceSetName = sourceSet.name
85 | def sourceSetPath = project.file("src/$sourceSetName/groovy")
86 |
87 | if (!sourceSetPath.exists()) {
88 | log.debug('SourceSet path does not exists for {} {}', sourceSetName, sourceSetPath)
89 | return
90 | }
91 |
92 | // add so Android Studio will recognize groovy files can see these
93 | sourceSet.java.srcDir(sourceSetPath)
94 |
95 | // create groovy source set so we can access it later
96 | GroovySourceSet groovySourceSet = extension.sourceSetsContainer.maybeCreate(sourceSetName)
97 | sourceSet.convention.plugins['groovy'] = groovySourceSet
98 | def groovyDirSet = groovySourceSet.groovy
99 | groovyDirSet.srcDir(sourceSetPath)
100 |
101 | log.debug('Created groovy sourceDirectorySet at {}', groovyDirSet.srcDirs)
102 | }
103 |
104 | project.afterEvaluate {
105 | forEachVariant(project) { BaseVariant variant ->
106 | processVariant(variant, project, androidExtension, androidPlugin, extension)
107 | }
108 | }
109 | }
110 |
111 | private static void forEachVariant(Project project, Closure action) {
112 | def androidExtension = project.extensions.getByName("android")
113 |
114 | log.debug('Project has {} as an extension', androidExtension)
115 |
116 | if (androidExtension instanceof AppExtension) {
117 | androidExtension.applicationVariants.all(action)
118 | }
119 |
120 | if (androidExtension instanceof LibraryExtension) {
121 | androidExtension.libraryVariants.all(action)
122 | if (androidExtension instanceof FeatureExtension) {
123 | androidExtension.featureVariants.all(action)
124 | }
125 | }
126 |
127 | if (androidExtension instanceof TestExtension) {
128 | androidExtension.applicationVariants.all(action)
129 | }
130 |
131 | if (androidExtension instanceof TestedExtension) {
132 | androidExtension.testVariants.all(action)
133 | androidExtension.unitTestVariants.all(action)
134 | }
135 | }
136 |
137 | private static void processVariant(BaseVariant variantData, Project project, BaseExtension androidExtension, BasePlugin androidPlugin, GroovyAndroidExtension extension) {
138 | def variantName = getVariantName(variantData)
139 | log.debug('Processing variant {}', variantName)
140 |
141 | def javaTask = getJavaTaskProvider(variantData).get()
142 | if (javaTask == null) {
143 | log.info('javaTask it null for {}', variantName)
144 | return
145 | }
146 |
147 | def taskName = javaTask.name.replace('Java', 'Groovy')
148 | def groovyTask = project.tasks.create(taskName, GroovyCompile)
149 |
150 | // do before configuration so users can override / don't break backwards compatibility
151 | groovyTask.targetCompatibility = javaTask.targetCompatibility
152 | groovyTask.sourceCompatibility = javaTask.sourceCompatibility
153 | extension.configure(groovyTask)
154 |
155 | groovyTask.destinationDir = javaTask.destinationDir
156 | groovyTask.classpath = javaTask.classpath
157 | groovyTask.dependsOn = javaTask.dependsOn
158 | groovyTask.groovyClasspath = javaTask.classpath
159 |
160 | def providers = getSourceProviders(variantData)
161 | providers.each { SourceProvider provider ->
162 | def groovySourceSet = provider.convention.plugins['groovy'] as GroovySourceSet
163 | if (groovySourceSet == null) {
164 | return
165 | }
166 |
167 | def groovySourceDirectorySet = groovySourceSet.groovy
168 | groovyTask.source(groovySourceDirectorySet)
169 |
170 | // Exclude any java files that may be included in both java and groovy source sets
171 | javaTask.exclude { file ->
172 | file.file in groovySourceSet.groovy.files
173 | }
174 |
175 | if (extension.skipJavaC) {
176 | groovyTask.source(*(javaTask.source.files as List))
177 | javaTask.exclude {
178 | true
179 | }
180 | javaTask.onlyIf {
181 | false
182 | }
183 | }
184 | }
185 |
186 | // no sources for groovy to compile skip the groovy task
187 | if (groovyTask.source.empty) {
188 | log.debug('no groovy sources found for {} removing groovy task', variantName)
189 | groovyTask.enabled = false
190 | return
191 | }
192 | log.debug('groovy sources for {}: {}', variantName, groovyTask.source.files)
193 |
194 | def additionalSourceFiles = getGeneratedSourceDirs(variantData)
195 | log.debug('additional source files found at {}', additionalSourceFiles)
196 | groovyTask.source(*additionalSourceFiles)
197 |
198 | groovyTask.doFirst { GroovyCompile task ->
199 | def androidRunTime = project.files(getRuntimeJars(androidPlugin, androidExtension))
200 | task.classpath = androidRunTime + javaTask.classpath
201 | task.groovyClasspath = task.classpath
202 | task.options.compilerArgs += getJavaTaskCompilerArgs(javaTask, extension.skipJavaC)
203 | task.groovyOptions.javaAnnotationProcessing = true
204 | task.options.annotationProcessorPath = javaTask.options.annotationProcessorPath
205 | log.debug('Java annotationProcessorPath {}', javaTask.options.annotationProcessorPath)
206 | log.debug('Groovy compiler args {}', task.options.compilerArgs)
207 | }
208 |
209 | log.debug('Groovy classpath: {}', groovyTask.classpath)
210 |
211 | javaTask.finalizedBy(groovyTask)
212 | }
213 |
214 | private static getRuntimeJars(BasePlugin plugin, BaseExtension extension) {
215 | if (plugin.metaClass.getMetaMethod('getRuntimeJarList')) {
216 | return plugin.runtimeJarList
217 | }
218 |
219 | if (extension.metaClass.getMetaMethod('getBootClasspath')) {
220 | return extension.bootClasspath
221 | }
222 |
223 | return plugin.bootClasspath
224 | }
225 |
226 | private static List getJavaTaskCompilerArgs(JavaCompile javaTask, boolean skipJavaC) {
227 | def compilerArgs = javaTask.options.compilerArgs
228 | log.debug('javaTask.options.compilerArgs = {}', compilerArgs)
229 |
230 | if (skipJavaC) {
231 | // if we skip java c the java compiler will still look for the annotation processor directory
232 | // we should create it for it.
233 | compilerArgs.findAll { !it.startsWith('-') }
234 | .each { new File(it).mkdirs() }
235 | }
236 |
237 | return compilerArgs
238 | }
239 |
240 |
241 | private static String getVariantName(BaseVariant variant) {
242 | return variant.name
243 | }
244 |
245 | private static TaskProvider getJavaTaskProvider(BaseVariant variantData) {
246 | // just get actual javac we don't support jack.
247 | return variantData.getJavaCompileProvider()
248 | }
249 |
250 | private static Iterable getSourceProviders(BaseVariant variantData) {
251 | return variantData.sourceSets
252 | }
253 |
254 | private static List getGeneratedSourceDirs(BaseVariant variantData) {
255 | return variantData.getSourceFolders(SourceKind.JAVA).collect { it.dir }
256 | }
257 | }
258 |
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | :groovyVersion: 2.4.12
2 | :pluginVersion: 2.0.1
3 | :pluginSnapshotVersion: 2.0.2
4 | :androidPluginVersion: 3.0.0
5 |
6 | = Groovy language support for Android
7 |
8 | *Deprecated:* This plugin has been deprecated in favor of Kotlin which has the full support of JetBrains
9 | and Google. The changes that go into each Android Plugin Version make it really hard for this plugin
10 | to keep up. As of Gradle 6.0 this plugin does not work.
11 |
12 | This plugin adds http://groovy-lang.org[Groovy Language] support for Android applications and libraries.
13 |
14 | == Updates
15 | As of 2.0.0 of this plugin only will work with the Android Gradle Plugin 3.0.0 and above. For support of lower
16 | version use 1.2.0.
17 |
18 | There is an issues when using build tool 26+ and the Groovy jar. The current work around is to use proguard or
19 | to use JarJar to create a jar file that does not have invoke dynamic classes.
20 | See https://gist.github.com/AndrewReitz/3e1145d66a8ef3f7b578d8604ecd671c[ZarZaring the Groovy Jar for Android 26+]
21 | to create your own jar and avoid having to run proguard.
22 | See https://github.com/groovy/groovy-android-gradle-plugin/issues/145[Github Issue] for more details.
23 |
24 | == Quick Start
25 | Use a https://github.com/pledbrook/lazybones[lazybones] template from
26 | https://github.com/rvanderwerf/grooid-templates[grooid-template]
27 |
28 | == Usage
29 |
30 | Edit your `build.gradle` file to contain the following:
31 |
32 | [source, groovy, subs='attributes']
33 | ----
34 | buildscript {
35 | repositories {
36 | jcenter()
37 | }
38 |
39 | dependencies {
40 | classpath 'com.android.tools.build:gradle:{androidPluginVersion}'
41 | classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:{pluginVersion}'
42 | }
43 | }
44 |
45 | apply plugin: 'com.android.application'
46 | apply plugin: 'groovyx.android'
47 | ----
48 |
49 | The latest version of the Groovy Android Plugin can be found https://github.com/groovy/groovy-android-gradle-plugin/releases[here]
50 |
51 | You must choose which version of Groovy you use. Android support is available in
52 | starting at the 2.4.x releases. You will need to add the following repository to your `build.gradle` file:
53 |
54 | [source, groovy]
55 | ----
56 | repositories {
57 | jcenter()
58 | }
59 | ----
60 |
61 | Then you can start using Groovy by adding the groovy dependency with the `grooid` classifier:
62 |
63 | [source, groovy, subs='attributes']
64 | ----
65 | dependencies {
66 | compile 'org.codehaus.groovy:groovy:{groovyVersion}:grooid'
67 | }
68 | ----
69 |
70 | Full list of releases can be found here https://bintray.com/groovy/maven/groovy[here].
71 | Then use the `assembleDebug` gradle task to test out your build and make sure everything compiles.
72 |
73 | Should you want to test development versions of the plugin, you can add the snapshot repository and
74 | depend on a SNAPSHOT:
75 |
76 | [source, groovy, subs='attributes']
77 | ----
78 | buildscript {
79 | repositories {
80 | jcenter()
81 | maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
82 | }
83 | }
84 | dependencies {
85 | classpath 'com.android.tools.build:gradle:3.0.0'
86 | classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:{pluginSnapshotVersion}-SNAPSHOT'
87 | }
88 | }
89 | ----
90 |
91 | Go http://oss.jfrog.org/oss-snapshot-local/org/codehaus/groovy/groovy-android-gradle-plugin/[here]
92 | to see what the latest SNAPSHOT version is.
93 |
94 | == Where to put sources?
95 |
96 | Groovy sources may be placed in `src/main/groovy`, `src/test/groovy`, `src/androidTest/groovy` and any `src/${buildVariant}/groovy`
97 | configured by default. A default project will have the `release` and `debug` variants but these can be configured with build
98 | types and flavors. See the https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Build-Types[android plugin docs]
99 | for more about configuring different build variants.
100 |
101 | Extra groovy sources may be added in a similar fashion as the https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Sourcesets-and-Dependencies[android plugin]
102 | using the `androidGroovy.sourceSets` block. This is especially useful for sharing code between the different test types, and also
103 | allows you to add Groovy to an existing project. For example
104 |
105 | [source, groovy]
106 | ----
107 | androidGroovy {
108 | sourceSets {
109 | main {
110 | groovy {
111 | srcDirs += 'src/main/java'
112 | }
113 | }
114 | }
115 | }
116 | ----
117 |
118 | would add all of the Java files in `src/main/java` directory to the Groovy
119 | compile task. These files will be removed from the Java compile task,
120 | instead being compiled by GroovyC, and will allow for the Java sources
121 | to be referenced in the Groovy sources (joint compilation).
122 | Please note, that you may need to also add these extra directories to the Java
123 | source sets in the android plugin for Android Studio to recognize the Groovy
124 | files as source.
125 |
126 | == Writing Groovy Code
127 |
128 | This plugin has been successfully tested with Android Studio and will make no attempts to add support for other IDEs.
129 | This plugin will let you write an application in Groovy but it is recommended, for performance, memory and battery life,
130 | that you use `@CompileStatic` wherever possible.
131 |
132 | Details can be found on Melix's http://melix.github.io/blog/2014/06/grooid.html[blog]
133 | and http://melix.github.io/blog/2014/06/grooid2.html[here for more technical details]
134 |
135 | == Including Groovy Libraries
136 |
137 | In order to include libraries written in groovy that include the groovy or
138 | groovy-all jars, you will need to exclude the groovy dependency allowing the
139 | grooid jar to be the one to be compiled against.
140 |
141 | For example to use the groovy-xml library you would simply need to do exclude
142 | the group `org.codehaus.groovy`.
143 |
144 | [source, groovy]
145 | ----
146 | compile ('org.codehaus.groovy:groovy-xml:2.4.3') {
147 | exclude group: 'org.codehaus.groovy'
148 | }
149 | ----
150 |
151 | == Skipping Groovy Compile
152 |
153 | As of version 1.2.0 only build types/build flavors with groovy sources included in them will have
154 | the groovy compile task added. If you would like to skip the groovy compilation tasks on older
155 | versions or on newer version wish to skip them in build types that have groovy sources you can use
156 | the following to disable the groovy compiler task.
157 |
158 | [source, groovy]
159 | ```
160 | tasks.whenTaskAdded { task ->
161 | if (task.name == 'compileDebugGroovyWithGroovyc') { # <1>
162 | task.enabled = false
163 | }
164 | }
165 | ```
166 |
167 | <1> Disables groovy compilation only for the debug build type, simply replace
168 | `compileDebugGroovyWithGroovyc` with whichever compilation task you would like skip to disable it.
169 |
170 | == Configuring the Groovy compilation options
171 |
172 | The Groovy compilation tasks can be configured in the `androidGroovy` block using the `options` block:
173 |
174 | [source, groovy]
175 | ----
176 | androidGroovy {
177 | options {
178 | configure(groovyOptions) {
179 | encoding = 'UTF-8'
180 | forkOptions.jvmArgs = ['-noverify'] // maybe necessary if you use Google Play Services
181 | }
182 | }
183 | }
184 | ----
185 |
186 | See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.GroovyCompile.html[GroovyCompile]
187 | for more options.
188 | See https://github.com/pieces029/is-taylor-swift-single-groovy-android/blob/master/build.gradle[Example Application]
189 | for an example of using these settings to enable custom compilation options.
190 |
191 | == Only Use GroovyC
192 |
193 | For integration with plain java projects or for working with generated files
194 | (such as BuildConfig) it may be desirable to only have GroovyC run in order to
195 | have Java files reference Groovy files. This is roughly the equivalent of placing
196 | all java source files into the groovy source directory (including auto
197 | generated files like BuildConfig). In order to only have GroovyC run simply set
198 | the flag `skipJavaC` in the `androidGroovy` block to true.
199 |
200 | [source, groovy]
201 | ----
202 | androidGroovy {
203 | skipJavaC = true
204 | }
205 | ----
206 |
207 | == Annotation Processing
208 |
209 | As of 1.2.0 Release annotation processing is configured by default.
210 |
211 | Previous versions would require `javaAnnotationProcessing` to be set to true.
212 |
213 | [source, groovy]
214 | ----
215 | androidGroovy {
216 | options {
217 | configure(groovyOptions) {
218 | javaAnnotationProcessing = true
219 | }
220 | }
221 | }
222 | ----
223 |
224 | == Android `packagingOptions`
225 |
226 | Groovy Extension Modules and Global transformations both need a file
227 | descriptor in order to work. Android packaging has a restriction
228 | related to files having the same name located in the same path.
229 |
230 | If you are using several Groovy libraries containing extension modules
231 | and/or global transformations, Android may complain about those files.
232 |
233 | You can simply add the following rule:
234 |
235 | [source, groovy]
236 | ----
237 | android {
238 | packagingOptions {
239 | exclude 'META-INF/services/org.codehaus.groovy.transform.ASTTransformation'
240 | exclude 'META-INF/services/org.codehaus.groovy.runtime.ExtensionModule'
241 | // you may need to exclude other files if you get "duplicate files during packaging of APK"
242 | exclude 'META-INF/groovy-release-info.properties'
243 | exclude 'META-INF/LICENSE'
244 | }
245 | }
246 | ----
247 |
248 | There are no problems excluding global transformation descriptors because
249 | those are only used at compile time, never at runtime.
250 |
251 | The problem comes with module extensions. Unless you statically
252 | compile classes using extension modules with `@CompileStatic` they won't
253 | be available at runtime and you'll get a runtime exception.
254 |
255 | There is an alternative. The https://github.com/kaleidos/emerger[emerger]
256 | gradle plugin will add excludes for you and merges all extension module
257 | descriptors into a single file which will be available at runtime.
258 |
259 | == Groovy Community
260 |
261 | Have questions, want to learn more!?
262 | Come ask questions or help others in #android in the Groovy Community Slack
263 | groovycommunity.com[Sign-Up Here]
264 |
--------------------------------------------------------------------------------
/groovy-android-gradle-plugin/src/test/groovy/groovyx/functional/SourceSetSpec.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovyx.functional
18 |
19 | import groovyx.functional.internal.AndroidFunctionalSpec
20 | import spock.lang.IgnoreIf
21 |
22 | import java.lang.Void as Should
23 |
24 | import static groovyx.internal.TestProperties.allTests
25 | import static groovyx.internal.TestProperties.androidPluginVersion
26 | import static groovyx.internal.TestProperties.compileSdkVersion
27 | import static groovyx.internal.TestProperties.groovyVersion
28 |
29 | @IgnoreIf({ !allTests })
30 | class SourceSetSpec extends AndroidFunctionalSpec {
31 |
32 | Should "compile groovy files added to groovy sourceDirs"() {
33 | file("settings.gradle") << "rootProject.name = 'test-app'"
34 |
35 | createProguardRules()
36 |
37 | buildFile << """
38 | buildscript {
39 | repositories {
40 | maven { url "${localRepo.toURI()}" }
41 | jcenter()
42 | google()
43 | }
44 | dependencies {
45 | classpath 'com.android.tools.build:gradle:$androidPluginVersion'
46 | classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:$PLUGIN_VERSION'
47 | }
48 | }
49 |
50 | apply plugin: 'com.android.application'
51 | apply plugin: 'groovyx.android'
52 |
53 | repositories {
54 | jcenter()
55 | google()
56 | }
57 |
58 | android {
59 | compileSdkVersion $compileSdkVersion
60 |
61 | defaultConfig {
62 | minSdkVersion 16
63 | targetSdkVersion $compileSdkVersion
64 |
65 | versionCode 1
66 | versionName '1.0.0'
67 |
68 | testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
69 | }
70 |
71 | buildTypes {
72 | debug {
73 | applicationIdSuffix '.dev'
74 | }
75 | }
76 |
77 | compileOptions {
78 | sourceCompatibility '1.8'
79 | targetCompatibility '1.8'
80 | }
81 |
82 | buildTypes {
83 | debug {
84 | minifyEnabled true
85 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
86 | testProguardFile 'proguard-rules.txt'
87 | }
88 | release {
89 | minifyEnabled true
90 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
91 | }
92 | }
93 | }
94 |
95 | androidGroovy {
96 | sourceSets {
97 | main {
98 | groovy.srcDirs += 'src/example/groovy'
99 | }
100 | }
101 | }
102 |
103 | dependencies {
104 | implementation 'org.codehaus.groovy:groovy:$groovyVersion:grooid'
105 | }
106 | """
107 |
108 | file('src/main/AndroidManifest.xml') << """
109 |
110 |
112 |
113 |
116 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 | """.trim()
128 |
129 | file('src/main/res/layout/activity_main.xml') << """
130 |
131 |
135 |
136 |
143 |
144 |
145 | """.trim()
146 |
147 | file('src/example/groovy/groovyx/test/ExampleGroovy.groovy') << """
148 | package groovyx.test
149 |
150 | import groovy.transform.CompileStatic
151 |
152 | @CompileStatic
153 | class ExampleGroovy {
154 | String getCoolString() {
155 | 'this is a cool string'
156 | }
157 | }
158 | """
159 |
160 | file('src/main/groovy/groovyx/test/MainActivity.groovy') << """
161 | package groovyx.test
162 |
163 | import android.app.Activity
164 | import android.os.Bundle
165 | import groovy.transform.CompileStatic
166 |
167 | @CompileStatic
168 | class MainActivity extends Activity {
169 | @Override void onCreate(Bundle savedInstanceState) {
170 | super.onCreate(savedInstanceState)
171 | contentView = R.layout.activity_main
172 |
173 | new ExampleGroovy().coolString
174 | }
175 | }
176 | """
177 |
178 | when:
179 | run 'assemble'
180 |
181 | then:
182 | noExceptionThrown()
183 | file('build/outputs/apk/debug/test-app-debug.apk').exists()
184 | file('build/intermediates/javac/debug/classes/groovyx/test/MainActivity.class').exists()
185 | file('build/intermediates/javac/debug/classes/groovyx/test/ExampleGroovy.class').exists()
186 | }
187 |
188 | Should "joint compile java files added to groovy sourceDirs"() {
189 | file("settings.gradle") << "rootProject.name = 'test-app'"
190 |
191 | createProguardRules()
192 |
193 | buildFile << """
194 | buildscript {
195 | repositories {
196 | maven { url "${localRepo.toURI()}" }
197 | jcenter()
198 | google()
199 | }
200 | dependencies {
201 | classpath 'com.android.tools.build:gradle:$androidPluginVersion'
202 | classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:$PLUGIN_VERSION'
203 | }
204 | }
205 |
206 | apply plugin: 'com.android.application'
207 | apply plugin: 'groovyx.android'
208 |
209 | repositories {
210 | jcenter()
211 | google()
212 | }
213 |
214 | android {
215 | compileSdkVersion $compileSdkVersion
216 |
217 | defaultConfig {
218 | minSdkVersion 16
219 | targetSdkVersion $compileSdkVersion
220 |
221 | versionCode 1
222 | versionName '1.0.0'
223 |
224 | testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
225 | }
226 |
227 | buildTypes {
228 | debug {
229 | applicationIdSuffix '.dev'
230 | }
231 | }
232 |
233 | compileOptions {
234 | sourceCompatibility '1.8'
235 | targetCompatibility '1.8'
236 | }
237 |
238 | buildTypes {
239 | debug {
240 | minifyEnabled true
241 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
242 | testProguardFile 'proguard-rules.txt'
243 | }
244 | release {
245 | minifyEnabled true
246 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
247 | }
248 | }
249 | }
250 |
251 | androidGroovy {
252 | sourceSets {
253 | main {
254 | groovy.srcDirs += 'src/main/java'
255 | }
256 | }
257 | }
258 |
259 | dependencies {
260 | implementation 'org.codehaus.groovy:groovy:$groovyVersion:grooid'
261 | }
262 | """
263 |
264 | file('src/main/AndroidManifest.xml') << """
265 |
266 |
268 |
269 |
272 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 | """.trim()
284 |
285 | file('src/main/res/layout/activity_main.xml') << """
286 |
287 |
291 |
292 |
299 |
300 |
301 | """.trim()
302 |
303 | file('src/main/java/groovyx/test/ExampleJava.java') << """
304 | package groovyx.test;
305 |
306 | class ExampleJava {
307 | String getCoolString() {
308 | return "this is a cool string";
309 | }
310 |
311 | // proof that join compilation can work
312 | // from java sources
313 | String getGroovyString() {
314 | return MainActivity.getCoolString();
315 | }
316 | }
317 | """
318 |
319 | file('src/main/groovy/groovyx/test/MainActivity.groovy') << """
320 | package groovyx.test
321 |
322 | import android.app.Activity
323 | import android.os.Bundle
324 | import groovy.transform.CompileStatic
325 |
326 | @CompileStatic
327 | class MainActivity extends Activity {
328 |
329 | static String getCoolString() {
330 | 'cool string from groovy'
331 | }
332 |
333 | @Override void onCreate(Bundle savedInstanceState) {
334 | super.onCreate(savedInstanceState)
335 | contentView = R.layout.activity_main
336 |
337 | new ExampleJava().coolString
338 | }
339 | }
340 | """
341 |
342 | when:
343 | run 'assemble'
344 |
345 | then:
346 | noExceptionThrown()
347 | file('build/outputs/apk/debug/test-app-debug.apk').exists()
348 | file('build/intermediates/javac/debug/classes/groovyx/test/MainActivity.class').exists()
349 | file('build/intermediates/javac/debug/classes/groovyx/test/ExampleJava.class').exists()
350 | }
351 | }
352 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2014 Cédric Champeau
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------