From 6a4e4d57010d331073ca1239ba6393f4b12baa61 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 19 Oct 2022 14:30:39 +0200 Subject: [PATCH] Don't throw an error if main source set is missing Test courtesy of Adler Fleurant. Fixes #27950 (cherry picked from commit ec2fdbcc003f3b7153c71deeccf9008a326e93f8) --- .../gradle-application-plugin/build.gradle | 4 + .../gradle/gradle-application-plugin/pom.xml | 14 +++- .../io/quarkus/gradle/QuarkusPluginTest.java | 74 ++++++++++++++++++- .../tooling/dependency/DependencyUtils.java | 5 +- 4 files changed, 94 insertions(+), 3 deletions(-) diff --git a/devtools/gradle/gradle-application-plugin/build.gradle b/devtools/gradle/gradle-application-plugin/build.gradle index 2f24773c33488..57cd56b24de05 100644 --- a/devtools/gradle/gradle-application-plugin/build.gradle +++ b/devtools/gradle/gradle-application-plugin/build.gradle @@ -33,3 +33,7 @@ pluginBundle { vcsUrl = 'https://github.com/quarkusio/quarkus' tags = ['quarkus', 'quarkusio', 'graalvm'] } + +test { + systemProperty 'kotlin_version', project.kotlin_version +} diff --git a/devtools/gradle/gradle-application-plugin/pom.xml b/devtools/gradle/gradle-application-plugin/pom.xml index cefcb1fc66b3c..fb682887162d3 100644 --- a/devtools/gradle/gradle-application-plugin/pom.xml +++ b/devtools/gradle/gradle-application-plugin/pom.xml @@ -54,6 +54,18 @@ quarkus-devmode-test-utils test + + org.jetbrains.kotlin + kotlin-gradle-plugin + ${kotlin.version} + test + + + org.checkerframework + checker-qual + + + @@ -70,4 +82,4 @@ - \ No newline at end of file + diff --git a/devtools/gradle/gradle-application-plugin/src/test/java/io/quarkus/gradle/QuarkusPluginTest.java b/devtools/gradle/gradle-application-plugin/src/test/java/io/quarkus/gradle/QuarkusPluginTest.java index 0f29e3f3c2e51..38d1eb6dc0c41 100644 --- a/devtools/gradle/gradle-application-plugin/src/test/java/io/quarkus/gradle/QuarkusPluginTest.java +++ b/devtools/gradle/gradle-application-plugin/src/test/java/io/quarkus/gradle/QuarkusPluginTest.java @@ -1,10 +1,15 @@ package io.quarkus.gradle; import static org.assertj.core.api.Assertions.assertThat; +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -16,12 +21,18 @@ import org.gradle.api.provider.Provider; import org.gradle.api.tasks.TaskContainer; import org.gradle.testfixtures.ProjectBuilder; +import org.gradle.testkit.runner.BuildResult; +import org.gradle.testkit.runner.GradleRunner; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import io.quarkus.gradle.extension.QuarkusPluginExtension; public class QuarkusPluginTest { + @TempDir + Path testProjectDir; + @Test public void shouldCreateTasks() { Project project = ProjectBuilder.builder().build(); @@ -67,7 +78,7 @@ public void shouldMakeQuarkusDevAndQuarkusBuildDependOnClassesTask() { } @Test - public void shouldReturnMutlipleOutputSourceDirectories() { + public void shouldReturnMultipleOutputSourceDirectories() { Project project = ProjectBuilder.builder().build(); project.getPluginManager().apply(QuarkusPlugin.ID); project.getPluginManager().apply("java"); @@ -84,6 +95,67 @@ public void shouldReturnMutlipleOutputSourceDirectories() { } + @Test + public void shouldNotFailOnProjectDependenciesWithoutMain() throws IOException { + var kotlinVersion = System.getProperty("kotlin_version", "1.7.20"); + var settingFile = testProjectDir.resolve("settings.gradle.kts"); + var mppProjectDir = testProjectDir.resolve("mpp"); + var quarkusProjectDir = testProjectDir.resolve("quarkus"); + var mppBuild = mppProjectDir.resolve("build.gradle.kts"); + var quarkusBuild = quarkusProjectDir.resolve("build.gradle.kts"); + Files.createDirectory(mppProjectDir); + Files.createDirectory(quarkusProjectDir); + Files.writeString(settingFile, + "rootProject.name = \"quarkus-mpp-sample\"\n" + + "\n" + + "include(\n" + + " \"mpp\",\n" + + " \"quarkus\"\n" + + ")"); + + Files.writeString(mppBuild, + "buildscript {\n" + + " repositories {\n" + + " mavenLocal()\n" + + " mavenCentral()\n" + + " }\n" + + " dependencies {\n" + + " classpath(\"org.jetbrains.kotlin:kotlin-gradle-plugin:" + kotlinVersion + "\")\n" + + " }\n" + + "}\n" + + "\n" + + "apply(plugin = \"org.jetbrains.kotlin.multiplatform\")\n" + + "\n" + + "repositories {\n" + + " mavenCentral()\n" + + "}\n" + + "\n" + + "configure{\n" + + " jvm()\n" + + "}"); + + Files.writeString(quarkusBuild, + "plugins {\n" + + " id(\"io.quarkus\")\n" + + "}\n" + + "\n" + + "repositories {\n" + + " mavenCentral()\n" + + "}\n" + + "\n" + + "dependencies {\n" + + " implementation(project(\":mpp\"))\n" + + "}"); + + BuildResult result = GradleRunner.create() + .withPluginClasspath() + .withProjectDir(testProjectDir.toFile()) + .withArguments("quarkusGenerateCode") + .build(); + + assertEquals(SUCCESS, result.task(":quarkus:quarkusGenerateCode").getOutcome()); + } + private static final List getDependantProvidedTaskName(Task task) { List dependantTaskNames = new ArrayList<>(); for (Object t : task.getDependsOn()) { diff --git a/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/tooling/dependency/DependencyUtils.java b/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/tooling/dependency/DependencyUtils.java index 5d0f37b1793e3..66ac10d30b5ad 100644 --- a/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/tooling/dependency/DependencyUtils.java +++ b/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/tooling/dependency/DependencyUtils.java @@ -83,7 +83,10 @@ public static ExtensionDependency getExtensionInfoOrNull(Project project, Resolv SourceSetContainer sourceSets = projectDep == null ? null : projectDep.getExtensions().findByType(SourceSetContainer.class); if (sourceSets != null) { - SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); + SourceSet mainSourceSet = sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME); + if (mainSourceSet == null) { + return null; + } File resourcesDir = mainSourceSet.getOutput().getResourcesDir(); Path descriptorPath = resourcesDir.toPath().resolve(BootstrapConstants.DESCRIPTOR_PATH); if (Files.exists(descriptorPath)) {