Skip to content

Commit

Permalink
fix configuration cache problem with reports (#54)
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Schmid <service@aaschmid.de>
  • Loading branch information
aaschmid committed Mar 27, 2021
1 parent 76c419e commit 8b1d436
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/main/java/de/aaschmid/gradle/plugins/cpd/Cpd.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.internal.CollectionCallbackActionDecorator;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.reporting.Reporting;
import org.gradle.api.reporting.SingleFileReport;
import org.gradle.api.tasks.CacheableTask;
Expand All @@ -28,7 +28,6 @@
import org.gradle.api.tasks.SourceTask;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.VerificationTask;
import org.gradle.internal.reflect.Instantiator;
import org.gradle.workers.WorkerExecutor;


Expand Down Expand Up @@ -72,7 +71,7 @@
public class Cpd extends SourceTask implements VerificationTask, Reporting<CpdReports> {

private final WorkerExecutor workerExecutor;
private final CpdReportsImpl reports;
private final CpdReports reports;

private String encoding;
private boolean ignoreAnnotations;
Expand All @@ -88,8 +87,8 @@ public class Cpd extends SourceTask implements VerificationTask, Reporting<CpdRe
private String skipBlocksPattern;

@Inject
public Cpd(CollectionCallbackActionDecorator callbackActionDecorator, Instantiator instantiator, WorkerExecutor workerExecutor) {
this.reports = instantiator.newInstance(CpdReportsImpl.class, this, callbackActionDecorator);
public Cpd(ObjectFactory objectFactory, WorkerExecutor workerExecutor) {
this.reports = objectFactory.newInstance(CpdReportsImpl.class, this);
this.workerExecutor = workerExecutor;
}

Expand All @@ -109,7 +108,7 @@ private void checkTaskState() {
if (getMinimumTokenCount() <= 0) {
throw new InvalidUserDataException(String.format("Task '%s' requires 'minimumTokenCount' to be greater than zero.", getName()));
}
if (reports.getEnabled().isEmpty()) {
if (getReports().getEnabled().isEmpty()) {
throw new InvalidUserDataException(String.format("Task '%s' requires at least one enabled report.", getName()));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/aaschmid/gradle/plugins/cpd/CpdPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ private void setupTaskDefaults(Project project, CpdExtension extension) {
extensionMapping.map("reportsDir", () -> project.getExtensions().getByType(ReportingExtension.class).file("cpd"));

task.getReports().all(report -> {
ConventionMapping reportMapping = ((IConventionAware) report).getConventionMapping();
reportMapping.map("enabled", () -> "xml".equals(report.getName()));
reportMapping.map("destination", () -> new File(extension.getReportsDir(), task.getName() + "." + report.getName()));
report.getRequired().convention("xml".equals(report.getName()));
report.getOutputLocation().convention(project.getLayout().getProjectDirectory().file(project.provider(() ->
new File(extension.getReportsDir(), task.getName() + "." + report.getName()).getAbsolutePath())));
});
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.aaschmid.gradle.plugins.cpd.internal;

import javax.inject.Inject;

import de.aaschmid.gradle.plugins.cpd.Cpd;
import de.aaschmid.gradle.plugins.cpd.CpdCsvFileReport;
import de.aaschmid.gradle.plugins.cpd.CpdReports;
Expand All @@ -12,6 +14,7 @@

public class CpdReportsImpl extends TaskReportContainer<SingleFileReport> implements CpdReports {

@Inject
public CpdReportsImpl(Cpd task, CollectionCallbackActionDecorator callbackActionDecorator) {
super(SingleFileReport.class, task, callbackActionDecorator);

Expand Down

0 comments on commit 8b1d436

Please sign in to comment.