From 159eef83b387a9f81120b7a194cd0311f00459ab Mon Sep 17 00:00:00 2001 From: Steve Hill Date: Tue, 28 Oct 2025 04:08:25 +0000 Subject: [PATCH] Convert GradleLintExtension from Groovy to Java Migrate GradleLintExtension to Java while maintaining full backwards compatibility with existing Groovy code. The Java file is placed in src/main/groovy/ to avoid circular compilation dependencies. All public APIs are preserved including Groovy closure support for ignore() and fixme() methods. --- .../lint/plugin/GradleLintExtension.groovy | 72 ------- .../lint/plugin/GradleLintExtension.java | 184 ++++++++++++++++++ 2 files changed, 184 insertions(+), 72 deletions(-) delete mode 100644 src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintExtension.groovy create mode 100644 src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintExtension.java diff --git a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintExtension.groovy b/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintExtension.groovy deleted file mode 100644 index d395797b..00000000 --- a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintExtension.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2015-2019 Netflix, Inc. - * - * 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. - */ - -package com.netflix.nebula.lint.plugin - -import com.netflix.nebula.lint.GradleLintViolationAction -import org.gradle.api.Incubating -import org.gradle.api.InvalidUserDataException - -class GradleLintExtension { - List rules = [] - - /** - * Allows for the exclusion of individual rules when we include rule sets - */ - List excludedRules = [] - - /** - * Rules that, when violated, cause the build to fail - */ - List criticalRules = [] - - String reportFormat = 'html' - boolean reportOnlyFixableViolations = false - boolean alwaysRun = true - boolean autoLintAfterFailure = true - - List skipForTasks = ['help', 'tasks', 'dependencies', 'dependencyInsight', 'components', 'model', 'projects', 'properties', 'wrapper'] - - @Incubating - List listeners = [] - - void setReportFormat(String reportFormat) { - if (reportFormat in ['xml', 'html', 'text']) { - this.reportFormat = reportFormat - } else { - throw new InvalidUserDataException("'$reportFormat' is not a valid CodeNarc report format") - } - } - - // pass-thru markers for the linter to know which blocks of code to ignore - void ignore(Closure c) { c() } - void ignore(String ruleName, Closure c) { c() } - void ignore(String r1, String r2, Closure c) { c() } - void ignore(String r1, String r2, String r3, Closure c) { c() } - void ignore(String r1, String r2, String r3, String r4, Closure c) { c() } - void ignore(String r1, String r2, String r3, String r4, String r5, Closure c) { c() } - - void fixme(String ignoreUntil, Closure c) { c() } - void fixme(String ignoreUntil, String ruleName, Closure c) { c() } - void fixme(String ignoreUntil, String r1, String r2, Closure c) { c() } - void fixme(String ignoreUntil, String r1, String r2, String r3, Closure c) { c() } - void fixme(String ignoreUntil, String r1, String r2, String r3, String r4, Closure c) { c() } - void fixme(String ignoreUntil, String r1, String r2, String r3, String r4, String r5, Closure c) { c() } - - void skipForTask(String taskName) { - skipForTasks.add(taskName) - } -} diff --git a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintExtension.java b/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintExtension.java new file mode 100644 index 00000000..2b8d2a05 --- /dev/null +++ b/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintExtension.java @@ -0,0 +1,184 @@ +/* + * Copyright 2015-2019 Netflix, Inc. + * + * 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. + */ + +package com.netflix.nebula.lint.plugin; + +import com.netflix.nebula.lint.GradleLintViolationAction; +import groovy.lang.Closure; +import org.gradle.api.Incubating; +import org.gradle.api.InvalidUserDataException; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class GradleLintExtension { + private List rules = new ArrayList<>(); + + /** + * Allows for the exclusion of individual rules when we include rule sets + */ + private List excludedRules = new ArrayList<>(); + + /** + * Rules that, when violated, cause the build to fail + */ + private List criticalRules = new ArrayList<>(); + + private String reportFormat = "html"; + private boolean reportOnlyFixableViolations = false; + private boolean alwaysRun = true; + private boolean autoLintAfterFailure = true; + + private List skipForTasks = new ArrayList<>(Arrays.asList( + "help", "tasks", "dependencies", "dependencyInsight", "components", + "model", "projects", "properties", "wrapper" + )); + + @Incubating + private List listeners = new ArrayList<>(); + + public List getRules() { + return rules; + } + + public void setRules(List rules) { + this.rules = rules; + } + + public List getExcludedRules() { + return excludedRules; + } + + public void setExcludedRules(List excludedRules) { + this.excludedRules = excludedRules; + } + + public List getCriticalRules() { + return criticalRules; + } + + public void setCriticalRules(List criticalRules) { + this.criticalRules = criticalRules; + } + + public String getReportFormat() { + return reportFormat; + } + + public void setReportFormat(String reportFormat) { + if (Arrays.asList("xml", "html", "text").contains(reportFormat)) { + this.reportFormat = reportFormat; + } else { + throw new InvalidUserDataException("'" + reportFormat + "' is not a valid CodeNarc report format"); + } + } + + public boolean getReportOnlyFixableViolations() { + return reportOnlyFixableViolations; + } + + public void setReportOnlyFixableViolations(boolean reportOnlyFixableViolations) { + this.reportOnlyFixableViolations = reportOnlyFixableViolations; + } + + public boolean getAlwaysRun() { + return alwaysRun; + } + + public void setAlwaysRun(boolean alwaysRun) { + this.alwaysRun = alwaysRun; + } + + public boolean getAutoLintAfterFailure() { + return autoLintAfterFailure; + } + + public void setAutoLintAfterFailure(boolean autoLintAfterFailure) { + this.autoLintAfterFailure = autoLintAfterFailure; + } + + public List getSkipForTasks() { + return skipForTasks; + } + + public void setSkipForTasks(List skipForTasks) { + this.skipForTasks = skipForTasks; + } + + @Incubating + public List getListeners() { + return listeners; + } + + @Incubating + public void setListeners(List listeners) { + this.listeners = listeners; + } + + // pass-thru markers for the linter to know which blocks of code to ignore + public void ignore(Closure c) { + c.call(); + } + + public void ignore(String ruleName, Closure c) { + c.call(); + } + + public void ignore(String r1, String r2, Closure c) { + c.call(); + } + + public void ignore(String r1, String r2, String r3, Closure c) { + c.call(); + } + + public void ignore(String r1, String r2, String r3, String r4, Closure c) { + c.call(); + } + + public void ignore(String r1, String r2, String r3, String r4, String r5, Closure c) { + c.call(); + } + + public void fixme(String ignoreUntil, Closure c) { + c.call(); + } + + public void fixme(String ignoreUntil, String ruleName, Closure c) { + c.call(); + } + + public void fixme(String ignoreUntil, String r1, String r2, Closure c) { + c.call(); + } + + public void fixme(String ignoreUntil, String r1, String r2, String r3, Closure c) { + c.call(); + } + + public void fixme(String ignoreUntil, String r1, String r2, String r3, String r4, Closure c) { + c.call(); + } + + public void fixme(String ignoreUntil, String r1, String r2, String r3, String r4, String r5, Closure c) { + c.call(); + } + + public void skipForTask(String taskName) { + skipForTasks.add(taskName); + } +}