Skip to content

Commit

Permalink
forcing initializing compilejava if empty
Browse files Browse the repository at this point in the history
(cherry picked from commit 0462367)
  • Loading branch information
cdsap authored and gsmet committed Nov 12, 2024
1 parent dd35a81 commit 93072af
Show file tree
Hide file tree
Showing 14 changed files with 498 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -70,7 +71,6 @@
import io.quarkus.fs.util.ZipUtils;
import io.quarkus.gradle.tooling.ToolingUtils;
import io.quarkus.gradle.workspace.descriptors.DefaultProjectDescriptor;
import io.quarkus.gradle.workspace.descriptors.ProjectDescriptor;
import io.quarkus.gradle.workspace.descriptors.ProjectDescriptor.TaskType;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactDependency;
Expand Down Expand Up @@ -194,10 +194,13 @@ private ResolvedDependencyBuilder getProjectArtifact() {
.setBuildDir(getLayout().getBuildDirectory().getAsFile().get().toPath())
.setBuildFile(getProjectBuildFile().getAsFile().get().toPath());

ProjectDescriptor projectDescriptor = getProjectDescriptor().get();
initProjectModule(projectDescriptor, mainModule, ArtifactSources.MAIN, DEFAULT_CLASSIFIER);
DefaultProjectDescriptor projectDescriptor = getProjectDescriptor().get();

initProjectModule(projectDescriptor, mainModule, ArtifactSources.MAIN, DEFAULT_CLASSIFIER,
getProjectDescriptor().get().getSourceSetTasksRaw());
if (getLaunchMode().get().isDevOrTest()) {
initProjectModule(projectDescriptor, mainModule, ArtifactSources.TEST, "tests");
initProjectModule(projectDescriptor, mainModule, ArtifactSources.TEST, "tests",
getProjectDescriptor().get().getSourceSetTasksRaw());
}
final PathList.Builder paths = PathList.builder();
collectDestinationDirs(mainModule.getMainSources().getSourceDirs(), paths);
Expand All @@ -206,8 +209,8 @@ private ResolvedDependencyBuilder getProjectArtifact() {
return appArtifact.setWorkspaceModule(mainModule).setResolvedPaths(paths.build());
}

private static void initProjectModule(ProjectDescriptor projectDescriptor, WorkspaceModule.Mutable module,
String sourceSetName, String classifier) {
private static void initProjectModule(DefaultProjectDescriptor projectDescriptor, WorkspaceModule.Mutable module,
String sourceSetName, String classifier, Map<String, Set<String>> sourceSetTasksRaw) {
List<SourceDir> sourceDirs = new ArrayList<>();
List<SourceDir> resources = new ArrayList<>();
Set<String> tasks = projectDescriptor.getTasksForSourceSet(sourceSetName.isEmpty()
Expand All @@ -223,6 +226,23 @@ private static void initProjectModule(ProjectDescriptor projectDescriptor, Works
resources.add(new DefaultSourceDir(source, destDir, null));
}
}

// Issue https://github.com/quarkusio/quarkus/issues/44384
// no java sources are detected for compileJava before grpc configuration
// so we need to verify if the destination source for the task exist and add it manually
boolean containsJavaCompile = sourceDirs.stream()
.anyMatch(sourceDir -> "compileJava".equals(sourceDir.getValue("compiler", String.class)));
if (!containsJavaCompile && sourceSetTasksRaw.get("compileJava") != null) {

sourceSetTasksRaw.get("compileJava").forEach(s -> {
File output = new File(s);
if (output.exists() && Objects.requireNonNull(output.listFiles()).length > 0) {
sourceDirs.add(
new DefaultSourceDir(output.toPath(), output.toPath(), null, Map.of("compiler", "compileJava")));
}
});

}
module.addArtifactSources(new DefaultArtifactSources(classifier, sourceDirs, resources));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ public class DefaultProjectDescriptor implements Serializable, ProjectDescriptor

private final Map<String, QuarkusTaskDescriptor> tasks;
private final Map<String, Set<String>> sourceSetTasks;
private final Map<String, Set<String>> sourceSetTasksRaw;

public DefaultProjectDescriptor(File projectDir, File buildDir, File buildFile, Map<String, QuarkusTaskDescriptor> tasks,
Map<String, Set<String>> sourceSetTasks) {
Map<String, Set<String>> sourceSetTasks, Map<String, Set<String>> sourceSetTasksRaw) {
this.projectDir = projectDir;
this.buildDir = buildDir;
this.buildFile = buildFile;
this.tasks = tasks;
this.sourceSetTasks = sourceSetTasks;
this.sourceSetTasksRaw = sourceSetTasksRaw;
}

@Override
Expand All @@ -47,6 +49,10 @@ public Map<String, Set<String>> getSourceSetTasks() {
return sourceSetTasks;
}

public Map<String, Set<String>> getSourceSetTasksRaw() {
return sourceSetTasksRaw;
}

public Map<String, QuarkusTaskDescriptor> getTasks() {
return tasks;
}
Expand Down Expand Up @@ -81,7 +87,8 @@ public DefaultProjectDescriptor withSourceSetView(Set<String> acceptedSourceSets
Map<String, QuarkusTaskDescriptor> filteredTasks = tasks.entrySet().stream()
.filter(e -> filteredSourceSets.values().stream().anyMatch(tasks -> tasks.contains(e.getKey())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a, TreeMap::new));
return new DefaultProjectDescriptor(projectDir, buildDir, buildFile, filteredTasks, filteredSourceSets);
return new DefaultProjectDescriptor(projectDir, buildDir, buildFile, filteredTasks, filteredSourceSets,
sourceSetTasksRaw);
}

@Override
Expand All @@ -92,6 +99,7 @@ public String toString() {
",\nbuildFile=" + buildFile +
",\ntasks=" + tasks +
",\nsourceSetTasks=" + sourceSetTasks +
",\nsourceSetTasksRaw=" + sourceSetTasksRaw +
"\n}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public class ProjectDescriptorBuilder {
private final File buildFile;
private final Map<String, QuarkusTaskDescriptor> tasks;
private final Map<String, Set<String>> sourceSetTasks;
private final Map<String, Set<String>> sourceSetTasksRaw;
private final Set<String> collectOnlySourceSets;

private ProjectDescriptorBuilder(Project project, Set<String> collectOnlySourceSets) {
this.tasks = new LinkedHashMap<>();
this.sourceSetTasks = new LinkedHashMap<>();
this.sourceSetTasksRaw = new LinkedHashMap<>();
this.buildFile = project.getBuildFile();
this.projectDir = project.getLayout().getProjectDirectory().getAsFile();
this.buildDir = project.getLayout().getBuildDirectory().get().getAsFile();
Expand All @@ -59,7 +61,8 @@ public static Provider<DefaultProjectDescriptor> buildForApp(Project target) {
builder.buildDir,
builder.buildFile,
builder.tasks,
builder.sourceSetTasks));
builder.sourceSetTasks,
builder.sourceSetTasksRaw));
}

public static Provider<DefaultProjectDescriptor> buildForDependency(Project target) {
Expand All @@ -76,10 +79,14 @@ public static Provider<DefaultProjectDescriptor> buildForDependency(Project targ
builder.buildDir,
builder.buildFile,
builder.tasks,
builder.sourceSetTasks));
builder.sourceSetTasks,
builder.sourceSetTasksRaw));
}

