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

Work around apparent bug in Gradle 6.1 DirectoryProperty#file #411

Merged
merged 1 commit into from
Sep 20, 2021
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
Expand Up @@ -40,6 +40,28 @@ class IntegrationSpec extends Specification {
"3.4.0" | "6.5.1" || 7435 | 926 | 3847
}

@Unroll
def "completes successfully using AGP #agpVersion and Gradle #gradleVersion"() {
given: "an integration test project"
def project = projectDir(agpVersion, gradleVersion)

when:
def result = GradleRunner.create()
.withGradleVersion(gradleVersion)
.withProjectDir(project)
.withArguments(":app:countDebugDexMethods", "--stacktrace")
.build()

then:
result.task(":app:countDebugDexMethods").outcome == TaskOutcome.SUCCESS

// These version combinations were known to fail at some point.
// This spec serves to guard against regression.
where:
agpVersion | gradleVersion | reportedIn
"4.0.0" | "6.1.1" | "https://github.com/KeepSafe/dexcount-gradle-plugin/issues/410"
}

@Unroll
def "counting AARs using AGP #agpVersion and Gradle #gradleVersion"() {
given: "an integration test project"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected void createTask(
String treePath = path.replace("outputs", "intermediates") + "/tree.compact.gz";

TaskProvider<LegacyGeneratePackageTreeTask> gen = getProject().getTasks().register(treeTaskName, LegacyGeneratePackageTreeTask.class, t -> {
t.setDescription("Generates dex method count for ${variant.name}.");
t.setDescription("Generates dex method count for " + variant.getName() + ".");
t.setGroup("Reporting");

t.getConfigProperty().set(getExt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public interface Params extends WorkParameters {
Property<PrintOptions> getPrintOptions();
}

private File outputDirectory = null;

@Override
public void execute() {
try {
PackageTree packageTree = generatePackageTree();

File outputDir = getParameters().getOutputDirectory().get().getAsFile();
FileUtils.deleteDirectory(outputDir);
FileUtils.forceMkdir(outputDir);
ensureCleanOutputDirectory();

writeIntermediateThriftFile(packageTree);
writeSummaryFile(packageTree);
Expand All @@ -72,6 +72,11 @@ public void execute() {
}
}

private void ensureCleanOutputDirectory() throws IOException {
FileUtils.deleteDirectory(getOutputDirectory());
FileUtils.forceMkdir(getOutputDirectory());
}

private void writeIntermediateThriftFile(PackageTree packageTree) throws IOException {
TreeGenOutput thrift = new TreeGenOutput.Builder()
.tree(PackageTree.toThrift(packageTree))
Expand All @@ -92,7 +97,7 @@ private void writeIntermediateThriftFile(PackageTree packageTree) throws IOExcep
}

private void writeSummaryFile(PackageTree packageTree) throws IOException {
File summaryFile = getParameters().getOutputDirectory().file("summary.csv").get().getAsFile();
File summaryFile = new File(getOutputDirectory(), "summary.csv");
FileUtils.forceMkdirParent(summaryFile);

String headers = "methods,fields,classes";
Expand All @@ -109,7 +114,7 @@ private void writeSummaryFile(PackageTree packageTree) throws IOException {
}

private void writeChartFiles(PackageTree packageTree) throws IOException {
File chartDirectory = getParameters().getOutputDirectory().dir("chart").get().getAsFile();
File chartDirectory = new File(getOutputDirectory(), "chart");
FileUtils.forceMkdir(chartDirectory);

PrintOptions options = getParameters().getPrintOptions().get()
Expand Down Expand Up @@ -140,13 +145,20 @@ private void writeChartFiles(PackageTree packageTree) throws IOException {
private void writeFullTree(PackageTree packageTree) throws IOException {
PrintOptions options = getParameters().getPrintOptions().get();
String fullCountFileName = getParameters().getOutputFileName().get() + options.getOutputFormat().getExtension();
File fullCountFile = getParameters().getOutputDirectory().file(fullCountFileName).get().getAsFile();
File fullCountFile = new File(getOutputDirectory(), fullCountFileName);

try (BufferedWriter bw = Files.newBufferedWriter(fullCountFile.toPath())) {
packageTree.print(bw, options.getOutputFormat(), options);
}
}

private File getOutputDirectory() {
if (outputDirectory == null) {
outputDirectory = getParameters().getOutputDirectory().get().getAsFile();
}
return outputDirectory;
}

protected abstract PackageTree generatePackageTree() throws IOException;

protected abstract String getInputRepresentation();
Expand Down