diff options
author | Jean-Philippe Lesot <jplesot@google.com> | 2015-03-12 09:15:31 -0700 |
---|---|---|
committer | Jean-Philippe Lesot <jplesot@google.com> | 2015-03-12 09:15:31 -0700 |
commit | f22d22496d5087e149da2c0b9bbe566d4cbd6597 (patch) | |
tree | 997f52272c9a6391f5b255666cee536b6b087ad0 /sched/src | |
parent | a673473ff01da4e2585dfc5a790a0b7086f6110b (diff) | |
download | toolchain_jack-f22d22496d5087e149da2c0b9bbe566d4cbd6597.tar.gz toolchain_jack-f22d22496d5087e149da2c0b9bbe566d4cbd6597.tar.bz2 toolchain_jack-f22d22496d5087e149da2c0b9bbe566d4cbd6597.zip |
Add base directory support in TokenIterator and use it in the ServerTaskInsideVM
Change-Id: I2ac1048bf511b7f84774a9e1970eb407517cf6c8
Diffstat (limited to 'sched/src')
-rw-r--r-- | sched/src/com/android/sched/util/config/cli/TokenIterator.java | 37 | ||||
-rw-r--r-- | sched/src/com/android/sched/util/file/Directory.java | 2 |
2 files changed, 35 insertions, 4 deletions
diff --git a/sched/src/com/android/sched/util/config/cli/TokenIterator.java b/sched/src/com/android/sched/util/config/cli/TokenIterator.java index 348f661a..a4d79547 100644 --- a/sched/src/com/android/sched/util/config/cli/TokenIterator.java +++ b/sched/src/com/android/sched/util/config/cli/TokenIterator.java @@ -16,16 +16,24 @@ package com.android.sched.util.config.cli; +import com.android.sched.util.file.CannotCreateFileException; import com.android.sched.util.file.CannotReadException; +import com.android.sched.util.file.CannotSetPermissionException; +import com.android.sched.util.file.Directory; +import com.android.sched.util.file.FileAlreadyExistsException; +import com.android.sched.util.file.FileOrDirectory.ChangePermission; +import com.android.sched.util.file.FileOrDirectory.Existence; +import com.android.sched.util.file.FileOrDirectory.Permission; import com.android.sched.util.file.InputStreamFile; 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.NotFileOrDirectoryException; import com.android.sched.util.file.WrongPermissionException; -import com.android.sched.util.location.FileLocation; import com.android.sched.util.location.LineLocation; import com.android.sched.util.location.Location; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; @@ -51,6 +59,9 @@ public class TokenIterator { private boolean allowFileRefInArray = true; private boolean allowFileRefInFile = false; + @CheckForNull + private Directory baseDirectory = null; + @Nonnull private final String[] args; private int index = 0; @@ -88,6 +99,26 @@ public class TokenIterator { } @Nonnull + public TokenIterator withFileRelativeTo(@Nonnull File directory) throws NotDirectoryException, + WrongPermissionException, NoSuchFileException { + try { + this.baseDirectory = new Directory(directory.getPath(), null, Existence.MUST_EXIST, + Permission.EXECUTE, ChangePermission.NOCHANGE); + } catch (CannotSetPermissionException e) { + // we're not changing the permissions + throw new AssertionError(e); + } catch (FileAlreadyExistsException e) { + // we're not creating the directory + throw new AssertionError(e); + } catch (CannotCreateFileException e) { + // we're not creating the directory + throw new AssertionError(e); + } + + return this; + } + + @Nonnull public TokenIterator disallowFileReferenceInArray() { this.allowFileRefInArray = false; @@ -247,10 +278,10 @@ public class TokenIterator { private void pushFileTokenizer(@Nonnull String fileName) throws WrongPermissionException, NoSuchFileException, NotFileException { - InputStreamFile file = new InputStreamFile(fileName); + InputStreamFile file = new InputStreamFile(baseDirectory, fileName); tokenizers.push(getTokenizer(file)); - locations.push(new FileLocation(file.getPath())); + locations.push(file.getLocation()); } @Nonnull diff --git a/sched/src/com/android/sched/util/file/Directory.java b/sched/src/com/android/sched/util/file/Directory.java index 0af9fe94..7bac127c 100644 --- a/sched/src/com/android/sched/util/file/Directory.java +++ b/sched/src/com/android/sched/util/file/Directory.java @@ -35,7 +35,7 @@ public class Directory extends FileOrDirectory { @Nonnull private static final Logger logger = LoggerFactory.getLogger(); @Nonnull - private final File file; + private final File file; public Directory(@Nonnull String name, @CheckForNull RunnableHooks hooks, @Nonnull Existence existence, int permissions, @Nonnull ChangePermission change) |