Skip to content

Commit 442f557

Browse files
committed
better handling for missing source set
1 parent c4fc431 commit 442f557

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
public class Example {
2-
public String[] hello;
2+
public String[] hello2;
33
}

java2ts-plugin/src/main/java/dev/harrel/java2ts/JavaToTsPlugin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.gradle.api.tasks.SourceSet;
99
import org.gradle.api.tasks.SourceSetContainer;
1010

11+
import java.util.Optional;
1112
import java.util.Set;
1213

1314
public class JavaToTsPlugin implements Plugin<Project> {
@@ -42,9 +43,9 @@ public void apply(Project project) {
4243

4344
private Provider<SourceSet> getDefaultSourceSet(Project project) {
4445
return project.getProviders().provider(() ->
45-
project.getExtensions()
46-
.getByType(SourceSetContainer.class)
47-
.findByName("main"));
46+
Optional.ofNullable(project.getExtensions().findByType(SourceSetContainer.class))
47+
.map(s -> s.findByName("main"))
48+
.orElseThrow(() -> new IllegalArgumentException("Source set was not provided and there was no source set named 'main'")));
4849
}
4950

5051
private Provider<RegularFile> getDefaultOutput(Project project) {

0 commit comments

Comments
 (0)