Skip to content

Commit

Permalink
Don't compile when source or test directories are empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Sep 10, 2024
1 parent 09c324c commit 6a508f1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 32 deletions.
2 changes: 1 addition & 1 deletion examples/lib/bld/bld-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
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.sourceDirectories=
bld.version=2.1.0
30 changes: 14 additions & 16 deletions src/bld/java/rife/bld/extension/CompileKotlinOperationBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -57,28 +57,26 @@ public CompileKotlinOperationBuild() {

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"));
Expand Down
40 changes: 29 additions & 11 deletions src/main/java/rife/bld/extension/CompileKotlinOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,16 @@ protected void executeBuildMainSources() throws ExitStatusException {
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>();
Expand All @@ -294,8 +302,10 @@ protected void executeBuildSources(Collection<String> classpath, Collection<File
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");
Expand Down Expand Up @@ -376,16 +386,16 @@ protected void executeCreateBuildDirectories() throws IOException {
* <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>
Expand All @@ -406,9 +416,17 @@ public CompileKotlinOperation fromProject(BaseProject project) {
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());
}
Expand Down
17 changes: 13 additions & 4 deletions src/test/java/rife/bld/extension/CompileKotlinOperationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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;
Expand Down Expand Up @@ -87,7 +86,7 @@ void testBuildTestDirectory() {
@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")
Expand Down Expand Up @@ -206,6 +205,14 @@ void testExecute() throws Exception {
}
}

@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");
Expand Down Expand Up @@ -259,11 +266,13 @@ void testMainSourceDirectories() {
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();
}

Expand Down

0 comments on commit 6a508f1

Please sign in to comment.