summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Lamarche <benoitlamarche@google.com>2014-11-12 16:20:13 +0100
committerBenoit Lamarche <benoitlamarche@google.com>2014-11-12 18:27:26 +0100
commit5ec3a480f0126281fcca381d75911e07a79885ee (patch)
treee7301b25c70541eaf60102dd43aaec855815e12f
parentd3140c3902cd59af9b1393b3e29be55bf0bda345 (diff)
downloadtoolchain_jack-5ec3a480f0126281fcca381d75911e07a79885ee.zip
toolchain_jack-5ec3a480f0126281fcca381d75911e07a79885ee.tar.gz
toolchain_jack-5ec3a480f0126281fcca381d75911e07a79885ee.tar.bz2
Add support for suffixes and prefixes in VPath
Change-Id: If6c6e370d3de04021679a4c441d7650276f5264e
-rw-r--r--jack/src/com/android/jack/library/v0000/InputJackLibraryImpl.java4
-rw-r--r--jack/src/com/android/jack/library/v0000/OutputJackLibraryImpl.java4
-rw-r--r--jack/src/com/android/jack/library/v0001/InputJackLibraryImpl.java4
-rw-r--r--jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java4
-rw-r--r--sched/src/com/android/sched/vfs/VPath.java118
5 files changed, 100 insertions, 34 deletions
diff --git a/jack/src/com/android/jack/library/v0000/InputJackLibraryImpl.java b/jack/src/com/android/jack/library/v0000/InputJackLibraryImpl.java
index a98ce61..d8fb7ca 100644
--- a/jack/src/com/android/jack/library/v0000/InputJackLibraryImpl.java
+++ b/jack/src/com/android/jack/library/v0000/InputJackLibraryImpl.java
@@ -98,8 +98,8 @@ public class InputJackLibraryImpl extends InputJackLibrary {
public InputVFile getFile(@Nonnull FileType fileType, @Nonnull VPath typePath)
throws FileTypeDoesNotExistException {
try {
- return libraryVDir.getInputVFile(
- new VPath(typePath.getPathAsString('/') + fileType.getFileExtension(), '/'));
+ typePath.addSuffix(fileType.getFileExtension());
+ return libraryVDir.getInputVFile(typePath);
} catch (NotFileOrDirectoryException e) {
throw new FileTypeDoesNotExistException(getLocation(), typePath, fileType);
}
diff --git a/jack/src/com/android/jack/library/v0000/OutputJackLibraryImpl.java b/jack/src/com/android/jack/library/v0000/OutputJackLibraryImpl.java
index 84752bd..31df262 100644
--- a/jack/src/com/android/jack/library/v0000/OutputJackLibraryImpl.java
+++ b/jack/src/com/android/jack/library/v0000/OutputJackLibraryImpl.java
@@ -81,8 +81,8 @@ public class OutputJackLibraryImpl extends OutputJackLibrary {
public OutputVFile createFile(@Nonnull FileType fileType, @Nonnull VPath typePath)
throws CannotCreateFileException {
putProperty(fileType.getPropertyName(), String.valueOf(true));
- return outputVDir.createOutputVFile(
- new VPath(typePath.getPathAsString('/') + fileType.getFileExtension(), '/'));
+ typePath.addSuffix(fileType.getFileExtension());
+ return outputVDir.createOutputVFile(typePath);
}
@Override
diff --git a/jack/src/com/android/jack/library/v0001/InputJackLibraryImpl.java b/jack/src/com/android/jack/library/v0001/InputJackLibraryImpl.java
index 8222359..27742c7 100644
--- a/jack/src/com/android/jack/library/v0001/InputJackLibraryImpl.java
+++ b/jack/src/com/android/jack/library/v0001/InputJackLibraryImpl.java
@@ -98,8 +98,8 @@ public class InputJackLibraryImpl extends InputJackLibrary {
public InputVFile getFile(@Nonnull FileType fileType, @Nonnull VPath typePath)
throws FileTypeDoesNotExistException {
try {
- return libraryVDir.getInputVFile(
- new VPath(typePath.getPathAsString('/') + fileType.getFileExtension(), '/'));
+ typePath.addSuffix(fileType.getFileExtension());
+ return libraryVDir.getInputVFile(typePath);
} catch (NotFileOrDirectoryException e) {
throw new FileTypeDoesNotExistException(getLocation(), typePath, fileType);
}
diff --git a/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java b/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java
index e1a548f..30b12a4 100644
--- a/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java
+++ b/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java
@@ -82,8 +82,8 @@ public class OutputJackLibraryImpl extends OutputJackLibrary {
public OutputVFile createFile(@Nonnull FileType fileType, @Nonnull VPath typePath)
throws CannotCreateFileException {
putProperty(fileType.getPropertyName(), String.valueOf(true));
- return outputVDir.createOutputVFile(
- new VPath(typePath.getPathAsString('/') + fileType.getFileExtension(), '/'));
+ typePath.addSuffix(fileType.getFileExtension());
+ return outputVDir.createOutputVFile(typePath);
}
@Override
public boolean needsSequentialWriting() {
diff --git a/sched/src/com/android/sched/vfs/VPath.java b/sched/src/com/android/sched/vfs/VPath.java
index 13232a5..20f374d 100644
--- a/sched/src/com/android/sched/vfs/VPath.java
+++ b/sched/src/com/android/sched/vfs/VPath.java
@@ -18,6 +18,9 @@ package com.android.sched.vfs;
import com.google.common.base.Splitter;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.annotation.Nonnull;
/**
@@ -26,10 +29,10 @@ import javax.annotation.Nonnull;
*/
public final class VPath {
- @Nonnull
- private final CharSequence path;
+ private static final char INTERNAL_SEPARATOR = '/';
- private final char separator;
+ @Nonnull
+ List<VPathFragment> pathFragments;
/**
* Creates an instance of VFS-relative path. The {@link CharSequence} is evaluated lazily at each
@@ -39,25 +42,42 @@ public final class VPath {
* @param separator the separator used as file separator in the path
*/
public VPath(@Nonnull CharSequence path, char separator) {
- this.path = path;
- this.separator = separator;
- assert isValidPath();
+ pathFragments = new ArrayList<VPathFragment>(1);
+ VPathFragment pe = new VPathFragment(path, separator);
+ assert pe.isValidPath();
+ pathFragments.add(pe);
}
- private boolean isValidPath() {
- String toString = path.toString();
- String stringSeparator = String.valueOf(separator);
- String doubleSeparator = stringSeparator + separator;
- if (toString.contains(doubleSeparator)) {
- return false;
- }
- if (toString.startsWith(stringSeparator)) {
- return false;
- }
- if (toString.endsWith(stringSeparator)) {
- return false;
- }
- return true;
+ /**
+ * Inserts a path before an existing path. The resulting path is evaluated lazily at each usage.
+ * There is an implicit separator between the prepended path and the existing path.
+ * @param path the path to insert before the existing path
+ */
+ public void prependPath(@Nonnull VPath path) {
+ pathFragments.add(0, new VPathFragment(String.valueOf(INTERNAL_SEPARATOR), INTERNAL_SEPARATOR));
+ pathFragments.addAll(0, path.getPathFragments());
+ }
+
+ /**
+ * Inserts a path after an existing path. The resulting path is evaluated lazily at each usage.
+ * There is an implicit separator between the existing path and the appended path.
+ * @param path the path to insert after the existing path
+ */
+ public void appendPath(@Nonnull VPath path) {
+ pathFragments.add(new VPathFragment(String.valueOf(INTERNAL_SEPARATOR), INTERNAL_SEPARATOR));
+ pathFragments.addAll(path.getPathFragments());
+ }
+
+ /**
+ * Adds a suffix to the existing path. The resulting path is evaluated lazily at each usage.
+ * It may be identical or different from the previous path.
+ * No implicit separator will be added between the suffix and the previous path.
+ * @param suffix the suffix to add to the path
+ */
+ public void addSuffix(@Nonnull CharSequence suffix) {
+ VPathFragment pe = new VPathFragment(suffix, INTERNAL_SEPARATOR);
+ assert pe.isValidSuffix();
+ pathFragments.add(pe);
}
/**
@@ -65,8 +85,8 @@ public final class VPath {
*/
@Nonnull
public Iterable<String> split() {
- Splitter splitter = Splitter.on(separator).omitEmptyStrings();
- return splitter.split(path);
+ Splitter splitter = Splitter.on(INTERNAL_SEPARATOR).omitEmptyStrings();
+ return splitter.split(getInternalPath());
}
/**
@@ -76,7 +96,11 @@ public final class VPath {
*/
@Nonnull
public String getPathAsString(char separator) {
- return path.toString().replace(this.separator, separator);
+ StringBuffer buffer = new StringBuffer();
+ for (VPathFragment pathElement : pathFragments) {
+ buffer.append(pathElement.getPathElementAsString(separator));
+ }
+ return buffer.toString();
}
@Override
@@ -93,13 +117,55 @@ public final class VPath {
}
@Nonnull
+ private List<VPathFragment> getPathFragments() {
+ return pathFragments;
+ }
+
+ @Nonnull
private String getInternalPath() {
- return path.toString().replace(separator, '/');
+ return getPathAsString(INTERNAL_SEPARATOR);
}
@Nonnull
public String getLastPathElement() {
- String toString = path.toString();
- return toString.substring(toString.lastIndexOf(separator) + 1);
+ String internalPath = getInternalPath();
+ return internalPath.substring(internalPath.lastIndexOf(INTERNAL_SEPARATOR) + 1);
+ }
+
+ static class VPathFragment {
+ @Nonnull
+ private final CharSequence path;
+
+ private final char separator;
+
+ public VPathFragment(@Nonnull CharSequence path, char separator) {
+ this.path = path;
+ this.separator = separator;
+ }
+
+ @Nonnull
+ public String getPathElementAsString(char separator) {
+ return path.toString().replace(this.separator, separator);
+ }
+
+ private boolean isValidPath() {
+ String toString = path.toString();
+ String stringSeparator = String.valueOf(separator);
+ String doubleSeparator = stringSeparator + separator;
+ if (toString.contains(doubleSeparator)) {
+ return false;
+ }
+ if (toString.startsWith(stringSeparator)) {
+ return false;
+ }
+ if (toString.endsWith(stringSeparator)) {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean isValidSuffix() {
+ return !path.toString().contains(String.valueOf(separator));
+ }
}
}