Moved Paths.transformFileToAbsolutePath to MorePaths.
Summary: No point in using java.nio.text.Paths in this one, so just moving it to the new utility class.
Test Plan: ant clean test
diff --git a/src/com/facebook/buck/android/DxStep.java b/src/com/facebook/buck/android/DxStep.java
index 089fa28..23866bf 100644
--- a/src/com/facebook/buck/android/DxStep.java
+++ b/src/com/facebook/buck/android/DxStep.java
@@ -19,24 +19,26 @@
import com.facebook.buck.shell.ShellStep;
import com.facebook.buck.step.ExecutionContext;
import com.facebook.buck.util.AndroidPlatformTarget;
+import com.facebook.buck.util.ProjectFilesystem;
import com.facebook.buck.util.Verbosity;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import java.nio.file.Path;
import java.util.Set;
public class DxStep extends ShellStep {
private final String outputDexFile;
- private final Set<String> filesToDex;
+ private final Set<Path> filesToDex;
/**
* @param outputDexFile path to the file where the generated classes.dex should go
* @param filesToDex each element in this set is a path to a .class file, a zip file of .class
* files, or a directory of .class files
*/
- public DxStep(String outputDexFile, Iterable<String> filesToDex) {
+ public DxStep(String outputDexFile, Iterable<Path> filesToDex) {
this.outputDexFile = Preconditions.checkNotNull(outputDexFile);
this.filesToDex = ImmutableSet.copyOf(filesToDex);
}
@@ -60,8 +62,9 @@
}
builder.add("--output", outputDexFile);
- for (String fileToDex : filesToDex) {
- builder.add(fileToDex);
+ ProjectFilesystem projectFilesystem = context.getProjectFilesystem();
+ for (Path fileToDex : filesToDex) {
+ builder.add(projectFilesystem.resolve(fileToDex).toString());
}
return builder.build();
diff --git a/src/com/facebook/buck/android/ProGuardObfuscateStep.java b/src/com/facebook/buck/android/ProGuardObfuscateStep.java
index 7644019..ec5c682 100644
--- a/src/com/facebook/buck/android/ProGuardObfuscateStep.java
+++ b/src/com/facebook/buck/android/ProGuardObfuscateStep.java
@@ -23,10 +23,10 @@
import com.facebook.buck.step.ExecutionContext;
import com.facebook.buck.step.Step;
import com.facebook.buck.util.AndroidPlatformTarget;
-import com.facebook.buck.util.Functions;
import com.facebook.buck.zip.CustomZipOutputStream;
import com.facebook.buck.zip.ZipOutputStreams;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Functions;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
@@ -267,7 +267,8 @@
// -libraryjars
Iterable<String> bootclasspathPaths = Iterables.transform(
- androidPlatformTarget.getBootclasspathEntries(), Functions.FILE_TO_ABSOLUTE_PATH);
+ androidPlatformTarget.getBootclasspathEntries(),
+ Functions.toStringFunction());
Iterable<String> libraryJars = Iterables.concat(bootclasspathPaths,
additionalLibraryJarsForProguard);
args.add("-libraryjars").add(pathJoiner.join(libraryJars));
diff --git a/src/com/facebook/buck/android/SmartDexingStep.java b/src/com/facebook/buck/android/SmartDexingStep.java
index b08245b..fc41a9d 100644
--- a/src/com/facebook/buck/android/SmartDexingStep.java
+++ b/src/com/facebook/buck/android/SmartDexingStep.java
@@ -27,7 +27,6 @@
import com.facebook.buck.step.fs.RmStep;
import com.facebook.buck.step.fs.WriteFileStep;
import com.facebook.buck.step.fs.XzStep;
-import com.facebook.buck.util.Paths;
import com.facebook.buck.util.ProjectFilesystem;
import com.facebook.buck.zip.RepackZipEntriesStep;
import com.facebook.buck.zip.ZipStep;
@@ -38,7 +37,6 @@
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
-import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
@@ -54,7 +52,6 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
-import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executors;
@@ -236,7 +233,13 @@
// the outside world (commands generally seen as external, and rules are generated by parsing
// JSON input).
pseudoRules.add(new DxPseudoRule(context,
- ImmutableSet.copyOf(Paths.transformFileToAbsolutePath(outputToInputs.get(outputFile))),
+ ImmutableSet.copyOf(Iterables.transform(outputToInputs.get(outputFile), new Function<File, Path>() {
+
+ @Override
+ public Path apply(File input) {
+ return input.toPath();
+ }
+ })),
outputFile.getPath(),
context.getProjectFilesystem().resolve(successDir.resolve(outputFile.getName()))));
}
@@ -334,13 +337,13 @@
@VisibleForTesting
static class DxPseudoRule {
private final ExecutionContext context;
- private final Set<String> srcs;
+ private final Set<Path> srcs;
private final String outputPath;
private final Path outputHashPath;
private String newInputsHash;
public DxPseudoRule(ExecutionContext context,
- Set<String> srcs,
+ Set<Path> srcs,
String outputPath,
Path outputHashPath) {
this.context = Preconditions.checkNotNull(context);
@@ -383,14 +386,7 @@
// entry contents but change on disk due to entry metadata.
ClasspathTraverser traverser = new DefaultClasspathTraverser();
try {
- Collection<Path> paths = FluentIterable.from(srcs)
- .transform(new Function<String, Path>() {
- @Override
- public Path apply(String input) {
- return java.nio.file.Paths.get(input);
- }
- }).toList();
- traverser.traverse(new ClasspathTraversal(paths) {
+ traverser.traverse(new ClasspathTraversal(srcs) {
@Override
public void visit(FileLike fileLike) {
try {
diff --git a/src/com/facebook/buck/java/JUnitStep.java b/src/com/facebook/buck/java/JUnitStep.java
index ff67de0..1465e68 100644
--- a/src/com/facebook/buck/java/JUnitStep.java
+++ b/src/com/facebook/buck/java/JUnitStep.java
@@ -28,6 +28,7 @@
import com.google.common.collect.Lists;
import java.io.File;
+import java.nio.file.Path;
import java.util.List;
import java.util.Set;
@@ -149,8 +150,8 @@
// Next, add the bootclasspath entries specific to the Android platform being targeted.
if (context.getAndroidPlatformTargetOptional().isPresent()) {
AndroidPlatformTarget androidPlatformTarget = context.getAndroidPlatformTarget();
- for (File bootclasspathEntry : androidPlatformTarget.getBootclasspathEntries()) {
- classpath.add(bootclasspathEntry.getAbsolutePath());
+ for (Path bootclasspathEntry : androidPlatformTarget.getBootclasspathEntries()) {
+ classpath.add(bootclasspathEntry.toString());
}
}
diff --git a/src/com/facebook/buck/rules/BuildContext.java b/src/com/facebook/buck/rules/BuildContext.java
index e5ed128..e4e7efd 100644
--- a/src/com/facebook/buck/rules/BuildContext.java
+++ b/src/com/facebook/buck/rules/BuildContext.java
@@ -32,7 +32,6 @@
import com.google.common.base.Suppliers;
import com.google.common.util.concurrent.ListeningExecutorService;
-import java.io.File;
import java.nio.file.Path;
import java.util.List;
@@ -245,7 +244,7 @@
@Override
@Nullable
public String get() {
- List<File> bootclasspathEntries = androidPlatformTarget.getBootclasspathEntries();
+ List<Path> bootclasspathEntries = androidPlatformTarget.getBootclasspathEntries();
Preconditions.checkState(!bootclasspathEntries.isEmpty(),
"There should be entries for the bootclasspath");
return Joiner.on(":").join(bootclasspathEntries);
diff --git a/src/com/facebook/buck/util/AndroidPlatformTarget.java b/src/com/facebook/buck/util/AndroidPlatformTarget.java
index f233aa6..09c70c0 100644
--- a/src/com/facebook/buck/util/AndroidPlatformTarget.java
+++ b/src/com/facebook/buck/util/AndroidPlatformTarget.java
@@ -29,6 +29,7 @@
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
+import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
@@ -48,7 +49,7 @@
private final String name;
private final File androidJar;
- private final List<File> bootclasspathEntries;
+ private final List<Path> bootclasspathEntries;
private final File aaptExecutable;
private final File adbExecutable;
private final File aidlExecutable;
@@ -62,7 +63,7 @@
private AndroidPlatformTarget(
String name,
File androidJar,
- List<File> bootclasspathEntries,
+ List<Path> bootclasspathEntries,
File aaptExecutable,
File adbExecutable,
File aidlExecutable,
@@ -99,7 +100,10 @@
return androidJar;
}
- public List<File> getBootclasspathEntries() {
+ /**
+ * @return bootclasspath entries as absolute {@link Path}s
+ */
+ public List<Path> getBootclasspathEntries() {
return bootclasspathEntries;
}
@@ -175,15 +179,15 @@
* Resolves all of the jarPaths against the androidSdkDir path.
* @return a mutable list
*/
- private static LinkedList<File> resolvePaths(final File androidSdkDir, Set<String> jarPaths) {
- return Lists.newLinkedList(Iterables.transform(jarPaths, new Function<String, File>() {
+ private static LinkedList<Path> resolvePaths(final File androidSdkDir, Set<String> jarPaths) {
+ return Lists.newLinkedList(Iterables.transform(jarPaths, new Function<String, Path>() {
@Override
- public File apply(String jarPath) {
+ public Path apply(String jarPath) {
File jar = new File(androidSdkDir, jarPath);
if (!jar.isFile()) {
throw new RuntimeException("File not found: " + jar.getAbsolutePath());
}
- return jar;
+ return jar.toPath();
}
}));
}
@@ -199,12 +203,15 @@
File androidSdkDir,
String platformDirectoryPath,
Set<String> additionalJarPaths) {
+ if (!androidSdkDir.isAbsolute()) {
+ throw new HumanReadableException("Path to Android SDK must be absolute but was: %s.", androidSdkDir);
+ }
File platformDirectory = new File(androidSdkDir, platformDirectoryPath);
File androidJar = new File(platformDirectory, "android.jar");
- LinkedList<File> bootclasspathEntries = resolvePaths(androidSdkDir, additionalJarPaths);
+ LinkedList<Path> bootclasspathEntries = resolvePaths(androidSdkDir, additionalJarPaths);
// Make sure android.jar is at the front of the bootclasspath.
- bootclasspathEntries.addFirst(androidJar);
+ bootclasspathEntries.addFirst(androidJar.toPath());
File buildToolsDir = new File(androidSdkDir, "build-tools");
diff --git a/src/com/facebook/buck/util/Functions.java b/src/com/facebook/buck/util/Functions.java
deleted file mode 100644
index c817389..0000000
--- a/src/com/facebook/buck/util/Functions.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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 com.google.common.base.Function;
-
-import java.io.File;
-
-public final class Functions {
-
- /** Utility class: do not instantiate. */
- private Functions() {}
-
- public static Function<File, String> FILE_TO_ABSOLUTE_PATH = new Function<File, String>() {
- @Override
- public String apply(File file) {
- return file.getAbsolutePath();
- }
- };
-
-}
diff --git a/src/com/facebook/buck/util/Paths.java b/src/com/facebook/buck/util/Paths.java
index e71f6a9..3a685e4 100644
--- a/src/com/facebook/buck/util/Paths.java
+++ b/src/com/facebook/buck/util/Paths.java
@@ -16,18 +16,10 @@
package com.facebook.buck.util;
-import com.google.common.collect.Iterables;
-
-import java.io.File;
-
public class Paths {
private Paths() {}
- public static Iterable<String> transformFileToAbsolutePath(Iterable<File> files) {
- return Iterables.transform(files, Functions.FILE_TO_ABSOLUTE_PATH);
- }
-
/**
* Returns normalized path. On Windows \ will be replaced with /.
* @return Normalized path
diff --git a/test/com/facebook/buck/android/SmartDexingStepTest.java b/test/com/facebook/buck/android/SmartDexingStepTest.java
index 29ce2e9..02a13f6 100644
--- a/test/com/facebook/buck/android/SmartDexingStepTest.java
+++ b/test/com/facebook/buck/android/SmartDexingStepTest.java
@@ -118,7 +118,7 @@
Path outputHashFile = new File(tmpDir.getRoot(), "out.dex.hash").toPath();
Files.write("dummy", outputHashFile.toFile(), Charsets.UTF_8);
- DxPseudoRule rule = new DxPseudoRule(context, ImmutableSet.of(testIn.getPath()),
+ DxPseudoRule rule = new DxPseudoRule(context, ImmutableSet.of(testIn.toPath()),
outputFile.getPath(), outputHashFile);
assertFalse("'dummy' is not a matching input hash", rule.checkIsCached());
diff --git a/test/com/facebook/buck/java/DefaultJavaLibraryRuleTest.java b/test/com/facebook/buck/java/DefaultJavaLibraryRuleTest.java
index afe1292..8baffea 100644
--- a/test/com/facebook/buck/java/DefaultJavaLibraryRuleTest.java
+++ b/test/com/facebook/buck/java/DefaultJavaLibraryRuleTest.java
@@ -89,6 +89,8 @@
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -778,9 +780,9 @@
@Nullable String bootclasspath,
@Nullable ProjectFilesystem projectFilesystem) {
AndroidPlatformTarget platformTarget = EasyMock.createMock(AndroidPlatformTarget.class);
- ImmutableList<File> bootclasspathEntries = (bootclasspath == null)
- ? ImmutableList.<File>of(new File("I am not used"))
- : ImmutableList.of(new File(bootclasspath));
+ ImmutableList<Path> bootclasspathEntries = (bootclasspath == null)
+ ? ImmutableList.<Path>of(Paths.get("I am not used"))
+ : ImmutableList.of(Paths.get(bootclasspath));
EasyMock.expect(platformTarget.getBootclasspathEntries()).andReturn(bootclasspathEntries)
.anyTimes();
replay(platformTarget);
diff --git a/test/com/facebook/buck/rules/BuildContextTest.java b/test/com/facebook/buck/rules/BuildContextTest.java
index 1b66822..a27cdff 100644
--- a/test/com/facebook/buck/rules/BuildContextTest.java
+++ b/test/com/facebook/buck/rules/BuildContextTest.java
@@ -23,7 +23,6 @@
import com.facebook.buck.testutil.TestConsole;
import com.facebook.buck.util.AndroidPlatformTarget;
import com.facebook.buck.util.HumanReadableException;
-import com.facebook.buck.util.Paths;
import com.facebook.buck.util.ProjectFilesystem;
import com.facebook.buck.util.Verbosity;
import com.google.common.base.Optional;
@@ -33,7 +32,8 @@
import org.easymock.EasyMock;
import org.junit.Test;
-import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.List;
public class BuildContextTest {
@@ -51,10 +51,10 @@
builder.setEventBus(BuckEventBusFactory.newInstance());
AndroidPlatformTarget androidPlatformTarget = EasyMock.createMock(AndroidPlatformTarget.class);
- List<File> entries = ImmutableList.of(
- new File("add-ons/addon-google_apis-google-15/libs/effects.jar"),
- new File("add-ons/addon-google_apis-google-15/libs/maps.jar"),
- new File("add-ons/addon-google_apis-google-15/libs/usb.jar"));
+ List<Path> entries = ImmutableList.of(
+ Paths.get("add-ons/addon-google_apis-google-15/libs/effects.jar"),
+ Paths.get("add-ons/addon-google_apis-google-15/libs/maps.jar"),
+ Paths.get("add-ons/addon-google_apis-google-15/libs/usb.jar"));
EasyMock.expect(androidPlatformTarget.getBootclasspathEntries()).andReturn(entries);
EasyMock.replay(androidPlatformTarget);
@@ -64,7 +64,8 @@
BuildContext context = builder.build();
Supplier<String> androidBootclasspathSupplier = context.getAndroidBootclasspathSupplier();
- String androidBootclasspath = Paths.normalizePathSeparator(androidBootclasspathSupplier.get());
+ String androidBootclasspath = com.facebook.buck.util.Paths.normalizePathSeparator(
+ androidBootclasspathSupplier.get());
assertEquals(
"add-ons/addon-google_apis-google-15/libs/effects.jar:" +
"add-ons/addon-google_apis-google-15/libs/maps.jar:" +
diff --git a/test/com/facebook/buck/util/AndroidPlatformTargetTest.java b/test/com/facebook/buck/util/AndroidPlatformTargetTest.java
index bcdf058..43f67bf 100644
--- a/test/com/facebook/buck/util/AndroidPlatformTargetTest.java
+++ b/test/com/facebook/buck/util/AndroidPlatformTargetTest.java
@@ -46,7 +46,7 @@
.createFromDefaultDirectoryStructure(
name, androidSdkDir, platformDirectoryPath, additionalJarPaths);
assertEquals(name, androidPlatformTarget.getName());
- assertEquals(ImmutableList.of(new File("/home/android/platforms/android-16/android.jar")),
+ assertEquals(ImmutableList.of(java.nio.file.Paths.get("/home/android/platforms/android-16/android.jar")),
androidPlatformTarget.getBootclasspathEntries());
assertEquals(new File("/home/android/platforms/android-16/android.jar"),
androidPlatformTarget.getAndroidJar());
@@ -88,10 +88,10 @@
assertEquals(platformId, androidPlatformTarget.getName());
assertEquals(
ImmutableList.of(
- new File(androidSdkDir, "platforms/android-17/android.jar"),
- new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/effects.jar"),
- new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/maps.jar"),
- new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/usb.jar")),
+ MorePaths.newPathInstance(new File(androidSdkDir, "platforms/android-17/android.jar")),
+ MorePaths.newPathInstance(new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/effects.jar")),
+ MorePaths.newPathInstance(new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/maps.jar")),
+ MorePaths.newPathInstance(new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/usb.jar"))),
androidPlatformTarget.getBootclasspathEntries());
assertEquals(new File(androidSdkDir, "platforms/android-17/android.jar"),
androidPlatformTarget.getAndroidJar());
@@ -129,10 +129,10 @@
assertEquals(platformId, androidPlatformTarget.getName());
assertEquals(
ImmutableList.of(
- new File(androidSdkDir, "platforms/android-17/android.jar"),
- new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/effects.jar"),
- new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/maps.jar"),
- new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/usb.jar")),
+ MorePaths.newPathInstance(new File(androidSdkDir, "platforms/android-17/android.jar")),
+ MorePaths.newPathInstance(new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/effects.jar")),
+ MorePaths.newPathInstance(new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/maps.jar")),
+ MorePaths.newPathInstance(new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs/usb.jar"))),
androidPlatformTarget.getBootclasspathEntries());
assertEquals(new File(androidSdkDir, "platforms/android-17/android.jar"),
androidPlatformTarget.getAndroidJar());