mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
(Fix) https://projekte.kosit.org/kosit/validator/-/issues/95 NPE when using empty repository definition (-r "")
This commit is contained in:
parent
38ab54438c
commit
b244f73d3a
3 changed files with 45 additions and 43 deletions
14
CHANGELOG.md
14
CHANGELOG.md
|
|
@ -9,19 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Fixed
|
||||
|
||||
- [#93](https://projekte.kosit.org/kosit/validator/-/issues/93) Remove usage information, when validation failed (CLI)
|
||||
- [CLI][#93](https://projekte.kosit.org/kosit/validator/-/issues/93) Remove usage information, when validation failed
|
||||
- [CLI][#95](https://projekte.kosit.org/kosit/validator/-/issues/95) NPE when using empty repository definition (-r "")
|
||||
|
||||
### Added
|
||||
|
||||
- Support for multiple configurations and multiple repositories. See [cli documentation](docs/cli.md) for details
|
||||
- Possibility to use preconfigured Saxon `Processor` instance for validation
|
||||
- [CLI] Support for multiple configurations and multiple repositories. See [cli documentation](docs/cli.md) for details
|
||||
- [API ]Possibility to use preconfigured Saxon `Processor` instance for validation
|
||||
|
||||
### Changed
|
||||
|
||||
- [ResolvingConfigurationStrategy.java#getProcessor()](de/kosit/validationtool/api/ResolvingConfigurationStrategy) is
|
||||
- [API] [ResolvingConfigurationStrategy.java#getProcessor()](de/kosit/validationtool/api/ResolvingConfigurationStrategy)
|
||||
is
|
||||
removed.
|
||||
- Bump [Saxon HE](https://www.saxonica.com/documentation11/documentation.xml) to 11.4
|
||||
- Bump [jaxb-ri](https://github.com/eclipse-ee4j/jaxb-ri) to 2.3.7
|
||||
- [INTERNAL] Bump [Saxon HE](https://www.saxonica.com/documentation11/documentation.xml) to 11.4
|
||||
- [INTERNAL] Bump [jaxb-ri](https://github.com/eclipse-ee4j/jaxb-ri) to 2.3.7
|
||||
|
||||
- [INTERNAL] CLI parsing based on pico-cli, commons-cli is removed
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package de.kosit.validationtool.cmd;
|
||||
|
||||
import static de.kosit.validationtool.impl.Printer.writeErr;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
|
|
@ -96,7 +97,8 @@ public class CommandLineApplication {
|
|||
}
|
||||
|
||||
private static int logExecutionException(final Exception ex, final CommandLine cli, final ParseResult parseResult) {
|
||||
Printer.writeErr(ex, ex.getMessage());
|
||||
final String message = isNotEmpty(ex.getMessage()) ? ex.getMessage() : "Es ist eine Fehler aufgetreten";
|
||||
Printer.writeErr(ex, message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package de.kosit.validationtool.cmd;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -37,6 +37,38 @@ import picocli.CommandLine.ITypeConverter;
|
|||
*/
|
||||
class TypeConverter {
|
||||
|
||||
final static Map<Class<?>, AtomicInteger> counter = new HashMap<>();
|
||||
|
||||
private static String getDefaultName(final Class<?> type) {
|
||||
final AtomicInteger current = counter.computeIfAbsent(type, a -> new AtomicInteger(1));
|
||||
return ScenarioRepository.DEFAULT + "_" + current.getAndIncrement();
|
||||
}
|
||||
|
||||
private static <T extends Definition> T convert(final Class<T> type, final String value) {
|
||||
final T def;
|
||||
final String[] splitted = defaultIfBlank(value, "").split("=");
|
||||
if (splitted.length == 1) {
|
||||
def = createNewInstance(type);
|
||||
def.setName(getDefaultName(type));
|
||||
def.setPath(Paths.get(splitted[0].trim()));
|
||||
} else if (splitted.length == 2) {
|
||||
def = createNewInstance(type);
|
||||
def.setName(splitted[0].trim());
|
||||
def.setPath(Paths.get(splitted[1].trim()));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid repository specification " + value);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
private static <T extends Definition> T createNewInstance(final Class<T> type) {
|
||||
try {
|
||||
return type.getConstructor().newInstance();
|
||||
} catch (final ReflectiveOperationException e) {
|
||||
throw new IllegalStateException("Error creating instance of type " + type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Type converter for a repository definition specification e.g. '-r somelocation.xml OR -r myid=somelocation.xml'
|
||||
*
|
||||
|
|
@ -62,38 +94,4 @@ class TypeConverter {
|
|||
return TypeConverter.convert(ScenarioDefinition.class, value);
|
||||
}
|
||||
}
|
||||
|
||||
final static Map<Class<?>, AtomicInteger> counter = new HashMap<>();
|
||||
|
||||
private static String getDefaultName(final Class<?> type) {
|
||||
final AtomicInteger current = counter.computeIfAbsent(type, a -> new AtomicInteger(1));
|
||||
return ScenarioRepository.DEFAULT + "_" + current.getAndIncrement();
|
||||
}
|
||||
|
||||
private static <T extends Definition> T convert(final Class<T> type, final String value) {
|
||||
T def = null;
|
||||
if (isNotBlank(value)) {
|
||||
final String[] splitted = value.split("=");
|
||||
if (splitted.length == 1) {
|
||||
def = createNewInstance(type);
|
||||
def.setName(getDefaultName(type));
|
||||
def.setPath(Paths.get(splitted[0].trim()));
|
||||
} else if (splitted.length == 2) {
|
||||
def = createNewInstance(type);
|
||||
def.setName(splitted[0].trim());
|
||||
def.setPath(Paths.get(splitted[1].trim()));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid repository specification " + value);
|
||||
}
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
private static <T extends Definition> T createNewInstance(final Class<T> type) {
|
||||
try {
|
||||
return type.getConstructor().newInstance();
|
||||
} catch (final ReflectiveOperationException e) {
|
||||
throw new IllegalStateException("Error creating instance of type " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue