Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate Runtime properties in JBang Dev mode #44415

Merged
merged 1 commit into from
Nov 12, 2024
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 @@ -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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC when this is set, there is no point to continue, so maybe break the loop.

}
}
return properties;
}
}
Loading