Start removing Paths.normalizePathSeparators.
Summary:
Starting to remove Paths.normalizePathSeparators. It seems like a
PathUtils class will still be needed, however.
Test Plan: Ran AndroidBinaryRuleTest JUnit tests. Ran 'ant clean test'.
diff --git a/src/com/facebook/buck/android/AndroidBinaryRule.java b/src/com/facebook/buck/android/AndroidBinaryRule.java
index ce7f141..052eafa 100644
--- a/src/com/facebook/buck/android/AndroidBinaryRule.java
+++ b/src/com/facebook/buck/android/AndroidBinaryRule.java
@@ -59,6 +59,7 @@
import com.facebook.buck.util.DirectoryTraversal;
import com.facebook.buck.util.DirectoryTraverser;
import com.facebook.buck.util.HumanReadableException;
+import com.facebook.buck.util.MorePaths;
import com.facebook.buck.util.Paths;
import com.facebook.buck.zip.RepackZipEntriesStep;
import com.facebook.buck.zip.ZipDirectoryWithMaxDeflateStep;
@@ -670,8 +671,8 @@
for (Map.Entry<String, File> entry : allAssets.build().entrySet()) {
commands.add(new MkdirAndSymlinkFileStep(
- Paths.normalizePathSeparator(entry.getValue().getPath()),
- Paths.normalizePathSeparator(destinationDirectory + "/" + entry.getKey())));
+ MorePaths.newPathInstance(entry.getValue()).toString(),
+ MorePaths.newPathInstance(destinationDirectory + "/" + entry.getKey()).toString()));
}
return Optional.of(destination);
diff --git a/src/com/facebook/buck/util/MorePaths.java b/src/com/facebook/buck/util/MorePaths.java
new file mode 100644
index 0000000..a71d8f8
--- /dev/null
+++ b/src/com/facebook/buck/util/MorePaths.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2012-present Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.facebook.buck.util;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public final class MorePaths {
+ // Utility class: do not instantiate.
+ private MorePaths() {}
+
+ public static Path newPathInstance(String path) {
+ return separatorsToUnix(path);
+ }
+
+ public static Path newPathInstance(File file) {
+ return separatorsToUnix(file.getPath());
+ }
+
+ /**
+ * @return The path using UNIX path separators.
+ */
+ public static Path separatorsToUnix(String path) {
+ return Paths.get(path.replace(File.separator, "/")).normalize();
+ }
+
+ /**
+ * @return The path using UNIX path separators.
+ */
+ public static Path separatorsToUnix(Path path) {
+ return separatorsToUnix(path.toString());
+ }
+}
diff --git a/test/com/facebook/buck/android/AndroidBinaryRuleTest.java b/test/com/facebook/buck/android/AndroidBinaryRuleTest.java
index 65296b2..131c330 100644
--- a/test/com/facebook/buck/android/AndroidBinaryRuleTest.java
+++ b/test/com/facebook/buck/android/AndroidBinaryRuleTest.java
@@ -47,7 +47,7 @@
import com.facebook.buck.testutil.RuleMap;
import com.facebook.buck.util.DirectoryTraversal;
import com.facebook.buck.util.DirectoryTraverser;
-import com.facebook.buck.util.Paths;
+import com.facebook.buck.util.MorePaths;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
@@ -250,7 +250,7 @@
DirectoryTraverser traverser = new DirectoryTraverser() {
@Override
public void traverse(DirectoryTraversal traversal) throws IOException {
- String rootPath = Paths.normalizePathSeparator(traversal.getRoot().getPath());
+ String rootPath = MorePaths.newPathInstance(traversal.getRoot()).toString();
if ("java/src/com/facebook/base/assets2".equals(rootPath)) {
traversal.visit(
new File("java/src/com/facebook/base/assets2",
@@ -327,7 +327,7 @@
DirectoryTraverser traverser = new DirectoryTraverser() {
@Override
public void traverse(DirectoryTraversal traversal) throws IOException {
- String rootPath = Paths.normalizePathSeparator(traversal.getRoot().getPath());
+ String rootPath = MorePaths.newPathInstance(traversal.getRoot()).toString();
if ("java/src/com/facebook/base/assets1".equals(rootPath)) {
traversal.visit(
new File("java/src/com/facebook/base/assets1",