-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add configuration option for liquibase.allowDuplicatedChangesetIdentifiers
- Loading branch information
Showing
7 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
core/runtime/src/main/java/io/quarkus/runtime/ResettableSystemProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.quarkus.runtime; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Utility that allows for setting system properties when it's created and resetting them when it's closed. | ||
* This is meant to be used in try-with-resources statements | ||
*/ | ||
public class ResettableSystemProperties implements AutoCloseable { | ||
|
||
private final Map<String, String> toRestore; | ||
|
||
public ResettableSystemProperties(Map<String, String> toSet) { | ||
Objects.requireNonNull(toSet); | ||
if (toSet.isEmpty()) { | ||
toRestore = Collections.emptyMap(); | ||
return; | ||
} | ||
toRestore = new HashMap<>(); | ||
for (var entry : toSet.entrySet()) { | ||
String oldValue = System.setProperty(entry.getKey(), entry.getValue()); | ||
toRestore.put(entry.getKey(), oldValue); | ||
} | ||
} | ||
|
||
public static ResettableSystemProperties of(String name, String value) { | ||
return new ResettableSystemProperties(Map.of(name, value)); | ||
} | ||
|
||
public static ResettableSystemProperties empty() { | ||
return new ResettableSystemProperties(Collections.emptyMap()); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
for (var entry : toRestore.entrySet()) { | ||
if (entry.getValue() != null) { | ||
System.setProperty(entry.getKey(), entry.getValue()); | ||
} else { | ||
System.clearProperty(entry.getKey()); | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
core/runtime/src/test/java/io/quarkus/runtime/ResettableSystemPropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.quarkus.runtime; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class ResettableSystemPropertiesTest { | ||
|
||
@Test | ||
public void happyPath() { | ||
System.setProperty("prop1", "val1"); | ||
assertThat(System.getProperty("prop1")).isEqualTo("val1"); | ||
try (var ignored = new ResettableSystemProperties( | ||
Map.of("prop1", "val11", "prop2", "val2"))) { | ||
assertThat(System.getProperty("prop1")).isEqualTo("val11"); | ||
assertThat(System.getProperty("prop2")).isEqualTo("val2"); | ||
} | ||
assertThat(System.getProperty("prop1")).isEqualTo("val1"); | ||
assertThat(System.getProperties()).doesNotContainKey("prop2"); | ||
} | ||
|
||
@Test | ||
public void exceptionThrown() { | ||
System.setProperty("prop1", "val1"); | ||
int initCount = System.getProperties().size(); | ||
assertThat(System.getProperty("prop1")).isEqualTo("val1"); | ||
try (var ignored = new ResettableSystemProperties( | ||
Map.of("prop1", "val11", "prop2", "val2"))) { | ||
assertThat(System.getProperty("prop1")).isEqualTo("val11"); | ||
assertThat(System.getProperty("prop2")).isEqualTo("val2"); | ||
|
||
throw new RuntimeException("dummy"); | ||
} catch (Exception ignored) { | ||
|
||
} | ||
assertThat(System.getProperty("prop1")).isEqualTo("val1"); | ||
assertThat(System.getProperties()).doesNotContainKey("prop2"); | ||
assertThat(System.getProperties().size()).isEqualTo(initCount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters