Skip to content

Commit

Permalink
Merge pull request #326 from chali/Gradle7CompatibilityMaster
Browse files Browse the repository at this point in the history
Gradle 7.0 compatibility, Groovy 3 compatibility
  • Loading branch information
chali authored Mar 18, 2021
2 parents f7f3000 + ddb85bb commit f4a5342
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class EmptyClosureRule extends GradleLintRule {
}

@Override
protected void visitClassComplete(ClassNode node) {
void visitClassComplete(ClassNode node) {
(emptyClosureCalls - taskNames).unique().each {
addBuildLintViolation('this is an empty configuration closure that can be removed', it)
.delete(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.codehaus.groovy.ast.ClassCodeVisitorSupport
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.ast.ConstructorNode
import org.codehaus.groovy.ast.FieldNode
import org.codehaus.groovy.ast.GroovyCodeVisitor
import org.codehaus.groovy.ast.MethodNode
import org.codehaus.groovy.ast.ModuleNode
import org.codehaus.groovy.ast.PackageNode
Expand Down Expand Up @@ -274,7 +275,7 @@ class CompositeGroovyAstVisitor extends ClassCodeVisitorSupport implements AstVi
}

@Override
protected void visitEmptyStatement(EmptyStatement statement) {
void visitEmptyStatement(EmptyStatement statement) {
visitors.each { it.visitEmptyStatement(statement) }
super.visitEmptyStatement(statement)
}
Expand Down Expand Up @@ -468,9 +469,16 @@ class CompositeGroovyAstVisitor extends ClassCodeVisitorSupport implements AstVi
}

@Override
protected void visitListOfExpressions(List<? extends Expression> list) {
void visitListOfExpressions(List<? extends Expression> list) {
visitors.each { it.visitListOfExpressions(list) }
super.visitListOfExpressions(list)
//Groovy has a issue when calling java default methods In Groovy 3 `super.visitListOfExpressions(list)`
//is implemented as default methods. The code is extracted and directly placed here to avoid the issue
//https://stackoverflow.com/questions/54822838/explicitly-calling-a-default-method-in-groovy
if (list != null) {
list.each {
it.visit(this)
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ import org.codehaus.groovy.classgen.BytecodeExpression
* CodeNarc's AbstractAstVisitor, and ClassCodeVisitorSupport.
*/
abstract class GroovyAstVisitor implements GroovyClassVisitor, GroovyCodeVisitor {
protected void visitClassComplete(ClassNode node) {}
protected void visitAnnotations(AnnotatedNode node) {}
protected void visitPackage(PackageNode node) {}
protected void visitImports(ModuleNode node) {}
protected void visitClassCodeContainer(Statement node) {}
protected void visitStatement(Statement statement) {}
protected void visitListOfExpressions(List<? extends Expression> list) {}
protected void visitObjectInitializerStatements(ClassNode node) {}
protected void visitEmptyStatement(EmptyStatement statement) {}
void visitClassComplete(ClassNode node) {}
void visitAnnotations(AnnotatedNode node) {}
void visitPackage(PackageNode node) {}
void visitImports(ModuleNode node) {}
void visitClassCodeContainer(Statement node) {}
void visitStatement(Statement statement) {}
void visitListOfExpressions(List<? extends Expression> list) {}
void visitObjectInitializerStatements(ClassNode node) {}
void visitEmptyStatement(EmptyStatement statement) {}

@Override void visitClass(ClassNode classNode) {}
@Override void visitConstructor(ConstructorNode constructorNode) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract class AbstractDuplicateDependencyClassRule extends GradleLintRule imple
}

@Override
protected void visitClassComplete(ClassNode node) {
void visitClassComplete(ClassNode node) {
for (Configuration conf : directlyUsedConfigurations) {
String resolvableConfigurationName = dependencyService.findAndReplaceNonResolvableConfiguration(conf).name
if(!resolvableConfigurationName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class BypassedForcesRule extends GradleLintRule implements GradleModelAware {

@CompileStatic
@Override
protected void visitClassComplete(ClassNode node) {
void visitClassComplete(ClassNode node) {
Collection<BypassedForce> bypassedForces = new ArrayList<BypassedForce>()

forcedDependenciesPerProject.each { affectedProjectName, forcedDependencies ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class MinimumDependencyVersionRule extends GradleLintRule implements GradleModel
}

@Override
protected void visitClassComplete(ClassNode node) {
void visitClassComplete(ClassNode node) {
project.configurations.each { conf ->
if (resolvableAndResolvedConfigurations.contains(conf)) {
minimumVersions.each { constraint ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class RecommendedVersionsRule extends GradleLintRule implements GradleModelAware
}

@Override
protected void visitClassComplete(ClassNode node) {
void visitClassComplete(ClassNode node) {
if (!recommenderIsEnabled) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UndeclaredDependencyRule extends GradleLintRule implements GradleModelAwar
}

@Override
protected void visitClassComplete(ClassNode node) {
void visitClassComplete(ClassNode node) {
Set<ModuleVersionIdentifier> insertedDependencies = [] as Set
Map<String, HashMap<String, ASTNode>> violations = new HashMap()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class UnusedDependencyRule extends GradleLintRule implements GradleModelAware {
}

@Override
protected void visitClassComplete(ClassNode node) {
void visitClassComplete(ClassNode node) {
Set<ModuleVersionIdentifier> insertedDependencies = [] as Set

def convention = project.convention.findPlugin(JavaPluginConvention)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class GradleLintRuleSpec extends AbstractRuleSpec {
String description = 'test'

@Override
void visitGradlePlugin(MethodCallExpression call, String conf, GradlePlugin plugin) {
void visitGradlePlugin(MethodCallExpression call, String conf, GradlePlugin gradlePluginGradleLintRuleSpec) {
pluginCount++
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class DuplicateDependencyClassRuleSpec extends IntegrationTestKitSpec {
}

@Unroll
def 'dependencies with duplicate classes cause violations #configuration results in #message - custom configuration'() {
def 'dependencies with duplicate classes cause violations results in #message - custom configuration'() {
given:
buildFile.text = """
plugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class UnusedDependencyRuleSpec extends IntegrationTestKitSpec {


@Unroll
def 'unused api dependencies are marked for deletion'() {
def 'unused api dependencies (#libraryName) are marked for deletion'() {
when:
buildFile.text = """\
|plugins {
Expand All @@ -108,14 +108,14 @@ class UnusedDependencyRuleSpec extends IntegrationTestKitSpec {
}
where:
deps | expectedWarnings
[guava, asm] | ['warning unused-dependency this dependency is unused and can be removed']
[springfox] | ['warning unused-dependency one or more classes in com.google.guava:guava:18.0 are required by your code directly', 'warning unused-dependency this dependency is unused and can be removed']
[guava, springfox] | ['warning unused-dependency this dependency is unused and can be removed']
libraryName | deps | expectedWarnings
'guava and asm' | [guava, asm] | ['warning unused-dependency this dependency is unused and can be removed']
'springfox' | [springfox] | ['warning unused-dependency one or more classes in com.google.guava:guava:18.0 are required by your code directly', 'warning unused-dependency this dependency is unused and can be removed']
'guava and springfox' | [guava, springfox] | ['warning unused-dependency this dependency is unused and can be removed']
}
@Unroll
def 'unused implementation dependencies are marked for deletion'() {
def 'unused implementation (#libraryName) dependencies are marked for deletion'() {
when:
buildFile.text = """\
|plugins {
Expand All @@ -142,10 +142,10 @@ class UnusedDependencyRuleSpec extends IntegrationTestKitSpec {
}
where:
deps | expectedWarnings
[guava, asm] | ['warning unused-dependency this dependency is unused and can be removed']
[springfox] | ['warning unused-dependency one or more classes in com.google.guava:guava:18.0 are required by your code directly', 'warning unused-dependency this dependency is unused and can be removed']
[guava, springfox] | ['warning unused-dependency this dependency is unused and can be removed']
libraryName | deps | expectedWarnings
'guava and asm' | [guava, asm] | ['warning unused-dependency this dependency is unused and can be removed']
'springfox' | [springfox] | ['warning unused-dependency one or more classes in com.google.guava:guava:18.0 are required by your code directly', 'warning unused-dependency this dependency is unused and can be removed']
'guava and springfox' | [guava, springfox] | ['warning unused-dependency this dependency is unused and can be removed']
}
def 'find dependency references in test code'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.netflix.nebula.lint.self

abstract trait AbstractShadedDependencies {
Collection<ShadedCoordinate> shadedCoordinates = [
static Collection<ShadedCoordinate> SHARED_COORDINATES = [
new ShadedCoordinate('org.eclipse.jdt', 'com.netflix.nebula.lint.jdt', 'org.eclipse.jdt', 'core'),
new ShadedCoordinate('org.eclipse.jgit', 'com.netflix.nebula.lint.jgit', 'org.eclipse.jgit', 'org.eclipse.jgit'),
new ShadedCoordinate('org.apache.commons.lang', 'com.netflix.nebula.lint.commons.lang', 'commons-lang', 'commons-lang'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ShadedArtifactsTest extends Specification implements AbstractShadedDepende
assert !pomFile.text.contains("<artifactId>${shadedCoordinate.artifactName}</artifactId>"), "Metadata file should not contain shaded dependency ${shadedCoordinate.artifactGroup}:${shadedCoordinate.artifactName}"

where:
shadedCoordinate << shadedCoordinates
shadedCoordinate << SHARED_COORDINATES
}

@Unroll
Expand All @@ -100,7 +100,7 @@ class ShadedArtifactsTest extends Specification implements AbstractShadedDepende
assert filteredEntries.size() >= 1, "Jar should contain shaded and relocated dependencies: $matchingPath"

where:
shadedCoordinate << shadedCoordinates
shadedCoordinate << SHARED_COORDINATES
}

@Unroll
Expand All @@ -113,7 +113,7 @@ class ShadedArtifactsTest extends Specification implements AbstractShadedDepende
assert filteredEntries.size() == 0, "Jar should not contain non relocated dependencies: $matchingPath"

where:
shadedCoordinate << shadedCoordinates
shadedCoordinate << SHARED_COORDINATES
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ShadedDependenciesTest extends Specification implements AbstractShadedDepe
report.exists()

then:
shadedCoordinates.each { shadedCoordinate ->
SHARED_COORDINATES.each { shadedCoordinate ->
String artifactGroupAndName = "${shadedCoordinate.artifactGroup}:${shadedCoordinate.artifactName}"
report.text.contains(artifactGroupAndName)
}
Expand All @@ -46,7 +46,7 @@ class ShadedDependenciesTest extends Specification implements AbstractShadedDepe
report.exists()

then:
shadedCoordinates.each { shadedCoordinate ->
SHARED_COORDINATES.each { shadedCoordinate ->
String artifactGroupAndName = "${shadedCoordinate.artifactGroup}:${shadedCoordinate.artifactName}"
report.text.contains(artifactGroupAndName)
}
Expand All @@ -60,7 +60,7 @@ class ShadedDependenciesTest extends Specification implements AbstractShadedDepe
report.exists()

then:
shadedCoordinates.each { shadedCoordinate ->
SHARED_COORDINATES.each { shadedCoordinate ->
String artifactGroupAndName = "${shadedCoordinate.artifactGroup}:${shadedCoordinate.artifactName}"
report.text.contains(artifactGroupAndName)
}
Expand All @@ -74,7 +74,7 @@ class ShadedDependenciesTest extends Specification implements AbstractShadedDepe
report.exists()

then:
shadedCoordinates.each { shadedCoordinate ->
SHARED_COORDINATES.each { shadedCoordinate ->
String artifactGroupAndName = "${shadedCoordinate.artifactGroup}:${shadedCoordinate.artifactName}"
report.text.contains(artifactGroupAndName)
}
Expand Down

0 comments on commit f4a5342

Please sign in to comment.