Remove superflous enforce deprecation failure plugin (#59770) (#59898)

- With enforcing the build to fail on all gradle deprecated api usage we do not need
this tailored plugin anymore
This commit is contained in:
Rene Groeschke 2020-07-21 12:54:17 +02:00 committed by GitHub
parent cefaa17c52
commit 60d46f1d13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 213 deletions

View File

@ -435,8 +435,6 @@ gradle.projectsEvaluated {
}
allprojects {
apply plugin: 'elasticsearch.enforce-deprecation-use-failures'
tasks.register('resolveAllDependencies') {
if (project.path.contains("fixture")) {
dependsOn tasks.withType(ComposePull)

View File

@ -1,120 +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
import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
import spock.lang.Unroll
import java.lang.management.ManagementFactory
class EnforceDeprecationFailuresPluginFuncTest extends Specification {
@Rule
TemporaryFolder testProjectDir = new TemporaryFolder()
File settingsFile
File buildFile
def setup() {
settingsFile = testProjectDir.newFile('settings.gradle')
settingsFile << "rootProject.name = 'hello-world'"
buildFile = testProjectDir.newFile('build.gradle')
buildFile << """plugins {
id 'elasticsearch.enforce-deprecation-use-failures'
}
"""
}
@Unroll
def "fails on #compileConfigName resolution"() {
given:
buildFile << """
apply plugin:'java'
task resolve {
doLast {
configurations.${compileConfigName}.resolve()
}
}
"""
when:
def result = gradleRunner("resolve").buildAndFail()
then:
assertOutputContains(result.output, """
* What went wrong:
Execution failed for task ':resolve'.
> Resolving configuration $compileConfigName is no longer supported. Use $implementationConfigName instead.
""")
where:
compileConfigName | implementationConfigName
"compile" | "implementation"
"testCompile" | "testImplementation"
}
@Unroll
def "fails on #compileConfigName dependency declaration"() {
given:
buildFile << """
apply plugin:'java'
dependencies {
$compileConfigName "org.acme:some-lib:1.0"
}
tasks.register("resolve") {
doLast {
configurations.${compileConfigName}.resolve()
}
}
"""
when:
def result = gradleRunner("resolve").buildAndFail()
then:
assertOutputContains(result.output, """
* What went wrong:
Execution failed for task ':resolve'.
> Declaring dependencies for configuration ${compileConfigName} is no longer supported. Use ${implementationConfigName} instead.
""")
where:
compileConfigName | implementationConfigName
"compile" | "implementation"
"testCompile" | "testImplementation"
}
private GradleRunner gradleRunner(String... arguments) {
GradleRunner.create()
.withDebug(ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0)
.withProjectDir(testProjectDir.root)
.withArguments(arguments)
.withPluginClasspath()
.forwardOutput()
}
def assertOutputContains(String givenOutput, String expected) {
assert normalizedString(givenOutput).contains(normalizedString(expected))
true
}
String normalizedString(String input) {
return input.readLines().join("\n")
}
}

View File

@ -1,91 +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;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
/**
* This plugin enforces build failure if certain deprecated apis are used.
* <p>
* For now we support build failure on:
* - declaring dependencies for testCompile
* - resolving testCompile configuration
*/
public class EnforceDeprecationFailuresPlugin implements Plugin<Project> {
private Project project;
@Override
public void apply(Project project) {
this.project = project;
handleDeprecatedConfigurations();
}
private void handleDeprecatedConfigurations() {
project.getPlugins().withType(JavaBasePlugin.class, javaBasePlugin -> {
SourceSetContainer sourceSetContainer = project.getExtensions().getByType(SourceSetContainer.class);
sourceSetContainer.all(
sourceSet -> {
// TODO: remove that guard once we removed general compile usage from es build
if (sourceSet.getName().equals("test") || sourceSet.getName().equals("main")) {
failOnCompileConfigurationResolution(sourceSet);
failOnCompileConfigurationDependencyDeclaration(sourceSet);
}
}
);
});
}
private void failOnCompileConfigurationDependencyDeclaration(SourceSet sourceSet) {
// fail on using deprecated testCompile
project.getConfigurations().getByName(sourceSet.getCompileConfigurationName()).withDependencies(dependencies -> {
if (dependencies.size() > 0) {
throw new GradleException(
"Declaring dependencies for configuration "
+ sourceSet.getCompileConfigurationName()
+ " is no longer supported. Use "
+ sourceSet.getImplementationConfigurationName()
+ " instead."
);
}
});
}
private void failOnCompileConfigurationResolution(SourceSet sourceSet) {
project.getConfigurations()
.getByName(sourceSet.getCompileConfigurationName())
.getIncoming()
.beforeResolve(resolvableDependencies -> {
throw new GradleException(
"Resolving configuration "
+ sourceSet.getCompileConfigurationName()
+ " is no longer supported. Use "
+ sourceSet.getImplementationConfigurationName()
+ " instead."
);
});
}
}