Improve input checking for command line execution
Environment Details
- Transformer Version: 0.5.0
- JDK version: openjdk 11.0.12
- OS: Red Hat Enterprise Linux 7.4
Problem Description
By adding validation of input values, I want users to be aware of the following two input errors before running the conversion process.
- If an empty string "" is specified in the argument, the current directory is treated as the input or output path. However, when specifying the current directory as the input value, many users specify dot(.). So specifying consecutive double quotes "" are almost always a typo. Also, as described in the Steps to reproduce, the log becomes difficult to understand. Therefore, it is better to introduce validation of empty strings.
- If three or more arguments are specified incorrectly, command execution does not result in an error. Therefore, there is a risk of overwriting the original file by mistakenly specifying the argument. For example, if the -o option is specified, the first and second arguments incorrectly specify the original conversion target, and the third argument specifies the destination file, the original conversion target will be overwritten. This type of operation error can be prevented by adding an argument count validation process.
Steps to reproduce
# java -jar org.eclipse.transformer.cli/target/org.eclipse.transformer.cli-0.5.0-
SNAPSHOT.jar /work/transformer/test ""
Copyright (c) Contributors to the Eclipse Foundation
org.eclipse.transformer.cli.JakartaTransformerCLI Version [ 0.5.0-SNAPSHOT ]
[main] INFO Transformer - Input [ /work/transformer/test ]
[main] INFO Transformer - Output [ /home/k5user/Github/11rx4f/transformer ]
# java -jar org.eclipse.transformer.cli/target/org.eclipse.transformer.cli-0.5.0-SNAPSHOT.jar /work/transformer/test/TestServlet.java /work/transformer/test/TestServlet.java /work/transformer/test/TestServlet.java -o
Copyright (c) Contributors to the Eclipse Foundation
org.eclipse.transformer.cli.JakartaTransformerCLI Version [ 0.5.0-SNAPSHOT ]
[main] INFO Transformer - Input [ /work/transformer/test/TestServlet.java ]
[main] INFO Transformer - Output [ /work/transformer/test/TestServlet.java ]
[main] INFO Transformer - Overwrite of output is enabled
[main] INFO Transformer - Output exists and will be overwritten [ /work/transformer/test/TestServlet.java ]
Cause
There is not enough input value check for both problems.
-
Checking empty string does not exist. https://github.com/eclipse/transformer/blob/2411075cc0413f4a3aa36a21c360d780dc55555c/org.eclipse.transformer/src/main/java/org/eclipse/transformer/Transformer.java#L946-L949 https://github.com/eclipse/transformer/blob/2411075cc0413f4a3aa36a21c360d780dc55555c/org.eclipse.transformer/src/main/java/org/eclipse/transformer/Transformer.java#L969
-
Checking the number of arguments does not exist. https://github.com/eclipse/transformer/blob/2411075cc0413f4a3aa36a21c360d780dc55555c/org.eclipse.transformer.cli/src/main/java/org/eclipse/transformer/cli/TransformerCLI.java#L366-L379