Skip to content

Commit

Permalink
Don't throw an error if main source set is missing
Browse files Browse the repository at this point in the history
Test courtesy of Adler Fleurant.

Fixes quarkusio#27950

(cherry picked from commit ec2fdbc)
  • Loading branch information
gsmet committed Oct 31, 2022
1 parent a564784 commit 6a4e4d5
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
4 changes: 4 additions & 0 deletions devtools/gradle/gradle-application-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ pluginBundle {
vcsUrl = 'https://github.com/quarkusio/quarkus'
tags = ['quarkus', 'quarkusio', 'graalvm']
}

test {
systemProperty 'kotlin_version', project.kotlin_version
}
14 changes: 13 additions & 1 deletion devtools/gradle/gradle-application-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@
<artifactId>quarkus-devmode-test-utils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-gradle-plugin</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand All @@ -70,4 +82,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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");
Expand All @@ -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<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension>{\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<String> getDependantProvidedTaskName(Task task) {
List<String> dependantTaskNames = new ArrayList<>();
for (Object t : task.getDependsOn()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 6a4e4d5

Please sign in to comment.