Compare commits
No commits in common. "8e2415eda4daa2d30a80d9421462d03219e6b3dd" and "b5b6b4056487329135148e1def6aca7750198a74" have entirely different histories.
8e2415eda4
...
b5b6b40564
7 changed files with 50 additions and 73 deletions
|
@ -61,11 +61,17 @@ public class ExampleBuild extends Project {
|
|||
@Override
|
||||
public void compile() throws Exception {
|
||||
// The source code located in src/main/kotlin and src/test/kotlin will be compiled
|
||||
new CompileKotlinOperation()
|
||||
var options = new CompileOptions().verbose(true);
|
||||
var op = new CompileKotlinOperation()
|
||||
// .kotlinHome("path/to/kotlin")
|
||||
// .kotlinc("path/to/kotlinc")
|
||||
.compileOptions(new CompileOptions().verbose(true))
|
||||
.fromProject(this)
|
||||
.execute();
|
||||
.compileOptions(options)
|
||||
.fromProject(this);
|
||||
|
||||
if (!CompileKotlinOperation.isWindows()) {
|
||||
op.jvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
||||
}
|
||||
|
||||
op.execute();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
private static final Logger LOGGER = Logger.getLogger(CompileKotlinOperation.class.getName());
|
||||
private static final String OS_NAME =
|
||||
System.getProperty("os.name") != null ? System.getProperty("os.name").toLowerCase(Locale.US) : null;
|
||||
private static final String KOTLINC_EXECUTABLE = "kotlinc" + (isWindows() ? ".bat" : "");
|
||||
private static final String KOTLINC_EXECUTABLE = "kotlinc" + (isWindows() && !isCygwin() && !isMinGW() ? ".bat" : "");
|
||||
private final Collection<String> compileMainClasspath_ = new ArrayList<>();
|
||||
private final Collection<String> compileTestClasspath_ = new ArrayList<>();
|
||||
private final JvmOptions jvmOptions_ = new JvmOptions();
|
||||
|
@ -191,6 +191,17 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
return KOTLINC_EXECUTABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the current runtime environment is Cygwin.
|
||||
*
|
||||
* @return {@code true} if the current runtime environment is Cygwin, {@code false} otherwise.
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public static boolean isCygwin() {
|
||||
var path = System.getenv("ORIGINAL_PATH");
|
||||
return path != null && path.contains("/cygdrive/");
|
||||
}
|
||||
|
||||
private static boolean isExecutable(File file) {
|
||||
return file != null && file.exists() && file.isFile() && file.canExecute();
|
||||
}
|
||||
|
@ -215,6 +226,17 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
return OS_NAME != null && (OS_NAME.contains("mac") || OS_NAME.contains("darwin") || OS_NAME.contains("osx"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the current runtime environment is MinGW.
|
||||
*
|
||||
* @return {@code true} if the current runtime environment is MinGW, {@code false} otherwise.
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public static boolean isMinGW() {
|
||||
var msys = System.getenv("MSYSTEM");
|
||||
return msys != null && (msys.startsWith("MINGW") || msys.startsWith("MSYS"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given string is not blank.
|
||||
*
|
||||
|
@ -508,20 +530,18 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
jvmOptions_.forEach(s -> command.add("-J" + s));
|
||||
}
|
||||
|
||||
// classpath
|
||||
if (compileOptions_ != null && !compileOptions_.classpath().isEmpty()) {
|
||||
// compiler options
|
||||
if (compileOptions_ != null) {
|
||||
args.addAll(compileOptions_.args());
|
||||
cp.addAll(compileOptions_.classpath().stream().map(this::cleanPath).toList());
|
||||
}
|
||||
|
||||
// classpath
|
||||
if (!cp.isEmpty()) {
|
||||
args.add("-cp");
|
||||
args.add('"' + FileUtils.joinPaths(cp.stream().map(this::cleanPath).toList()) + '"');
|
||||
}
|
||||
|
||||
// compile options
|
||||
if (compileOptions_ != null && !compileOptions_.args().isEmpty()) {
|
||||
args.addAll(compileOptions_.args());
|
||||
}
|
||||
|
||||
// destination
|
||||
args.add("-d");
|
||||
args.add('"' + cleanPath(destination) + '"');
|
||||
|
@ -596,10 +616,10 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
*/
|
||||
protected void executeCreateBuildDirectories() throws IOException {
|
||||
if (buildMainDirectory() != null && !buildMainDirectory().exists() && !buildMainDirectory().mkdirs()) {
|
||||
throw new IOException("Could not create build main directory: " + buildMainDirectory().getAbsolutePath());
|
||||
throw new IOException("Could not created build main directory: " + buildMainDirectory().getAbsolutePath());
|
||||
}
|
||||
if (buildTestDirectory() != null && !buildTestDirectory().exists() && !buildTestDirectory().mkdirs()) {
|
||||
throw new IOException("Could not create build test directory: " + buildTestDirectory().getAbsolutePath());
|
||||
throw new IOException("Could not created build test directory: " + buildTestDirectory().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,18 +17,12 @@
|
|||
package rife.bld.extension.kotlin;
|
||||
|
||||
import rife.bld.extension.CompileKotlinOperation;
|
||||
import rife.bld.operations.AbstractToolProviderOperation;
|
||||
|
||||
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.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static rife.bld.extension.CompileKotlinOperation.isNotBlank;
|
||||
|
||||
|
@ -39,7 +33,6 @@ import static rife.bld.extension.CompileKotlinOperation.isNotBlank;
|
|||
* @since 1.0
|
||||
*/
|
||||
public class CompileOptions {
|
||||
private static final Logger LOGGER = Logger.getLogger(CompileOptions.class.getName());
|
||||
private final Collection<String> advancedOptions_ = new ArrayList<>();
|
||||
private final Collection<File> argFile_ = new ArrayList<>();
|
||||
private final Collection<File> classpath_ = new ArrayList<>();
|
||||
|
@ -255,27 +248,7 @@ public class CompileOptions {
|
|||
|
||||
// @argfile
|
||||
if (!argFile_.isEmpty()) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
argFile_.forEach(f -> args.add("@" + f.getAbsolutePath()));
|
||||
}
|
||||
|
||||
// expression
|
||||
|
|
|
@ -180,7 +180,7 @@ class CompileKotlinOperationTest {
|
|||
.compileTestClasspath(mainDir.getAbsolutePath());
|
||||
|
||||
op.compileOptions().verbose(true);
|
||||
op.compileOptions().argFile("src/test/resources/argfile.txt", "src/test/resources/argfile2.txt");
|
||||
op.compileOptions().jdkRelease("17");
|
||||
|
||||
if (!CompileKotlinOperation.isWindows()) {
|
||||
op.jvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
||||
|
@ -188,8 +188,7 @@ class CompileKotlinOperationTest {
|
|||
}
|
||||
|
||||
var args = op.compileOptions().args();
|
||||
var matches = List.of("-Xjdk-release=17", "-no-reflect", "-progressive", "-include-runtime", "-no-stdlib",
|
||||
"-verbose");
|
||||
var matches = List.of("-Xjdk-release=17", "-no-stdlib", "-verbose");
|
||||
assertThat(args).as(args + " == " + matches).isEqualTo(matches);
|
||||
|
||||
op.execute();
|
||||
|
|
|
@ -52,6 +52,7 @@ class CompileOptionsTest {
|
|||
void testArgs() {
|
||||
var options = new CompileOptions()
|
||||
.apiVersion("11")
|
||||
.argFile(new File("file.txt"), new File("file2.txt"))
|
||||
.javaParameters(true)
|
||||
.jvmTarget("11")
|
||||
.includeRuntime(true)
|
||||
|
@ -75,6 +76,7 @@ class CompileOptionsTest {
|
|||
|
||||
var matches = List.of(
|
||||
"-api-version", "11",
|
||||
"@" + localPath("file.txt"), "@" + localPath("file2.txt"),
|
||||
"-java-parameters",
|
||||
"-jvm-target", "11",
|
||||
"-include-runtime",
|
||||
|
@ -185,23 +187,17 @@ class CompileOptionsTest {
|
|||
var bar = new File("bar.txt");
|
||||
var options = new CompileOptions();
|
||||
|
||||
options = options.argFile(foo);
|
||||
assertThat(options.argFile()).contains(foo);
|
||||
options.argFile().clear();
|
||||
assertThat(options.argFile()).isEmpty();
|
||||
|
||||
options.argFile(foo, bar);
|
||||
assertThat(options.argFile()).contains(foo, bar);
|
||||
options.argFile().clear();
|
||||
assertThat(options.argFile()).isEmpty();
|
||||
|
||||
options = options.argFile(foo.toPath(), bar.toPath());
|
||||
assertThat(options.argFile()).contains(foo, bar);
|
||||
options.argFile().clear();
|
||||
assertThat(options.argFile()).isEmpty();
|
||||
|
||||
options = options.argFile(foo.getAbsolutePath(), bar.getAbsolutePath());
|
||||
options.argFile(foo.getAbsolutePath(), bar.getAbsolutePath());
|
||||
assertThat(options.argFile()).contains(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
|
||||
options.argFile().clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -214,6 +210,7 @@ class CompileOptionsTest {
|
|||
var params = new CompileOptions()
|
||||
.advancedOptions("Xoption")
|
||||
.apiVersion("11")
|
||||
.argFile("file")
|
||||
.expression("expression")
|
||||
.includeRuntime(true)
|
||||
.javaParameters(true)
|
||||
|
@ -236,7 +233,7 @@ class CompileOptionsTest {
|
|||
.wError(true)
|
||||
.wExtra(true);
|
||||
|
||||
var skipArgs = List.of("-J", "-classpath", "@");
|
||||
var skipArgs = List.of("-J", "-classpath");
|
||||
assertThat(args).as(skipArgs + " not found.").containsAll(skipArgs);
|
||||
args.removeAll(skipArgs);
|
||||
|
||||
|
@ -260,45 +257,31 @@ class CompileOptionsTest {
|
|||
var bar = new File("bar.txt");
|
||||
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);
|
||||
assertThat(options.classpath()).as("File...").containsExactly(foo, bar);
|
||||
options.classpath().clear();
|
||||
assertThat(options.argFile()).isEmpty();
|
||||
|
||||
|
||||
options.classpath(List.of(foo, bar));
|
||||
assertThat(options.classpath()).as("List(File...)").containsExactly(foo, bar);
|
||||
options.classpath().clear();
|
||||
assertThat(options.argFile()).isEmpty();
|
||||
|
||||
|
||||
options = options.classpath(foo.toPath(), bar.toPath());
|
||||
assertThat(options.classpath()).as("Path...").containsExactly(foo, bar);
|
||||
options.classpath().clear();
|
||||
assertThat(options.argFile()).isEmpty();
|
||||
|
||||
|
||||
options = options.classpathPaths(List.of(foo.toPath(), bar.toPath()));
|
||||
assertThat(options.classpath()).as("List(Path...)").containsExactly(foo, bar);
|
||||
options.classpath().clear();
|
||||
assertThat(options.argFile()).isEmpty();
|
||||
|
||||
|
||||
options.classpath(foo.getAbsolutePath(), bar.getAbsolutePath());
|
||||
assertThat(options.classpath()).as("String...")
|
||||
.containsExactly(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
|
||||
options.classpath().clear();
|
||||
assertThat(options.argFile()).isEmpty();
|
||||
|
||||
options.classpathStrings(List.of(foo.getAbsolutePath(), bar.getAbsolutePath()));
|
||||
assertThat(options.classpath()).as("List(String...)")
|
||||
.containsExactly(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
|
||||
options.classpath().clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
-Xjdk-release=17 -no-reflect
|
||||
|
||||
-progressive
|
|
@ -1 +0,0 @@
|
|||
-include-runtime
|
Loading…
Add table
Add a link
Reference in a new issue