From 442f557e23aa59db9744f39fecda426e95a50771 Mon Sep 17 00:00:00 2001 From: Harrel Date: Fri, 29 Sep 2023 21:03:07 +0200 Subject: [PATCH] better handling for missing source set --- examples/simple/src/main/java/Example.java | 2 +- .../src/main/java/dev/harrel/java2ts/JavaToTsPlugin.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/simple/src/main/java/Example.java b/examples/simple/src/main/java/Example.java index 75cff36..db221c3 100644 --- a/examples/simple/src/main/java/Example.java +++ b/examples/simple/src/main/java/Example.java @@ -1,3 +1,3 @@ public class Example { - public String[] hello; + public String[] hello2; } diff --git a/java2ts-plugin/src/main/java/dev/harrel/java2ts/JavaToTsPlugin.java b/java2ts-plugin/src/main/java/dev/harrel/java2ts/JavaToTsPlugin.java index b826fef..22185b4 100644 --- a/java2ts-plugin/src/main/java/dev/harrel/java2ts/JavaToTsPlugin.java +++ b/java2ts-plugin/src/main/java/dev/harrel/java2ts/JavaToTsPlugin.java @@ -8,6 +8,7 @@ import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSetContainer; +import java.util.Optional; import java.util.Set; public class JavaToTsPlugin implements Plugin { @@ -42,9 +43,9 @@ public void apply(Project project) { private Provider getDefaultSourceSet(Project project) { return project.getProviders().provider(() -> - project.getExtensions() - .getByType(SourceSetContainer.class) - .findByName("main")); + Optional.ofNullable(project.getExtensions().findByType(SourceSetContainer.class)) + .map(s -> s.findByName("main")) + .orElseThrow(() -> new IllegalArgumentException("Source set was not provided and there was no source set named 'main'"))); } private Provider getDefaultOutput(Project project) {