Minor cleanups
This commit is contained in:
parent
bf82ea1920
commit
8e2415eda4
3 changed files with 34 additions and 18 deletions
|
@ -61,17 +61,11 @@ public class ExampleBuild extends Project {
|
||||||
@Override
|
@Override
|
||||||
public void compile() throws Exception {
|
public void compile() throws Exception {
|
||||||
// The source code located in src/main/kotlin and src/test/kotlin will be compiled
|
// The source code located in src/main/kotlin and src/test/kotlin will be compiled
|
||||||
var options = new CompileOptions().verbose(true);
|
new CompileKotlinOperation()
|
||||||
var op = new CompileKotlinOperation()
|
|
||||||
// .kotlinHome("path/to/kotlin")
|
// .kotlinHome("path/to/kotlin")
|
||||||
// .kotlinc("path/to/kotlinc")
|
// .kotlinc("path/to/kotlinc")
|
||||||
.compileOptions(options)
|
.compileOptions(new CompileOptions().verbose(true))
|
||||||
.fromProject(this);
|
.fromProject(this)
|
||||||
|
.execute();
|
||||||
if (!CompileKotlinOperation.isWindows()) {
|
|
||||||
op.jvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
|
||||||
}
|
|
||||||
|
|
||||||
op.execute();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,18 +508,20 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
jvmOptions_.forEach(s -> command.add("-J" + s));
|
jvmOptions_.forEach(s -> command.add("-J" + s));
|
||||||
}
|
}
|
||||||
|
|
||||||
// compiler options
|
// classpath
|
||||||
if (compileOptions_ != null) {
|
if (compileOptions_ != null && !compileOptions_.classpath().isEmpty()) {
|
||||||
args.addAll(compileOptions_.args());
|
|
||||||
cp.addAll(compileOptions_.classpath().stream().map(this::cleanPath).toList());
|
cp.addAll(compileOptions_.classpath().stream().map(this::cleanPath).toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// classpath
|
|
||||||
if (!cp.isEmpty()) {
|
if (!cp.isEmpty()) {
|
||||||
args.add("-cp");
|
args.add("-cp");
|
||||||
args.add('"' + FileUtils.joinPaths(cp.stream().map(this::cleanPath).toList()) + '"');
|
args.add('"' + FileUtils.joinPaths(cp.stream().map(this::cleanPath).toList()) + '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// compile options
|
||||||
|
if (compileOptions_ != null && !compileOptions_.args().isEmpty()) {
|
||||||
|
args.addAll(compileOptions_.args());
|
||||||
|
}
|
||||||
|
|
||||||
// destination
|
// destination
|
||||||
args.add("-d");
|
args.add("-d");
|
||||||
args.add('"' + cleanPath(destination) + '"');
|
args.add('"' + cleanPath(destination) + '"');
|
||||||
|
|
|
@ -185,17 +185,23 @@ class CompileOptionsTest {
|
||||||
var bar = new File("bar.txt");
|
var bar = new File("bar.txt");
|
||||||
var options = new CompileOptions();
|
var options = new CompileOptions();
|
||||||
|
|
||||||
|
options = options.argFile(foo);
|
||||||
|
assertThat(options.argFile()).contains(foo);
|
||||||
|
options.argFile().clear();
|
||||||
|
assertThat(options.argFile()).isEmpty();
|
||||||
|
|
||||||
options.argFile(foo, bar);
|
options.argFile(foo, bar);
|
||||||
assertThat(options.argFile()).contains(foo, bar);
|
assertThat(options.argFile()).contains(foo, bar);
|
||||||
options.argFile().clear();
|
options.argFile().clear();
|
||||||
|
assertThat(options.argFile()).isEmpty();
|
||||||
|
|
||||||
options = options.argFile(foo.toPath(), bar.toPath());
|
options = options.argFile(foo.toPath(), bar.toPath());
|
||||||
assertThat(options.argFile()).contains(foo, bar);
|
assertThat(options.argFile()).contains(foo, bar);
|
||||||
options.argFile().clear();
|
options.argFile().clear();
|
||||||
|
assertThat(options.argFile()).isEmpty();
|
||||||
|
|
||||||
options.argFile(foo.getAbsolutePath(), bar.getAbsolutePath());
|
options = options.argFile(foo.getAbsolutePath(), bar.getAbsolutePath());
|
||||||
assertThat(options.argFile()).contains(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
|
assertThat(options.argFile()).contains(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
|
||||||
options.argFile().clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -254,31 +260,45 @@ class CompileOptionsTest {
|
||||||
var bar = new File("bar.txt");
|
var bar = new File("bar.txt");
|
||||||
var options = new CompileOptions();
|
var options = new CompileOptions();
|
||||||
|
|
||||||
|
options = options.classpath(foo);
|
||||||
|
assertThat(options.classpath()).as("File").containsExactly(foo);
|
||||||
|
options.classpath().clear();
|
||||||
|
assertThat(options.argFile()).isEmpty();
|
||||||
|
|
||||||
|
|
||||||
options.classpath(foo, bar);
|
options.classpath(foo, bar);
|
||||||
assertThat(options.classpath()).as("File...").containsExactly(foo, bar);
|
assertThat(options.classpath()).as("File...").containsExactly(foo, bar);
|
||||||
options.classpath().clear();
|
options.classpath().clear();
|
||||||
|
assertThat(options.argFile()).isEmpty();
|
||||||
|
|
||||||
|
|
||||||
options.classpath(List.of(foo, bar));
|
options.classpath(List.of(foo, bar));
|
||||||
assertThat(options.classpath()).as("List(File...)").containsExactly(foo, bar);
|
assertThat(options.classpath()).as("List(File...)").containsExactly(foo, bar);
|
||||||
options.classpath().clear();
|
options.classpath().clear();
|
||||||
|
assertThat(options.argFile()).isEmpty();
|
||||||
|
|
||||||
|
|
||||||
options = options.classpath(foo.toPath(), bar.toPath());
|
options = options.classpath(foo.toPath(), bar.toPath());
|
||||||
assertThat(options.classpath()).as("Path...").containsExactly(foo, bar);
|
assertThat(options.classpath()).as("Path...").containsExactly(foo, bar);
|
||||||
options.classpath().clear();
|
options.classpath().clear();
|
||||||
|
assertThat(options.argFile()).isEmpty();
|
||||||
|
|
||||||
|
|
||||||
options = options.classpathPaths(List.of(foo.toPath(), bar.toPath()));
|
options = options.classpathPaths(List.of(foo.toPath(), bar.toPath()));
|
||||||
assertThat(options.classpath()).as("List(Path...)").containsExactly(foo, bar);
|
assertThat(options.classpath()).as("List(Path...)").containsExactly(foo, bar);
|
||||||
options.classpath().clear();
|
options.classpath().clear();
|
||||||
|
assertThat(options.argFile()).isEmpty();
|
||||||
|
|
||||||
|
|
||||||
options.classpath(foo.getAbsolutePath(), bar.getAbsolutePath());
|
options.classpath(foo.getAbsolutePath(), bar.getAbsolutePath());
|
||||||
assertThat(options.classpath()).as("String...")
|
assertThat(options.classpath()).as("String...")
|
||||||
.containsExactly(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
|
.containsExactly(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
|
||||||
options.classpath().clear();
|
options.classpath().clear();
|
||||||
|
assertThat(options.argFile()).isEmpty();
|
||||||
|
|
||||||
options.classpathStrings(List.of(foo.getAbsolutePath(), bar.getAbsolutePath()));
|
options.classpathStrings(List.of(foo.getAbsolutePath(), bar.getAbsolutePath()));
|
||||||
assertThat(options.classpath()).as("List(String...)")
|
assertThat(options.classpath()).as("List(String...)")
|
||||||
.containsExactly(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
|
.containsExactly(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
|
||||||
options.classpath().clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue