mirror of
https://github.com/jlengrand/quarkus.git
synced 2026-03-10 08:41:22 +00:00
Gradle plugin: move serialized app model out of the test classes dir to avoid it being removed as 'stale content' before the tests are executed
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
package io.quarkus.gradle.tasks;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.SourceSetContainer;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import org.gradle.api.tasks.testing.Test;
|
||||
|
||||
@@ -30,19 +27,15 @@ public class QuarkusTestConfig extends QuarkusTask {
|
||||
.toAbsolutePath()
|
||||
.toString();
|
||||
|
||||
SourceSetContainer sourceSets = getProject().getConvention().getPlugin(JavaPluginConvention.class)
|
||||
.getSourceSets();
|
||||
SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
|
||||
File classesDir = testSourceSet.getOutput().getClassesDirs().getFiles().iterator().next();
|
||||
classesDir.mkdirs();
|
||||
try (ObjectOutputStream out = new ObjectOutputStream(
|
||||
new FileOutputStream(new File(classesDir, BootstrapConstants.SERIALIZED_APP_MODEL)))) {
|
||||
final Path serializedModel = Files.createTempFile("quarkus-", "-gradle-test");
|
||||
try (ObjectOutputStream out = new ObjectOutputStream(Files.newOutputStream(serializedModel))) {
|
||||
out.writeObject(deploymentDeps);
|
||||
}
|
||||
|
||||
for (Test test : getProject().getTasks().withType(Test.class)) {
|
||||
final Map<String, Object> props = test.getSystemProperties();
|
||||
props.put("native.image.path", nativeRunner);
|
||||
props.put(BootstrapConstants.SERIALIZED_APP_MODEL, serializedModel.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to resolve deployment classpath", e);
|
||||
|
||||
@@ -45,6 +45,7 @@ import io.quarkus.bootstrap.resolver.update.DependenciesOrigin;
|
||||
import io.quarkus.bootstrap.resolver.update.UpdateDiscovery;
|
||||
import io.quarkus.bootstrap.resolver.update.VersionUpdate;
|
||||
import io.quarkus.bootstrap.resolver.update.VersionUpdateNumber;
|
||||
import io.quarkus.bootstrap.util.IoUtils;
|
||||
import io.quarkus.bootstrap.util.ZipUtils;
|
||||
|
||||
/**
|
||||
@@ -215,13 +216,20 @@ public class BootstrapAppModelFactory {
|
||||
if (test || devMode) {
|
||||
//gradle tests and dev encode the result on the class path
|
||||
|
||||
try (InputStream existing = getClass().getClassLoader().getResourceAsStream(BootstrapConstants.SERIALIZED_APP_MODEL)){
|
||||
if(existing != null ) {
|
||||
AppModel appModel = (AppModel) new ObjectInputStream(existing).readObject();
|
||||
return new CurationResult(appModel);
|
||||
final String serializedModel = System.getProperty(BootstrapConstants.SERIALIZED_APP_MODEL);
|
||||
if (serializedModel != null) {
|
||||
final Path p = Paths.get(serializedModel);
|
||||
if (Files.exists(p)) {
|
||||
try (InputStream existing = Files.newInputStream(Paths.get(serializedModel))) {
|
||||
AppModel appModel = (AppModel) new ObjectInputStream(existing).readObject();
|
||||
return new CurationResult(appModel);
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
log.error("Failed to load serialized app mode", e);
|
||||
}
|
||||
IoUtils.recursiveDelete(p);
|
||||
} else {
|
||||
log.error("Failed to locate serialized application model at " + serializedModel);
|
||||
}
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
log.error("Failed to load serialized app mode", e);
|
||||
}
|
||||
}
|
||||
if (appClasses == null) {
|
||||
|
||||
@@ -6,12 +6,12 @@ package io.quarkus.bootstrap;
|
||||
*/
|
||||
public interface BootstrapConstants {
|
||||
|
||||
String SERIALIZED_APP_MODEL = "serialized-app-model.data";
|
||||
String SERIALIZED_APP_MODEL = "quarkus-internal.serialized-app-model.path";
|
||||
String DESCRIPTOR_FILE_NAME = "quarkus-extension.properties";
|
||||
|
||||
|
||||
@Deprecated
|
||||
String EXTENSION_PROPS_JSON_FILE_NAME = "quarkus-extension.json";
|
||||
|
||||
|
||||
String QUARKUS_EXTENSION_FILE_NAME = "quarkus-extension.yaml";
|
||||
|
||||
String META_INF = "META-INF";
|
||||
|
||||
Reference in New Issue
Block a user