Skip to content

Commit 485ce41

Browse files
committed
simplify stencil.fs.unix-path
1 parent 8adaa8b commit 485ce41

File tree

2 files changed

+7
-28
lines changed

2 files changed

+7
-28
lines changed

java-src/io/github/erdos/stencil/impl/FileHelper.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import java.io.File;
44
import java.io.IOException;
5-
import java.nio.file.FileSystems;
6-
import java.nio.file.Path;
75
import java.util.UUID;
8-
import java.util.regex.Pattern;
96

107
import static java.lang.System.getProperty;
118

@@ -101,29 +98,6 @@ public static void forceDelete(final File file) {
10198
file.delete();
10299
}
103100

104-
/**
105-
* Returns a string representation of path with unix separators ("/") instead of the
106-
* system-dependent separators (which is backslash on Windows).
107-
*
108-
* @param path not null path object
109-
* @return string of path with slash separators
110-
* @throws IllegalArgumentException if path is null
111-
*/
112-
public static String toUnixSeparatedString(Path path) {
113-
if (path == null) {
114-
throw new IllegalArgumentException("Path must not be null!");
115-
} else {
116-
final String separator = FileSystems.getDefault().getSeparator();
117-
if (separator.equals("/")) {
118-
// on unix systems
119-
return path.toString();
120-
} else {
121-
// on Windows systems we replace backslash with slashes
122-
return path.toString().replaceAll(Pattern.quote(separator), "/");
123-
}
124-
}
125-
}
126-
127101
private static <T> T requireNonNullElse(T first, T second) {
128102
return first == null ? second : first;
129103
}

src/stencil/fs.clj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
(defn directory? [^File file]
1111
(.isDirectory file))
1212

13-
(defn unix-path ^String [^File f]
14-
(some-> f .toPath FileHelper/toUnixSeparatedString))
13+
(defn unix-path
14+
"Returns a string representation of path with unix separators ('/')
15+
instead of the system-dependent separators (which is backslash on Windows)."
16+
^String [^File f]
17+
(when f
18+
(let [path (.toPath f)]
19+
(.replace (str path) (.getSeparator (.getFileSystem path)) "/"))))
1520

1621
(defn parent-file ^File [^File f]
1722
(.getParentFile f))

0 commit comments

Comments
 (0)