Skip to content

Commit

Permalink
Support spaces in paths in argfile (#403)
Browse files Browse the repository at this point in the history
This commit fixes the AOT tasks which use `@arfile` for calling
Micronaut AOT: they suffer the same bug as in native build tools,
which is that spaces in paths need to be escaped.

See #401
  • Loading branch information
melix authored Mar 19, 2022
1 parent 3d66736 commit 85191a5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public final void execute() throws IOException {
configureExtraArguments(args);
boolean useArgFile = true;
try (PrintWriter wrt = new PrintWriter(new FileWriter(argFile))) {
args.forEach(wrt::println);
args.forEach(arg -> wrt.println(escapeArg(arg)));
} catch (IOException e) {
useArgFile = false;
}
Expand Down Expand Up @@ -128,4 +128,12 @@ private void maybeAddOptimizerClasspath(List<String> args, ConfigurableFileColle
}
}

private static String escapeArg(String arg) {
arg = arg.replace("\\", "\\\\");
if (arg.contains(" ")) {
arg = "\"" + arg + "\"";
}
return arg;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.micronaut.gradle.aot


import org.gradle.testkit.runner.TaskOutcome
import spock.lang.Issue
import spock.lang.Requires

@Requires({ jvm.isJava11Compatible() })
Expand Down Expand Up @@ -138,4 +139,18 @@ class BasicMicronautAOTSpec extends AbstractAOTPluginSpec {

}

@Issue("https://github.com/micronaut-projects/micronaut-gradle-plugin/issues/401")
def "supports spaces in file names"() {
withSpacesInTestDir()
withSample("aot/basic-app")
withPlugins(Plugins.MINIMAL_APPLICATION)
println("Base directory: $baseDir")

when:
def result = build "prepareJitOptimizations"

then:
result.task(":prepareJitOptimizations").outcome == TaskOutcome.SUCCESS
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,35 @@ abstract class AbstractGradleBuildSpec extends Specification {

@Rule
TemporaryFolder testProjectDir = new TemporaryFolder()
protected Path baseDir

File settingsFile
File buildFile
File kotlinBuildFile
File getSettingsFile() {
baseDir.resolve("settings.gradle").toFile()
}

File getBuildFile() {
baseDir.resolve("build.gradle").toFile()
}

File getKotlinBuildFile() {
baseDir.resolve("build.gradle.kts").toFile()
}

// This can be used during development to add statements like includeBuild
final List<String> postSettingsStatements = [
]

def setup() {
settingsFile = testProjectDir.newFile('settings.gradle')
buildFile = testProjectDir.newFile('build.gradle')
kotlinBuildFile = testProjectDir.newFile('build.gradle.kts')
baseDir = testProjectDir.root.toPath()
}

void withSpacesInTestDir() {
baseDir = testProjectDir.newFolder("with spaces").toPath()
}

protected void withSample(String name) {
File sampleDir = new File("../samples/$name").canonicalFile
copySample(sampleDir.toPath(), testProjectDir.root.toPath())
copySample(sampleDir.toPath(), baseDir)
}

private static void copySample(Path from, Path into) {
Expand All @@ -51,7 +62,7 @@ abstract class AbstractGradleBuildSpec extends Specification {
}

File file(String relativePath) {
testProjectDir.root.toPath().resolve(relativePath).toFile()
baseDir.resolve(relativePath).toFile()
}

def getRepositoriesBlock(String dsl = 'groovy') {
Expand Down Expand Up @@ -85,7 +96,7 @@ abstract class AbstractGradleBuildSpec extends Specification {
)
}
}
runner.withProjectDir(testProjectDir.root)
runner.withProjectDir(baseDir.toFile())
.withArguments(["--no-watch-fs",
"-S",
"-Porg.gradle.java.installations.auto-download=false",
Expand Down

0 comments on commit 85191a5

Please sign in to comment.