private void readConfigurationFor(AbstractCompile task) {
sourceSetTasksRaw.computeIfAbsent(task.getName(), s -> new HashSet<>())
.add(task.getDestinationDirectory().getAsFile().get().getAbsolutePath());

if (task.getEnabled() && !task.getSource().isEmpty()) {
File destDir = task.getDestinationDirectory().getAsFile().get();
task.getSource().visit(fileVisitDetails -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
id("io.quarkus")
}

dependencies {
implementation(project(":module1"))

implementation("io.quarkus:quarkus-rest-jackson")
implementation("io.quarkus:quarkus-rest")
implementation("io.quarkus:quarkus-kotlin")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("io.quarkus:quarkus-arc")
implementation("io.quarkus:quarkus-grpc")

testImplementation("io.quarkus:quarkus-junit5")
testImplementation("io.rest-assured:rest-assured")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.acme

import io.quarkus.grpc.GrpcClient
import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
import jakarta.ws.rs.core.MediaType
import org.acme.module1.SomeClass1
import org.acme.proto.Greeter

@Path("/version")
class GreetingResource {

@GrpcClient
lateinit var hello: Greeter

@GET
@Produces(MediaType.TEXT_PLAIN)
fun getVersion(): String {
return SomeClass1().getVersion()
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quarkus.generate-code.grpc.scan-for-proto=org.acme:module1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
plugins {
kotlin("jvm") version "2.0.21"
kotlin("plugin.allopen") version "2.0.21"

id("io.quarkus") apply false
}
allprojects {

repositories {
mavenLocal {
content {
includeGroupByRegex("io.quarkus.*")
includeGroup("org.hibernate.orm")
}
}
mavenCentral()
}

}
subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.kotlin.plugin.allopen")


tasks.withType<Test> {
systemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager")
}

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

dependencies {
implementation(enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}"))
}

allOpen {
annotation("jakarta.ws.rs.Path")
annotation("jakarta.enterprise.context.ApplicationScoped")
annotation("jakarta.persistence.Entity")
annotation("io.quarkus.test.junit.QuarkusTest")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformGroupId=io.quarkus

group=org.acme
version=1.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.acme.module1

class SomeClass1 {
fun getVersion(): String {
return "123"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "proto3";

option java_multiple_files = true;
option java_package = "org.acme.proto";
option java_outer_classname = "HelloWorldProto";

package helloworld;

// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
string name = 1;
}

// The response message containing the greetings
message HelloReply {
string message = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pluginManagement {
repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
includeGroup 'org.hibernate.orm'
}
}
mavenCentral()
gradlePluginPortal()
}
//noinspection GroovyAssignabilityCheck
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}

rootProject.name = 'quarkus-grpc-multi-module-no-java'

include ':module1'
include ':application'

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

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.nio.file.Path;

import org.junit.jupiter.api.Test;

public class GrpcMultiModuleNoJavaQuarkusBuildTest extends QuarkusGradleWrapperTestBase {

@Test
public void testGrpcMultiModuleBuild() throws Exception {

final File projectDir = getProjectDir("grpc-multi-module-no-java");

final BuildResult build = runGradleWrapper(projectDir, "clean", "build");
assertThat(BuildResult.isSuccessful(build.getTasks().get(":application:quarkusBuild"))).isTrue();
assertThat(BuildResult.isSuccessful(build.getTasks().get(":application:quarkusAppPartsBuild"))).isTrue();

final Path applicationLib = projectDir.toPath().resolve("application").resolve("build").resolve("quarkus-app")
.resolve("lib").resolve("main");
assertThat(applicationLib).exists();
assertThat(applicationLib.resolve("org.acme.module1-1.0.0-SNAPSHOT.jar")).exists();
}

}

0 comments on commit 93072af

Please sign in to comment.