Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CompileStatic #253

Merged
merged 4 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.netflix.nebula.config.plugin

import groovy.transform.CompileStatic
import org.gradle.api.Plugin
import org.gradle.api.Project

Expand All @@ -9,6 +10,7 @@ import org.gradle.api.Project
* new lint rules that may depend on manipulating dependencies in a
* configuration-dependent way.
*/
@CompileStatic
class ConfigurationEnvironmentPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/groovy/com/netflix/nebula/lint/FileMode.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

package com.netflix.nebula.lint

import groovy.transform.CompileStatic

import static java.nio.file.Files.isSymbolicLink

@CompileStatic
enum FileMode {
Regular(100644),
Symlink(120000),
Expand Down
8 changes: 8 additions & 0 deletions src/main/groovy/com/netflix/nebula/lint/GradleLintFix.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.netflix.nebula.lint

import groovy.transform.CompileStatic

import java.nio.file.Files

/**
Expand Down Expand Up @@ -59,6 +61,7 @@ abstract class GradleLintMultilineFix extends GradleLintFix {
Integer to() { affectedLines.to }
}

@CompileStatic
class GradleLintReplaceWith extends GradleLintMultilineFix {
Integer fromColumn // the first affected column of the first line (1-based, inclusive)
Integer toColumn // the last affected column of the last line (1-based, exclusive)
Expand All @@ -78,6 +81,7 @@ class GradleLintReplaceWith extends GradleLintMultilineFix {
String changes() { changes }
}

@CompileStatic
class GradleLintDeleteLines extends GradleLintMultilineFix {

GradleLintDeleteLines(GradleViolation violation, File affectedFile, Range<Integer> affectedLines) {
Expand All @@ -90,6 +94,7 @@ class GradleLintDeleteLines extends GradleLintMultilineFix {
String changes() { null }
}

@CompileStatic
class GradleLintInsertAfter extends GradleLintFix {
Integer afterLine // 1-based
String changes
Expand All @@ -111,6 +116,7 @@ class GradleLintInsertAfter extends GradleLintFix {
String changes() { changes }
}

@CompileStatic
class GradleLintInsertBefore extends GradleLintFix {
Integer beforeLine // 1-based
String changes
Expand All @@ -132,6 +138,7 @@ class GradleLintInsertBefore extends GradleLintFix {
String changes() { changes }
}

@CompileStatic
class GradleLintDeleteFile extends GradleLintMultilineFix implements RequiresOwnPatchset {
GradleLintDeleteFile(GradleViolation violation, File affectedFile) {
this.violation = violation
Expand All @@ -144,6 +151,7 @@ class GradleLintDeleteFile extends GradleLintMultilineFix implements RequiresOwn
String changes() { null }
}

@CompileStatic
class GradleLintCreateFile extends GradleLintInsertBefore implements RequiresOwnPatchset {
FileMode fileMode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.netflix.nebula.lint

import com.netflix.nebula.lint.rule.BuildFiles
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import org.codehaus.groovy.ast.ASTNode
import org.codehaus.groovy.ast.expr.ArgumentListExpression
Expand All @@ -27,6 +28,7 @@ import org.codenarc.rule.Violation

import java.util.concurrent.atomic.AtomicInteger

@CompileStatic
@EqualsAndHashCode(includes = 'id')
class GradleViolation extends Violation {
BuildFiles files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.netflix.nebula.lint

import groovy.transform.CompileStatic

@CompileStatic
enum UnfixedViolationReason {
OverlappingPatch('one or more fixes overlap with another, run fixGradleLint again to apply the change')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.netflix.nebula.lint.rule

import groovy.transform.CompileStatic

/**
* This class provides transformation from multiple build files to one concatenated text which is used for applying
* lint rules. We keep original mapping so we can get based on line number in concatenated text original line and file.
*/
@CompileStatic
class BuildFiles {

private Map<LineRange, File> orderedFiles = new LinkedHashMap<>()
Expand Down Expand Up @@ -53,7 +56,7 @@ class BuildFiles {
} else {
new Original(
file: orderedFiles.values().first(),
line: null
line: null as Integer
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/groovy/com/netflix/nebula/lint/rule/FixmeRule.groovy
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.netflix.nebula.lint.rule

import groovy.transform.CompileStatic
import org.codenarc.rule.Rule
import org.codenarc.rule.Violation
import org.codenarc.source.SourceCode

@CompileStatic
class FixmeRule implements Rule {
@Override
List<Violation> applyTo(SourceCode sourceCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package com.netflix.nebula.lint.rule

import groovy.transform.Canonical
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.gradle.api.artifacts.ModuleIdentifier
import org.gradle.api.artifacts.ModuleVersionIdentifier
import org.gradle.api.internal.artifacts.DefaultModuleIdentifier
import org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier

@CompileStatic
@Canonical
class GradleDependency implements Cloneable {
String group
Expand All @@ -38,10 +41,12 @@ class GradleDependency implements Cloneable {
EvaluatedArbitraryCode
}

@CompileDynamic
ModuleVersionIdentifier toModuleVersion() {
return new DefaultModuleVersionIdentifier(group, name, version)
}


@CompileDynamic
ModuleIdentifier toModule() {
return new DefaultModuleIdentifier(group, name)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.netflix.nebula.lint.rule

import groovy.transform.Canonical
import groovy.transform.CompileStatic

@Canonical
@CompileStatic
class GradlePlugin {
String id
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ package com.netflix.nebula.lint.rule.dependency
import com.netflix.nebula.lint.rule.GradleDependency
import com.netflix.nebula.lint.rule.GradleLintRule
import com.netflix.nebula.lint.rule.GradleModelAware
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.ast.expr.MethodCallExpression
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ModuleVersionIdentifier

@CompileStatic
abstract class AbstractDuplicateDependencyClassRule extends GradleLintRule implements GradleModelAware {
String description = 'classpaths with duplicate classes may break unpredictably depending on the order in which dependencies are provided to the classpath'

Set<Configuration> directlyUsedConfigurations = [] as Set
Set<ModuleVersionIdentifier> ignoredDependencies = [] as Set

def resolvableAndResolvedConfigurations
Set<Configuration> resolvableAndResolvedConfigurations

abstract protected List<ModuleVersionIdentifier> moduleIds(Configuration conf)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package com.netflix.nebula.lint.rule.dependency

import groovy.transform.CompileStatic
import groovy.transform.Memoized
import org.slf4j.Logger
import org.slf4j.LoggerFactory

@CompileStatic
class ClassHierarchyUtils {
private static Logger logger = LoggerFactory.getLogger(ClassHierarchyUtils)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.netflix.nebula.lint.rule.dependency

import groovy.transform.CompileStatic

@CompileStatic
class ClassInformation {
String filePath
String source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import com.netflix.nebula.lint.rule.GradleAstUtil
import com.netflix.nebula.lint.rule.GradleDependency
import com.netflix.nebula.lint.rule.GradleLintRule
import com.netflix.nebula.lint.rule.GradleModelAware
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.expr.MethodCallExpression

@CompileStatic
class DependencyTupleExpressionRule extends GradleLintRule implements GradleModelAware {
String description = "use the more compact string representation of a dependency when possible"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.netflix.nebula.lint.rule.dependency

import com.netflix.nebula.lint.GradleViolation
import com.netflix.nebula.lint.rule.GradleDependency
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.expr.MethodCallExpression

@CompileStatic
class DependencyViolationUtil {

static void replaceProjectDependencyConfiguration(GradleViolation violation, MethodCallExpression call, String configuration, String project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import com.netflix.nebula.lint.GradleViolation
import com.netflix.nebula.lint.rule.GradleDependency
import com.netflix.nebula.lint.rule.GradleLintRule
import com.netflix.nebula.lint.rule.GradleModelAware
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.expr.MethodCallExpression

@CompileStatic
class DeprecatedDependencyConfigurationRule extends GradleLintRule implements GradleModelAware {
String description = 'Replace deprecated configurations in dependencies'

Expand Down Expand Up @@ -51,6 +54,7 @@ class DeprecatedDependencyConfigurationRule extends GradleLintRule implements Gr
* Responsible for replacing configurations in project dependencies only
* @param call
*/
@CompileDynamic
private void handleProjectDependencies(MethodCallExpression call) {
List statements = call.arguments.expressions*.code*.statements.flatten().findAll { it.expression instanceof MethodCallExpression }
statements.each { statement ->
Expand All @@ -71,6 +75,7 @@ class DeprecatedDependencyConfigurationRule extends GradleLintRule implements Gr
}
}

@CompileDynamic
private void handleDependencyVisit(MethodCallExpression call, String conf, GradleDependency dep) {
if(CONFIGURATION_REPLACEMENTS.containsKey(conf) && !GradleKt.versionLessThan(project.gradle, MINIMUM_GRADLE_VERSION)) {
if (call.arguments.expressions.size() == 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.netflix.nebula.lint.rule.dependency

import groovy.transform.CompileStatic
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ModuleVersionIdentifier

@CompileStatic
class FirstOrderDuplicateDependencyClassRule extends AbstractDuplicateDependencyClassRule {
@Override
protected List<ModuleVersionIdentifier> moduleIds(Configuration conf) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.netflix.nebula.lint.rule.dependency

import groovy.transform.CompileStatic

@CompileStatic
class JarContents {
Set<String> entryNames

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.netflix.nebula.lint.rule.dependency

import groovy.transform.CompileStatic


@CompileStatic
class MethodReference {
String methodName
String owner
Expand Down Expand Up @@ -32,13 +35,13 @@ class MethodReference {
INVOKEINTERFACE(185),
INVOKEDYNAMIC(186)

private int code
int code

OpCode(int code) {
this.code = code
}

static findByCode(int code) {
static OpCode findByCode(int code) {
values().find { it.code == code }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.nio.file.Path
class MethodScanner {
private AppClassVisitor classVisitor

private ArrayList<MethodReference> methodReferences = []
private List<MethodReference> methodReferences = []

private class AppMethodVisitor extends MethodVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.netflix.nebula.lint.rule.dependency
import com.netflix.nebula.lint.rule.GradleDependency
import com.netflix.nebula.lint.rule.GradleLintRule
import com.netflix.nebula.lint.rule.GradleModelAware
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.ASTNode
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.ast.expr.Expression
Expand All @@ -18,10 +19,11 @@ import org.gradle.util.VersionNumber
* Continuing confluence of these two plugins may eventually result in a different way to parameterize the rule.
*/
@Incubating
@CompileStatic
class MinimumDependencyVersionRule extends GradleLintRule implements GradleModelAware {
String description = 'pull up dependencies to a minimum version if necessary'
def alreadyAdded = [] as Set
def resolvableAndResolvedConfigurations
Set alreadyAdded = [] as Set
Set<Configuration> resolvableAndResolvedConfigurations

@Lazy
List<GradleDependency> minimumVersions = {
Expand All @@ -32,7 +34,7 @@ class MinimumDependencyVersionRule extends GradleLintRule implements GradleModel
collect { GradleDependency.fromConstant(it) }?.
findAll { it != null } ?:
[]
} else []
} else [] as List<GradleDependency>
}()

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
package com.netflix.nebula.lint.rule.dependency

import com.netflix.nebula.lint.rule.GradleDependency
import groovy.transform.CompileStatic
import groovy.transform.Immutable

@Immutable
@CompileStatic
class ModuleDescriptor {
String group
String name
Expand Down
Loading