Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import io.quarkus.maven.dependency.DependencyFlags;
import io.quarkus.maven.dependency.GACT;
import io.quarkus.maven.dependency.GACTV;
import io.quarkus.maven.dependency.GAV;
import io.quarkus.maven.dependency.ResolvedDependencyBuilder;
import io.quarkus.paths.PathCollection;
import io.quarkus.paths.PathList;
Expand Down Expand Up @@ -169,7 +168,8 @@ public static ResolvedDependencyBuilder getProjectArtifact(Project project, bool

final SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
final WorkspaceModule.Mutable mainModule = WorkspaceModule.builder()
.setModuleId(new GAV(appArtifact.getGroupId(), appArtifact.getArtifactId(), appArtifact.getVersion()))
.setModuleId(
WorkspaceModuleId.of(appArtifact.getGroupId(), appArtifact.getArtifactId(), appArtifact.getVersion()))
.setModuleDir(project.getProjectDir().toPath())
.setBuildDir(project.getBuildDir().toPath())
.setBuildFile(project.getBuildFile().toPath());
Expand Down Expand Up @@ -701,6 +701,6 @@ private static ArtifactCoords toArtifactCoords(ResolvedArtifact a) {
}

private static ArtifactKey toAppDependenciesKey(String groupId, String artifactId, String classifier) {
return new GACT(groupId, artifactId, classifier, ArtifactCoords.TYPE_JAR);
return ArtifactKey.of(groupId, artifactId, classifier, ArtifactCoords.TYPE_JAR);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.quarkus.gradle.tooling;

import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.gradle.api.Project;
Expand All @@ -11,7 +13,9 @@
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.SourceSetOutput;
import org.gradle.api.tasks.bundling.Jar;
import org.gradle.api.tasks.testing.Test;

import io.quarkus.bootstrap.workspace.ArtifactSources;
import io.quarkus.bootstrap.workspace.DefaultArtifactSources;
import io.quarkus.bootstrap.workspace.LazySourceDir;
import io.quarkus.bootstrap.workspace.SourceDir;
Expand All @@ -28,8 +32,8 @@ public static Provider<DefaultProjectDescriptor> buildForApp(Project project) {

public static void initSourceDirs(Project project, WorkspaceModule.Mutable result) {
final SourceSetContainer srcSets = project.getExtensions().getByType(SourceSetContainer.class);
// Here we are checking JARs will be produced, which directories they will use as the source of content
// and figure out which source directories are processed to produce the content of the JARs.
// Here we are iterating through the JARs that will be produced, collecting directories that will be used as sources
// of their content. Then we are figuring out which source directories would be processed to produce the content of the JARs.
// It has to be configureEach instead of forEach, apparently to avoid concurrent collection modification in some cases.
project.getTasks().withType(Jar.class).configureEach(jarTask -> {
final String classifier = jarTask.getArchiveClassifier().get();
Expand All @@ -38,7 +42,7 @@ public static void initSourceDirs(Project project, WorkspaceModule.Mutable resul
final List<File> resourcesOutputDirs = new ArrayList<>(2);
collectSourceSetOutput(((DefaultCopySpec) jarTask.getRootSpec()), classesDirs, resourcesOutputDirs);

final List<SourceDir> sourceDirs = new ArrayList<>(2);
final List<SourceDir> sourceDirs = new ArrayList<>();
final List<SourceDir> resourceDirs = new ArrayList<>(2);
for (SourceSet srcSet : srcSets) {
for (var classesDir : srcSet.getOutput().getClassesDirs().getFiles()) {
Expand All @@ -49,10 +53,10 @@ public static void initSourceDirs(Project project, WorkspaceModule.Mutable resul
}
}

final File resourcesOutputDir = srcSet.getOutput().getResourcesDir();
if (resourcesOutputDirs.contains(resourcesOutputDir)) {
if (resourcesOutputDirs.contains(srcSet.getOutput().getResourcesDir())) {
var resourcesTarget = srcSet.getOutput().getResourcesDir().toPath();
for (var dir : srcSet.getResources().getSrcDirs()) {
resourceDirs.add(new LazySourceDir(dir.toPath(), resourcesOutputDir.toPath()));
resourceDirs.add(new LazySourceDir(dir.toPath(), resourcesTarget));
}
}
}
Expand All @@ -61,6 +65,60 @@ public static void initSourceDirs(Project project, WorkspaceModule.Mutable resul
result.addArtifactSources(new DefaultArtifactSources(classifier, sourceDirs, resourceDirs));
}
});

// This is for the test sources and resources since, by default, they won't be put in JARs
project.getTasks().withType(Test.class).configureEach(testTask -> {
for (SourceSet srcSet : srcSets) {
String classifier = null;
List<SourceDir> testSourcesDirs = Collections.emptyList();
List<SourceDir> testResourcesDirs = Collections.emptyList();
for (var classesDir : srcSet.getOutput().getClassesDirs().getFiles()) {
if (testTask.getTestClassesDirs().contains(classesDir)) {
if (classifier == null) {
classifier = sourceSetNameToClassifier(srcSet.getName());
if (result.hasSources(classifier)) {
// this source set should already be present in the module
break;
}
}
for (var srcDir : srcSet.getAllJava().getSrcDirs()) {
if (testSourcesDirs.isEmpty()) {
testSourcesDirs = new ArrayList<>(6);
}
testSourcesDirs.add(new LazySourceDir(srcDir.toPath(), classesDir.toPath())); // TODO findGeneratedSourceDir(destDir, sourceSet));
}
}
}
if (classifier != null && !testSourcesDirs.isEmpty()) {
if (srcSet.getOutput().getResourcesDir() != null) {
final Path resourcesOutputDir = srcSet.getOutput().getResourcesDir().toPath();
for (var dir : srcSet.getResources().getSrcDirs()) {
if (testResourcesDirs.isEmpty()) {
testResourcesDirs = new ArrayList<>(2);
}
testResourcesDirs.add(new LazySourceDir(dir.toPath(), resourcesOutputDir));
}
}
result.addArtifactSources(new DefaultArtifactSources(classifier, testSourcesDirs, testResourcesDirs));
}
}
});
}

private static String sourceSetNameToClassifier(String sourceSetName) {
if (SourceSet.TEST_SOURCE_SET_NAME.equals(sourceSetName)) {
return ArtifactSources.TEST;
}
var sb = new StringBuilder(sourceSetName.length() + 2);
for (int i = 0; i < sourceSetName.length(); ++i) {
char original = sourceSetName.charAt(i);
char lowerCase = Character.toLowerCase(original);
if (original != lowerCase) {
sb.append('-');
}
sb.append(lowerCase);
}
return sb.toString();
}

private static void collectSourceSetOutput(DefaultCopySpec spec, List<File> classesDir, List<File> resourcesDir) {
Expand Down
17 changes: 17 additions & 0 deletions integration-tests/gradle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jacoco</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
Expand Down Expand Up @@ -305,6 +309,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jacoco-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
kotlin("jvm")
kotlin("plugin.allopen")
id("io.quarkus")
}

repositories {
mavenCentral()
mavenLocal()
}

val quarkusPlatformGroupId: String by project
val quarkusPlatformArtifactId: String by project
val quarkusPlatformVersion: String by project

dependencies {
implementation(enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}"))
implementation("io.quarkus:quarkus-kotlin")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("io.quarkus:quarkus-arc")
implementation("io.quarkus:quarkus-rest")
testImplementation("io.quarkus:quarkus-jacoco")
testImplementation("io.quarkus:quarkus-junit5")
testImplementation("io.rest-assured:rest-assured")
}

group = "org.acme"
version = "1.0.0-SNAPSHOT"

tasks.withType<Test> {
systemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager")
}
allOpen {
annotation("jakarta.ws.rs.Path")
annotation("jakarta.enterprise.context.ApplicationScoped")
annotation("jakarta.persistence.Entity")
annotation("io.quarkus.test.junit.QuarkusTest")
}

kotlin {
compilerOptions {
javaParameters = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
quarkusPluginId=io.quarkus
quarkusPlatformGroupId=io.quarkus
quarkusPlatformArtifactId=quarkus-bom
kotlinVersion=${kotlin.version}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pluginManagement {
val quarkusPluginVersion: String by settings
val quarkusPluginId: String by settings
val kotlinVersion: String by settings
repositories {
mavenLocal {
content {
includeGroupByRegex("io.quarkus.*")
includeGroup("org.hibernate.orm")
}
}
mavenCentral()
gradlePluginPortal()
}
plugins {
id(quarkusPluginId) version quarkusPluginVersion
kotlin("jvm") version kotlinVersion
kotlin("multiplatform") version kotlinVersion apply false
kotlin("plugin.allopen") version kotlinVersion
}
}
rootProject.name="code-with-quarkus"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.acme

import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
import jakarta.ws.rs.core.MediaType

@Path("/hello")
class GreetingResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
fun hello() = "Hello from Quarkus REST"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.acme

import io.quarkus.test.junit.QuarkusTest
import io.restassured.RestAssured.given
import org.hamcrest.CoreMatchers.`is`
import org.junit.jupiter.api.Test

@QuarkusTest
class GreetingResourceTest {

@Test
fun testHelloEndpoint() {
given()
.`when`().get("/hello")
.then()
.statusCode(200)
.body(`is`("Hello from Quarkus REST"))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.gradle;

import java.io.File;

import org.junit.jupiter.api.Test;

public class KotlinJacocoTest extends QuarkusGradleWrapperTestBase {

/**
* This test should probably do more than simply verify a successful command execution.
* It was originally added to make sure the process doesn't fail (which it used to).
*/
@Test
public void testFastJarFormatWorks() throws Exception {
final File projectDir = getProjectDir("kotlin-jacoco");
runGradleWrapper(projectDir, "clean", "test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void assertProjectModule(WorkspaceModule projectModule, File projectDir,
assertThat(sourceTree.getRoots()).hasSize(1);
assertThat(sourceTree.getRoots().iterator().next()).isEqualTo(projectDir.toPath().resolve("src/test/resources"));
} else {
assertThat(projectModule.getTestSources()).isNull();
assertThat(projectModule.getTestSources().isOutputAvailable()).isFalse();
}
}

Expand Down
Loading