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

@ -1,7 +1,7 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true bld.downloadExtensionSources=true
bld.downloadLocation= bld.downloadLocation=
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.1 bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.2
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories= bld.sourceDirectories=
bld.version=2.1.0 bld.version=2.1.0

View file

@ -33,7 +33,7 @@ public class CompileKotlinOperationBuild extends Project {
public CompileKotlinOperationBuild() { public CompileKotlinOperationBuild() {
pkg = "rife.bld.extension"; pkg = "rife.bld.extension";
name = "bld-kotlin"; name = "bld-kotlin";
version = version(1, 0, 1); version = version(1, 0, 2);
javaRelease = 17; javaRelease = 17;
@ -57,28 +57,26 @@ public class CompileKotlinOperationBuild extends Project {
publishOperation() publishOperation()
.repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2")) .repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2"))
.repository(repository("github"))
.info() .info()
.groupId("com.uwyn.rife2") .groupId("com.uwyn.rife2")
.artifactId("bld-kotlin") .artifactId("bld-kotlin")
.description("bld Kotlin Extension") .description("bld Kotlin Extension")
.url("https://github.com/rife2/bld-kotlin") .url("https://github.com/rife2/bld-kotlin")
.developer( .developer(new PublishDeveloper()
new PublishDeveloper() .id("ethauvin")
.id("ethauvin") .name("Erik C. Thauvin")
.name("Erik C. Thauvin") .email("erik@thauvin.net")
.email("erik@thauvin.net") .url("https://erik.thauvin.net/")
.url("https://erik.thauvin.net/")
) )
.license( .license(new PublishLicense()
new PublishLicense() .name("The Apache License, Version 2.0")
.name("The Apache License, Version 2.0") .url("https://www.apache.org/licenses/LICENSE-2.0.txt")
.url("https://www.apache.org/licenses/LICENSE-2.0.txt")
) )
.scm( .scm(new PublishScm()
new PublishScm() .connection("scm:git:https://github.com/rife2/bld-kotlin.git")
.connection("scm:git:https://github.com/rife2/bld-kotlin.git") .developerConnection("scm:git:git@github.com:rife2/bld-kotlin.git")
.developerConnection("scm:git:git@github.com:rife2/bld-kotlin.git") .url("https://github.com/rife2/bld-kotlin")
.url("https://github.com/rife2/bld-kotlin")
) )
.signKey(property("sign.key")) .signKey(property("sign.key"))
.signPassphrase(property("sign.passphrase")); .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, protected void executeBuildSources(Collection<String> classpath, Collection<File> sources, File destination,
File friendPaths) File friendPaths)
throws ExitStatusException { throws ExitStatusException {
if (sources.isEmpty() || destination == null) { if (sources.isEmpty()) {
if (!silent() && LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning("Nothing to compile.");
}
return; 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>(); var args = new ArrayList<String>();
@ -294,8 +302,10 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
args.add(kotlinCompiler()); args.add(kotlinCompiler());
// classpath // classpath
args.add("-cp"); if (classpath != null && !classpath.isEmpty()) {
args.add(FileUtils.joinPaths(classpath.stream().toList())); args.add("-cp");
args.add(FileUtils.joinPaths(classpath.stream().toList()));
}
// destination // destination
args.add("-d"); args.add("-d");
@ -376,16 +386,16 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
* <p> * <p>
* Sets the following from the project: * Sets the following from the project:
* <ul> * <ul>
* <li>{@link #kotlinHome()} to the {@code KOTLIN_HOME} environment variable, if set.</li> * <li>{@link #kotlinHome() kotlinHome} to the {@code KOTLIN_HOME} environment variable, if set.</li>
* <li>{@link #workDir()} to the project's directory.</li> * <li>{@link #workDir() workDir} to the project's directory.</li>
* <li>{@link #buildMainDirectory() buildMainDirectory}</li> * <li>{@link #buildMainDirectory() buildMainDirectory}</li>
* <li>{@link #buildTestDirectory() buildTestDirectory}</li> * <li>{@link #buildTestDirectory() buildTestDirectory}</li>
* <li>{@link #compileMainClasspath() compileMainClassPath}</li> * <li>{@link #compileMainClasspath() compileMainClassPath}</li>
* <li>{@link #compileTestClasspath() compilesTestClassPath}</li> * <li>{@link #compileTestClasspath() compilesTestClassPath}</li>
* <li>{@link #mainSourceDirectories()} () mainSourceDirectories} to the {@code kotlin} directory in * <li>{@link #mainSourceDirectories() mainSourceDirectories} to the {@code kotlin} directory in
* {@link BaseProject#srcMainDirectory() srcMainDirectory}</li> * {@link BaseProject#srcMainDirectory() srcMainDirectory}, if present.</li>
* <li>{@link #testSourceDirectories() testSourceDirectories} to the {@code kotlin} directory in * <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#jdkRelease jdkRelease} to {@link BaseProject#javaRelease() javaRelease}</li>
* <li>{@link CompileOptions#noStdLib(boolean) noStdLib} to {@code true}</li> * <li>{@link CompileOptions#noStdLib(boolean) noStdLib} to {@code true}</li>
* </ul> * </ul>
@ -406,9 +416,17 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
var op = buildMainDirectory(project.buildMainDirectory()) var op = buildMainDirectory(project.buildMainDirectory())
.buildTestDirectory(project.buildTestDirectory()) .buildTestDirectory(project.buildTestDirectory())
.compileMainClasspath(project.compileMainClasspath()) .compileMainClasspath(project.compileMainClasspath())
.compileTestClasspath(project.compileTestClasspath()) .compileTestClasspath(project.compileTestClasspath());
.mainSourceDirectories(new File(project.srcMainDirectory(), "kotlin"))
.testSourceDirectories(new File(project.srcTestDirectory(), "kotlin")); 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()) { if (project.javaRelease() != null && !compileOptions_.hasRelease()) {
compileOptions_.jdkRelease(project.javaRelease()); 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.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import rife.bld.BaseProject; import rife.bld.BaseProject;
import rife.bld.Project;
import rife.bld.blueprints.BaseProjectBlueprint; import rife.bld.blueprints.BaseProjectBlueprint;
import rife.bld.extension.kotlin.CompileOptions; import rife.bld.extension.kotlin.CompileOptions;
import rife.bld.extension.kotlin.CompilerPlugin; import rife.bld.extension.kotlin.CompilerPlugin;
@ -87,7 +86,7 @@ class CompileKotlinOperationTest {
@Test @Test
void testCollections() { void testCollections() {
var op = new CompileKotlinOperation() var op = new CompileKotlinOperation()
.fromProject(new Project()) .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", "Example"))
.kotlinHome("/kotlin_home") .kotlinHome("/kotlin_home")
.kotlinc("kotlinc") .kotlinc("kotlinc")
.workDir("work_dir") .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 @Test
void testKotlinHome() { void testKotlinHome() {
var foo = new File("foo"); var foo = new File("foo");
@ -259,11 +266,13 @@ class CompileKotlinOperationTest {
op.mainSourceDirectories().clear(); op.mainSourceDirectories().clear();
op.mainSourceDirectoriesPaths(List.of(new File(FILE_1).toPath(), new File(FILE_2).toPath())); 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.mainSourceDirectories().clear();
op.mainSourceDirectoriesStrings(List.of(FILE_1, FILE_2)); 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(); op.mainSourceDirectories().clear();
} }