pax_global_header00006660000000000000000000000064133452315260014516gustar00rootroot0000000000000052 comment=fa6bbd26852a31de069d2ecc41d01901eded8a04 gradle-apt-plugin-0.10/000077500000000000000000000000001334523152600147525ustar00rootroot00000000000000gradle-apt-plugin-0.10/.gitignore000066400000000000000000000002351334523152600167420ustar00rootroot00000000000000.gradle build/ # Ignore Gradle GUI config gradle-app.setting # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) !gradle-wrapper.jar gradle-apt-plugin-0.10/.travis.yml000066400000000000000000000026241334523152600170670ustar00rootroot00000000000000language: java # Those lines enable using openjdk9 # See https://github.com/travis-ci/travis-ci/issues/5520 sudo: required dist: trusty group: edge matrix: include: - jdk: openjdk7 env: TEST_GRADLE_VERSIONS=3.4 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=2.5 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=2.6 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=2.7 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=2.8 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=2.9 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=2.10 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=2.11 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=2.12 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=2.13 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=2.14 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=3.0 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=3.1 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=3.2 - jdk: oraclejdk8 env: TEST_GRADLE_VERSIONS=3.4 - jdk: oraclejdk9 env: TEST_GRADLE_VERSIONS=3.4 allow_failures: - jdk: oraclejdk9 install: true script: ./gradlew build -Ptest.gradle-versions="$TEST_GRADLE_VERSIONS" before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ cache: directories: - $HOME/.gradle/caches/ - $HOME/.gradle/wrapper/ gradle-apt-plugin-0.10/LICENSE000066400000000000000000000261361334523152600157670ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. gradle-apt-plugin-0.10/README.md000066400000000000000000000170631334523152600162400ustar00rootroot00000000000000# gradle-apt-plugin This plugin does a few things to make it easier/safer to use Java annotation processors in a Gradle build: * it adds configurations for your compile-time only dependencies (annotations, generally) and annotation processors; * automatically configures the corresponding `JavaCompile` and `GroovyCompile` tasks to make use of these configurations, when the `java` or `groovy` plugin is applied; * automatically configures IntelliJ IDEA and/or Eclipse when the `idea` or `eclipse` plugins are applied. ## Using the plugin The plugin is published to the Plugin Portal; see instructions there: https://plugins.gradle.org/plugin/net.ltgt.apt You can try snapshots using JitPack: https://jitpack.io/#tbroyer/gradle-apt-plugin ## Added configurations For each `SourceSet`, two configurations are added: * for Gradle ≥ 2.12: `CompileOnly`, extends `Compile` (Gradle ≥ 2.12 already provides those configurations; note that this plugin doesn't provide a `CompileClasspath` like Gradle ≥ 2.12) * `Apt` As a result, the following configurations are added to any Java project: * `compileOnly`, extends `compile` * `apt` * `testCompileOnly`, extends `testCompile` * `testApt` The `*Only` configurations are used to specify compile-time only dependencies such as annotations that will be processed by annotation processors. Annotation processors themselves are to be added to the `apt` and `testApt` configurations. The `*Only` configurations are part of the `classpath` of the `JavaCompile` and `GroovyCompile` tasks, whereas the `apt` and `testApt` configurations are turned into `-processorpath` compiler arguments. Note that up until version 0.7, if those configurations were empty, an empty processor path (`-processorpath :`) would be passed to `javac`; this was a breaking change compared to the normal behavior of Gradle, as it meant annotation processors wouldn't be looked up in the tasks' `classpath`. Starting with version 0.8, no `-processorpath` will be passed if the `Apt` configuration is empty; this is to follow the [proposal to add first-class support for annotation processing to Gradle proper](https://github.com/gradle/gradle/blob/master/design-docs/java-annotation-processing.md) Finally, note that those configurations don't extend each others: `testCompileOnly` doesn't extend `compileOnly`, and `testApt` doesn't extend `apt`; those configurations are only use for their respective `JavaCompile` and `GroovyCompile` tasks. ### Example usage After applying the plugin following the above instructions, those added configurations can be used when declaring dependencies: ```gradle dependencies { compile "com.google.dagger:dagger:2.6" apt "com.google.dagger:dagger-compiler:2.6" // auto-factory contains both annotations and their processor, neither is needed at runtime compileOnly "com.google.auto.factory:auto-factory:1.0-beta3" apt "com.google.auto.factory:auto-factory:1.0-beta3" compileOnly "org.immutables:value:2.2.10:annotations" apt "org.immutables:value:2.2.10" } ``` ## Groovy support Starting with version 0.6, the plugin also configures `GroovyCompile` tasks added when the `groovy` plugin is applied. It does not however configure annotation processing for Groovy sources, only for Java sources used in joint compilation. Turn process annotations on Groovy sources, you'll have to configure your `GroovyCompile` tasks; e.g. ```gradle compileGroovy { groovyOptions.javaAnnotationProcessing = true } ``` ## Usage with IDEs IDE configuration is provided on a best-effort basis. ### Eclipse When the `eclipse` plugin is applied, the `eclipse` task will auto-configure the generated files to enable annotation processing in Eclipse. When using Buildship, you'll have to manually run the `eclipseJdtApt` and `eclipseFactorypath` tasks to generate the Eclipse configuration files, then either run the `eclipseJdt` task or manually enable annotation processing: in the project properties → Java Compiler → Annotation Processing, check `Enable Annotation Processing`. Note that while all those tasks are depended on by the `eclipse` task, that one is incompatible with Buildship, so you have to explicitly run the two or three aforementioned tasks and _not_ run the `eclipse` task. In any case, the `eclipse` plugin has to be applied to the project. ### IntelliJ IDEA When the `idea` plugin is applied, the `idea` task will auto-configure the generated files to enable annotation processing in intelliJ IDEA. When using the Gradle integration in IntelliJ IDEA however, rather than the `idea` task, you'll have to manually enable annotation processing: in Settings… → Build, Execution, Deployment → Compiler → Annotation Processors, check `Enable annotation processing` and `Obtain processors from project classpath`. To mimic the Gradle behavior and generated files behavior, you can configure the production and test sources directories to `build/generated/source/apt/main` and `build/generated/source/apt/test` respectively and choose to `Store generated sources relative to:` `Module content root`. Note that starting with IntelliJ IDEA 2016.1, you'll have to uncheck `Create separate module per source set` when importing the project. In any case, the `idea` plugin has to be applied to the project. An alternative, starting with IntelliJ IDEA 2016.3, is to delegate the IDE build actions to Gradle itself: https://www.jetbrains.com/idea/whatsnew/#v2016-3-gradle ## Configuration Starting with version 0.8, the plugin follows the [proposal to add first-class support for annotation processing to Gradle proper](https://github.com/gradle/gradle/blob/master/design-docs/java-annotation-processing.md), making many things configurable by enhancing source sets and tasks. One notable exception is that the proposed new `CompileOptions` properties are actually available on an `aptOptions` object, as the `CompileOptions` cannot actually be enhanced by plugins. Each source set gains a few properties: * for Gradle ≥ 2.12: `compileOnlyConfigurationName` (read-only `String`) returning the `CompileOnly` configuration name; Gradle ≥ 2.12 already provides that property * `aptConfigurationName` (read-only `String`) returning the `Apt` configuration name * `processorpath`, a `FileCollection` defaulting to the `Apt` configuration Each source set `output` gains a `generatedSourcesDir` property, a `File` defaulting to `${project.buildDir}/generated/source/apt/${sourceSet.name}`. Each `JavaCompile` and `GroovyCompile` task gains a couple properties: * `generatedSourcesDestinationDir`, corresponding to the `-s` compiler argument, i.e. whether (if set) and where to write sources files generated by annotation processors * `aptOptions` (read-only), itself with 4 properties: * `annotationProcessing`, a `boolean` setting whether annotation processing is enabled or not; this maps to the `-proc:none` compiler argument, and defaults to `true` (meaning that argument is not passed in, and annotation processing is enabled) * `processorpath`, a `FileCollection` corresponding to the `-processorpath` compiler argument * `processors`, a list of annotation processor class names, mapping to the `-processor` compiler argument * `processorArgs`, a map of annotation processor options, each entry mapping to a `-Akey=value` compiler argument For each source set, the corresponding `JavaCompile` and `GroovyCompile` tasks are configured such that: * `generatedSourcesDestinationDir` maps to the source set's `output.generatedSourcesDir` * `aptOptions.processorpath` maps to the source set's `processorpath` gradle-apt-plugin-0.10/appveyor.yml000066400000000000000000000013061334523152600173420ustar00rootroot00000000000000build: verbosity: detailed build_script: - cmd: .\gradlew.bat assemble --no-daemon test_script: - cmd: .\gradlew.bat check --no-daemon -Ptest.gradle-versions=3.4 environment: matrix: - JAVA_HOME: C:\Program Files\Java\jdk1.7.0 - JAVA_HOME: C:\Program Files\Java\jdk1.8.0 on_success: - cmd: if exist "%USERPROFILE%\.gradle\caches\modules-2\modules-2.lock" del /Q "%USERPROFILE%\.gradle\caches\modules-2\modules-2.lock" - cmd: for /D %%d in ("%USERPROFILE%\.gradle\caches\*") do if exist "%%d\plugin-resolution" rmdir /S /Q "%%d\plugin-resolution" cache: - '%USERPROFILE%\.gradle\caches -> build.gradle' - '%USERPROFILE%\.gradle\wrapper -> gradle\wrapper\gradle-wrapper.properties' gradle-apt-plugin-0.10/build.gradle000066400000000000000000000044701334523152600172360ustar00rootroot00000000000000buildscript { repositories { maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath "com.gradle.publish:plugin-publish-plugin:0.9.7" } } apply plugin: "com.gradle.plugin-publish" apply plugin: 'java-gradle-plugin' apply plugin: 'groovy' group = 'net.ltgt.gradle' if (JavaVersion.current().isJava9Compatible()) { tasks.withType(JavaCompile).all { options.compilerArgs.addAll(['-release', '7']) } tasks.withType(GroovyCompile).all { options.compilerArgs.addAll(['-release', '7']) } } gradle.taskGraph.whenReady { graph -> if (graph.hasTask(publishPlugins)) { assert JavaVersion.current().isJava7() || JavaVersion.current().isJava9Compatible() : "Releases must be built with JDK 7 or JDK 9 (make sure to clean and rebuild after changing JDK)" assert 'git diff --quiet --exit-code'.execute(null, rootDir).waitFor() == 0 : "Working tree is dirty" def process ='git describe --exact-match'.execute(null, rootDir) assert process.waitFor() == 0 : "Version is not tagged" version = process.text.trim() - ~'^v' } } repositories { jcenter() } dependencies { compile gradleApi() compile localGroovy() testCompile('com.netflix.nebula:nebula-test:5.0.0') testCompile('org.spockframework:spock-core:1.0-groovy-2.4') { exclude group: 'org.codehaus.groovy' } testCompile gradleTestKit() } wrapper { gradleVersion = "3.4" } test { inputs.file tasks.jar systemProperty("plugin", tasks.jar.archivePath) if (project.hasProperty("test.gradle-versions")) { systemProperty("test.gradle-versions", project.property("test.gradle-versions")) } testLogging { showExceptions = true showStackTraces = true exceptionFormat = 'FULL' } } pluginBundle { website = 'https://github.com/tbroyer/gradle-apt-plugin' vcsUrl = 'https://github.com/tbroyer/gradle-apt-plugin' description = 'Gradle plugin making it easier/safer to use Java annotation processors' tags = [ 'annotation-processing', 'annotation-processors', 'apt' ] plugins { aptPlugin { id = 'net.ltgt.apt' displayName = 'Gradle APT plugin' } } mavenCoordinates { groupId = project.group artifactId = project.name } } gradle-apt-plugin-0.10/settings.gradle000066400000000000000000000000471334523152600177730ustar00rootroot00000000000000rootProject.name = 'gradle-apt-plugin' gradle-apt-plugin-0.10/src/000077500000000000000000000000001334523152600155415ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/main/000077500000000000000000000000001334523152600164655ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/main/groovy/000077500000000000000000000000001334523152600200125ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/main/groovy/net/000077500000000000000000000000001334523152600206005ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/main/groovy/net/ltgt/000077500000000000000000000000001334523152600215525ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/main/groovy/net/ltgt/gradle/000077500000000000000000000000001334523152600230105ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/main/groovy/net/ltgt/gradle/apt/000077500000000000000000000000001334523152600235745ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/main/groovy/net/ltgt/gradle/apt/AptPlugin.groovy000066400000000000000000000361501334523152600267530ustar00rootroot00000000000000package net.ltgt.gradle.apt import groovy.transform.PackageScope import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.FileCollection import org.gradle.api.plugins.GroovyBasePlugin import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.tasks.Delete import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.compile.AbstractCompile import org.gradle.api.tasks.compile.GroovyCompile import org.gradle.api.tasks.compile.JavaCompile import org.gradle.plugins.ide.eclipse.EclipsePlugin import org.gradle.plugins.ide.idea.IdeaPlugin import org.gradle.util.GradleVersion class AptPlugin implements Plugin { @Override void apply(Project project) { def cl = { AbstractCompile task -> task.convention.plugins.put("net.ltgt.apt", new AptConvention(project)) task.inputs.property("aptOptions.annotationProcessing", { task.convention.getPlugin(AptConvention).aptOptions.annotationProcessing }) task.inputs.property("aptOptions.processors", { task.convention.getPlugin(AptConvention).aptOptions.processors }) task.inputs.property("aptOptions.processorArgs", { task.convention.getPlugin(AptConvention).aptOptions.processorArgs }) def propBuilder = task.inputs.files { task.convention.getPlugin(AptConvention).aptOptions.processorpath } if (!propBuilder.is(task.inputs)) { propBuilder.withPropertyName("aptOptions.processorpath") } propBuilder = task.outputs.dir { task.convention.getPlugin(AptConvention).generatedSourcesDestinationDir } if (!propBuilder.is(task.outputs)) { propBuilder.withPropertyName("generatedSourcesDestinationDir").optional() } task.doFirst { def aptConvention = task.convention.getPlugin(AptConvention) aptConvention.makeDirectories() task.options.compilerArgs += aptConvention.buildCompilerArgs() } } project.tasks.withType(JavaCompile, cl) project.tasks.withType(GroovyCompile, cl) project.plugins.withType(JavaBasePlugin) { def javaConvention = project.convention.getPlugin(JavaPluginConvention) javaConvention.sourceSets.all { SourceSet sourceSet -> def convention = new AptSourceSetConvention(project, sourceSet) sourceSet.convention.plugins.put("net.ltgt.apt", convention) sourceSet.output.convention.plugins.put("net.ltgt.apt", new AptSourceSetOutputConvention(project, sourceSet)) def compileOnlyConfigurationName = convention.compileOnlyConfigurationName // Gradle 2.12 already creates such a configuration in the JavaBasePlugin; our compileOnlyConfigurationName has the same value def configuration = project.configurations.findByName(compileOnlyConfigurationName) if (configuration == null) { configuration = project.configurations.create(compileOnlyConfigurationName) configuration.visible = false configuration.description = "Compile-only classpath for ${sourceSet}." configuration.extendsFrom project.configurations.findByName(sourceSet.compileConfigurationName) sourceSet.compileClasspath = configuration // Special-case the JavaPlugin's 'test' source set, only if we created the testCompileOnly configuration // Note that Gradle 2.12 actually creates a testCompilationClasspath configuration that extends testCompileOnly // and sets it as sourceSets.test.compileClasspath; rather than directly using the testCompileOnly configuration. if (sourceSet.name == SourceSet.TEST_SOURCE_SET_NAME) { project.plugins.withType(JavaPlugin) { sourceSet.compileClasspath = project.files(javaConvention.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).output, configuration) } } } def aptConfiguration = project.configurations.create(convention.aptConfigurationName) aptConfiguration.visible = false aptConfiguration.description = "Processor path for ${sourceSet}" configureCompileTask(project, sourceSet, sourceSet.compileJavaTaskName) } } project.plugins.withType(JavaPlugin) { def javaConvention = project.convention.getPlugin(JavaPluginConvention) def mainSourceSet = javaConvention.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME) def testSourceSet = javaConvention.sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME) configureEclipse(project, mainSourceSet, testSourceSet) configureIdeaModule(project, mainSourceSet, testSourceSet) } project.plugins.withType(GroovyBasePlugin) { def javaConvention = project.convention.getPlugin(JavaPluginConvention) javaConvention.sourceSets.all { SourceSet sourceSet -> configureCompileTask(project, sourceSet, sourceSet.getCompileTaskName("groovy")) } } configureIdeaProject(project) } private void configureCompileTask(Project project, SourceSet sourceSet, String taskName) { def task = project.tasks.withType(AbstractCompile).getByName(taskName) def aptConvention = task.convention.getPlugin(AptConvention) aptConvention.generatedSourcesDestinationDir = { sourceSet.output.convention.getPlugin(AptSourceSetOutputConvention).generatedSourcesDir } aptConvention.aptOptions.processorpath = { sourceSet.convention.getPlugin(AptSourceSetConvention).processorpath } } /** * Inspired by https://github.com/mkarneim/pojobuilder/wiki/Enabling-PojoBuilder-for-Eclipse-Using-Gradle */ private void configureEclipse(Project project, SourceSet mainSourceSet, SourceSet testSourceSet) { project.plugins.withType(EclipsePlugin) { project.eclipse.jdt.file.withProperties { it.'org.eclipse.jdt.core.compiler.processAnnotations' = 'enabled' } project.afterEvaluate { project.eclipse.classpath { plusConfigurations += [ project.configurations.getByName(mainSourceSet.compileOnlyConfigurationName), project.configurations.getByName(testSourceSet.compileOnlyConfigurationName) ] } } if (!project.tasks.findByName('eclipseJdtApt')) { def task = project.tasks.create('eclipseJdtApt') { ext.aptPrefs = project.file('.settings/org.eclipse.jdt.apt.core.prefs') outputs.file(aptPrefs) doLast { project.mkdir(aptPrefs.parentFile) aptPrefs.text = """\ eclipse.preferences.version=1 org.eclipse.jdt.apt.aptEnabled=true org.eclipse.jdt.apt.genSrcDir=.apt_generated org.eclipse.jdt.apt.reconcileEnabled=true """.stripIndent() } } project.tasks.eclipse.dependsOn task def cleanTask = project.tasks.create('cleanEclipseJdtApt', Delete) cleanTask.delete task.outputs project.tasks.cleanEclipse.dependsOn cleanTask } if (!project.tasks.findByName('eclipseFactorypath')) { def task = project.tasks.create('eclipseFactorypath') { ext.factorypath = project.file('.factorypath') inputs.files project.configurations.getByName(mainSourceSet.aptConfigurationName), project.configurations.getByName(testSourceSet.aptConfigurationName) outputs.file factorypath doLast { factorypath.withWriter { new groovy.xml.MarkupBuilder(it).'factorypath' { [project.configurations.getByName(mainSourceSet.aptConfigurationName), project.configurations.getByName(testSourceSet.aptConfigurationName)]*.each { factorypathentry( kind: 'EXTJAR', id: it.absolutePath, enabled: true, runInBatchMode: false, ) } } } } } project.tasks.eclipse.dependsOn task def cleanTask = project.tasks.create('cleanEclipseFactorypath', Delete) cleanTask.delete task.outputs project.tasks.cleanEclipse.dependsOn cleanTask } } } private void configureIdeaModule(Project project, SourceSet mainSourceSet, SourceSet testSourceSet) { project.plugins.withType(IdeaPlugin) { project.afterEvaluate { project.idea.module { def excl = [ mainSourceSet, testSourceSet ].collect { it.output.generatedSourcesDir } .collect { def ancestors = [] for (File f = it; f != null && f != project.projectDir; f = f.parentFile) { ancestors.add(f) } return ancestors } .flatten() if (excl.contains(project.buildDir) && excludeDirs.contains(project.buildDir)) { excludeDirs -= project.buildDir // Race condition: many of these will actually be created afterwards… def subdirs = project.buildDir.listFiles({ f -> f.directory } as FileFilter) if (subdirs != null) { excludeDirs += subdirs as List } } excludeDirs -= excl sourceDirs += mainSourceSet.output.generatedSourcesDir testSourceDirs += testSourceSet.output.generatedSourcesDir generatedSourceDirs += [ mainSourceSet.output.generatedSourcesDir, testSourceSet.output.generatedSourcesDir ] if (GradleVersion.current() >= GradleVersion.version("3.4")) { // Gradle 3.4 changed IDEA mappings // See https://docs.gradle.org/3.4/release-notes.html#idea-mapping-has-been-simplified scopes.PROVIDED.plus += [ project.configurations.getByName(mainSourceSet.aptConfigurationName) ] scopes.TEST.plus += [ project.configurations.getByName(testSourceSet.aptConfigurationName) ] } else { // NOTE: ideally we'd use PROVIDED for both, but then every transitive dependency in // compile or testCompile configurations that would also be in compileOnly and // testCompileOnly would end up in PROVIDED. scopes.COMPILE.plus += [ project.configurations.getByName(mainSourceSet.compileOnlyConfigurationName), project.configurations.getByName(mainSourceSet.aptConfigurationName) ] scopes.TEST.plus += [ project.configurations.getByName(testSourceSet.compileOnlyConfigurationName), project.configurations.getByName(testSourceSet.aptConfigurationName) ] } } } } } private void configureIdeaProject(Project project) { if (project.parent == null) { project.plugins.withType(IdeaPlugin) { project.idea.project.ipr.withXml { def compilerConfiguration = it.node.component.find { it.@name == 'CompilerConfiguration' } compilerConfiguration.remove(compilerConfiguration.annotationProcessing) compilerConfiguration.append(new NodeBuilder().annotationProcessing() { profile(name: 'Default', enabled: true, default: true) { // XXX: this assumes that all subprojects use the same name for their buildDir sourceOutputDir(name: "${project.relativePath(project.buildDir)}/generated/source/apt/$SourceSet.MAIN_SOURCE_SET_NAME") sourceTestOutputDir(name: "${project.relativePath(project.buildDir)}/generated/source/apt/$SourceSet.TEST_SOURCE_SET_NAME") outputRelativeToContentRoot(value: true) processorPath(useClasspath: true) } }) } } } } class AptConvention { private final Project project AptConvention(Project project) { this.project = project this.aptOptions = new AptOptions(project); } private Object generatedSourcesDestinationDir public File getGeneratedSourcesDestinationDir() { if (generatedSourcesDestinationDir == null) { return null } return project.file(generatedSourcesDestinationDir) } public void setGeneratedSourcesDestinationDir(Object generatedSourcesDestinationDir) { this.generatedSourcesDestinationDir = generatedSourcesDestinationDir } final AptOptions aptOptions @PackageScope void makeDirectories() { if (generatedSourcesDestinationDir != null) { project.mkdir(generatedSourcesDestinationDir) } } @PackageScope List buildCompilerArgs() { def result = [] if (generatedSourcesDestinationDir != null) { result += ["-s", getGeneratedSourcesDestinationDir().path] } if (!aptOptions.annotationProcessing) { result += ["-proc:none"] } if (aptOptions.processorpath != null && !aptOptions.processorpath.empty) { result += ["-processorpath", aptOptions.processorpath.asPath] } if (aptOptions.processors != null && !aptOptions.processors.empty) { result += ["-processor", aptOptions.processors.join(",")] } result += aptOptions.processorArgs?.collect { key, value -> "-A$key=$value" } return result } } class AptOptions { private final Project project AptOptions(Project project) { this.project = project } boolean annotationProcessing = true private Object processorpath public FileCollection getProcessorpath() { if (processorpath == null) { return null } return project.files(processorpath) } public void setProcessorpath(Object processorpath) { this.processorpath = processorpath } List processors = [] Map processorArgs = [:] } class AptSourceSetConvention { private final Project project private final SourceSet sourceSet AptSourceSetConvention(Project project, SourceSet sourceSet) { this.project = project this.sourceSet = sourceSet this.processorpath = { project.configurations.findByName(this.aptConfigurationName) } } private Object processorpath public FileCollection getProcessorpath() { if (processorpath == null) { return null; } return project.files(processorpath) } public void setProcessorpath(Object processorpath) { this.processorpath = processorpath } public String getCompileOnlyConfigurationName() { return sourceSet.compileConfigurationName + "Only" } public String getAptConfigurationName() { // HACK: we use the same naming logic/scheme as for tasks, so just use SourceSet#getTaskName return sourceSet.getTaskName("", "apt") } } class AptSourceSetOutputConvention { private final Project project private final SourceSet sourceSet AptSourceSetOutputConvention(Project project, SourceSet sourceSet) { this.project = project this.sourceSet = sourceSet this.generatedSourcesDir = { project.file("${project.buildDir}/generated/source/apt/${sourceSet.name}") } } private Object generatedSourcesDir public File getGeneratedSourcesDir() { if (generatedSourcesDir == null) { return null } return project.file(generatedSourcesDir) } public void setGeneratedSourcesDir(Object generatedSourcesDir) { this.generatedSourcesDir = generatedSourcesDir } } } gradle-apt-plugin-0.10/src/main/resources/000077500000000000000000000000001334523152600204775ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/main/resources/META-INF/000077500000000000000000000000001334523152600216375ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/main/resources/META-INF/gradle-plugins/000077500000000000000000000000001334523152600245545ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/main/resources/META-INF/gradle-plugins/net.ltgt.apt.properties000066400000000000000000000000631334523152600312130ustar00rootroot00000000000000implementation-class=net.ltgt.gradle.apt.AptPlugin gradle-apt-plugin-0.10/src/test/000077500000000000000000000000001334523152600165205ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/test/groovy/000077500000000000000000000000001334523152600200455ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/test/groovy/net/000077500000000000000000000000001334523152600206335ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/test/groovy/net/ltgt/000077500000000000000000000000001334523152600216055ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/test/groovy/net/ltgt/gradle/000077500000000000000000000000001334523152600230435ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/test/groovy/net/ltgt/gradle/apt/000077500000000000000000000000001334523152600236275ustar00rootroot00000000000000gradle-apt-plugin-0.10/src/test/groovy/net/ltgt/gradle/apt/AptPluginIntegrationSpec.groovy000066400000000000000000000223771334523152600320330ustar00rootroot00000000000000package net.ltgt.gradle.apt import org.gradle.testkit.runner.GradleRunner import org.gradle.testkit.runner.TaskOutcome import org.junit.Rule import org.junit.rules.TemporaryFolder import spock.lang.Specification import spock.lang.Unroll class AptPluginIntegrationSpec extends Specification { @Rule TemporaryFolder testProjectDir = new TemporaryFolder() File buildFile def setup() { buildFile = testProjectDir.newFile('build.gradle') buildFile << """\ buildscript { dependencies { classpath files(\$/${System.getProperty('plugin')}/\$) } } """.stripIndent() } @Unroll def "simple non-java project, with Gradle #gradleVersion"() { given: buildFile << """\ apply plugin: 'net.ltgt.apt' task javaCompilationTask(type: JavaCompile) { source 'src/' include '**/*.java' classpath = project.files() destinationDir = project.file('build/classes') sourceCompatibility = org.gradle.api.JavaVersion.current() targetCompatibility = org.gradle.api.JavaVersion.current() dependencyCacheDir = project.file('build/dependency-cache') } """.stripIndent() def f = new File(testProjectDir.newFolder('src', 'simple'), 'HelloWorld.java') f.createNewFile() f << """\ package simple; public class HelloWorld { public String sayHello(String name) { return "Hello, " + name + "!"; } } """.stripIndent() when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments('javaCompilationTask') .build() then: result.task(':javaCompilationTask').outcome == TaskOutcome.SUCCESS new File(testProjectDir.root, 'build/classes/simple/HelloWorld.class').exists() where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } @Unroll def "simple java project, with Gradle #gradleVersion"() { given: buildFile << """\ apply plugin: 'net.ltgt.apt' apply plugin: 'java' """.stripIndent() def f = new File(testProjectDir.newFolder('src', 'main', 'java', 'simple'), 'HelloWorld.java') f.createNewFile() f << """\ package simple; public class HelloWorld { public String sayHello(String name) { return "Hello, " + name + "!"; } } """.stripIndent() f = new File(testProjectDir.newFolder('src', 'test', 'java', 'simple'), 'HelloWorldTest.java') f.createNewFile() f << """\ package simple; public class HelloWorldTest { // Not a real unit-test public static void main(String[] args) { System.out.println(new HelloWorld().sayHello("World")); } } """.stripIndent() when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments('compileTestJava') .build() then: result.task(':compileJava').outcome == TaskOutcome.SUCCESS result.task(':compileTestJava').outcome == TaskOutcome.SUCCESS where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } @Unroll def "simple java project with compile-only dependency, with Gradle #gradleVersion"() { given: def settingsFile = testProjectDir.newFile('settings.gradle') settingsFile << """\ include 'annotations' include 'core' """.stripIndent() buildFile << """\ subprojects { apply plugin: 'java' } project('core') { apply plugin: 'net.ltgt.apt' dependencies { compileOnly project(':annotations') } } """.stripIndent() def f = new File(testProjectDir.newFolder('annotations', 'src', 'main', 'java', 'annotations'), 'MyAnnotation.java') f.createNewFile() f << """\ package annotations; import java.lang.annotation.Documented; public @interface MyAnnotation { } """.stripIndent() f = new File(testProjectDir.newFolder('core', 'src', 'main', 'java', 'core'), 'HelloWorld.java') f.createNewFile() f << """\ package core; import annotations.MyAnnotation; @MyAnnotation public class HelloWorld { public String sayHello(String name) { return "Hello, " + name + "!"; } } """.stripIndent() expect: when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments(':core:javadoc') .build() then: result.task(':annotations:compileJava').outcome == TaskOutcome.SUCCESS result.task(':core:compileJava').outcome == TaskOutcome.SUCCESS result.task(':core:javadoc').outcome == TaskOutcome.SUCCESS where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } @Unroll def "simple non-groovy project, with Gradle #gradleVersion"() { given: buildFile << """\ apply plugin: 'net.ltgt.apt' configurations { groovy } dependencies { groovy localGroovy() } task groovyCompilationTask(type: GroovyCompile) { source 'src/' include '**/*.groovy' classpath = configurations.groovy destinationDir = project.file('build/classes') sourceCompatibility = org.gradle.api.JavaVersion.current() targetCompatibility = org.gradle.api.JavaVersion.current() groovyClasspath = configurations.groovy } """.stripIndent() def f = new File(testProjectDir.newFolder('src', 'simple'), 'HelloWorld.groovy') f.createNewFile() f << """\ package simple; class HelloWorld { String sayHello(String name) { "Hello, \${name}!"; } } """.stripIndent() when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments('groovyCompilationTask') .build() then: result.task(':groovyCompilationTask').outcome == TaskOutcome.SUCCESS new File(testProjectDir.root, 'build/classes/simple/HelloWorld.class').exists() where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } @Unroll def "simple groovy project, with Gradle #gradleVersion"() { given: buildFile << """\ apply plugin: 'net.ltgt.apt' apply plugin: 'groovy' dependencies { compile localGroovy() } """.stripIndent() def f = new File(testProjectDir.newFolder('src', 'main', 'groovy', 'simple'), 'HelloWorld.groovy') f.createNewFile() f << """\ package simple; class HelloWorld { String sayHello(String name) { "Hello, \${name}!"; } } """.stripIndent() f = new File(testProjectDir.newFolder('src', 'test', 'groovy', 'simple'), 'HelloWorldTest.groovy') f.createNewFile() f << """\ package simple; class HelloWorldTest { // Not a real unit-test public static void main(String[] args) { System.out.println(new HelloWorld().sayHello("World")); } } """.stripIndent() when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments('compileTestGroovy') .build() then: result.task(':compileGroovy').outcome == TaskOutcome.SUCCESS result.task(':compileTestGroovy').outcome == TaskOutcome.SUCCESS where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } @Unroll def "simple groovy project with compile-only dependency, with Gradle #gradleVersion"() { given: def settingsFile = testProjectDir.newFile('settings.gradle') settingsFile << """\ include 'annotations' include 'core' """.stripIndent() buildFile << """\ project('annotations') { apply plugin: 'java' } project('core') { apply plugin: 'groovy' apply plugin: 'net.ltgt.apt' dependencies { compile localGroovy() compileOnly project(':annotations') } } """.stripIndent() def f = new File(testProjectDir.newFolder('annotations', 'src', 'main', 'java', 'annotations'), 'MyAnnotation.java') f.createNewFile() f << """\ package annotations; import java.lang.annotation.Documented; public @interface MyAnnotation { } """.stripIndent() f = new File(testProjectDir.newFolder('core', 'src', 'main', 'groovy', 'core'), 'HelloWorld.groovy') f.createNewFile() f << """\ package core; import annotations.MyAnnotation; @MyAnnotation class HelloWorld { String sayHello(String name) { "Hello, \${name}!"; } } """.stripIndent() expect: when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments(':core:groovydoc') .build() then: result.task(':annotations:compileJava').outcome == TaskOutcome.SUCCESS result.task(':core:compileGroovy').outcome == TaskOutcome.SUCCESS result.task(':core:groovydoc').outcome == TaskOutcome.SUCCESS where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } } gradle-apt-plugin-0.10/src/test/groovy/net/ltgt/gradle/apt/AptPluginSpec.groovy000066400000000000000000000300251334523152600276140ustar00rootroot00000000000000package net.ltgt.gradle.apt import nebula.test.PluginProjectSpec import nebula.test.dependencies.DependencyGraphBuilder import nebula.test.dependencies.GradleDependencyGenerator import nebula.test.dependencies.ModuleBuilder class AptPluginSpec extends PluginProjectSpec { @Override String getPluginName() { return 'net.ltgt.apt' } def 'empty project'() { when: project.apply plugin: pluginName project.evaluate() then: project.configurations.empty } def 'empty java project'() { when: project.apply plugin: pluginName project.apply plugin: 'java' project.evaluate() then: project.configurations.findByName('apt') project.configurations.findByName('testApt') project.configurations.findByName('compileOnly') project.configurations.findByName('testCompileOnly') with(project.tasks.compileJava.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs()) { compilerArgs -> compilerArgs.containsAll(['-s', new File(project.buildDir, 'generated/source/apt/main').path]) !compilerArgs.contains('-processorpath') } with (project.tasks.compileTestJava.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs()) { compilerArgs -> compilerArgs.containsAll(['-s', new File(project.buildDir, 'generated/source/apt/test').path]) !compilerArgs.contains('-processorpath') } } def 'empty groovy project'() { when: project.apply plugin: pluginName project.apply plugin: 'groovy' project.evaluate() then: project.configurations.findByName('apt') project.configurations.findByName('testApt') project.configurations.findByName('compileOnly') project.configurations.findByName('testCompileOnly') with(project.tasks.compileJava.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs()) { compilerArgs -> compilerArgs.containsAll([ '-s', new File(project.buildDir, 'generated/source/apt/main').path ]) !compilerArgs.contains('-processorpath') } with(project.tasks.compileGroovy.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs()) { compilerArgs -> compilerArgs.containsAll([ '-s', new File(project.buildDir, 'generated/source/apt/main').path ]) !compilerArgs.contains('-processorpath') } with(project.tasks.compileTestJava.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs()) { compilerArgs -> compilerArgs.containsAll([ '-s', new File(project.buildDir, 'generated/source/apt/test').path ]) !compilerArgs.contains('-processorpath') } with(project.tasks.compileTestGroovy.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs()) { compilerArgs -> compilerArgs.containsAll([ '-s', new File(project.buildDir, 'generated/source/apt/test').path ]) !compilerArgs.contains('-processorpath') } } def 'project with annotation processors'() { setup: def mavenRepo = new GradleDependencyGenerator( new DependencyGraphBuilder() .addModule('leaf:compile:1.0') .addModule('leaf:testCompile:1.0') .addModule(new ModuleBuilder('compile:compile:1.0') .addDependency('leaf:compile:1.0') .build()) .addModule(new ModuleBuilder('testCompile:testCompile:1.0') .addDependency('leaf:testCompile:1.0') .build()) .addModule(new ModuleBuilder('processor:compile:1.0') .addDependency('leaf:compile:2.0') .build()) .addModule(new ModuleBuilder('processor:testCompile:1.0') .addDependency('leaf:testCompile:2.0') .build()) .build(), project.mkdir('repo').path) .generateTestMavenRepo() when: project.apply plugin: pluginName project.apply plugin: 'groovy' project.repositories { maven { url mavenRepo } } project.dependencies { compile 'compile:compile:1.0' apt 'processor:compile:1.0' testCompile 'testCompile:testCompile:1.0' testApt 'processor:testCompile:1.0' } project.evaluate() then: with(project.tasks.compileJava.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs()) { compilerArgs -> compilerArgs.containsAll([ '-s', new File(project.buildDir, 'generated/source/apt/main').path, '-processorpath', project.configurations.apt.asPath ]) !compilerArgs.any { arg -> project.configurations.compile.files.any { arg.contains(it.path) } } } with(project.tasks.compileGroovy.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs()) { compilerArgs -> compilerArgs.containsAll([ '-s', new File(project.buildDir, 'generated/source/apt/main').path, '-processorpath', project.configurations.apt.asPath ]) !compilerArgs.any { arg -> project.configurations.compile.files.any { arg.contains(it.path) } } } with(project.tasks.compileTestJava.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs()) { compilerArgs -> compilerArgs.containsAll([ '-s', new File(project.buildDir, 'generated/source/apt/test').path, '-processorpath', project.configurations.testApt.asPath ]) !compilerArgs.any { arg -> project.configurations.testCompile.files.any { arg.contains(it.path) } } } with(project.tasks.compileTestGroovy.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs()) { compilerArgs -> compilerArgs.containsAll([ '-s', new File(project.buildDir, 'generated/source/apt/test').path, '-processorpath', project.configurations.testApt.asPath ]) !compilerArgs.any { arg -> project.configurations.testCompile.files.any { arg.contains(it.path) } } } project.configurations.compile.resolvedConfiguration.resolvedArtifacts*.moduleVersion.id.collect { "$it.group:$it.name:$it.version" as String }.toSet() .equals([ 'compile:compile:1.0', 'leaf:compile:1.0' ] as Set) project.configurations.testCompile.resolvedConfiguration.resolvedArtifacts*.moduleVersion.id.collect { "$it.group:$it.name:$it.version" as String }.toSet() .equals([ 'compile:compile:1.0', 'leaf:compile:1.0', 'testCompile:testCompile:1.0', 'leaf:testCompile:1.0' ] as Set) } def 'project with annotation processors through AptOptions'() { setup: def mavenRepo = new GradleDependencyGenerator( new DependencyGraphBuilder() .addModule('leaf:compile:1.0') .addModule('leaf:testCompile:1.0') .addModule(new ModuleBuilder('compile:compile:1.0') .addDependency('leaf:compile:1.0') .build()) .addModule(new ModuleBuilder('testCompile:testCompile:1.0') .addDependency('leaf:testCompile:1.0') .build()) .addModule(new ModuleBuilder('processor:compile:1.0') .addDependency('leaf:compile:2.0') .build()) .addModule(new ModuleBuilder('processor:testCompile:1.0') .addDependency('leaf:testCompile:2.0') .build()) .build(), project.mkdir('repo').path) .generateTestMavenRepo() when: project.apply plugin: pluginName project.apply plugin: 'groovy' project.repositories { maven { url mavenRepo } } project.configurations { annotationProcessor testAnnotationProcessor } project.dependencies { compile 'compile:compile:1.0' annotationProcessor 'processor:compile:1.0' testCompile 'testCompile:testCompile:1.0' testAnnotationProcessor 'processor:testCompile:1.0' } project.tasks.compileJava { generatedSourcesDestinationDir = 'src/main/generated' aptOptions.processorpath = project.configurations.annotationProcessor } project.tasks.compileGroovy { generatedSourcesDestinationDir = 'src/main/generated' aptOptions.processorpath = project.configurations.annotationProcessor } project.tasks.compileTestJava { generatedSourcesDestinationDir = 'src/test/generated' aptOptions.processorpath = project.configurations.testAnnotationProcessor } project.tasks.compileTestGroovy { generatedSourcesDestinationDir = 'src/test/generated' aptOptions.processorpath = project.configurations.testAnnotationProcessor } project.evaluate() then: project.tasks.compileJava.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs() .containsAll([ '-s', new File(project.projectDir, 'src/main/generated').path, '-processorpath', project.configurations.annotationProcessor.asPath ]) project.tasks.compileGroovy.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs() .containsAll([ '-s', new File(project.projectDir, 'src/main/generated').path, '-processorpath', project.configurations.annotationProcessor.asPath ]) project.tasks.compileTestJava.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs() .containsAll([ '-s', new File(project.projectDir, 'src/test/generated').path, '-processorpath', project.configurations.testAnnotationProcessor.asPath ]) project.tasks.compileTestGroovy.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs() .containsAll([ '-s', new File(project.projectDir, 'src/test/generated').path, '-processorpath', project.configurations.testAnnotationProcessor.asPath ]) } def 'project with annotation processors through SourceSet'() { setup: def mavenRepo = new GradleDependencyGenerator( new DependencyGraphBuilder() .addModule('leaf:compile:1.0') .addModule('leaf:testCompile:1.0') .addModule(new ModuleBuilder('compile:compile:1.0') .addDependency('leaf:compile:1.0') .build()) .addModule(new ModuleBuilder('testCompile:testCompile:1.0') .addDependency('leaf:testCompile:1.0') .build()) .addModule(new ModuleBuilder('processor:compile:1.0') .addDependency('leaf:compile:2.0') .build()) .addModule(new ModuleBuilder('processor:testCompile:1.0') .addDependency('leaf:testCompile:2.0') .build()) .build(), project.mkdir('repo').path) .generateTestMavenRepo() when: project.apply plugin: pluginName project.apply plugin: 'groovy' project.repositories { maven { url mavenRepo } } project.configurations { annotationProcessor testAnnotationProcessor } project.dependencies { compile 'compile:compile:1.0' annotationProcessor 'processor:compile:1.0' testCompile 'testCompile:testCompile:1.0' testAnnotationProcessor 'processor:testCompile:1.0' } project.sourceSets.main { output.generatedSourcesDir = 'src/main/generated' processorpath = project.configurations.annotationProcessor } project.sourceSets.test { output.generatedSourcesDir = 'src/test/generated' processorpath = project.configurations.testAnnotationProcessor } project.evaluate() then: project.tasks.compileJava.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs() .containsAll([ '-s', new File(project.projectDir, 'src/main/generated').path, '-processorpath', project.configurations.annotationProcessor.asPath ]) project.tasks.compileGroovy.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs() .containsAll([ '-s', new File(project.projectDir, 'src/main/generated').path, '-processorpath', project.configurations.annotationProcessor.asPath ]) project.tasks.compileTestJava.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs() .containsAll([ '-s', new File(project.projectDir, 'src/test/generated').path, '-processorpath', project.configurations.testAnnotationProcessor.asPath ]) project.tasks.compileTestGroovy.convention.getPlugin(AptPlugin.AptConvention).buildCompilerArgs() .containsAll([ '-s', new File(project.projectDir, 'src/test/generated').path, '-processorpath', project.configurations.testAnnotationProcessor.asPath ]) } } gradle-apt-plugin-0.10/src/test/groovy/net/ltgt/gradle/apt/EclipseIntegrationSpec.groovy000066400000000000000000000175761334523152600315210ustar00rootroot00000000000000package net.ltgt.gradle.apt import nebula.test.dependencies.DependencyGraphBuilder import nebula.test.dependencies.GradleDependencyGenerator import nebula.test.dependencies.ModuleBuilder import org.gradle.testkit.runner.GradleRunner import org.gradle.testkit.runner.TaskOutcome import org.gradle.tooling.GradleConnector import org.gradle.tooling.ProjectConnection import org.gradle.tooling.model.eclipse.EclipseProject import org.junit.Rule import org.junit.rules.TemporaryFolder import spock.lang.Specification import spock.lang.Unroll class EclipseIntegrationSpec extends Specification { @Rule TemporaryFolder testProjectDir = new TemporaryFolder() File buildFile def setup() { buildFile = testProjectDir.newFile('build.gradle') buildFile << """\ buildscript { dependencies { classpath files(\$/${System.getProperty('plugin')}/\$) } } apply plugin: 'net.ltgt.apt' apply plugin: 'eclipse' """.stripIndent() } @Unroll def "eclipse without java, with Gradle #gradleVersion"() { when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments('eclipse') .build() then: result.task(':eclipse').outcome == TaskOutcome.SUCCESS result.task(':eclipseJdtApt') == null result.task(':eclipseFactorypath') == null !new File(testProjectDir.root, '.factorypath').exists() where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } @Unroll def "eclipse task, with Gradle #gradleVersion"() { given: def mavenRepo = new GradleDependencyGenerator( new DependencyGraphBuilder() .addModule(new ModuleBuilder('compile:compile:1.0') .addDependency('leaf:compile:1.0') .build()) .addModule(new ModuleBuilder('testCompile:testCompile:1.0') .addDependency('leaf:testCompile:1.0') .build()) .addModule('annotations:compile:1.0') .addModule('annotations:testCompile:1.0') .addModule(new ModuleBuilder('processor:compile:1.0') .addDependency('annotations:compile:1.0') .addDependency('leaf:compile:2.0') .build()) .addModule(new ModuleBuilder('processor:testCompile:1.0') .addDependency('annotations:testCompile:1.0') .addDependency('leaf:testCompile:2.0') .build()) .build(), testProjectDir.newFolder('repo').path) .generateTestMavenRepo() buildFile << """\ apply plugin: 'java' repositories { maven { url file(\$/${mavenRepo}/\$) } } dependencies { compile 'compile:compile:1.0' compileOnly 'annotations:compile:1.0' apt 'processor:compile:1.0' testCompile 'testCompile:testCompile:1.0' testCompileOnly 'annotations:testCompile:1.0' testApt 'processor:testCompile:1.0' } """.stripIndent() when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments('eclipse') .build() then: result.task(':eclipse').outcome == TaskOutcome.SUCCESS result.task(':eclipseJdtApt').outcome == TaskOutcome.SUCCESS result.task(':eclipseFactorypath').outcome == TaskOutcome.SUCCESS def factorypath = new File(testProjectDir.root, '.factorypath') factorypath.exists() def entries = new XmlSlurper().parse(factorypath).factorypathentry entries.size() == 6 entries.every { it.@kind == 'EXTJAR' && it.@enabled == true && it.@runInBatchMode == false } (entries.@id as Set).equals([ "$mavenRepo/leaf/compile/2.0/compile-2.0.jar", "$mavenRepo/annotations/compile/1.0/compile-1.0.jar", "$mavenRepo/processor/compile/1.0/compile-1.0.jar", "$mavenRepo/leaf/testCompile/2.0/testCompile-2.0.jar", "$mavenRepo/annotations/testCompile/1.0/testCompile-1.0.jar", "$mavenRepo/processor/testCompile/1.0/testCompile-1.0.jar", ].collect { it.replace('/', File.separator) }.toSet()) def jdtSettings = loadProperties('.settings/org.eclipse.jdt.core.prefs') jdtSettings.getProperty('org.eclipse.jdt.core.compiler.processAnnotations') == 'enabled' def aptSettings = loadProperties('.settings/org.eclipse.jdt.apt.core.prefs') aptSettings.getProperty('org.eclipse.jdt.apt.aptEnabled') == 'true' aptSettings.getProperty('org.eclipse.jdt.apt.genSrcDir') == '.apt_generated' aptSettings.getProperty('org.eclipse.jdt.apt.reconcileEnabled') == 'true' when: def result2 = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments('cleanEclipse') .build() then: result2.task(':cleanEclipse').outcome == TaskOutcome.SUCCESS result2.task(':cleanEclipseJdtApt').outcome == TaskOutcome.SUCCESS result2.task(':cleanEclipseFactorypath').outcome == TaskOutcome.SUCCESS !factorypath.exists() !new File(testProjectDir.root, '.settings/org.eclipse.jdt.apt.core.prefs').exists() where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } def loadProperties(String path) { def props = new Properties() new File(testProjectDir.root, path).withInputStream { props.load(it) } props } @Unroll def "tooling api, with Gradle #gradleVersion"() { given: def mavenRepo = new GradleDependencyGenerator( new DependencyGraphBuilder() .addModule(new ModuleBuilder('compile:compile:1.0') .addDependency('leaf:compile:1.0') .build()) .addModule(new ModuleBuilder('testCompile:testCompile:1.0') .addDependency('leaf:testCompile:1.0') .build()) .addModule('annotations:compile:1.0') .addModule('annotations:testCompile:1.0') .addModule(new ModuleBuilder('processor:compile:1.0') .addDependency('annotations:compile:1.0') .addDependency('leaf:compile:2.0') .build()) .addModule(new ModuleBuilder('processor:testCompile:1.0') .addDependency('annotations:testCompile:1.0') .addDependency('leaf:testCompile:2.0') .build()) .build(), testProjectDir.newFolder('repo').path) .generateTestMavenRepo() buildFile << """\ apply plugin: 'java' repositories { maven { url file(\$/${mavenRepo}/\$) } } dependencies { compile 'compile:compile:1.0' compileOnly 'annotations:compile:1.0' apt 'processor:compile:1.0' testCompile 'testCompile:testCompile:1.0' testCompileOnly 'annotations:testCompile:1.0' testApt 'processor:testCompile:1.0' } """.stripIndent() when: ProjectConnection connection = GradleConnector.newConnector() .forProjectDirectory(testProjectDir.root) .useGradleVersion(gradleVersion) .connect() def classpath = connection.getModel(EclipseProject).classpath.collect { "${it.gradleModuleVersion.group}:${it.gradleModuleVersion.name}:${it.gradleModuleVersion.version}" as String }.toSet() then: classpath.contains('leaf:compile:1.0') classpath.contains('compile:compile:1.0') classpath.contains('annotations:compile:1.0') classpath.contains('leaf:testCompile:1.0') classpath.contains('testCompile:testCompile:1.0') classpath.contains('annotations:testCompile:1.0') !classpath.contains('leaf:compile:2.0') !classpath.contains('processor:compile:1.0') !classpath.contains('leaf:testCompile:2.0') !classpath.contains('processor:testCompile:1.0') cleanup: connection.close() where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } } gradle-apt-plugin-0.10/src/test/groovy/net/ltgt/gradle/apt/IdeaIntegrationSpec.groovy000066400000000000000000000207071334523152600307650ustar00rootroot00000000000000package net.ltgt.gradle.apt import nebula.test.dependencies.DependencyGraphBuilder import nebula.test.dependencies.GradleDependencyGenerator import nebula.test.dependencies.ModuleBuilder import org.gradle.testkit.runner.GradleRunner import org.gradle.testkit.runner.TaskOutcome import org.gradle.tooling.GradleConnector import org.gradle.tooling.ProjectConnection import org.gradle.tooling.model.idea.IdeaProject import org.gradle.util.GradleVersion import org.junit.Rule import org.junit.rules.TemporaryFolder import spock.lang.Specification import spock.lang.Unroll class IdeaIntegrationSpec extends Specification { @Rule TemporaryFolder testProjectDir = new TemporaryFolder() File settingsFile, buildFile String moduleName = 'testProject' def setup() { settingsFile = testProjectDir.newFile('settings.gradle') settingsFile << """\ rootProject.name = '${moduleName}' """.stripIndent() buildFile = testProjectDir.newFile('build.gradle') buildFile << """\ buildscript { dependencies { classpath files(\$/${System.getProperty('plugin')}/\$) } } apply plugin: 'net.ltgt.apt' apply plugin: 'idea' """.stripIndent() } @Unroll def "idea without java, with Gradle #gradleVersion"() { when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments('idea') .build() then: result.task(':idea').outcome == TaskOutcome.SUCCESS result.task(':ideaProject').outcome == TaskOutcome.SUCCESS result.task(':ideaModule').outcome == TaskOutcome.SUCCESS hasAnnotationProcessingConfigured() where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } void hasAnnotationProcessingConfigured() { with (new XmlSlurper().parse(new File(testProjectDir.root, "${moduleName}.ipr")).component.find { it.@name == 'CompilerConfiguration' } .annotationProcessing.profile) { assert it.size() == 1 assert it.@default == true assert it.@enabled == true assert it.sourceOutputDir.@name == 'build/generated/source/apt/main' assert it.sourceTestOutputDir.@name == 'build/generated/source/apt/test' assert it.outputRelativeToContentRoot.@value == true assert it.processorPath.@useClasspath == true } } @Unroll def "idea task, with Gradle #gradleVersion"() { setup: def mavenRepo = new GradleDependencyGenerator( new DependencyGraphBuilder() .addModule(new ModuleBuilder('compile:compile:1.0') .addDependency('leaf:compile:1.0') .build()) .addModule(new ModuleBuilder('testCompile:testCompile:1.0') .addDependency('leaf:testCompile:1.0') .build()) .addModule('annotations:compile:1.0') .addModule('annotations:testCompile:1.0') .addModule(new ModuleBuilder('processor:compile:1.0') .addDependency('annotations:compile:1.0') .addDependency('leaf:compile:2.0') .build()) .addModule(new ModuleBuilder('processor:testCompile:1.0') .addDependency('annotations:testCompile:1.0') .addDependency('leaf:testCompile:2.0') .build()) .build(), testProjectDir.newFolder('repo').path) .generateTestMavenRepo() buildFile << """\ apply plugin: 'java' repositories { maven { url file(\$/${mavenRepo}/\$) } } dependencies { compile 'compile:compile:1.0' compileOnly 'annotations:compile:1.0' apt 'processor:compile:1.0' testCompile 'testCompile:testCompile:1.0' testCompileOnly 'annotations:testCompile:1.0' testApt 'processor:testCompile:1.0' } """.stripIndent() when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments('idea') .build() then: result.task(':idea').outcome == TaskOutcome.SUCCESS result.task(':ideaModule').outcome == TaskOutcome.SUCCESS hasAnnotationProcessingConfigured() // TODO: check IML for content roots and dependencies where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } @Unroll def "tooling api, with Gradle #gradleVersion"() { setup: def mavenRepo = new GradleDependencyGenerator( new DependencyGraphBuilder() .addModule(new ModuleBuilder('compile:compile:1.0') .addDependency('leaf:compile:1.0') .build()) .addModule(new ModuleBuilder('testCompile:testCompile:1.0') .addDependency('leaf:testCompile:1.0') .build()) .addModule('annotations:compile:1.0') .addModule('annotations:testCompile:1.0') .addModule(new ModuleBuilder('processor:compile:1.0') .addDependency('annotations:compile:1.0') .addDependency('leaf:compile:2.0') .build()) .addModule(new ModuleBuilder('processor:testCompile:1.0') .addDependency('annotations:testCompile:1.0') .addDependency('leaf:testCompile:2.0') .build()) .build(), testProjectDir.newFolder('repo').path) .generateTestMavenRepo() buildFile << """\ apply plugin: 'java' repositories { maven { url file(\$/${mavenRepo}/\$) } } dependencies { compile 'compile:compile:1.0' compileOnly 'annotations:compile:1.0' apt 'processor:compile:1.0' testCompile 'testCompile:testCompile:1.0' testCompileOnly 'annotations:testCompile:1.0' testApt 'processor:testCompile:1.0' } """.stripIndent() when: ProjectConnection connection = GradleConnector.newConnector() .forProjectDirectory(testProjectDir.root) .useGradleVersion(gradleVersion) .connect() def ideaModule = connection.getModel(IdeaProject).modules[0] then: ideaModule.contentRoots*.generatedSourceDirectories*.directory.flatten() .contains(new File(testProjectDir.root, 'build/generated/source/apt/main')) ideaModule.contentRoots*.generatedTestDirectories*.directory.flatten() .contains(new File(testProjectDir.root, 'build/generated/source/apt/test')) !ideaModule.contentRoots*.excludeDirectories.flatten() .contains(new File(testProjectDir.root, 'build')) // XXX: We can't test buildDir subdirectories unless we also build the project, should we? def dependencies = ideaModule.dependencies.collect { "${it.gradleModuleVersion.group}:${it.gradleModuleVersion.name}:${it.gradleModuleVersion.version}:${it.scope.scope}" as String } // XXX: it's unfortunate that we have both versions of "leaf" artifacts, but we can't easily do otherwise if (GradleVersion.version(gradleVersion) >= GradleVersion.version("3.4")) { dependencies.contains('leaf:compile:1.0:PROVIDED') dependencies.contains('compile:compile:1.0:PROVIDED') dependencies.contains('annotations:compile:1.0:PROVIDED') dependencies.contains('leaf:compile:2.0:PROVIDED') dependencies.contains('processor:compile:1.0:PROVIDED') dependencies.contains('leaf:compile:1.0:RUNTIME') dependencies.contains('compile:compile:1.0:RUNTIME') dependencies.contains('leaf:testCompile:1.0:TEST') dependencies.contains('testCompile:testCompile:1.0:TEST') dependencies.contains('annotations:testCompile:1.0:TEST') dependencies.contains('leaf:testCompile:2.0:TEST') dependencies.contains('processor:testCompile:1.0:TEST') } else { dependencies.contains('leaf:compile:1.0:COMPILE') dependencies.contains('compile:compile:1.0:COMPILE') dependencies.contains('annotations:compile:1.0:COMPILE') dependencies.contains('leaf:compile:2.0:COMPILE') dependencies.contains('processor:compile:1.0:COMPILE') dependencies.contains('leaf:testCompile:1.0:TEST') dependencies.contains('testCompile:testCompile:1.0:TEST') dependencies.contains('annotations:testCompile:1.0:TEST') dependencies.contains('leaf:testCompile:2.0:TEST') dependencies.contains('processor:testCompile:1.0:TEST') } cleanup: connection.close() where: gradleVersion << IntegrationTestHelper.GRADLE_VERSIONS } } gradle-apt-plugin-0.10/src/test/groovy/net/ltgt/gradle/apt/IntegrationTestHelper.groovy000066400000000000000000000003431334523152600313610ustar00rootroot00000000000000package net.ltgt.gradle.apt class IntegrationTestHelper { static final GRADLE_VERSIONS = System.getProperty("test.gradle-versions", "2.5,2.6,2.7,2.8,2.9,2.10,2.11,2.12,2.13,2.14,3.0,3.1,3.2,3.3,3.4") .tokenize(','); }