Clean up file output handling (#1895)

* Clean up file output handling

This attempts to normalize all generators to use OS agnostic
File.separator.

It also cleans up some areas in code where we replace "." in full file
output path with File.separator. We should only be modifying directory
names we own, and should avoid modifying anything that can be provided
by a user.

It would probably be better to use Paths.get(…).toString() in all cases.

* Fix missed path separators in java codegen

* Adjust Java codegen path replacements

* Convert / in full path replacements, as / is forbidden in Windows, and noop elsewhere

* Use Paths.get where files are written, to better handle Windows path constraints
This commit is contained in:
Jim Schubert
2019-01-14 09:49:39 -05:00
committed by William Cheng
parent d2769e646e
commit db9102a440
16 changed files with 40 additions and 36 deletions

View File

@@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
@@ -65,7 +66,7 @@ public class ConfigHelp implements Runnable {
generatePlainTextHelp(sb, config);
if (!isEmpty(outputFile)) {
File out = new File(outputFile);
File out = Paths.get(outputFile).toFile();
//noinspection ResultOfMethodCallIgnored
out.mkdirs();