diff --git a/src/integrationTest/groovy/com/getkeepsafe/dexcount/IntegrationSpec.groovy b/src/integrationTest/groovy/com/getkeepsafe/dexcount/IntegrationSpec.groovy index cccbd86..b220403 100644 --- a/src/integrationTest/groovy/com/getkeepsafe/dexcount/IntegrationSpec.groovy +++ b/src/integrationTest/groovy/com/getkeepsafe/dexcount/IntegrationSpec.groovy @@ -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" diff --git a/src/main/java/com/getkeepsafe/dexcount/plugin/AbstractLegacyTaskApplicator.java b/src/main/java/com/getkeepsafe/dexcount/plugin/AbstractLegacyTaskApplicator.java index 73d1cff..afae976 100644 --- a/src/main/java/com/getkeepsafe/dexcount/plugin/AbstractLegacyTaskApplicator.java +++ b/src/main/java/com/getkeepsafe/dexcount/plugin/AbstractLegacyTaskApplicator.java @@ -143,7 +143,7 @@ protected void createTask( String treePath = path.replace("outputs", "intermediates") + "/tree.compact.gz"; TaskProvider 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()); diff --git a/src/main/java/com/getkeepsafe/dexcount/treegen/workers/BaseWorker.java b/src/main/java/com/getkeepsafe/dexcount/treegen/workers/BaseWorker.java index b2b53e6..8344cb3 100644 --- a/src/main/java/com/getkeepsafe/dexcount/treegen/workers/BaseWorker.java +++ b/src/main/java/com/getkeepsafe/dexcount/treegen/workers/BaseWorker.java @@ -54,14 +54,14 @@ public interface Params extends WorkParameters { Property 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); @@ -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)) @@ -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"; @@ -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() @@ -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();