Read @argfile manually
This commit is contained in:
parent
b5b6b40564
commit
b0ad8ad056
6 changed files with 38 additions and 9 deletions
|
@ -616,10 +616,10 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
*/
|
*/
|
||||||
protected void executeCreateBuildDirectories() throws IOException {
|
protected void executeCreateBuildDirectories() throws IOException {
|
||||||
if (buildMainDirectory() != null && !buildMainDirectory().exists() && !buildMainDirectory().mkdirs()) {
|
if (buildMainDirectory() != null && !buildMainDirectory().exists() && !buildMainDirectory().mkdirs()) {
|
||||||
throw new IOException("Could not created build main directory: " + buildMainDirectory().getAbsolutePath());
|
throw new IOException("Could not create build main directory: " + buildMainDirectory().getAbsolutePath());
|
||||||
}
|
}
|
||||||
if (buildTestDirectory() != null && !buildTestDirectory().exists() && !buildTestDirectory().mkdirs()) {
|
if (buildTestDirectory() != null && !buildTestDirectory().exists() && !buildTestDirectory().mkdirs()) {
|
||||||
throw new IOException("Could not created build test directory: " + buildTestDirectory().getAbsolutePath());
|
throw new IOException("Could not create build test directory: " + buildTestDirectory().getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,18 @@
|
||||||
package rife.bld.extension.kotlin;
|
package rife.bld.extension.kotlin;
|
||||||
|
|
||||||
import rife.bld.extension.CompileKotlinOperation;
|
import rife.bld.extension.CompileKotlinOperation;
|
||||||
|
import rife.bld.operations.AbstractToolProviderOperation;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static rife.bld.extension.CompileKotlinOperation.isNotBlank;
|
import static rife.bld.extension.CompileKotlinOperation.isNotBlank;
|
||||||
|
|
||||||
|
@ -33,6 +39,7 @@ import static rife.bld.extension.CompileKotlinOperation.isNotBlank;
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class CompileOptions {
|
public class CompileOptions {
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(CompileOptions.class.getName());
|
||||||
private final Collection<String> advancedOptions_ = new ArrayList<>();
|
private final Collection<String> advancedOptions_ = new ArrayList<>();
|
||||||
private final Collection<File> argFile_ = new ArrayList<>();
|
private final Collection<File> argFile_ = new ArrayList<>();
|
||||||
private final Collection<File> classpath_ = new ArrayList<>();
|
private final Collection<File> classpath_ = new ArrayList<>();
|
||||||
|
@ -248,7 +255,27 @@ public class CompileOptions {
|
||||||
|
|
||||||
// @argfile
|
// @argfile
|
||||||
if (!argFile_.isEmpty()) {
|
if (!argFile_.isEmpty()) {
|
||||||
argFile_.forEach(f -> args.add("@" + f.getAbsolutePath()));
|
argFile_.forEach(f -> {
|
||||||
|
if (f.exists()) {
|
||||||
|
try {
|
||||||
|
try (var reader = Files.newBufferedReader(f.toPath(), Charset.defaultCharset())) {
|
||||||
|
var tokenizer = new AbstractToolProviderOperation.CommandLineTokenizer(reader);
|
||||||
|
String token;
|
||||||
|
while ((token = tokenizer.nextToken()) != null) {
|
||||||
|
args.add(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (LOGGER.isLoggable(Level.WARNING)) {
|
||||||
|
LOGGER.log(Level.WARNING, "Could not read: " + f.getAbsolutePath(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (LOGGER.isLoggable(Level.WARNING)) {
|
||||||
|
LOGGER.warning("File not found: " + f.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// expression
|
// expression
|
||||||
|
|
|
@ -180,7 +180,7 @@ class CompileKotlinOperationTest {
|
||||||
.compileTestClasspath(mainDir.getAbsolutePath());
|
.compileTestClasspath(mainDir.getAbsolutePath());
|
||||||
|
|
||||||
op.compileOptions().verbose(true);
|
op.compileOptions().verbose(true);
|
||||||
op.compileOptions().jdkRelease("17");
|
op.compileOptions().argFile("src/test/resources/argfile.txt", "src/test/resources/argfile2.txt");
|
||||||
|
|
||||||
if (!CompileKotlinOperation.isWindows()) {
|
if (!CompileKotlinOperation.isWindows()) {
|
||||||
op.jvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
op.jvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
||||||
|
@ -188,7 +188,8 @@ class CompileKotlinOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
var args = op.compileOptions().args();
|
var args = op.compileOptions().args();
|
||||||
var matches = List.of("-Xjdk-release=17", "-no-stdlib", "-verbose");
|
var matches = List.of("-Xjdk-release=17", "-no-reflect", "-progressive", "-include-runtime", "-no-stdlib",
|
||||||
|
"-verbose");
|
||||||
assertThat(args).as(args + " == " + matches).isEqualTo(matches);
|
assertThat(args).as(args + " == " + matches).isEqualTo(matches);
|
||||||
|
|
||||||
op.execute();
|
op.execute();
|
||||||
|
|
|
@ -52,7 +52,6 @@ class CompileOptionsTest {
|
||||||
void testArgs() {
|
void testArgs() {
|
||||||
var options = new CompileOptions()
|
var options = new CompileOptions()
|
||||||
.apiVersion("11")
|
.apiVersion("11")
|
||||||
.argFile(new File("file.txt"), new File("file2.txt"))
|
|
||||||
.javaParameters(true)
|
.javaParameters(true)
|
||||||
.jvmTarget("11")
|
.jvmTarget("11")
|
||||||
.includeRuntime(true)
|
.includeRuntime(true)
|
||||||
|
@ -76,7 +75,6 @@ class CompileOptionsTest {
|
||||||
|
|
||||||
var matches = List.of(
|
var matches = List.of(
|
||||||
"-api-version", "11",
|
"-api-version", "11",
|
||||||
"@" + localPath("file.txt"), "@" + localPath("file2.txt"),
|
|
||||||
"-java-parameters",
|
"-java-parameters",
|
||||||
"-jvm-target", "11",
|
"-jvm-target", "11",
|
||||||
"-include-runtime",
|
"-include-runtime",
|
||||||
|
@ -210,7 +208,6 @@ class CompileOptionsTest {
|
||||||
var params = new CompileOptions()
|
var params = new CompileOptions()
|
||||||
.advancedOptions("Xoption")
|
.advancedOptions("Xoption")
|
||||||
.apiVersion("11")
|
.apiVersion("11")
|
||||||
.argFile("file")
|
|
||||||
.expression("expression")
|
.expression("expression")
|
||||||
.includeRuntime(true)
|
.includeRuntime(true)
|
||||||
.javaParameters(true)
|
.javaParameters(true)
|
||||||
|
@ -233,7 +230,7 @@ class CompileOptionsTest {
|
||||||
.wError(true)
|
.wError(true)
|
||||||
.wExtra(true);
|
.wExtra(true);
|
||||||
|
|
||||||
var skipArgs = List.of("-J", "-classpath");
|
var skipArgs = List.of("-J", "-classpath", "@");
|
||||||
assertThat(args).as(skipArgs + " not found.").containsAll(skipArgs);
|
assertThat(args).as(skipArgs + " not found.").containsAll(skipArgs);
|
||||||
args.removeAll(skipArgs);
|
args.removeAll(skipArgs);
|
||||||
|
|
||||||
|
|
3
src/test/resources/argfile.txt
Normal file
3
src/test/resources/argfile.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
-Xjdk-release=17 -no-reflect
|
||||||
|
|
||||||
|
-progressive
|
1
src/test/resources/argfile2.txt
Normal file
1
src/test/resources/argfile2.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
-include-runtime
|
Loading…
Add table
Add a link
Reference in a new issue