Compare commits
2 commits
81ab2e829c
...
1623b902f9
Author | SHA1 | Date | |
---|---|---|---|
1623b902f9 | |||
b4c8952538 |
10 changed files with 217 additions and 52 deletions
|
@ -5,12 +5,19 @@ new=/tmp/checkcliargs-new
|
|||
old=/tmp/checkcliargs-old
|
||||
|
||||
java -cp "lib/compile/*" $main -h >$new
|
||||
java -cp "/examples/lib/bld*" $main -h >$old
|
||||
java -cp "examples/lib/bld/*" $main -h >$old
|
||||
|
||||
diff $old $new
|
||||
|
||||
java -cp "lib/compile/*" $main -sourceSet -h >$new
|
||||
java -cp "/examples/lib/bld*" $main -sourceSet -h >$old
|
||||
java -cp "examples/lib/bld/*" $main -sourceSet -h >$old
|
||||
|
||||
diff $old $new
|
||||
|
||||
main=org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
|
||||
java -cp "lib/compile/*" $main -h 2>$new
|
||||
java -cp "examples/lib/bld/*" $main -h 2>$old
|
||||
|
||||
diff $old $new
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
java -cp "lib/compile/*" org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -h 2> >(grep "^ ") |\
|
||||
sed -e "s/^ //" -e "s/ .*//" -e "s/<.*//" -e '/-help/d' -e '/-version/d' -e '/^$/d'|\
|
||||
sort > "src/test/resources/kotlinc-args.txt"
|
||||
|
||||
main=org.jetbrains.dokka.MainKt
|
||||
|
||||
java -cp "lib/compile/*" $main -h |\
|
||||
|
|
|
@ -98,15 +98,6 @@ public class CompileKotlinOperationBuild extends Project {
|
|||
new CompileKotlinOperationBuild().start(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test() throws Exception {
|
||||
new ExecOperation()
|
||||
.fromProject(this)
|
||||
.command("scripts/cliargs.sh")
|
||||
.execute();
|
||||
super.test();
|
||||
}
|
||||
|
||||
@BuildCommand(summary = "Runs PMD analysis")
|
||||
public void pmd() {
|
||||
new PmdOperation()
|
||||
|
@ -115,4 +106,13 @@ public class CompileKotlinOperationBuild extends Project {
|
|||
.ruleSets("config/pmd.xml")
|
||||
.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test() throws Exception {
|
||||
new ExecOperation()
|
||||
.fromProject(this)
|
||||
.command("scripts/cliargs.sh")
|
||||
.execute();
|
||||
super.test();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOperation compileMainClasspath(String... classpath) {
|
||||
compileMainClasspath_.addAll(Arrays.asList(classpath));
|
||||
Collections.addAll(compileMainClasspath_, classpath);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOperation compileTestClasspath(String... classpath) {
|
||||
compileTestClasspath_.addAll(Arrays.asList(classpath));
|
||||
Collections.addAll(compileTestClasspath_, classpath);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -398,7 +398,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOperation mainSourceDirectories(File... directories) {
|
||||
mainSourceDirectories_.addAll(List.of(directories));
|
||||
Collections.addAll(mainSourceDirectories_, directories);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -460,7 +460,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this class instance
|
||||
*/
|
||||
public CompileKotlinOperation plugins(String... plugins) {
|
||||
plugins_.addAll(List.of(plugins));
|
||||
Collections.addAll(plugins_, plugins);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -526,7 +526,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOperation testSourceDirectories(File... directories) {
|
||||
testSourceDirectories_.addAll(List.of(directories));
|
||||
Collections.addAll(testSourceDirectories_, directories);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package rife.bld.extension;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static rife.bld.extension.CompileKotlinOperation.isNotBlank;
|
||||
|
@ -30,13 +31,16 @@ import static rife.bld.extension.CompileKotlinOperation.isNotBlank;
|
|||
* @since 1.0
|
||||
*/
|
||||
public class CompileKotlinOptions {
|
||||
private final List<String> advancedOptions_ = new ArrayList<>();
|
||||
private final List<String> argFile_ = new ArrayList<>();
|
||||
private final List<String> classpath_ = new ArrayList<>();
|
||||
private final List<String> jvmOptions_ = new ArrayList<>();
|
||||
private final List<String> optIn_ = new ArrayList<>();
|
||||
private final List<String> options_ = new ArrayList<>();
|
||||
private final List<String> plugin_ = new ArrayList<>();
|
||||
private final List<String> scriptTemplates_ = new ArrayList<>();
|
||||
private String apiVersion_;
|
||||
private String expression_;
|
||||
private boolean includeRuntime_;
|
||||
private boolean javaParameters_;
|
||||
private String jdkHome_;
|
||||
|
@ -54,6 +58,28 @@ public class CompileKotlinOptions {
|
|||
private boolean verbose_;
|
||||
private boolean wError_;
|
||||
|
||||
/**
|
||||
* Specify advanced compiler options.
|
||||
*
|
||||
* @param options one or more advanced options
|
||||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOptions advancedOptions(String... options) {
|
||||
Collections.addAll(advancedOptions_, options);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify advanced compiler options.
|
||||
*
|
||||
* @param options list of compiler options
|
||||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOptions advancedOptions(Collection<String> options) {
|
||||
advancedOptions_.addAll(options);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow using declarations only from the specified version of Kotlin bundled libraries.
|
||||
*
|
||||
|
@ -95,7 +121,7 @@ public class CompileKotlinOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOptions argFile(String... files) {
|
||||
argFile_.addAll(List.of(files));
|
||||
Collections.addAll(argFile_, files);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -119,7 +145,7 @@ public class CompileKotlinOptions {
|
|||
public List<String> args() {
|
||||
var args = new ArrayList<String>();
|
||||
|
||||
// api-isNotBlankversion
|
||||
// api-version
|
||||
if (isNotBlank(apiVersion_)) {
|
||||
args.add("-api-version");
|
||||
args.add(apiVersion_);
|
||||
|
@ -136,6 +162,12 @@ public class CompileKotlinOptions {
|
|||
args.add(String.join(File.pathSeparator, classpath_));
|
||||
}
|
||||
|
||||
// expression
|
||||
if (isNotBlank(expression_)) {
|
||||
args.add("-expression");
|
||||
args.add(expression_);
|
||||
}
|
||||
|
||||
// java-parameters
|
||||
if (javaParameters_) {
|
||||
args.add("-java-parameters");
|
||||
|
@ -163,6 +195,11 @@ public class CompileKotlinOptions {
|
|||
args.add("-Xjdk-release=" + jdkRelease_);
|
||||
}
|
||||
|
||||
// JVM options
|
||||
if (!jvmOptions_.isEmpty()) {
|
||||
jvmOptions_.forEach(s -> args.add("-J" + s));
|
||||
}
|
||||
|
||||
// kotlin-home
|
||||
if (isNotBlank(kotlinHome_)) {
|
||||
args.add("-kotlin-home");
|
||||
|
@ -198,7 +235,7 @@ public class CompileKotlinOptions {
|
|||
|
||||
// no-warn
|
||||
if (noWarn_) {
|
||||
args.add("-no-warn");
|
||||
args.add("-nowarn");
|
||||
}
|
||||
|
||||
// opt-in
|
||||
|
@ -245,6 +282,11 @@ public class CompileKotlinOptions {
|
|||
args.add("-Werror");
|
||||
}
|
||||
|
||||
// advanced option (X)
|
||||
if (!advancedOptions_.isEmpty()) {
|
||||
advancedOptions_.forEach(it -> args.add("-X" + it));
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
@ -257,7 +299,7 @@ public class CompileKotlinOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOptions classpath(String... paths) {
|
||||
classpath_.addAll(List.of(paths));
|
||||
Collections.addAll(classpath_, paths);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -274,6 +316,17 @@ public class CompileKotlinOptions {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate the given string as a Kotlin script.
|
||||
*
|
||||
* @param expression the expression
|
||||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOptions expression(String expression) {
|
||||
expression_ = expression;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the {@link #jdkRelease(String) jdkRelease} was set.
|
||||
*
|
||||
|
@ -345,6 +398,28 @@ public class CompileKotlinOptions {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass an option directly to JVM
|
||||
*
|
||||
* @param jvmOptions one or more JVM option
|
||||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOptions jvmOptions(String... jvmOptions) {
|
||||
Collections.addAll(jvmOptions_, jvmOptions);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass an option directly to JVM
|
||||
*
|
||||
* @param jvmOptions the list JVM options
|
||||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOptions jvmOptions(Collection<String> jvmOptions) {
|
||||
jvmOptions_.addAll(jvmOptions);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the target version of the generated JVM bytecode.
|
||||
* <p>
|
||||
|
@ -455,7 +530,7 @@ public class CompileKotlinOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOptions optIn(String... annotations) {
|
||||
optIn_.addAll(List.of(annotations));
|
||||
Collections.addAll(optIn_, annotations);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -477,7 +552,7 @@ public class CompileKotlinOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOptions options(String... options) {
|
||||
options_.addAll(List.of(options));
|
||||
Collections.addAll(options_, options);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -551,7 +626,7 @@ public class CompileKotlinOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOptions scriptTemplates(String... classNames) {
|
||||
scriptTemplates_.addAll(List.of(classNames));
|
||||
Collections.addAll(scriptTemplates_, classNames);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -309,7 +309,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public DokkaOperation globalPackageOptions(String... options) {
|
||||
globalPackageOptions_.addAll(Arrays.asList(options));
|
||||
Collections.addAll(globalPackageOptions_, options);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -342,7 +342,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public DokkaOperation globalSrcLink(String... links) {
|
||||
globalSrcLinks_.addAll(Arrays.asList(links));
|
||||
Collections.addAll(globalSrcLinks_, links);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public DokkaOperation includes(String... files) {
|
||||
includes_.addAll(Arrays.asList(files));
|
||||
Collections.addAll(includes_, files);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -555,7 +555,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public DokkaOperation pluginsClasspath(String... jars) {
|
||||
pluginsClasspath_.addAll(Arrays.asList(jars));
|
||||
Collections.addAll(pluginsClasspath_, jars);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -241,7 +241,7 @@ public class SourceSet {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public SourceSet classpath(String... files) {
|
||||
classpath_.addAll(Arrays.asList(files));
|
||||
Collections.addAll(classpath_, files);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -371,7 +371,7 @@ public class SourceSet {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public SourceSet includes(String... files) {
|
||||
includes_.addAll(Arrays.asList(files));
|
||||
Collections.addAll(includes_, files);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -535,7 +535,7 @@ public class SourceSet {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public SourceSet perPackageOptions(String... perPackageOptions) {
|
||||
perPackageOptions_.addAll(List.of(perPackageOptions));
|
||||
Collections.addAll(perPackageOptions_, perPackageOptions);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -581,7 +581,7 @@ public class SourceSet {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public SourceSet samples(String... samples) {
|
||||
samples_.addAll(List.of(samples));
|
||||
Collections.addAll(samples_, samples);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -635,7 +635,7 @@ public class SourceSet {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public SourceSet src(String... src) {
|
||||
src_.addAll(List.of(src));
|
||||
Collections.addAll(src_, src);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,9 @@ package rife.bld.extension;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
@ -30,8 +33,10 @@ class CompileKotlinOptionsTest {
|
|||
@Test
|
||||
void argsCollectionTest() {
|
||||
var args = new CompileKotlinOptions()
|
||||
.advancedOptions(List.of("Xoption1", "Xoption2"))
|
||||
.argFile(List.of("arg1.txt", "arg2.txt"))
|
||||
.classpath(List.of("path1", "path2"))
|
||||
.jvmOptions(List.of("option1", "option2"))
|
||||
.noStdLib(false)
|
||||
.optIn(List.of("opt1", "opt2"))
|
||||
.options(List.of("-foo", "-bar"))
|
||||
|
@ -40,19 +45,27 @@ class CompileKotlinOptionsTest {
|
|||
var matches = List.of(
|
||||
"@arg1.txt", "@arg2.txt",
|
||||
"-classpath", "path1:path2",
|
||||
"-Joption1", "-Joption2",
|
||||
"-opt-in", "opt1",
|
||||
"-opt-in", "opt2",
|
||||
"-foo",
|
||||
"-bar",
|
||||
"-script-templates", "temp1,temp2");
|
||||
|
||||
assertThat(args).hasSize(matches.size());
|
||||
|
||||
IntStream.range(0, args.size()).forEach(i -> assertThat(args.get(i)).isEqualTo(matches.get(i)));
|
||||
|
||||
"-foo", "-bar",
|
||||
"-script-templates",
|
||||
"temp1,temp2",
|
||||
"-XXoption1", "-XXoption2");
|
||||
|
||||
for (var arg : args) {
|
||||
var found = false;
|
||||
for (var match : matches) {
|
||||
if (match.equals(arg)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertThat(found).as(arg).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void argsTest() {
|
||||
var options = new CompileKotlinOptions()
|
||||
|
@ -93,7 +106,7 @@ class CompileKotlinOptionsTest {
|
|||
"-module-name", "module",
|
||||
"-no-jdk",
|
||||
"-no-reflect",
|
||||
"-no-warn",
|
||||
"-nowarn",
|
||||
"-opt-in", "opt1",
|
||||
"-opt-in", "opt2",
|
||||
"-foo",
|
||||
|
@ -114,4 +127,47 @@ class CompileKotlinOptionsTest {
|
|||
IntStream.range(0, a.size()).forEach(i -> assertThat(a.get(i)).isEqualTo(matches.get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkAllParamsTest() throws IOException {
|
||||
var args = Files.readAllLines(Paths.get("src", "test", "resources", "kotlinc-args.txt"));
|
||||
|
||||
assertThat(args).isNotEmpty();
|
||||
|
||||
var params = new CompileKotlinOptions()
|
||||
.advancedOptions("Xoption")
|
||||
.argFile("file")
|
||||
.classpath("classpath")
|
||||
.expression("expression")
|
||||
.jvmOptions("option")
|
||||
.includeRuntime(true)
|
||||
.javaParameters(true)
|
||||
.jdkHome("jdkhome")
|
||||
.jvmTarget(12)
|
||||
.kotlinHome("kotlin")
|
||||
.moduleName("moduleName")
|
||||
.noJdk(true)
|
||||
.noReflect(true)
|
||||
.noStdLib(true)
|
||||
.noWarn(true)
|
||||
.optIn("annotation")
|
||||
.options("option")
|
||||
.path("path")
|
||||
.plugin("id", "option", "value")
|
||||
.progressive(true)
|
||||
.scriptTemplates("template")
|
||||
.verbose(true)
|
||||
.wError(true);
|
||||
|
||||
for (var p : args) {
|
||||
var found = false;
|
||||
for (var a : params.args()) {
|
||||
if (a.startsWith(p)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertThat(found).as(p + " not found.").isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,13 +34,13 @@ class DokkaOperationTest {
|
|||
@Test
|
||||
@SuppressWarnings({"ExtractMethodRecommender", "PMD.AvoidDuplicateLiterals"})
|
||||
void executeConstructProcessCommandListTest() throws IOException {
|
||||
var params = Files.readAllLines(Paths.get("src", "test", "resources", "dokka-args.txt"));
|
||||
var args = Files.readAllLines(Paths.get("src", "test", "resources", "dokka-args.txt"));
|
||||
|
||||
assertThat(params).isNotEmpty();
|
||||
assertThat(args).isNotEmpty();
|
||||
|
||||
var examples = new File("examples");
|
||||
var jsonConf = new File("config.json");
|
||||
var args = new DokkaOperation()
|
||||
var params = new DokkaOperation()
|
||||
.delayTemplateSubstitution(true)
|
||||
.failOnWarning(true)
|
||||
.fromProject(new BaseProjectBlueprint(examples, "com.example", "Example"))
|
||||
|
@ -72,9 +72,9 @@ class DokkaOperationTest {
|
|||
.suppressInheritedMembers(true)
|
||||
.executeConstructProcessCommandList();
|
||||
|
||||
for (var p : params) {
|
||||
for (var p : args) {
|
||||
var found = false;
|
||||
for (var a : args) {
|
||||
for (var a : params) {
|
||||
if (a.startsWith(p)) {
|
||||
found = true;
|
||||
break;
|
||||
|
@ -109,14 +109,14 @@ class DokkaOperationTest {
|
|||
"-suppressInheritedMembers",
|
||||
jsonConf.getAbsolutePath());
|
||||
|
||||
assertThat(args).hasSize(matches.size());
|
||||
assertThat(params).hasSize(matches.size());
|
||||
|
||||
IntStream.range(0, args.size()).forEach(i -> {
|
||||
if (args.get(i).contains(".jar;")) {
|
||||
var jars = args.get(i).split(";");
|
||||
IntStream.range(0, params.size()).forEach(i -> {
|
||||
if (params.get(i).contains(".jar;")) {
|
||||
var jars = params.get(i).split(";");
|
||||
Arrays.stream(jars).forEach(jar -> assertThat(matches.get(i)).as(matches.get(i)).contains(jar));
|
||||
} else {
|
||||
assertThat(args.get(i)).as(args.get(i)).isEqualTo(matches.get(i));
|
||||
assertThat(params.get(i)).as(params.get(i)).isEqualTo(matches.get(i));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
23
src/test/resources/kotlinc-args.txt
Normal file
23
src/test/resources/kotlinc-args.txt
Normal file
|
@ -0,0 +1,23 @@
|
|||
@
|
||||
-classpath
|
||||
-d
|
||||
-expression
|
||||
-include-runtime
|
||||
-J
|
||||
-java-parameters
|
||||
-jdk-home
|
||||
-jvm-target
|
||||
-kotlin-home
|
||||
-module-name
|
||||
-no-jdk
|
||||
-no-reflect
|
||||
-no-stdlib
|
||||
-nowarn
|
||||
-opt-in
|
||||
-P
|
||||
-progressive
|
||||
-script
|
||||
-script-templates
|
||||
-verbose
|
||||
-Werror
|
||||
-X
|
Loading…
Add table
Add a link
Reference in a new issue