summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Lamarche <benoitlamarche@google.com>2015-01-19 16:59:06 +0100
committerBenoit Lamarche <benoitlamarche@google.com>2015-01-26 19:18:02 +0100
commit0f560d93473dcee618d3cfa85d9f4b14ddf8b8fb (patch)
tree8b0a4a41c1e8b2e4888ce4a831ab64cbd4c2e685
parent1c8c646006df3b4e854403f3b2c18b0dcb479028 (diff)
downloadtoolchain_jack-0f560d93473dcee618d3cfa85d9f4b14ddf8b8fb.zip
toolchain_jack-0f560d93473dcee618d3cfa85d9f4b14ddf8b8fb.tar.gz
toolchain_jack-0f560d93473dcee618d3cfa85d9f4b14ddf8b8fb.tar.bz2
Add new PrefixedFS
Change-Id: I4b71e032221ccfe2ebc4fd5d110aa1b389dc4812
-rw-r--r--sched/src/com/android/sched/vfs/PrefixedFS.java183
-rw-r--r--sched/tests/com/android/sched/vfs/VFSTest.java45
2 files changed, 228 insertions, 0 deletions
diff --git a/sched/src/com/android/sched/vfs/PrefixedFS.java b/sched/src/com/android/sched/vfs/PrefixedFS.java
new file mode 100644
index 0000000..488f59e
--- /dev/null
+++ b/sched/src/com/android/sched/vfs/PrefixedFS.java
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * 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.android.sched.vfs;
+
+import com.android.sched.util.file.CannotCreateFileException;
+import com.android.sched.util.file.CannotDeleteFileException;
+import com.android.sched.util.file.NoSuchFileException;
+import com.android.sched.util.file.NotDirectoryException;
+import com.android.sched.util.file.NotFileException;
+import com.android.sched.util.file.WrongPermissionException;
+import com.android.sched.util.location.Location;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.Set;
+
+import javax.annotation.Nonnull;
+
+/**
+ * A {@link VFS} filter that adds a prefix to all paths.
+ */
+public class PrefixedFS extends BaseVFS<BaseVDir, BaseVFile> implements VFS{
+ @Nonnull
+ private final BaseVFS<BaseVDir, BaseVFile> vfs;
+ @Nonnull
+ private final BaseVDir rootDir;
+
+ @SuppressWarnings("unchecked")
+ public PrefixedFS(@Nonnull BaseVFS<? extends BaseVDir, ? extends BaseVFile> vfs,
+ @Nonnull VPath prefix) throws CannotCreateFileException {
+ this.vfs = (BaseVFS<BaseVDir, BaseVFile>) vfs;
+ rootDir = vfs.getRootDir().createVDir(prefix);
+ }
+
+ @Override
+ @Nonnull
+ public Location getLocation() {
+ return rootDir.getLocation();
+ }
+
+ @Override
+ public void close() {
+ // do not actually close
+ }
+
+ @Override
+ @Nonnull
+ public String getPath() {
+ return vfs.getPath();
+ }
+
+ @Override
+ @Nonnull
+ public BaseVDir getRootDir() {
+ return rootDir;
+ }
+
+ @Override
+ @Nonnull
+ InputStream openRead(@Nonnull BaseVFile file) throws WrongPermissionException {
+ return vfs.openRead(file);
+ }
+
+ @Override
+ @Nonnull
+ OutputStream openWrite(@Nonnull BaseVFile file) throws WrongPermissionException {
+ return vfs.openWrite(file);
+ }
+
+ @Override
+ @Nonnull
+ void delete(@Nonnull BaseVFile file) throws CannotDeleteFileException {
+ vfs.delete(file);
+ }
+
+ @Override
+ @Nonnull
+ Collection<? extends BaseVElement> list(@Nonnull BaseVDir dir) {
+ return vfs.list(dir);
+ }
+
+ @Override
+ @Nonnull
+ BaseVFile createVFile(@Nonnull BaseVDir parent, @Nonnull String name)
+ throws CannotCreateFileException {
+ return vfs.createVFile(parent, name);
+ }
+
+ @Override
+ @Nonnull
+ BaseVDir createVDir(@Nonnull BaseVDir parent, @Nonnull String name)
+ throws CannotCreateFileException {
+ return vfs.createVDir(parent, name);
+ }
+
+ @Override
+ @Nonnull
+ BaseVDir getVDir(@Nonnull BaseVDir parent, @Nonnull String name) throws NotDirectoryException,
+ NoSuchFileException {
+ return vfs.getVDir(parent, name);
+ }
+
+ @Override
+ @Nonnull
+ BaseVFile getVFile(@Nonnull BaseVDir parent, @Nonnull String name) throws NotFileException,
+ NoSuchFileException {
+ return vfs.getVFile(parent, name);
+ }
+
+
+ @Override
+ public boolean needsSequentialWriting() {
+ return vfs.needsSequentialWriting();
+ }
+
+ @Override
+ @Nonnull
+ public String getDescription() {
+ return "prefixed wrapper";
+ }
+
+ @Override
+ @Nonnull
+ public Set<Capabilities> getCapabilities() {
+ return vfs.getCapabilities();
+ }
+
+ @Override
+ boolean isEmpty(@Nonnull BaseVDir dir) {
+ return vfs.isEmpty(dir);
+ }
+
+ @Override
+ @Nonnull
+ Location getVFileLocation(@Nonnull BaseVFile file) {
+ return vfs.getVFileLocation(file);
+ }
+
+ @Override
+ @Nonnull
+ Location getVFileLocation(@Nonnull BaseVDir parent, @Nonnull String name) {
+ return vfs.getVFileLocation(parent, name);
+ }
+
+ @Override
+ @Nonnull
+ Location getVFileLocation(@Nonnull BaseVDir parent, @Nonnull VPath path) {
+ return vfs.getVFileLocation(parent, path);
+ }
+
+ @Override
+ @Nonnull
+ Location getVDirLocation(@Nonnull BaseVDir dir) {
+ return vfs.getVDirLocation(dir);
+ }
+
+ @Override
+ @Nonnull
+ Location getVDirLocation(@Nonnull BaseVDir parent, @Nonnull String name) {
+ return vfs.getVDirLocation(parent, name);
+ }
+
+ @Override
+ @Nonnull
+ Location getVDirLocation(@Nonnull BaseVDir parent, @Nonnull VPath path) {
+ return vfs.getVDirLocation(parent, path);
+ }
+}
diff --git a/sched/tests/com/android/sched/vfs/VFSTest.java b/sched/tests/com/android/sched/vfs/VFSTest.java
index 6b21bd7..9b8c9e9 100644
--- a/sched/tests/com/android/sched/vfs/VFSTest.java
+++ b/sched/tests/com/android/sched/vfs/VFSTest.java
@@ -290,6 +290,51 @@ public class VFSTest {
}
@Test
+ public void testPrefixFS()
+ throws NotDirectoryException,
+ CannotCreateFileException,
+ WrongPermissionException,
+ CannotSetPermissionException,
+ NoSuchFileException,
+ FileAlreadyExistsException,
+ IOException {
+ File file = null;
+ InputOutputVFS directVFS = null;
+ InputOutputVFS directVFS2 = null;
+ try {
+ file = File.createTempFile("vfs", "dir");
+ String path = file.getAbsolutePath();
+ Assert.assertTrue(file.delete());
+
+ directVFS =
+ new GenericInputOutputVFS(new PrefixedFS(new DirectFS(new Directory(path, null,
+ Existence.NOT_EXIST, Permission.WRITE, ChangePermission.NOCHANGE), Permission.READ
+ | Permission.WRITE), new VPath("stuff", '/')));
+
+ testOutputVFS(directVFS);
+ testInputVFS(directVFS);
+ directVFS.close();
+
+ directVFS2 =
+ new GenericInputOutputVFS(new PrefixedFS(new DirectFS(new Directory(path, null,
+ Existence.MUST_EXIST, Permission.WRITE, ChangePermission.NOCHANGE), Permission.READ
+ | Permission.WRITE), new VPath("stuff", '/')));
+ testInputVFS(directVFS2);
+
+ } finally {
+ if (directVFS != null) {
+ directVFS.close();
+ }
+ if (directVFS2 != null) {
+ directVFS2.close();
+ }
+ if (file != null) {
+ FileUtils.deleteDir(file);
+ }
+ }
+ }
+
+ @Test
public void testInputOutputZipVFS()
throws NotDirectoryException,
CannotCreateFileException,