-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
601 additions
and
24 deletions.
There are no files selected for viewing
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,25 @@ | ||
version: 1 | ||
update_configs: | ||
- package_manager: "java:maven" | ||
directory: "/" | ||
update_schedule: "daily" | ||
automerged_updates: | ||
- match: | ||
dependency_name: "org.apache.maven.plugins:*" | ||
- match: | ||
dependency_name: "org.codehaus.mojo:*" | ||
- match: | ||
dependency_name: "org.gaul:modernizer-maven-plugin" | ||
- match: | ||
dependency_name: "org.jacoco:jacoco-maven-plugin" | ||
- match: | ||
dependency_name: "org.checkerframework:checker-qual" | ||
- match: | ||
dependency_name: "org.assertj:assertj-core" | ||
- match: | ||
dependency_name: "org.openjdk.jmh:*" | ||
- match: | ||
dependency_name: "com.akathist.maven.plugins.launch4j:launch4j-maven-plugin" | ||
- match: | ||
dependency_name: "net.nicoulaj.maven.plugins:checksum-maven-plugin" | ||
|
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
107 changes: 107 additions & 0 deletions
107
java-desktop-util-os/src/main/java/ec/util/desktop/impl/InternalCopyOfRegWrapper.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,107 @@ | ||
/* | ||
* Copyright 2018 National Bank of Belgium | ||
* | ||
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved | ||
* by the European Commission - subsequent versions of the EUPL (the "Licence"); | ||
* You may not use this work except in compliance with the Licence. | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* http://ec.europa.eu/idabc/eupl | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the Licence is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Licence for the specific language governing permissions and | ||
* limitations under the Licence. | ||
*/ | ||
package ec.util.desktop.impl; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
* | ||
* @author Philippe Charles | ||
*/ | ||
@lombok.experimental.UtilityClass | ||
class InternalCopyOfRegWrapper { | ||
|
||
public static final String COMMAND = "reg"; | ||
|
||
@NonNull | ||
public Map<String, List<RegValue>> query(@NonNull String keyName, boolean recursive) throws IOException { | ||
Objects.requireNonNull(keyName); | ||
try (BufferedReader reader = InternalCopyofProcessReader.newReader(getArgs(keyName, recursive))) { | ||
return parse(reader); | ||
} | ||
} | ||
|
||
String[] getArgs(String keyName, boolean recursive) { | ||
List<String> args = new ArrayList<>(); | ||
args.add(COMMAND); | ||
args.add("query"); | ||
args.add(keyName); | ||
if (recursive) { | ||
args.add("/s"); | ||
} | ||
return args.toArray(new String[0]); | ||
} | ||
|
||
Map<String, List<RegValue>> parse(BufferedReader reader) throws IOException { | ||
Map<String, List<RegValue>> result = new LinkedHashMap<>(); | ||
String line; | ||
String subKey = null; | ||
List<RegValue> values = null; | ||
while ((line = reader.readLine()) != null) { | ||
if (!line.isEmpty()) { | ||
if (subKey == null) { | ||
subKey = line; | ||
values = new ArrayList<>(); | ||
} else { | ||
RegValue regValue = RegValue.parseOrNull(line); | ||
if (regValue != null) { | ||
values.add(regValue); | ||
} else { | ||
result.put(subKey, values); | ||
subKey = line; | ||
values = new ArrayList<>(); | ||
} | ||
} | ||
} | ||
} | ||
if (subKey != null) { | ||
result.put(subKey, values); | ||
} | ||
return result; | ||
} | ||
|
||
@lombok.Value | ||
public static final class RegValue { | ||
|
||
private static final Pattern PATTERN = Pattern.compile("^[ ]{4}(.+)[ ]{4}(REG_(?:SZ|MULTI_SZ|EXPAND_SZ|DWORD|QWORD|BINARY|NONE))[ ]{4}(.*)$"); | ||
|
||
@Nullable | ||
public static RegValue parseOrNull(@NonNull CharSequence line) { | ||
Matcher m = PATTERN.matcher(line); | ||
return m.matches() ? new RegValue(m.group(1), m.group(2), m.group(3)) : null; | ||
} | ||
|
||
@lombok.NonNull | ||
private String name; | ||
|
||
@lombok.NonNull | ||
private String dataType; | ||
|
||
@lombok.NonNull | ||
private String value; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
java-desktop-util-os/src/main/java/ec/util/desktop/impl/InternalCopyofProcessReader.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,80 @@ | ||
/* | ||
* Copyright 2018 National Bank of Belgium | ||
* | ||
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved | ||
* by the European Commission - subsequent versions of the EUPL (the "Licence"); | ||
* You may not use this work except in compliance with the Licence. | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* http://ec.europa.eu/idabc/eupl | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the Licence is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Licence for the specific language governing permissions and | ||
* limitations under the Licence. | ||
*/ | ||
package ec.util.desktop.impl; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.Charset; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
/** | ||
* | ||
* @author Philippe Charles | ||
*/ | ||
@lombok.experimental.UtilityClass | ||
class InternalCopyofProcessReader { | ||
|
||
@NonNull | ||
public static BufferedReader newReader(@NonNull String... args) throws IOException { | ||
return newReader(new ProcessBuilder(args).start()); | ||
} | ||
|
||
@NonNull | ||
public static BufferedReader newReader(@NonNull Process process) throws IOException { | ||
return new BufferedReader(new InputStreamReader(new ProcessInputStream(process), Charset.defaultCharset())); | ||
} | ||
|
||
private static final class ProcessInputStream extends InputStream { | ||
|
||
@lombok.experimental.Delegate(excludes = Closeable.class) | ||
private final InputStream delegate; | ||
|
||
private final Process process; | ||
|
||
public ProcessInputStream(Process process) { | ||
this.delegate = process.getInputStream(); | ||
this.process = process; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
try { | ||
readUntilEnd(); | ||
waitForEndOfProcess(); | ||
} finally { | ||
delegate.close(); | ||
} | ||
} | ||
|
||
// we need the process to end, else we'll get an illegal Thread State Exception | ||
private void readUntilEnd() throws IOException { | ||
while (delegate.read() != -1) { | ||
} | ||
} | ||
|
||
private void waitForEndOfProcess() throws IOException { | ||
try { | ||
process.waitFor(); | ||
} catch (InterruptedException ex) { | ||
throw new IOException(ex); | ||
} | ||
} | ||
} | ||
} |
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
70 changes: 70 additions & 0 deletions
70
java-desktop-util-os/src/main/java/ec/util/desktop/impl/RegRegistry.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,70 @@ | ||
/* | ||
* Copyright 2020 National Bank of Belgium | ||
* | ||
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved | ||
* by the European Commission - subsequent versions of the EUPL (the "Licence"); | ||
* You may not use this work except in compliance with the Licence. | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* http://ec.europa.eu/idabc/eupl | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the Licence is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Licence for the specific language governing permissions and | ||
* limitations under the Licence. | ||
*/ | ||
package ec.util.desktop.impl; | ||
|
||
import ec.util.desktop.impl.InternalCopyOfRegWrapper.RegValue; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.SortedMap; | ||
import java.util.TreeMap; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* | ||
* @author Philippe Charles | ||
*/ | ||
final class RegRegistry extends WinRegistry { | ||
|
||
private static final String KEY_SEPARATOR = "\\"; | ||
|
||
private List<InternalCopyOfRegWrapper.RegValue> getValuesOrNull(WinRegistry.Root root, String key) throws IOException { | ||
Objects.requireNonNull(root); | ||
Objects.requireNonNull(key); | ||
String keyName = root.name() + KEY_SEPARATOR + key; | ||
return InternalCopyOfRegWrapper.query(keyName, false).get(keyName); | ||
} | ||
|
||
@Override | ||
public boolean keyExists(WinRegistry.Root root, String key) throws IOException { | ||
List<InternalCopyOfRegWrapper.RegValue> data = getValuesOrNull(root, key); | ||
return data != null; | ||
} | ||
|
||
@Override | ||
public Object getValue(WinRegistry.Root root, String key, String name) throws IOException { | ||
List<InternalCopyOfRegWrapper.RegValue> data = getValuesOrNull(root, key); | ||
Objects.requireNonNull(name); | ||
return data != null | ||
? data | ||
.stream() | ||
.filter(regValue -> regValue.getName().equals(name)) | ||
.map(regValue -> regValue.getValue()) | ||
.findFirst() | ||
.orElse(null) | ||
: null; | ||
} | ||
|
||
@Override | ||
public SortedMap<String, Object> getValues(WinRegistry.Root root, String key) throws IOException { | ||
List<InternalCopyOfRegWrapper.RegValue> data = getValuesOrNull(root, key); | ||
return data != null | ||
? data.stream().collect(Collectors.toMap(RegValue::getName, regValue -> (Object) regValue.getValue(), (l, r) -> l, TreeMap::new)) | ||
: Collections.emptySortedMap(); | ||
} | ||
} |
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
Oops, something went wrong.