Skip to content

Commit 6a508f1

Browse files
committed
Don't compile when source or test directories are empty.
1 parent 09c324c commit 6a508f1

File tree

4 files changed

+57
-32
lines changed

4 files changed

+57
-32
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
bld.downloadExtensionJavadoc=false
22
bld.downloadExtensionSources=true
33
bld.downloadLocation=
4-
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.1
4+
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.2
55
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
66
bld.sourceDirectories=
77
bld.version=2.1.0

src/bld/java/rife/bld/extension/CompileKotlinOperationBuild.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class CompileKotlinOperationBuild extends Project {
3333
public CompileKotlinOperationBuild() {
3434
pkg = "rife.bld.extension";
3535
name = "bld-kotlin";
36-
version = version(1, 0, 1);
36+
version = version(1, 0, 2);
3737

3838
javaRelease = 17;
3939

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

5858
publishOperation()
5959
.repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2"))
60+
.repository(repository("github"))
6061
.info()
6162
.groupId("com.uwyn.rife2")
6263
.artifactId("bld-kotlin")
6364
.description("bld Kotlin Extension")
6465
.url("https://github.com/rife2/bld-kotlin")
65-
.developer(
66-
new PublishDeveloper()
67-
.id("ethauvin")
68-
.name("Erik C. Thauvin")
69-
.email("erik@thauvin.net")
70-
.url("https://erik.thauvin.net/")
66+
.developer(new PublishDeveloper()
67+
.id("ethauvin")
68+
.name("Erik C. Thauvin")
69+
.email("erik@thauvin.net")
70+
.url("https://erik.thauvin.net/")
7171
)
72-
.license(
73-
new PublishLicense()
74-
.name("The Apache License, Version 2.0")
75-
.url("https://www.apache.org/licenses/LICENSE-2.0.txt")
72+
.license(new PublishLicense()
73+
.name("The Apache License, Version 2.0")
74+
.url("https://www.apache.org/licenses/LICENSE-2.0.txt")
7675
)
77-
.scm(
78-
new PublishScm()
79-
.connection("scm:git:https://github.com/rife2/bld-kotlin.git")
80-
.developerConnection("scm:git:git@github.com:rife2/bld-kotlin.git")
81-
.url("https://github.com/rife2/bld-kotlin")
76+
.scm(new PublishScm()
77+
.connection("scm:git:https://github.com/rife2/bld-kotlin.git")
78+
.developerConnection("scm:git:git@github.com:rife2/bld-kotlin.git")
79+
.url("https://github.com/rife2/bld-kotlin")
8280
)
8381
.signKey(property("sign.key"))
8482
.signPassphrase(property("sign.passphrase"));

src/main/java/rife/bld/extension/CompileKotlinOperation.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,16 @@ protected void executeBuildMainSources() throws ExitStatusException {
284284
protected void executeBuildSources(Collection<String> classpath, Collection<File> sources, File destination,
285285
File friendPaths)
286286
throws ExitStatusException {
287-
if (sources.isEmpty() || destination == null) {
287+
if (sources.isEmpty()) {
288+
if (!silent() && LOGGER.isLoggable(Level.WARNING)) {
289+
LOGGER.warning("Nothing to compile.");
290+
}
288291
return;
292+
} else if (destination == null) {
293+
if (!silent() && LOGGER.isLoggable(Level.SEVERE)) {
294+
LOGGER.severe("No destination specified.");
295+
}
296+
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
289297
}
290298

291299
var args = new ArrayList<String>();
@@ -294,8 +302,10 @@ protected void executeBuildSources(Collection<String> classpath, Collection<File
294302
args.add(kotlinCompiler());
295303

296304
// classpath
297-
args.add("-cp");
298-
args.add(FileUtils.joinPaths(classpath.stream().toList()));
305+
if (classpath != null && !classpath.isEmpty()) {
306+
args.add("-cp");
307+
args.add(FileUtils.joinPaths(classpath.stream().toList()));
308+
}
299309

300310
// destination
301311
args.add("-d");
@@ -376,16 +386,16 @@ protected void executeCreateBuildDirectories() throws IOException {
376386
* <p>
377387
* Sets the following from the project:
378388
* <ul>
379-
* <li>{@link #kotlinHome()} to the {@code KOTLIN_HOME} environment variable, if set.</li>
380-
* <li>{@link #workDir()} to the project's directory.</li>
389+
* <li>{@link #kotlinHome() kotlinHome} to the {@code KOTLIN_HOME} environment variable, if set.</li>
390+
* <li>{@link #workDir() workDir} to the project's directory.</li>
381391
* <li>{@link #buildMainDirectory() buildMainDirectory}</li>
382392
* <li>{@link #buildTestDirectory() buildTestDirectory}</li>
383393
* <li>{@link #compileMainClasspath() compileMainClassPath}</li>
384394
* <li>{@link #compileTestClasspath() compilesTestClassPath}</li>
385-
* <li>{@link #mainSourceDirectories()} () mainSourceDirectories} to the {@code kotlin} directory in
386-
* {@link BaseProject#srcMainDirectory() srcMainDirectory}</li>
395+
* <li>{@link #mainSourceDirectories() mainSourceDirectories} to the {@code kotlin} directory in
396+
* {@link BaseProject#srcMainDirectory() srcMainDirectory}, if present.</li>
387397
* <li>{@link #testSourceDirectories() testSourceDirectories} to the {@code kotlin} directory in
388-
* {@link BaseProject#srcTestDirectory() srcTestDirectory}</li>
398+
* {@link BaseProject#srcTestDirectory() srcTestDirectory}, if present.</li>
389399
* <li>{@link CompileOptions#jdkRelease jdkRelease} to {@link BaseProject#javaRelease() javaRelease}</li>
390400
* <li>{@link CompileOptions#noStdLib(boolean) noStdLib} to {@code true}</li>
391401
* </ul>
@@ -406,9 +416,17 @@ public CompileKotlinOperation fromProject(BaseProject project) {
406416
var op = buildMainDirectory(project.buildMainDirectory())
407417
.buildTestDirectory(project.buildTestDirectory())
408418
.compileMainClasspath(project.compileMainClasspath())
409-
.compileTestClasspath(project.compileTestClasspath())
410-
.mainSourceDirectories(new File(project.srcMainDirectory(), "kotlin"))
411-
.testSourceDirectories(new File(project.srcTestDirectory(), "kotlin"));
419+
.compileTestClasspath(project.compileTestClasspath());
420+
421+
var mainDir = new File(project.srcMainDirectory(), "kotlin");
422+
if (mainDir.exists()) {
423+
op = op.mainSourceDirectories(mainDir);
424+
}
425+
var testDir = new File(project.srcTestDirectory(), "kotlin");
426+
if (testDir.exists()) {
427+
op = op.testSourceDirectories(testDir);
428+
}
429+
412430
if (project.javaRelease() != null && !compileOptions_.hasRelease()) {
413431
compileOptions_.jdkRelease(project.javaRelease());
414432
}

src/test/java/rife/bld/extension/CompileKotlinOperationTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.junit.jupiter.api.BeforeAll;
2121
import org.junit.jupiter.api.Test;
2222
import rife.bld.BaseProject;
23-
import rife.bld.Project;
2423
import rife.bld.blueprints.BaseProjectBlueprint;
2524
import rife.bld.extension.kotlin.CompileOptions;
2625
import rife.bld.extension.kotlin.CompilerPlugin;
@@ -87,7 +86,7 @@ void testBuildTestDirectory() {
8786
@Test
8887
void testCollections() {
8988
var op = new CompileKotlinOperation()
90-
.fromProject(new Project())
89+
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", "Example"))
9190
.kotlinHome("/kotlin_home")
9291
.kotlinc("kotlinc")
9392
.workDir("work_dir")
@@ -206,6 +205,14 @@ void testExecute() throws Exception {
206205
}
207206
}
208207

208+
@Test
209+
void testFromProjectNoKotlin() {
210+
var op = new CompileKotlinOperation().fromProject(
211+
new BaseProjectBlueprint(new File("foo"), "org.example", "foo"));
212+
assertThat(op.mainSourceDirectories()).isEmpty();
213+
assertThat(op.testSourceDirectories()).isEmpty();
214+
}
215+
209216
@Test
210217
void testKotlinHome() {
211218
var foo = new File("foo");
@@ -259,11 +266,13 @@ void testMainSourceDirectories() {
259266
op.mainSourceDirectories().clear();
260267

261268
op.mainSourceDirectoriesPaths(List.of(new File(FILE_1).toPath(), new File(FILE_2).toPath()));
262-
assertThat(op.mainSourceDirectories()).as("List(Path...)").containsExactly(new File(FILE_1), new File(FILE_2));
269+
assertThat(op.mainSourceDirectories()).as("List(Path...)")
270+
.containsExactly(new File(FILE_1), new File(FILE_2));
263271
op.mainSourceDirectories().clear();
264272

265273
op.mainSourceDirectoriesStrings(List.of(FILE_1, FILE_2));
266-
assertThat(op.mainSourceDirectories()).as("List(String...)").containsExactly(new File(FILE_1), new File(FILE_2));
274+
assertThat(op.mainSourceDirectories()).as("List(String...)")
275+
.containsExactly(new File(FILE_1), new File(FILE_2));
267276
op.mainSourceDirectories().clear();
268277
}
269278

0 commit comments

Comments
 (0)