From 8775fbe6c4b409c0fcdcef6320080de0b78f117b Mon Sep 17 00:00:00 2001 From: Michael Schnell Date: Mon, 24 Jan 2022 11:13:23 +0100 Subject: [PATCH] Fixed parameter bug --- app/README.md | 12 ++++++------ app/src/main/app/code2svg-example.bat | 2 +- app/src/main/app/code2svg-example.sh | 4 ++-- .../java/org/fuin/code2svg/app/Code2SvgApp.java | 17 +++++++++-------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/README.md b/app/README.md index 4c2a7e1..71214fa 100644 --- a/app/README.md +++ b/app/README.md @@ -10,13 +10,13 @@ https://github.com/fuinorg/code2svg/releases Execute the shell script to start the conversion: ``` -./code2svg.sh CONFIG_NAME FILE_OR_DIR_1 ... FILE_OR_DIR_N +./code2svg.sh (CONFIG_NAME) (TARGET_DIR) (FILE_OR_DIR_1) ... (FILE_OR_DIR_N) ``` Examples: ``` -./code2svg.sh example/code-2-svg.xml example/Alpha3CountryCode-lf.ddd -./code2svg.sh example/code-2-svg.xml example/ +./code2svg.sh example/code-2-svg.xml example example/Alpha3CountryCode-lf.ddd +./code2svg.sh example/code-2-svg.xml example example/ ``` **Tip:** You can just execute the file ``./code2svg-example.sh`` without any arguments to run the above sample. @@ -29,13 +29,13 @@ https://github.com/fuinorg/code2svg/releases Execute the batch file to start the conversion: ``` -code2svg.bat CONFIG_NAME FILE_OR_DIR_1 ... FILE_OR_DIR_N +code2svg.bat (CONFIG_NAME) (TARGET_DIR) (FILE_OR_DIR_1) ... (FILE_OR_DIR_N) ``` Examples: ``` -code2svg.bat example/code-2-svg.xml example/Alpha3CountryCode-crlf.ddd -code2svg.bat example/code-2-svg.xml example/ +code2svg.bat example/code-2-svg.xml example example/Alpha3CountryCode-crlf.ddd +code2svg.bat example/code-2-svg.xml example example/ ``` **Tip:** You can just execute the file ``code2svg-example.bat`` without any arguments to run the above sample. diff --git a/app/src/main/app/code2svg-example.bat b/app/src/main/app/code2svg-example.bat index a32b9ed..63a8bae 100644 --- a/app/src/main/app/code2svg-example.bat +++ b/app/src/main/app/code2svg-example.bat @@ -1,2 +1,2 @@ -java -classpath *;lib/* org.fuin.code2svg.app.Code2SvgApp example/code-2-svg.xml example/Alpha3CountryCode-crlf.ddd +java -classpath *;lib/* org.fuin.code2svg.app.Code2SvgApp example example/code-2-svg.xml example/Alpha3CountryCode-crlf.ddd ECHO "Converted 'example/Alpha3CountryCode-crlf.ddd' to 'example/Alpha3CountryCode-crlf.ddd.svg'" \ No newline at end of file diff --git a/app/src/main/app/code2svg-example.sh b/app/src/main/app/code2svg-example.sh index 21ee712..dac2eb5 100644 --- a/app/src/main/app/code2svg-example.sh +++ b/app/src/main/app/code2svg-example.sh @@ -1,3 +1,3 @@ #!/bin/bash -java -classpath *:lib/* org.fuin.code2svg.app.Code2SvgApp example/code-2-svg.xml example/Alpha3CountryCode-lf.ddd -echo "Converted 'example/Alpha3CountryCode-lf.ddd' to 'example/Alpha3CountryCode-lf.ddd.svg'" \ No newline at end of file +java -classpath *:lib/* org.fuin.code2svg.app.Code2SvgApp example/code-2-svg.xml example example/Alpha3CountryCode-lf.ddd +echo "Converted 'example/Alpha3CountryCode-lf.ddd' to 'example/Alpha3CountryCode-lf.ddd.svg'" diff --git a/app/src/main/java/org/fuin/code2svg/app/Code2SvgApp.java b/app/src/main/java/org/fuin/code2svg/app/Code2SvgApp.java index 9ac2aff..d437275 100644 --- a/app/src/main/java/org/fuin/code2svg/app/Code2SvgApp.java +++ b/app/src/main/java/org/fuin/code2svg/app/Code2SvgApp.java @@ -21,6 +21,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; +import java.util.List; import org.fuin.code2svg.core.Code2Svg; import org.fuin.code2svg.core.Code2SvgConfig; @@ -47,20 +48,20 @@ private static URL url(File file) { } } - private static void execute(final File configFile, final File targetDir, final String[] args) { + private static void execute(final File configFile, final File targetDir, final List filenames) { final String configXml = Utils4J.readAsString(url(configFile), "utf-8", 1024); final Code2SvgConfig config = JaxbUtils.unmarshal(configXml, Code2SvgUtils.JAXB_CLASSES); final Code2Svg converter = new Code2Svg(); - for (int i = 1; i < args.length; i++) { - final File file = new File(args[i]); + filenames.forEach( filename -> { + final File file = new File(filename); if (file.isDirectory()) { converter.convertDir(config, file, targetDir); } else { converter.convertFile(config, file.getParentFile(), file, targetDir); } - } + }); } @@ -70,7 +71,7 @@ public static void main(String[] args) { System.out.println("Required arguments: ... "); System.exit(1); } - + try { new LogbackStandalone().init(new File("code2svg"), new NewLogConfigFileParams("org.fuin.code2svg.app", "code2svg")); LOG.info("Application running..."); @@ -79,13 +80,13 @@ public static void main(String[] args) { Utils4J.checkValidFile(configFile); final File targetDir = new File(args[1]); Utils4J.checkValidDir(targetDir); - final String[] args2 = Arrays.copyOfRange(args, 2, args.length - 1); + final List filenames = Arrays.asList(Arrays.copyOfRange(args, 2, args.length)); LOG.info("configFile={}", configFile); LOG.info("targetDir={}", targetDir); - LOG.info("args2={}", Arrays.asList(args2)); + LOG.info("filenames={}", filenames); - execute(configFile, targetDir, args2); + execute(configFile, targetDir, filenames); System.exit(0);