-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stop using org.gradle.api.plugins.quality.internal.CodeNarcReportsImp…
…l to support Gradle 8.11 (#409)
- Loading branch information
Showing
7 changed files
with
313 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
src/main/groovy/com/netflix/nebula/lint/plugin/report/LintReport.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package com.netflix.nebula.lint.plugin.report | ||
|
||
import com.netflix.nebula.lint.plugin.GradleLintReportTask | ||
import org.codehaus.groovy.runtime.GeneratedClosure | ||
import org.codenarc.AnalysisContext | ||
import org.codenarc.report.AbstractReportWriter | ||
import org.codenarc.results.Results | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.reporting.CustomizableHtmlReport | ||
import org.gradle.api.reporting.Report | ||
import org.gradle.api.reporting.SingleFileReport | ||
import org.gradle.api.resources.TextResource | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Internal | ||
import org.gradle.internal.metaobject.ConfigureDelegate | ||
import org.gradle.util.internal.ClosureBackedAction | ||
|
||
import javax.annotation.Nullable | ||
import javax.inject.Inject | ||
|
||
abstract class LintReport implements SingleFileReport, | ||
CustomizableHtmlReport { | ||
private final RegularFileProperty destination | ||
private final Property<Boolean> isEnabled | ||
private final Property<Boolean> isRequired | ||
private final GradleLintReportTask task | ||
|
||
@Inject | ||
LintReport(ObjectFactory objects, GradleLintReportTask task) { | ||
this.destination = objects.fileProperty() | ||
this.isEnabled = objects.property(Boolean.class) | ||
this.isRequired = objects.property(Boolean.class).value(Boolean.TRUE) | ||
this.task = task | ||
} | ||
|
||
/** | ||
* @deprecated use {@link #getOutputLocation()} instead. | ||
*/ | ||
@Deprecated | ||
@Internal | ||
File getDestination() { | ||
return destination.get().getAsFile() | ||
} | ||
|
||
// @Override // New API from 6.1 see https://github.com/gradle/gradle/issues/11923 | ||
@Override | ||
public RegularFileProperty getOutputLocation() { | ||
return destination | ||
} | ||
|
||
@Override | ||
@Internal("This property returns always same value") | ||
public OutputType getOutputType() { | ||
return OutputType.FILE | ||
} | ||
|
||
// @Override // New API from 6.1 see https://github.com/gradle/gradle/issues/11923 | ||
@Input | ||
Property<Boolean> getRequired() { | ||
return isRequired | ||
} | ||
|
||
/** | ||
* @deprecated use {@link #getRequired()} instead. | ||
*/ | ||
@Deprecated | ||
@Internal | ||
boolean isEnabled() { | ||
return isRequired.get() | ||
} | ||
|
||
/** | ||
* @deprecated use {@code getRequired().set(value)} instead. | ||
*/ | ||
@Deprecated | ||
void setEnabled(boolean b) { | ||
isRequired.set(b) | ||
} | ||
|
||
/** | ||
* @deprecated use {@code getRequired().set(provider)} instead. | ||
*/ | ||
@Deprecated | ||
void setEnabled(Provider<Boolean> provider) { | ||
isRequired.set(provider) | ||
} | ||
|
||
/** | ||
* @deprecated use {@code getOutputLocation().set(provider)} instead. | ||
*/ | ||
@Deprecated | ||
void setDestination(File file) { | ||
destination.set(file) | ||
} | ||
|
||
/** | ||
* @deprecated use {@code getOutputLocation().set(provider)} instead. | ||
*/ | ||
@Deprecated | ||
void setDestination(Provider<File> provider) { | ||
destination.set(this.task.getProject().getLayout().file(provider)) | ||
} | ||
|
||
@Override | ||
Report configure(Closure closure) { | ||
configureSelf(closure, this) | ||
return this | ||
} | ||
|
||
@Override | ||
@Internal("This property provides only a human readable name.") | ||
String getDisplayName() { | ||
return String.format("%s type report generated by the task %s", getName(), getTask().getPath()) | ||
} | ||
|
||
@Override | ||
TextResource getStylesheet() { | ||
return null | ||
} | ||
|
||
@Override | ||
void setStylesheet(@Nullable TextResource textResource) { | ||
throw new UnsupportedOperationException( | ||
String.format("stylesheet property is not available in the %s type report", getName())) | ||
} | ||
|
||
void setStylesheet(@Nullable String path) { | ||
throw new UnsupportedOperationException( | ||
String.format("stylesheet property is not available in the %s type report", getName())) | ||
} | ||
|
||
@Internal | ||
protected final GradleLintReportTask getTask() { | ||
return task | ||
} | ||
|
||
abstract AbstractReportWriter getWriter() | ||
|
||
void write(AnalysisContext analysisContext, Results results) { | ||
writer.writeReport(analysisContext, results) | ||
} | ||
|
||
/** | ||
* Called from an object's {@link org.gradle.util.Configurable#configure} method. | ||
*/ | ||
private static <T> T configureSelf(@Nullable Closure configureClosure, T target) { | ||
if (configureClosure == null) { | ||
return target | ||
} | ||
|
||
configureTarget(configureClosure, target, new ConfigureDelegate(configureClosure, target)) | ||
return target | ||
} | ||
|
||
private static <T> void configureTarget(Closure configureClosure, T target, ConfigureDelegate closureDelegate) { | ||
if (!(configureClosure instanceof GeneratedClosure)) { | ||
new ClosureBackedAction<T>(configureClosure, Closure.DELEGATE_FIRST, false).execute(target) | ||
return | ||
} | ||
|
||
// Hackery to make closure execution faster, by short-circuiting the expensive property and method lookup on Closure | ||
Closure withNewOwner = configureClosure.rehydrate(target, closureDelegate, configureClosure.getThisObject()) | ||
new ClosureBackedAction<T>(withNewOwner, Closure.OWNER_ONLY, false).execute(target) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/groovy/com/netflix/nebula/lint/plugin/report/internal/LintHtmlReport.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.netflix.nebula.lint.plugin.report.internal | ||
|
||
import com.netflix.nebula.lint.plugin.GradleLintReportTask | ||
import com.netflix.nebula.lint.plugin.report.LintReport | ||
import org.codenarc.report.AbstractReportWriter | ||
import org.codenarc.report.HtmlReportWriter | ||
import org.gradle.api.file.RegularFile | ||
import org.gradle.api.model.ObjectFactory | ||
|
||
import javax.inject.Inject | ||
|
||
abstract class LintHtmlReport extends LintReport { | ||
@Inject | ||
LintHtmlReport(ObjectFactory objects, GradleLintReportTask task) { | ||
super(objects, task) | ||
} | ||
|
||
@Override | ||
String getName() { | ||
return "html" | ||
} | ||
|
||
@Override | ||
AbstractReportWriter getWriter() { | ||
return new HtmlReportWriter(outputFile: outputLocation.get().asFile) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/groovy/com/netflix/nebula/lint/plugin/report/internal/LintTextReport.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.netflix.nebula.lint.plugin.report.internal | ||
|
||
import com.netflix.nebula.lint.plugin.GradleLintReportTask | ||
import com.netflix.nebula.lint.plugin.report.LintReport | ||
import org.codenarc.report.AbstractReportWriter | ||
import org.codenarc.report.TextReportWriter | ||
import org.gradle.api.file.RegularFile | ||
import org.gradle.api.model.ObjectFactory | ||
|
||
import javax.inject.Inject | ||
|
||
abstract class LintTextReport extends LintReport { | ||
@Inject | ||
LintTextReport(ObjectFactory objects, GradleLintReportTask task) { | ||
super(objects, task) | ||
} | ||
|
||
@Override | ||
String getName() { | ||
return "text" | ||
} | ||
|
||
@Override | ||
AbstractReportWriter getWriter() { | ||
return new TextReportWriter(outputFile: outputLocation.get().asFile) | ||
} | ||
} |
Oops, something went wrong.