Don't compile when source or test directories are empty.

This commit is contained in:
Erik C. Thauvin 2024-09-09 20:57:39 -07:00
parent 09c324c8de
commit 6a508f1f68
Signed by: erik
GPG key ID: 776702A6A2DA330E
4 changed files with 57 additions and 32 deletions

View file

@ -33,7 +33,7 @@ public class CompileKotlinOperationBuild extends Project {
public CompileKotlinOperationBuild() {
pkg = "rife.bld.extension";
name = "bld-kotlin";
version = version(1, 0, 1);
version = version(1, 0, 2);
javaRelease = 17;
@ -57,28 +57,26 @@ public class CompileKotlinOperationBuild extends Project {
publishOperation()
.repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2"))
.repository(repository("github"))
.info()
.groupId("com.uwyn.rife2")
.artifactId("bld-kotlin")
.description("bld Kotlin Extension")
.url("https://github.com/rife2/bld-kotlin")
.developer(
new PublishDeveloper()
.id("ethauvin")
.name("Erik C. Thauvin")
.email("erik@thauvin.net")
.url("https://erik.thauvin.net/")
.developer(new PublishDeveloper()
.id("ethauvin")
.name("Erik C. Thauvin")
.email("erik@thauvin.net")
.url("https://erik.thauvin.net/")
)
.license(
new PublishLicense()
.name("The Apache License, Version 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0.txt")
.license(new PublishLicense()
.name("The Apache License, Version 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0.txt")
)
.scm(
new PublishScm()
.connection("scm:git:https://github.com/rife2/bld-kotlin.git")
.developerConnection("scm:git:git@github.com:rife2/bld-kotlin.git")
.url("https://github.com/rife2/bld-kotlin")
.scm(new PublishScm()
.connection("scm:git:https://github.com/rife2/bld-kotlin.git")
.developerConnection("scm:git:git@github.com:rife2/bld-kotlin.git")
.url("https://github.com/rife2/bld-kotlin")
)
.signKey(property("sign.key"))
.signPassphrase(property("sign.passphrase"));

View file

@ -284,8 +284,16 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
protected void executeBuildSources(Collection<String> classpath, Collection<File> sources, File destination,
File friendPaths)
throws ExitStatusException {
if (sources.isEmpty() || destination == null) {
if (sources.isEmpty()) {
if (!silent() && LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning("Nothing to compile.");
}
return;
} else if (destination == null) {
if (!silent() && LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.severe("No destination specified.");
}
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
}
var args = new ArrayList<String>();
@ -294,8 +302,10 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
args.add(kotlinCompiler());
// classpath
args.add("-cp");
args.add(FileUtils.joinPaths(classpath.stream().toList()));
if (classpath != null && !classpath.isEmpty()) {
args.add("-cp");
args.add(FileUtils.joinPaths(classpath.stream().toList()));
}
// destination
args.add("-d");
@ -376,16 +386,16 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
* <p>
* Sets the following from the project:
* <ul>
* <li>{@link #kotlinHome()} to the {@code KOTLIN_HOME} environment variable, if set.</li>
* <li>{@link #workDir()} to the project's directory.</li>
* <li>{@link #kotlinHome() kotlinHome} to the {@code KOTLIN_HOME} environment variable, if set.</li>
* <li>{@link #workDir() workDir} to the project's directory.</li>
* <li>{@link #buildMainDirectory() buildMainDirectory}</li>
* <li>{@link #buildTestDirectory() buildTestDirectory}</li>
* <li>{@link #compileMainClasspath() compileMainClassPath}</li>
* <li>{@link #compileTestClasspath() compilesTestClassPath}</li>
* <li>{@link #mainSourceDirectories()} () mainSourceDirectories} to the {@code kotlin} directory in
* {@link BaseProject#srcMainDirectory() srcMainDirectory}</li>
* <li>{@link #mainSourceDirectories() mainSourceDirectories} to the {@code kotlin} directory in
* {@link BaseProject#srcMainDirectory() srcMainDirectory}, if present.</li>
* <li>{@link #testSourceDirectories() testSourceDirectories} to the {@code kotlin} directory in
* {@link BaseProject#srcTestDirectory() srcTestDirectory}</li>
* {@link BaseProject#srcTestDirectory() srcTestDirectory}, if present.</li>
* <li>{@link CompileOptions#jdkRelease jdkRelease} to {@link BaseProject#javaRelease() javaRelease}</li>
* <li>{@link CompileOptions#noStdLib(boolean) noStdLib} to {@code true}</li>
* </ul>
@ -406,9 +416,17 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
var op = buildMainDirectory(project.buildMainDirectory())
.buildTestDirectory(project.buildTestDirectory())
.compileMainClasspath(project.compileMainClasspath())
.compileTestClasspath(project.compileTestClasspath())
.mainSourceDirectories(new File(project.srcMainDirectory(), "kotlin"))
.testSourceDirectories(new File(project.srcTestDirectory(), "kotlin"));
.compileTestClasspath(project.compileTestClasspath());
var mainDir = new File(project.srcMainDirectory(), "kotlin");
if (mainDir.exists()) {
op = op.mainSourceDirectories(mainDir);
}
var testDir = new File(project.srcTestDirectory(), "kotlin");
if (testDir.exists()) {
op = op.testSourceDirectories(testDir);
}
if (project.javaRelease() != null && !compileOptions_.hasRelease()) {
compileOptions_.jdkRelease(project.javaRelease());
}

View file

@ -20,7 +20,6 @@ import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import rife.bld.BaseProject;
import rife.bld.Project;
import rife.bld.blueprints.BaseProjectBlueprint;
import rife.bld.extension.kotlin.CompileOptions;
import rife.bld.extension.kotlin.CompilerPlugin;
@ -87,7 +86,7 @@ class CompileKotlinOperationTest {
@Test
void testCollections() {
var op = new CompileKotlinOperation()
.fromProject(new Project())
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", "Example"))
.kotlinHome("/kotlin_home")
.kotlinc("kotlinc")
.workDir("work_dir")
@ -206,6 +205,14 @@ class CompileKotlinOperationTest {
}
}
@Test
void testFromProjectNoKotlin() {
var op = new CompileKotlinOperation().fromProject(
new BaseProjectBlueprint(new File("foo"), "org.example", "foo"));
assertThat(op.mainSourceDirectories()).isEmpty();
assertThat(op.testSourceDirectories()).isEmpty();
}
@Test
void testKotlinHome() {
var foo = new File("foo");
@ -259,11 +266,13 @@ class CompileKotlinOperationTest {
op.mainSourceDirectories().clear();
op.mainSourceDirectoriesPaths(List.of(new File(FILE_1).toPath(), new File(FILE_2).toPath()));
assertThat(op.mainSourceDirectories()).as("List(Path...)").containsExactly(new File(FILE_1), new File(FILE_2));
assertThat(op.mainSourceDirectories()).as("List(Path...)")
.containsExactly(new File(FILE_1), new File(FILE_2));
op.mainSourceDirectories().clear();
op.mainSourceDirectoriesStrings(List.of(FILE_1, FILE_2));
assertThat(op.mainSourceDirectories()).as("List(String...)").containsExactly(new File(FILE_1), new File(FILE_2));
assertThat(op.mainSourceDirectories()).as("List(String...)")
.containsExactly(new File(FILE_1), new File(FILE_2));
op.mainSourceDirectories().clear();
}