Skip to content

Commit

Permalink
fix: make sure changes to System.properties are always reset
Browse files Browse the repository at this point in the history
  • Loading branch information
quintesse committed Sep 28, 2023
1 parent 8038aa9 commit 8813727
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/main/java/dev/jbang/dependencies/ArtifactResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -382,8 +383,10 @@ private Settings newEffectiveSettings() {
DefaultSettingsBuilderFactory factory = new DefaultSettingsBuilderFactory();
DefaultSettingsBuilder builder = factory.newInstance();

Properties props = new Properties();
props.putAll(System.getProperties());
SettingsBuildingRequest settingsBuilderRequest = new DefaultSettingsBuildingRequest();
settingsBuilderRequest.setSystemProperties(System.getProperties());
settingsBuilderRequest.setSystemProperties(props);

if (withUserSettings) {
// find the settings
Expand Down
29 changes: 17 additions & 12 deletions src/main/java/dev/jbang/source/buildsteps/IntegrationBuildStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,28 @@ public IntegrationBuildStep(BuildContext ctx) {
public IntegrationResult build() throws IOException {
// todo: setting properties to avoid loosing properties in integration call.
Project project = ctx.getProject();
Properties old = System.getProperties();
Properties temp = new Properties(System.getProperties());
Properties oldProps = System.getProperties();
Properties tempProps = new Properties();
tempProps.putAll(oldProps);
System.setProperties(tempProps);
for (Map.Entry<String, String> entry : project.getProperties().entrySet()) {
System.setProperty(entry.getKey(), entry.getValue());
}
IntegrationResult integrationResult = IntegrationManager.runIntegrations(ctx);
System.setProperties(old);
try {
IntegrationResult integrationResult = IntegrationManager.runIntegrations(ctx);

if (project.getMainClass() == null) { // if non-null user forced set main
if (integrationResult.mainClass != null) {
project.setMainClass(integrationResult.mainClass);
if (project.getMainClass() == null) { // if non-null user forced set main
if (integrationResult.mainClass != null) {
project.setMainClass(integrationResult.mainClass);
}
}
if (integrationResult.javaArgs != null && !integrationResult.javaArgs.isEmpty()) {
// Add integration options to the java options
project.addRuntimeOptions(integrationResult.javaArgs);
}
return integrationResult;
} finally {
System.setProperties(oldProps);
}
if (integrationResult.javaArgs != null && !integrationResult.javaArgs.isEmpty()) {
// Add integration options to the java options
project.addRuntimeOptions(integrationResult.javaArgs);
}
return integrationResult;
}
}

0 comments on commit 8813727

Please sign in to comment.