diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/FeatureAwareTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/FeatureAwareTask.groovy deleted file mode 100644 index 2f03271812b25..0000000000000 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/FeatureAwareTask.groovy +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.gradle.precommit - -import org.elasticsearch.gradle.LoggedExec -import org.gradle.api.file.FileCollection -import org.gradle.api.tasks.InputFiles -import org.gradle.api.tasks.OutputFile - -class FeatureAwareTask extends LoggedExec { - - // we touch this when the task succeeds - private File successMarker = new File(project.buildDir, 'markers/featureAware') - - private FileCollection classpath - - private FileCollection classDirectories - - FeatureAwareTask() { - description = "Runs FeatureAwareCheck on main classes." - project.afterEvaluate { - dependsOn classpath - executable = new File(project.runtimeJavaHome, 'bin/java') - if (classDirectories == null) { - // default to main class files if such a source set exists - final List files = [] - if (project.sourceSets.findByName("main")) { - files.add(project.sourceSets.main.output.classesDir) - dependsOn project.tasks.classes - } - // filter out non-existent classes directories from empty source sets - classDirectories = project.files(files).filter { it.exists() } - } - doFirst { - args('-cp', getClasspath().asPath, 'org.elasticsearch.xpack.test.feature_aware.FeatureAwareCheck') - getClassDirectories().each { args it.getAbsolutePath() } - } - doLast { - successMarker.parentFile.mkdirs() - successMarker.setText("", 'UTF-8') - } - } - } - - @InputFiles - FileCollection getClasspath() { - return classpath - } - - void setClasspath(final FileCollection classpath) { - this.classpath = classpath - } - - @InputFiles - FileCollection getClassDirectories() { - return classDirectories - } - - void setClassDirectories(final FileCollection classDirectories) { - this.classDirectories = classDirectories - } - - @OutputFile - File getSuccessMarker() { - return successMarker - } - - void setSuccessMarker(final File successMarker) { - this.successMarker = successMarker - } - -} diff --git a/x-pack/plugin/build.gradle b/x-pack/plugin/build.gradle index 0eb7e3b1c0edc..007bca7ff40d4 100644 --- a/x-pack/plugin/build.gradle +++ b/x-pack/plugin/build.gradle @@ -1,5 +1,5 @@ import org.elasticsearch.gradle.LoggedExec -import org.elasticsearch.gradle.precommit.FeatureAwareTask +import org.elasticsearch.gradle.plugin.PluginBuildPlugin import org.elasticsearch.gradle.test.NodeInfo import java.nio.charset.StandardCharsets @@ -14,22 +14,46 @@ dependencies { } subprojects { - final SourceSet main = project.sourceSets.findByName("main") - if (main != null) { - final FeatureAwareTask featureAwareTask = project.tasks.create('featureAwareCheck', FeatureAwareTask.class) - - // see the root Gradle file for additional logic regarding this configuration - project.configurations.create('featureAwarePlugin') - project.dependencies.add( - 'featureAwarePlugin', - "org.elasticsearch.xpack.test:feature-aware:${org.elasticsearch.gradle.VersionProperties.elasticsearch}") - project.dependencies.add('featureAwarePlugin', main.output.getClassesDirs()) - - featureAwareTask.configure { FeatureAwareTask fat -> - fat.classpath = project.configurations.featureAwarePlugin - } + afterEvaluate { + if (project.plugins.hasPlugin(PluginBuildPlugin)) { + // see the root Gradle file for additional logic regarding this configuration + project.configurations.create('featureAwarePlugin') + project.dependencies.add('featureAwarePlugin', project.configurations.runtime) + project.dependencies.add( + 'featureAwarePlugin', + "org.elasticsearch.xpack.test:feature-aware:${org.elasticsearch.gradle.VersionProperties.elasticsearch}") + project.dependencies.add('featureAwarePlugin', project.sourceSets.main.output.getClassesDirs()) + + final Task featureAwareTask = project.tasks.create("featureAwareCheck", LoggedExec) { + description = "Runs FeatureAwareCheck on main classes." + dependsOn project.configurations.featureAwarePlugin + + final File successMarker = new File(project.buildDir, 'markers/featureAware') + outputs.file(successMarker) + + executable = new File(project.runtimeJavaHome, 'bin/java') + + // default to main class files if such a source set exists + final List files = [] + if (project.sourceSets.findByName("main")) { + files.add(project.sourceSets.main.output.classesDir) + dependsOn project.tasks.classes + } + // filter out non-existent classes directories from empty source sets + final FileCollection classDirectories = project.files(files).filter { it.exists() } - project.precommit.dependsOn featureAwareTask + doFirst { + args('-cp', project.configurations.featureAwarePlugin.asPath, 'org.elasticsearch.xpack.test.feature_aware.FeatureAwareCheck') + classDirectories.each { args it.getAbsolutePath() } + } + doLast { + successMarker.parentFile.mkdirs() + successMarker.setText("", 'UTF-8') + } + } + + project.precommit.dependsOn featureAwareTask + } } }