Add linux compatibility & Finalize Config Loader

This commit is contained in:
2023-02-19 15:51:50 +01:00
parent f69fbedee0
commit ce9a2fc805
29 changed files with 212 additions and 71 deletions

View File

@@ -54,9 +54,15 @@ public class Config {
return config; return config;
} }
public String getPathFor(MkvToolNix exe) { /**
return mkvToolNix.getAbsolutePath().endsWith("/") ? mkvToolNix.getAbsolutePath() + exe + ".exe" : * Get path to specific mkvtoolnix application.
mkvToolNix.getAbsolutePath() + "/" + exe + ".exe"; *
* @return absolute path to desired application.
*/
public String getPathFor(MkvToolNix application) {
String executable = isWindows() ? application + ".exe" : application.toString();
return mkvToolNix.getAbsolutePath().endsWith("/") ? mkvToolNix.getAbsolutePath() + executable :
mkvToolNix.getAbsolutePath() + "/" + executable;
} }
@Override @Override

View File

@@ -17,9 +17,8 @@ import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.*;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsUtil.optionOf; import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsUtil.optionOf;
public class ConfigLoader { public class ConfigLoader {
private static final ConfigValidator<?> CONFIG_VALIDATOR =
new ConfigPathValidator(CONFIG_PATH, false, Path.of("./config.yaml").toFile());
private static final List<ConfigValidator<?>> VALIDATORS = List.of( private static final List<ConfigValidator<?>> VALIDATORS = List.of(
new ConfigPathValidator(CONFIG_PATH, false, Path.of("./config.yaml").toFile()),
new PathValidator(LIBRARY, true, null), new PathValidator(LIBRARY, true, null),
new ThreadValidator(THREADS, false, 2), new ThreadValidator(THREADS, false, 2),
new MkvToolNixPathValidator(MKV_TOOL_NIX, true, Path.of("C:\\Program Files\\MKVToolNix").toFile()), new MkvToolNixPathValidator(MKV_TOOL_NIX, true, Path.of("C:\\Program Files\\MKVToolNix").toFile()),
@@ -34,20 +33,26 @@ public class ConfigLoader {
public static void initConfig(String[] args) { public static void initConfig(String[] args) {
HelpFormatter formatter = new HelpFormatter(); HelpFormatter formatter = new HelpFormatter();
YAML yamlConfig = null;
Options options = initOptions(); Options options = initOptions();
CommandLine cmd = parseCommandLineArgs(formatter, options, args); CommandLine cmd = parseCommandLineArgs(formatter, options, args);
exitIfHelp(cmd, options, formatter); exitIfHelp(cmd, options, formatter);
exitIfVersion(cmd); exitIfVersion(cmd);
exitIfConfigIsMissing(cmd);
List<ValidationResult> results = new ArrayList<>(); List<ValidationResult> results = new ArrayList<>();
try (YAML config = new YAML(Config.getInstance().getConfigPath())) {
for (ConfigValidator<?> validator: VALIDATORS) { for (ConfigValidator<?> validator: VALIDATORS) {
results.add(validator.validate(config, cmd)); results.add(validator.validate(yamlConfig, cmd));
} if (yamlConfig == null && Config.getInstance().getConfigPath() != null) {
try {
yamlConfig = Config.getInstance().getConfigPath() != null
? new YAML(Config.getInstance().getConfigPath())
: new YAML("");
} catch (IOException | YamlInvalidContentException ignored) {} } catch (IOException | YamlInvalidContentException ignored) {}
}
}
if (results.contains(ValidationResult.INVALID)) System.exit(1); if (results.contains(ValidationResult.INVALID)) System.exit(1);
System.out.println(); System.out.println();
@@ -55,16 +60,16 @@ public class ConfigLoader {
private static Options initOptions() { private static Options initOptions() {
Options options = new Options(); Options options = new Options();
options.addOption(optionOf(HELP, "h", false)); options.addOption(optionOf(HELP, HELP.abrv(), HELP.args()));
options.addOption(optionOf(VERSION, "v", false)); options.addOption(optionOf(VERSION, VERSION.abrv(), VERSION.args()));
options.addOption(optionOf(LIBRARY, "l", true)); options.addOption(optionOf(LIBRARY, LIBRARY.abrv(), LIBRARY.args() ));
options.addOption(optionOf(MKV_TOOL_NIX, "m", true)); options.addOption(optionOf(MKV_TOOL_NIX, MKV_TOOL_NIX.abrv(), MKV_TOOL_NIX.args() ));
options.addOption(optionOf(CONFIG_PATH, "c", true)); options.addOption(optionOf(CONFIG_PATH, CONFIG_PATH.abrv(), CONFIG_PATH.args() ));
options.addOption(optionOf(THREADS, "t", true)); options.addOption(optionOf(THREADS, THREADS.abrv(), THREADS.args()));
options.addOption(optionOf(SAFE_MODE, "s", false)); options.addOption(optionOf(SAFE_MODE, SAFE_MODE.abrv(), SAFE_MODE.args() ));
options.addOption(optionOf(FORCED_KEYWORDS, "k", Option.UNLIMITED_VALUES, false)); options.addOption(optionOf(FORCED_KEYWORDS, FORCED_KEYWORDS.abrv(), FORCED_KEYWORDS.args()));
options.addOption(optionOf(EXCLUDE_DIRECTORY, "e", Option.UNLIMITED_VALUES, false)); options.addOption(optionOf(EXCLUDE_DIRECTORY, FORCED_KEYWORDS.abrv(), FORCED_KEYWORDS.args()));
options.addOption(optionOf(INCLUDE_PATTERN, "i", true)); options.addOption(optionOf(INCLUDE_PATTERN, INCLUDE_PATTERN.abrv(), INCLUDE_PATTERN.args()));
return options; return options;
} }
@@ -100,13 +105,6 @@ public class ConfigLoader {
} }
} }
private static void exitIfConfigIsMissing(CommandLine cmd) {
if (CONFIG_VALIDATOR.validate(null, cmd).equals(ValidationResult.INVALID)) {
System.out.println("\nPlease use a valid config path!");
System.exit(0);
};
}
private static File loadConfigPath(CommandLine cmd) { private static File loadConfigPath(CommandLine cmd) {
File configPath = new File(cmd.getOptionValue(CONFIG_PATH.prop(), "config.yaml")); File configPath = new File(cmd.getOptionValue(CONFIG_PATH.prop(), "config.yaml"));
if (configPath.isFile()) return configPath; if (configPath.isFile()) return configPath;

View File

@@ -1,8 +1,5 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config; package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
import lombok.Getter;
import lombok.Setter;
public enum ValidationResult { public enum ValidationResult {
VALID, VALID,
DEFAULT, DEFAULT,

View File

@@ -18,6 +18,9 @@ public class AttributeConfigValidator extends ConfigValidator<List<AttributeConf
super(ConfigProperty.ATTRIBUTE_CONFIG, true, null); super(ConfigProperty.ATTRIBUTE_CONFIG, true, null);
} }
/**
* {@inheritDoc}
*/
public ValidationResult validate(YAML yaml, CommandLine cmd) { public ValidationResult validate(YAML yaml, CommandLine cmd) {
System.out.printf("%s: ", property.prop()); System.out.printf("%s: ", property.prop());
List<AttributeConfig> result; List<AttributeConfig> result;
@@ -48,11 +51,17 @@ public class AttributeConfigValidator extends ConfigValidator<List<AttributeConf
return ValidationResult.VALID; return ValidationResult.VALID;
} }
/**
* {@inheritDoc}
*/
@Override @Override
List<AttributeConfig> parse(String value) { List<AttributeConfig> parse(String value) {
return null; return null;
} }
/**
* {@inheritDoc}
*/
@Override @Override
boolean isValid(List<AttributeConfig> result) { boolean isValid(List<AttributeConfig> result) {
if (result.isEmpty()) { if (result.isEmpty()) {

View File

@@ -18,6 +18,9 @@ public class BooleanValidator extends ConfigValidator<Boolean> {
super(property, required, null); super(property, required, null);
} }
/**
* {@inheritDoc}
*/
protected BiFunction<YAML, ConfigProperty, Optional<Boolean>> provideDataYaml() { protected BiFunction<YAML, ConfigProperty, Optional<Boolean>> provideDataYaml() {
return (yaml, property) -> { return (yaml, property) -> {
if (yaml.isSet(ARGUMENTS.prop()) if (yaml.isSet(ARGUMENTS.prop())
@@ -28,6 +31,9 @@ public class BooleanValidator extends ConfigValidator<Boolean> {
}; };
} }
/**
* {@inheritDoc}
*/
protected BiFunction<CommandLine, ConfigProperty, Optional<Boolean>> provideDataCmd() { protected BiFunction<CommandLine, ConfigProperty, Optional<Boolean>> provideDataCmd() {
return (cmd, property) -> { return (cmd, property) -> {
if (cmd.hasOption(property.prop())) { if (cmd.hasOption(property.prop())) {
@@ -37,11 +43,19 @@ public class BooleanValidator extends ConfigValidator<Boolean> {
}; };
} }
/**
* {@inheritDoc}
* This should not be used.
*/
@Override @Override
Boolean parse(String value) { Boolean parse(String value) {
throw new RuntimeException("This should not be called"); throw new RuntimeException("This should not be called");
} }
/**
* {@inheritDoc}
* Validation is skipped.
*/
@Override @Override
boolean isValid(Boolean result) { boolean isValid(Boolean result) {
return true; // skip return true; // skip

View File

@@ -12,11 +12,17 @@ public class ConfigPathValidator extends PathValidator {
super(property, required, defaultValue); super(property, required, defaultValue);
} }
/**
* {@inheritDoc}
*/
@Override @Override
protected BiFunction<YAML, ConfigProperty, Optional<File>> provideDataYaml() { protected BiFunction<YAML, ConfigProperty, Optional<File>> provideDataYaml() {
return (yaml, property) -> Optional.empty(); return (yaml, property) -> Optional.empty();
} }
/**
* {@inheritDoc}
*/
@Override @Override
protected boolean isValid(File result) { protected boolean isValid(File result) {
return super.isValid(result) && (result.getAbsolutePath().endsWith(".yml") || result.getAbsolutePath().endsWith(".yaml")); return super.isValid(result) && (result.getAbsolutePath().endsWith(".yml") || result.getAbsolutePath().endsWith(".yaml"));

View File

@@ -24,6 +24,13 @@ public abstract class ConfigValidator<FieldType> {
protected final boolean required; protected final boolean required;
protected final FieldType defaultValue; protected final FieldType defaultValue;
/**
* Validate the user input. Parameters of cmd are prioritised.
*
* @param yaml config file
* @param cmd command line parameters
* @return {@link ValidationResult} containing validity of input.
*/
public ValidationResult validate(YAML yaml, CommandLine cmd) { public ValidationResult validate(YAML yaml, CommandLine cmd) {
System.out.printf("%s: ", property.prop()); System.out.printf("%s: ", property.prop());
FieldType result; FieldType result;
@@ -63,6 +70,9 @@ public abstract class ConfigValidator<FieldType> {
return ValidationResult.VALID; return ValidationResult.VALID;
} }
/**
* @return parsed input of yaml config for property
*/
protected BiFunction<YAML, ConfigProperty, Optional<FieldType>> provideDataYaml() { protected BiFunction<YAML, ConfigProperty, Optional<FieldType>> provideDataYaml() {
return (yaml, property) -> { return (yaml, property) -> {
if (yaml.isSet(property.prop())) { if (yaml.isSet(property.prop())) {
@@ -76,6 +86,9 @@ public abstract class ConfigValidator<FieldType> {
}; };
} }
/**
* @return parsed input of command line parameters config for property
*/
protected BiFunction<CommandLine, ConfigProperty, Optional<FieldType>> provideDataCmd() { protected BiFunction<CommandLine, ConfigProperty, Optional<FieldType>> provideDataCmd() {
return (cmd, property) -> { return (cmd, property) -> {
if (cmd.hasOption(property.prop())) { if (cmd.hasOption(property.prop())) {
@@ -85,10 +98,28 @@ public abstract class ConfigValidator<FieldType> {
}; };
} }
/**
* Parse input parameter to desired format.
*
* @param value input parameter
* @return parsed property
*/
abstract FieldType parse(String value); abstract FieldType parse(String value);
/**
* Validate if the data has the desired and allowed format.
*
* @param result parsed property
* @return true if data is in desired format.
*/
abstract boolean isValid(FieldType result); abstract boolean isValid(FieldType result);
/**
* Sets valid properties to {@link Config} via reflections.
*
* @param result parsed property
* @return false if method invocation failed
*/
protected boolean setValue(FieldType result) { protected boolean setValue(FieldType result) {
List<Method> methods = Arrays.stream(Config.getInstance().getClass().getDeclaredMethods()) List<Method> methods = Arrays.stream(Config.getInstance().getClass().getDeclaredMethods())
.filter(containsSetterOf(property)) .filter(containsSetterOf(property))

View File

@@ -9,6 +9,8 @@ import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix.MKV_MER
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix.MKV_PROP_EDIT; import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix.MKV_PROP_EDIT;
public class MkvToolNixPathValidator extends PathValidator { public class MkvToolNixPathValidator extends PathValidator {
private static final String EXE = ".exe";
public MkvToolNixPathValidator(ConfigProperty property, boolean required, File defaultValue) { public MkvToolNixPathValidator(ConfigProperty property, boolean required, File defaultValue) {
super(property, required, defaultValue); super(property, required, defaultValue);
} }
@@ -16,8 +18,9 @@ public class MkvToolNixPathValidator extends PathValidator {
@Override @Override
protected boolean isValid(File result) { protected boolean isValid(File result) {
return result.isDirectory() return result.isDirectory()
&& Path.of(result.getAbsolutePath() + "/" + MKV_MERGER + ".exe").toFile().isFile() && (Path.of(result.getAbsolutePath() + "/" + MKV_MERGER + EXE).toFile().isFile()
&& Path.of(result.getAbsolutePath() + "/" + MKV_PROP_EDIT+ ".exe").toFile().isFile(); && Path.of(result.getAbsolutePath() + "/" + MKV_PROP_EDIT + EXE).toFile().isFile())
// TODO: make linux compatible || (Path.of(result.getAbsolutePath() + "/" + MKV_MERGER).toFile().isFile()
&& Path.of(result.getAbsolutePath() + "/" + MKV_PROP_EDIT).toFile().isFile());
} }
} }

View File

@@ -12,6 +12,9 @@ public class OperatingSystemValidator extends BooleanValidator {
super(property, false); super(property, false);
} }
/**
* Gather operating system from system properties.
*/
@Override @Override
public ValidationResult validate(YAML yaml, CommandLine cmd) { public ValidationResult validate(YAML yaml, CommandLine cmd) {
System.out.printf("%s: ", property.prop()); System.out.printf("%s: ", property.prop());

View File

@@ -11,11 +11,17 @@ public class PathValidator extends ConfigValidator<File> {
super(property, required, defaultValue); super(property, required, defaultValue);
} }
/**
* {@inheritDoc}
*/
@Override @Override
protected File parse(String value) { protected File parse(String value) {
return Path.of(value).toFile(); return Path.of(value).toFile();
} }
/**
* {@inheritDoc}
*/
@Override @Override
protected boolean isValid(File result) { protected boolean isValid(File result) {
return result.isDirectory() || result.isFile(); return result.isDirectory() || result.isFile();

View File

@@ -12,6 +12,9 @@ public class PatternValidator extends ConfigValidator<Pattern> {
super(property, required, defaultValue); super(property, required, defaultValue);
} }
/**
* {@inheritDoc}
*/
@Override @Override
Pattern parse(String value) { Pattern parse(String value) {
try { try {
@@ -21,6 +24,9 @@ public class PatternValidator extends ConfigValidator<Pattern> {
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
boolean isValid(Pattern result) { boolean isValid(Pattern result) {
return !result.equals(EMPTY_PATTERN); return !result.equals(EMPTY_PATTERN);

View File

@@ -35,7 +35,7 @@ public class SetValidator extends ConfigValidator<Set<String>> {
System.out.println("missing"); System.out.println("missing");
return ValidationResult.MISSING; return ValidationResult.MISSING;
} else { } else {
System.out.println("not present"); System.out.println("ok");
return ValidationResult.NOT_PRESENT; return ValidationResult.NOT_PRESENT;
} }

View File

@@ -8,11 +8,17 @@ public class ThreadValidator extends ConfigValidator<Integer>{
super(property, required, defaultValue); super(property, required, defaultValue);
} }
/**
* {@inheritDoc}
*/
@Override @Override
Integer parse(String value) { Integer parse(String value) {
return NumberUtils.isParsable(value) ? Integer.parseInt(value) : defaultValue; return NumberUtils.isParsable(value) ? Integer.parseInt(value) : defaultValue;
} }
/**
* {@inheritDoc}
*/
@Override @Override
boolean isValid(Integer result) { boolean isValid(Integer result) {
return result > 0; return result > 0;

View File

@@ -1,6 +1,7 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model; package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.apache.commons.cli.Option;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
@@ -9,36 +10,41 @@ import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor
public enum ConfigProperty { public enum ConfigProperty {
CONFIG_PATH("config-path", "p", "Path to config file"), CONFIG_PATH("config-path", "Path to config file", "p", 1),
LIBRARY("library", "l", "Path to library"), LIBRARY("library", "Path to library", "l", 1),
SAFE_MODE("safe-mode", "s", "Test run (no files will be changes)"), SAFE_MODE("safe-mode", "Test run (no files will be changes)", "s", 0),
WINDOWS("windows", null, "Is operating system windows"), WINDOWS("windows", "Is operating system windows", null, 0),
THREADS("threads", "t", "thread count (default: 2)"), THREADS("threads", "thread count (default: 2)", "t", 1),
INCLUDE_PATTERN("include-pattern", "i", "Include files matching pattern"), INCLUDE_PATTERN("include-pattern", "Include files matching pattern", "i", 1),
MKV_TOOL_NIX("mkvtoolnix", "m", "Path to mkv tool nix installation"), MKV_TOOL_NIX("mkvtoolnix", "Path to mkv tool nix installation", "m", 1),
FORCED_KEYWORDS("forcedKeywords", "fk", "Additional keywords to identify forced tracks"), FORCED_KEYWORDS("forcedKeywords", "Additional keywords to identify forced tracks", "fk", Option.UNLIMITED_VALUES),
COMMENTARY_KEYWORDS("commentary-keywords", "ck", "Additional keywords to identify commentary tracks"), COMMENTARY_KEYWORDS("commentary-keywords", "Additional keywords to identify commentary tracks", "ck", Option.UNLIMITED_VALUES),
EXCLUDE_DIRECTORY("exclude-directories", "e", "Directories to be excluded, combines with config file"), EXCLUDE_DIRECTORY("exclude-directories", "Directories to be excluded, combines with config file", "e", 1),
COHERENT("coherent", "c", "Try to match whole series with same config"), COHERENT("coherent", "Try to match whole series with same config", "c", 0),
HELP("help", "h", "\"for help this is\" - Yoda"), HELP("help", "\"for help this is\" - Yoda", "h", 0),
VERSION("version", "v", "Display version"), VERSION("version", "Display version", "v", 0),
ARGUMENTS("arguments", null, "List of arguments"), ARGUMENTS("arguments", "List of arguments", null, 0),
ATTRIBUTE_CONFIG("attribute-config", "a", "Attribute config to decide which tracks to choose when"); ATTRIBUTE_CONFIG("attribute-config", "Attribute config to decide which tracks to choose when", "a", 1);
private final String property; private final String property;
private final String shortParameter;
private final String description; private final String description;
private final String shortParameter;
private final int args;
public String prop() { public String prop() {
return property; return property;
} }
public String desc() {
return description;
}
public String abrv() { public String abrv() {
return shortParameter; return shortParameter;
} }
public String desc() { public int args() {
return description; return args;
} }
/* /*

View File

@@ -12,7 +12,7 @@ public class ResultStatistic {
"├─ No suitable config found: %s%n" + "├─ No suitable config found: %s%n" +
"├─ Already fit config: %s%n" + "├─ Already fit config: %s%n" +
"└─ Failed: %s%n" + "└─ Failed: %s%n" +
"Runtime: %ss"; "Runtime: %s";
private int filesTotal = 0; private int filesTotal = 0;
@@ -64,9 +64,26 @@ public class ResultStatistic {
runtime = System.currentTimeMillis() - startTime; runtime = System.currentTimeMillis() - startTime;
} }
private String formatTimer() {
int seconds = (int) (runtime / 1000);
int minutes = seconds / 60;
int hours = minutes / 60;
int days = hours / 24;
if (days >= 1) {
return String.format("%sd %sh %sm %ss", days, hours % 24, minutes % 60, seconds % 60);
} else if (hours >= 1) {
return String.format("%sh %sm %ss", hours, minutes % 60, seconds % 60);
} else if (minutes >= 1) {
return String.format("%sm %ss", minutes , seconds % 60);
} else {
return String.format("%ss", seconds % 60);
}
}
@Override @Override
public String toString() { public String toString() {
return String.format(result, filesTotal, shouldChange, failedChanging, successfullyChanged, return String.format(result, filesTotal, shouldChange, failedChanging, successfullyChanged,
noSuitableConfigFound, alreadyFits, failed, runtime / 1000); noSuitableConfigFound, alreadyFits, failed, formatTimer());
} }
} }

View File

@@ -4,8 +4,8 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
import org.apache.commons.cli.Option; import org.apache.commons.cli.Option;
public class CommandLineOptionsUtil { public class CommandLineOptionsUtil {
public static Option optionOf(ConfigProperty property, String opt, boolean hasArg) { public static Option optionOf(ConfigProperty property, String opt, int args) {
return optionOf(property, opt, hasArg ? 1 : 0, false); return optionOf(property, opt, args, false);
} }
public static Option optionOf(ConfigProperty property, String opt, boolean hasArg, boolean required) { public static Option optionOf(ConfigProperty property, String opt, boolean hasArg, boolean required) {

View File

@@ -0,0 +1,30 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.nio.file.Path;
class ConfigTest {
private static final File TEST_MKVTOOLNIX_DIR = Path.of("src/test/resources/mkvtoolnix").toFile();
private static final File TEST_MKVTOOLNIX_EXE_DIR = Path.of("src/test/resources/mkvtoolnix_exe").toFile();
@Test
void getPathForWindows() {
Config.getInstance().setWindows(true);
Config.getInstance().setMkvToolNix(TEST_MKVTOOLNIX_EXE_DIR);
assert Config.getInstance().getPathFor(MkvToolNix.MKV_MERGER).endsWith(MkvToolNix.MKV_MERGER + ".exe");
assert Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT).endsWith(MkvToolNix.MKV_PROP_EDIT + ".exe");
}
@Test
void getPathForUnix() {
Config.getInstance().setWindows(false);
Config.getInstance().setMkvToolNix(TEST_MKVTOOLNIX_DIR);
assert Config.getInstance().getPathFor(MkvToolNix.MKV_MERGER).endsWith(MkvToolNix.MKV_MERGER.toString());
assert Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT).endsWith(MkvToolNix.MKV_PROP_EDIT.toString());
}
}

View File

@@ -32,7 +32,7 @@ class AttributeConfigValidatorTest {
static void before() { static void before() {
parser = new DefaultParser(); parser = new DefaultParser();
options = new Options(); options = new Options();
options.addOption(optionOf(ATTRIBUTE_CONFIG, ATTRIBUTE_CONFIG.abrv(), true)); options.addOption(optionOf(ATTRIBUTE_CONFIG, ATTRIBUTE_CONFIG.abrv(), ATTRIBUTE_CONFIG.args()));
} }
@BeforeEach @BeforeEach

View File

@@ -29,7 +29,7 @@ class BooleanValidatorTest {
static void before() { static void before() {
parser = new DefaultParser(); parser = new DefaultParser();
options = new Options(); options = new Options();
options.addOption(optionOf(SAFE_MODE, SAFE_MODE.abrv(), false)); options.addOption(optionOf(SAFE_MODE, SAFE_MODE.abrv(), SAFE_MODE.args()));
} }
private static Stream<Arguments> provideTestCases() { private static Stream<Arguments> provideTestCases() {

View File

@@ -35,7 +35,7 @@ class ConfigPathValidatorTest {
static void before() { static void before() {
parser = new DefaultParser(); parser = new DefaultParser();
options = new Options(); options = new Options();
options.addOption(optionOf(CONFIG_PATH, CONFIG_PATH.abrv(), true)); options.addOption(optionOf(CONFIG_PATH, CONFIG_PATH.abrv(), CONFIG_PATH.args()));
} }
private static Stream<Arguments> provideTestCases() { private static Stream<Arguments> provideTestCases() {

View File

@@ -24,6 +24,10 @@ import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsU
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class MkvToolNixPathValidatorTest { class MkvToolNixPathValidatorTest {
private static final String TEST_INVALID_DIR = "src/test/resources/test-dir";
private static final String TEST_MKVTOOLNIX_DIR = "src/test/resources/mkvtoolnix";
private static final String TEST_MKVTOOLNIX_EXE_DIR = "src/test/resources/mkvtoolnix_exe";
private static CommandLineParser parser; private static CommandLineParser parser;
private static Options options; private static Options options;
@@ -31,19 +35,19 @@ class MkvToolNixPathValidatorTest {
static void before() { static void before() {
parser = new DefaultParser(); parser = new DefaultParser();
options = new Options(); options = new Options();
options.addOption(optionOf(MKV_TOOL_NIX, MKV_TOOL_NIX.abrv(), true)); options.addOption(optionOf(MKV_TOOL_NIX, MKV_TOOL_NIX.abrv(), MKV_TOOL_NIX.args()));
} }
private static Stream<Arguments> provideTestCases() { private static Stream<Arguments> provideTestCases() {
return Stream.of( return Stream.of(
Arguments.of(MKV_TOOL_NIX, false, null, "", new String[]{"-m", "\"C:\\Program Files\\MKVToolNix\""}, VALID), Arguments.of(MKV_TOOL_NIX, false, null, "", new String[]{"-m", TEST_MKVTOOLNIX_DIR}, VALID),
Arguments.of(MKV_TOOL_NIX, true, null, "", new String[]{"-m", "\"C:\\Program Files\\MKVToolNix\""}, VALID), Arguments.of(MKV_TOOL_NIX, true, null, "", new String[]{"-m", TEST_MKVTOOLNIX_EXE_DIR}, VALID),
Arguments.of(MKV_TOOL_NIX, false, null, "mkvtoolnix: C:\\Program Files\\MKVToolNix", new String[]{}, VALID), Arguments.of(MKV_TOOL_NIX, false, null, "mkvtoolnix: " + TEST_MKVTOOLNIX_EXE_DIR, new String[]{}, VALID),
Arguments.of(MKV_TOOL_NIX, true, null, "mkvtoolnix: C:\\Program Files\\MKVToolNix", new String[]{}, VALID), Arguments.of(MKV_TOOL_NIX, true, null, "mkvtoolnix: " + TEST_MKVTOOLNIX_DIR, new String[]{}, VALID),
Arguments.of(MKV_TOOL_NIX, false, Path.of("C:\\Program Files\\MKVToolNix").toFile(), "", new String[]{}, DEFAULT), Arguments.of(MKV_TOOL_NIX, false, Path.of(TEST_MKVTOOLNIX_EXE_DIR).toFile(), "", new String[]{}, DEFAULT),
Arguments.of(MKV_TOOL_NIX, false, null, "", new String[]{}, NOT_PRESENT), Arguments.of(MKV_TOOL_NIX, false, null, "", new String[]{}, NOT_PRESENT),
Arguments.of(MKV_TOOL_NIX, true, null, "", new String[]{}, MISSING), Arguments.of(MKV_TOOL_NIX, true, null, "", new String[]{}, MISSING),
Arguments.of(MKV_TOOL_NIX, true, null, "", new String[]{"-m", "\"C:\\Program Files\\MKVTool\""}, INVALID) Arguments.of(MKV_TOOL_NIX, true, null, "", new String[]{"-m", TEST_INVALID_DIR}, INVALID)
); );
} }

View File

@@ -34,7 +34,7 @@ class PathValidatorTest {
static void before() { static void before() {
parser = new DefaultParser(); parser = new DefaultParser();
options = new Options(); options = new Options();
options.addOption(optionOf(LIBRARY, LIBRARY.abrv(), true)); options.addOption(optionOf(LIBRARY, LIBRARY.abrv(), LIBRARY.args()));
} }
private static Stream<Arguments> provideTestCases() { private static Stream<Arguments> provideTestCases() {

View File

@@ -31,7 +31,7 @@ class PatternValidatorTest {
static void before() { static void before() {
parser = new DefaultParser(); parser = new DefaultParser();
options = new Options(); options = new Options();
options.addOption(optionOf(INCLUDE_PATTERN, INCLUDE_PATTERN.abrv(), true)); options.addOption(optionOf(INCLUDE_PATTERN, INCLUDE_PATTERN.abrv(), INCLUDE_PATTERN.args()));
} }
private static Stream<Arguments> provideTestCases() { private static Stream<Arguments> provideTestCases() {

View File

@@ -32,7 +32,7 @@ class SetValidatorTest {
static void before() { static void before() {
parser = new DefaultParser(); parser = new DefaultParser();
options = new Options(); options = new Options();
options.addOption(optionOf(COMMENTARY_KEYWORDS, COMMENTARY_KEYWORDS.abrv(), true)); options.addOption(optionOf(COMMENTARY_KEYWORDS, COMMENTARY_KEYWORDS.abrv(), COMMENTARY_KEYWORDS.args()));
} }
@BeforeEach @BeforeEach
@@ -46,7 +46,6 @@ class SetValidatorTest {
argumentsOf(COMMENTARY_KEYWORDS, true, false, COMMENTARY_KEYWORDS.prop() + ": [test]", new String[]{}, VALID, 1), argumentsOf(COMMENTARY_KEYWORDS, true, false, COMMENTARY_KEYWORDS.prop() + ": [test]", new String[]{}, VALID, 1),
argumentsOf(COMMENTARY_KEYWORDS, false, true, COMMENTARY_KEYWORDS.prop() + ": [test]", new String[]{}, VALID, 3), argumentsOf(COMMENTARY_KEYWORDS, false, true, COMMENTARY_KEYWORDS.prop() + ": [test]", new String[]{}, VALID, 3),
argumentsOf(COMMENTARY_KEYWORDS, false, false, "", new String[]{"-ck", "test"}, VALID, 1), argumentsOf(COMMENTARY_KEYWORDS, false, false, "", new String[]{"-ck", "test"}, VALID, 1),
argumentsOf(COMMENTARY_KEYWORDS, true, true, COMMENTARY_KEYWORDS.prop() + ": [commentary]", new String[]{}, VALID, 2), argumentsOf(COMMENTARY_KEYWORDS, true, true, COMMENTARY_KEYWORDS.prop() + ": [commentary]", new String[]{}, VALID, 2),
argumentsOf(COMMENTARY_KEYWORDS, true, true, "", new String[]{}, MISSING, 2), argumentsOf(COMMENTARY_KEYWORDS, true, true, "", new String[]{}, MISSING, 2),

View File

@@ -30,7 +30,7 @@ class ThreadValidatorTest {
static void before() { static void before() {
parser = new DefaultParser(); parser = new DefaultParser();
options = new Options(); options = new Options();
options.addOption(optionOf(THREADS, "t", true)); options.addOption(optionOf(THREADS, "t", THREADS.args()));
} }
private static Stream<Arguments> provideTestCases() { private static Stream<Arguments> provideTestCases() {