Skip to content

Commit

Permalink
Merge pull request #44415 from radcortez/quarkus-44400
Browse files Browse the repository at this point in the history
Propagate Runtime properties in JBang Dev mode
  • Loading branch information
gastaldi authored Nov 12, 2024
2 parents 10ed7b1 + 0878a19 commit 81679eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ private BuildResult runAugment(boolean firstRun, Set<String> changedResources,
.setTargetDir(quarkusBootstrap.getTargetDirectory())
.setDeploymentClassLoader(deploymentClassLoader)
.setBuildSystemProperties(quarkusBootstrap.getBuildSystemProperties())
.setRuntimeProperties(quarkusBootstrap.getRuntimeProperties())
.setEffectiveModel(curatedApplication.getApplicationModel())
.setDependencyInfoProvider(quarkusBootstrap.getDependencyInfoProvider());
if (quarkusBootstrap.getBaseName() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -85,14 +86,16 @@ public static Closeable main(String... args) {

Path srcDir = projectRoot.resolve("src/main/java");
Files.createDirectories(srcDir);
Files.createSymbolicLink(srcDir.resolve(sourceFile.getFileName().toString()), sourceFile);
Path source = Files.createSymbolicLink(srcDir.resolve(sourceFile.getFileName().toString()), sourceFile);
final LocalProject currentProject = LocalProject.loadWorkspace(projectRoot);
final ResolvedDependency appArtifact = ResolvedDependencyBuilder.newInstance()
.setCoords(currentProject.getAppArtifact(ArtifactCoords.TYPE_JAR))
.setResolvedPath(targetClasses)
.setWorkspaceModule(currentProject.toWorkspaceModule())
.build();

Properties configurationProperties = getConfigurationProperties(source);

//todo : proper support for everything
final QuarkusBootstrap.Builder builder = QuarkusBootstrap.builder()
.setBaseClassLoader(JBangDevModeLauncherImpl.class.getClassLoader())
Expand All @@ -117,7 +120,9 @@ public static Closeable main(String... args) {
return artifact;
}).collect(Collectors.toList()))
.setApplicationRoot(targetClasses)
.setProjectRoot(projectRoot);
.setProjectRoot(projectRoot)
.setBuildSystemProperties(configurationProperties)
.setRuntimeProperties(configurationProperties);

Map<String, Object> context = new HashMap<>();
context.put("app-project", currentProject);
Expand Down Expand Up @@ -174,4 +179,19 @@ private static String getQuarkusVersion() {
throw new RuntimeException(e);
}
}

private static Properties getConfigurationProperties(final Path source) throws IOException {
Properties properties = new Properties();
for (String line : Files.readAllLines(source)) {
if (line.startsWith("//Q:CONFIG")) {
String conf = line.substring(10).trim();
int equals = conf.indexOf("=");
if (equals == -1) {
throw new RuntimeException("invalid config " + line);
}
properties.setProperty(conf.substring(0, equals), conf.substring(equals + 1));
}
}
return properties;
}
}

0 comments on commit 81679eb

Please sign in to comment.