Skip to content

Commit

Permalink
Merge pull request #43329 from cdsap/kotlin_not_included_in_sourceset
Browse files Browse the repository at this point in the history
Missing sourceSets for Kotlin in Project Descriptor
  • Loading branch information
aloubyansky authored Sep 17, 2024
2 parents 928010c + a61b9e8 commit 2a72e8b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ private void readConfigurationFor(KotlinJvmCompile task) {
}
});
tasks.put(task.getName(), new QuarkusTaskDescriptor(task.getName(), COMPILE, srcDir.get(), destDir));
SourceSetContainer sourceSets = task.getProject().getExtensions().getByType(SourceSetContainer.class);
sourceSets.stream().filter(sourceSet -> sourceSet.getOutput().getClassesDirs().contains(destDir))
.forEach(sourceSet -> sourceSetTasks
.computeIfAbsent(sourceSet.getName(), s -> new HashSet<>())
.add(task.getName()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.quarkus.gradle;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.nio.file.Path;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import org.junit.jupiter.api.Test;

public class KotlinIsIncludedInQuarkusJarTest extends QuarkusGradleWrapperTestBase {

@Test
public void testFastJarFormatWorks() throws Exception {

final File projectDir = getProjectDir("basic-kotlin-application-project");

runGradleWrapper(projectDir, "clean", "build");

final Path quarkusApp = projectDir.toPath().resolve("build").resolve("quarkus-app").resolve("app");
assertThat(quarkusApp).exists();
Path jar = quarkusApp.resolve("code-with-quarkus-unspecified.jar");
assertThat(jar).exists();
try (JarFile jarFile = new JarFile(jar.toFile())) {
assertJarContainsEntry(jarFile, "basic-kotlin-application-project/src/main/kotlin/org/acme/MyMainClass.class");
assertJarContainsEntry(jarFile, "org/acme/GreetingResource.class");
assertJarContainsEntry(jarFile, "META-INF/code-with-quarkus.kotlin_module");
}
}

private void assertJarContainsEntry(JarFile jarFile, String expectedEntry) {
boolean entryFound = false;
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
System.out.println(entry.getName());
if (entry.getName().equals(expectedEntry)) {
entryFound = true;
break;
}
}
assertTrue(entryFound, "Expected entry " + expectedEntry + " not found in JAR file.");
}
}

0 comments on commit 2a72e8b

Please sign in to comment.