diff options
author | Benoit Lamarche <benoitlamarche@google.com> | 2015-05-29 12:56:28 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-05-29 12:56:29 +0000 |
commit | e69b762d0712168bad4ffda22991064470efcabd (patch) | |
tree | d3b49a78e9d7176ad1f3007eaf131af0ca7458b5 | |
parent | ba3810e3267e8a899ac305b6c803e43ef513340f (diff) | |
parent | 6007144b3ab9a8c59648fa35a0af920d2a64356e (diff) | |
download | toolchain_jack-e69b762d0712168bad4ffda22991064470efcabd.zip toolchain_jack-e69b762d0712168bad4ffda22991064470efcabd.tar.gz toolchain_jack-e69b762d0712168bad4ffda22991064470efcabd.tar.bz2 |
Merge "Add support to append in VFS" into ub-jack-brest
21 files changed, 173 insertions, 29 deletions
diff --git a/jack/src/com/android/jack/incremental/IncrementalInputFilter.java b/jack/src/com/android/jack/incremental/IncrementalInputFilter.java index 887abcb..1330ada 100644 --- a/jack/src/com/android/jack/incremental/IncrementalInputFilter.java +++ b/jack/src/com/android/jack/incremental/IncrementalInputFilter.java @@ -199,9 +199,7 @@ public class IncrementalInputFilter extends CommonFilter implements InputFilter if (config.get(INCREMENTAL_LOG).booleanValue()) { IncrementalLogWriter incLog; try { - VFS incrementalFolder = config.get(Options.LIBRARY_OUTPUT_DIR); - assert incrementalFolder != null; - incLog = new IncrementalLogWriter(getOutputJackLibrary(), incrementalFolder); + incLog = new IncrementalLogWriter(getOutputJackLibrary()); incLog.writeString("type: " + (incrementalInputLibrary == null ? "full" : "incremental")); incLog.writeLibraryDescriptions("classpath", classpathContent); incLog.writeStrings("classpath digests (" + (libraryDependencies.hasSameLibraryOnClasspath( diff --git a/jack/src/com/android/jack/incremental/IncrementalLogWriter.java b/jack/src/com/android/jack/incremental/IncrementalLogWriter.java index ec7016a..d7e03f8 100644 --- a/jack/src/com/android/jack/incremental/IncrementalLogWriter.java +++ b/jack/src/com/android/jack/incremental/IncrementalLogWriter.java @@ -26,12 +26,10 @@ import com.android.jack.library.InputLibrary; import com.android.jack.library.LibraryIOException; import com.android.jack.library.OutputJackLibrary; import com.android.sched.util.file.CannotCreateFileException; -import com.android.sched.vfs.VFS; +import com.android.sched.util.file.WrongPermissionException; +import com.android.sched.vfs.OutputVFile; import com.android.sched.vfs.VPath; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.PrintStream; import java.util.Collection; @@ -55,27 +53,24 @@ class IncrementalLogWriter { @Nonnull private static Joiner commaJoiner = Joiner.on(",").useForNull(""); - IncrementalLogWriter(@Nonnull OutputJackLibrary library, @Nonnull VFS incrementalFolder) - throws LibraryIOException { + IncrementalLogWriter(@Nonnull OutputJackLibrary library) throws LibraryIOException { this.library = library; + OutputVFile vFile; try { - library.getFile(FileType.LOG, vpath); + vFile = library.getFile(FileType.LOG, vpath); } catch (FileTypeDoesNotExistException e) { try { - library.createFile(FileType.LOG, vpath); + vFile = library.createFile(FileType.LOG, vpath); } catch (CannotCreateFileException e1) { throw new LibraryIOException(library.getLocation(), e1); } } - File logFile = new File(incrementalFolder.getPath(), - FileType.LOG.buildFileVPath(vpath).getPathAsString(File.separatorChar)); try { - ps = new PrintStream(new FileOutputStream(logFile, true)); + ps = new PrintStream(vFile.getPrintStream(/* append = */ true)); writeString("***"); - } catch (FileNotFoundException e) { - // File already creates by using VFS - throw new AssertionError(); + } catch (WrongPermissionException e) { + throw new LibraryIOException(library.getLocation(), e); } } diff --git a/jack/src/com/android/jack/library/OutputLibrary.java b/jack/src/com/android/jack/library/OutputLibrary.java index 1e54346..f365d8a 100644 --- a/jack/src/com/android/jack/library/OutputLibrary.java +++ b/jack/src/com/android/jack/library/OutputLibrary.java @@ -18,6 +18,7 @@ package com.android.jack.library; import com.android.sched.util.file.CannotCreateFileException; import com.android.sched.util.file.CannotDeleteFileException; +import com.android.sched.vfs.InputOutputVFile; import com.android.sched.vfs.InputVFile; import com.android.sched.vfs.OutputVFile; import com.android.sched.vfs.VPath; @@ -46,7 +47,7 @@ public interface OutputLibrary extends Library { public Iterator<InputVFile> iterator(@Nonnull FileType fileType); @Nonnull - public InputVFile getFile(@Nonnull FileType fileType, @Nonnull VPath typePath) + public InputOutputVFile getFile(@Nonnull FileType fileType, @Nonnull VPath typePath) throws FileTypeDoesNotExistException; @Nonnull diff --git a/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java b/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java index 3a7f311..2c9eefd 100644 --- a/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java +++ b/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java @@ -39,6 +39,7 @@ import com.android.sched.vfs.GenericInputOutputVFS; import com.android.sched.vfs.GenericInputVFS; import com.android.sched.vfs.GenericOutputVFS; import com.android.sched.vfs.InputOutputVFS; +import com.android.sched.vfs.InputOutputVFile; import com.android.sched.vfs.InputVFS; import com.android.sched.vfs.InputVFile; import com.android.sched.vfs.MessageDigestFS; @@ -245,10 +246,10 @@ public class OutputJackLibraryImpl extends CommonJackLibrary implements OutputJa @Override @Nonnull - public InputVFile getFile(@Nonnull FileType fileType, @Nonnull VPath typePath) + public InputOutputVFile getFile(@Nonnull FileType fileType, @Nonnull VPath typePath) throws FileTypeDoesNotExistException { try { - return getSectionVFS(fileType).getRootInputVDir() + return getSectionVFS(fileType).getRootInputOutputVDir() .getInputVFile(buildFileVPath(fileType, typePath)); } catch (NotFileOrDirectoryException e) { throw new FileTypeDoesNotExistException(getLocation(), typePath, fileType); diff --git a/sched/src/com/android/sched/vfs/BaseVFS.java b/sched/src/com/android/sched/vfs/BaseVFS.java index 935a0e5..c316641 100644 --- a/sched/src/com/android/sched/vfs/BaseVFS.java +++ b/sched/src/com/android/sched/vfs/BaseVFS.java @@ -51,6 +51,10 @@ abstract class BaseVFS<DIR extends BaseVDir, FILE extends BaseVFile> implements @Nonnull abstract OutputStream openWrite(@Nonnull FILE file) throws WrongPermissionException; + @Nonnull + abstract OutputStream openWrite(@Nonnull FILE file, boolean append) + throws WrongPermissionException; + // // VElement related // diff --git a/sched/src/com/android/sched/vfs/BaseVFile.java b/sched/src/com/android/sched/vfs/BaseVFile.java index 896a556..8147c13 100644 --- a/sched/src/com/android/sched/vfs/BaseVFile.java +++ b/sched/src/com/android/sched/vfs/BaseVFile.java @@ -50,7 +50,13 @@ abstract class BaseVFile extends BaseVElement implements VFile { @Override @Nonnull public OutputStream getOutputStream() throws WrongPermissionException { - return vfs.openWrite(this); + return getOutputStream(false); + } + + @Override + @Nonnull + public OutputStream getOutputStream(boolean append) throws WrongPermissionException { + return vfs.openWrite(this, append); } @Override @@ -59,6 +65,11 @@ abstract class BaseVFile extends BaseVElement implements VFile { return new PrintStream(getOutputStream()); } + @Nonnull + public PrintStream getPrintStream(boolean append) throws WrongPermissionException { + return new PrintStream(getOutputStream(append)); + } + @Override @Nonnull public Location getLocation() { diff --git a/sched/src/com/android/sched/vfs/CachedDirectFS.java b/sched/src/com/android/sched/vfs/CachedDirectFS.java index 19affc3..9cafd3c 100644 --- a/sched/src/com/android/sched/vfs/CachedDirectFS.java +++ b/sched/src/com/android/sched/vfs/CachedDirectFS.java @@ -228,12 +228,19 @@ public class CachedDirectFS extends BaseVFS<CachedParentVDir, CachedParentVFile> @Nonnull @Override OutputStream openWrite(@Nonnull CachedParentVFile file) throws WrongPermissionException { + return openWrite(file, false); + } + + @Nonnull + @Override + OutputStream openWrite(@Nonnull CachedParentVFile file, boolean append) + throws WrongPermissionException { assert !isClosed(); assert capabilities.contains(Capabilities.WRITE); File path = getNativeFile(file.getPath()); try { - return new FileOutputStream(path); + return new FileOutputStream(path, append); } catch (FileNotFoundException e) { FileOrDirectory.checkPermissions(path, file.getLocation(), Permission.WRITE); throw new ConcurrentIOException(e); diff --git a/sched/src/com/android/sched/vfs/CaseInsensitiveFS.java b/sched/src/com/android/sched/vfs/CaseInsensitiveFS.java index 46b18ea..2c4bb61 100644 --- a/sched/src/com/android/sched/vfs/CaseInsensitiveFS.java +++ b/sched/src/com/android/sched/vfs/CaseInsensitiveFS.java @@ -368,9 +368,16 @@ public class CaseInsensitiveFS extends BaseVFS<CaseInsensitiveVDir, CaseInsensit @Override @Nonnull OutputStream openWrite(@Nonnull CaseInsensitiveVFile file) throws WrongPermissionException { + return openWrite(file, false); + } + + @Override + @Nonnull + OutputStream openWrite(@Nonnull CaseInsensitiveVFile file, boolean append) + throws WrongPermissionException { assert !isClosed(); - return file.getEncodedFile().getOutputStream(); + return file.getEncodedFile().getOutputStream(append); } // diff --git a/sched/src/com/android/sched/vfs/DeflateFS.java b/sched/src/com/android/sched/vfs/DeflateFS.java index 70fc31d..3bb9e81 100644 --- a/sched/src/com/android/sched/vfs/DeflateFS.java +++ b/sched/src/com/android/sched/vfs/DeflateFS.java @@ -93,7 +93,13 @@ public class DeflateFS extends BaseVFS<BaseVDir, BaseVFile> implements VFS{ @Override @Nonnull OutputStream openWrite(@Nonnull BaseVFile file) throws WrongPermissionException { - return new DeflaterOutputStream(vfs.openWrite(file), new Deflater()); + return openWrite(file, false); + } + + @Override + @Nonnull + OutputStream openWrite(@Nonnull BaseVFile file, boolean append) throws WrongPermissionException { + return new DeflaterOutputStream(vfs.openWrite(file, append), new Deflater()); } @Override diff --git a/sched/src/com/android/sched/vfs/DirectFS.java b/sched/src/com/android/sched/vfs/DirectFS.java index 1464cb3..01c1e24 100644 --- a/sched/src/com/android/sched/vfs/DirectFS.java +++ b/sched/src/com/android/sched/vfs/DirectFS.java @@ -125,12 +125,20 @@ public class DirectFS extends BaseVFS<ParentVDir, ParentVFile> implements VFS { @Nonnull @Override OutputStream openWrite(@Nonnull ParentVFile file) throws WrongPermissionException { + return openWrite(file, false); + } + + + @Override + @Nonnull + OutputStream openWrite(@Nonnull ParentVFile file, boolean append) + throws WrongPermissionException { assert !isClosed(); assert capabilities.contains(Capabilities.WRITE); File path = getNativeFile(file.getPath()); try { - return new FileOutputStream(path); + return new FileOutputStream(path, append); } catch (FileNotFoundException e) { FileOrDirectory.checkPermissions(path, file.getLocation(), Permission.WRITE); throw new ConcurrentIOException(e); diff --git a/sched/src/com/android/sched/vfs/GenericInputOutputVFile.java b/sched/src/com/android/sched/vfs/GenericInputOutputVFile.java index d5fab6f..f7bf045 100644 --- a/sched/src/com/android/sched/vfs/GenericInputOutputVFile.java +++ b/sched/src/com/android/sched/vfs/GenericInputOutputVFile.java @@ -64,7 +64,7 @@ public class GenericInputOutputVFile implements InputOutputVFile { @Override @Nonnull public OutputStream getOutputStream() throws WrongPermissionException { - return file.getOutputStream(); + return getOutputStream(false); } @Override @@ -74,6 +74,18 @@ public class GenericInputOutputVFile implements InputOutputVFile { } @Override + @Nonnull + public OutputStream getOutputStream(boolean append) throws WrongPermissionException { + return file.getOutputStream(append); + } + + @Override + @Nonnull + public PrintStream getPrintStream(boolean append) throws WrongPermissionException { + return new PrintStream(getOutputStream(append)); + } + + @Override public void delete() throws CannotDeleteFileException { file.delete(); } diff --git a/sched/src/com/android/sched/vfs/GenericOutputVFile.java b/sched/src/com/android/sched/vfs/GenericOutputVFile.java index 87cbeb8..434c4b9 100644 --- a/sched/src/com/android/sched/vfs/GenericOutputVFile.java +++ b/sched/src/com/android/sched/vfs/GenericOutputVFile.java @@ -60,7 +60,19 @@ public class GenericOutputVFile implements OutputVFile { @Override @Nonnull + public OutputStream getOutputStream(boolean append) throws WrongPermissionException { + return file.getOutputStream(append); + } + + @Override + @Nonnull public PrintStream getPrintStream() throws WrongPermissionException { return new PrintStream(getOutputStream()); } + + @Override + @Nonnull + public PrintStream getPrintStream(boolean append) throws WrongPermissionException { + return new PrintStream(getOutputStream(append)); + } }
\ No newline at end of file diff --git a/sched/src/com/android/sched/vfs/MessageDigestFS.java b/sched/src/com/android/sched/vfs/MessageDigestFS.java index 7a181a1..e1d76fd 100644 --- a/sched/src/com/android/sched/vfs/MessageDigestFS.java +++ b/sched/src/com/android/sched/vfs/MessageDigestFS.java @@ -139,6 +139,16 @@ public class MessageDigestFS extends BaseVFS<MessageDigestVDir, MessageDigestVFi } }; } + + @Override + @Nonnull + public OutputStream getOutputStream(boolean append) throws WrongPermissionException { + if (append) { + throw new UnsupportedOperationException(); + } else { + return getOutputStream(); + } + } } static class MessageDigestVDir extends BaseVDir { @@ -363,6 +373,13 @@ public class MessageDigestFS extends BaseVFS<MessageDigestVDir, MessageDigestVFi @Override @Nonnull + OutputStream openWrite(@Nonnull MessageDigestVFile file, boolean append) { + // should be implemented in MessageDigestVFile + throw new UnsupportedOperationException(); + } + + @Override + @Nonnull synchronized void delete(@Nonnull MessageDigestVFile file) throws CannotDeleteFileException { file.getWrappedFile().delete(); digests.remove(file.getPath()); diff --git a/sched/src/com/android/sched/vfs/MessageDigestOutputVFS.java b/sched/src/com/android/sched/vfs/MessageDigestOutputVFS.java index 6b2ba61..8664162 100644 --- a/sched/src/com/android/sched/vfs/MessageDigestOutputVFS.java +++ b/sched/src/com/android/sched/vfs/MessageDigestOutputVFS.java @@ -95,10 +95,22 @@ public class MessageDigestOutputVFS extends MessageDigestVFS implements OutputVF @Override @Nonnull + public OutputStream getOutputStream(boolean append) { + throw new UnsupportedOperationException(); + } + + @Override + @Nonnull public PrintStream getPrintStream() throws WrongPermissionException { return new PrintStream(getOutputStream()); } + @Override + @Nonnull + public PrintStream getPrintStream(boolean append) { + throw new UnsupportedOperationException(); + } + @CheckForNull public String getDigest() { return digest; diff --git a/sched/src/com/android/sched/vfs/OutputVFile.java b/sched/src/com/android/sched/vfs/OutputVFile.java index 9e2de04..afd528d 100644 --- a/sched/src/com/android/sched/vfs/OutputVFile.java +++ b/sched/src/com/android/sched/vfs/OutputVFile.java @@ -16,9 +16,22 @@ package com.android.sched.vfs; +import com.android.sched.util.file.WrongPermissionException; + +import java.io.OutputStream; +import java.io.PrintStream; + +import javax.annotation.Nonnull; + /** * Virtual file to write to. */ public interface OutputVFile extends OutputVElement, OutputStreamProvider { + @Nonnull + OutputStream getOutputStream(boolean append) throws WrongPermissionException; + + @Nonnull + PrintStream getPrintStream(boolean append) throws WrongPermissionException; + } diff --git a/sched/src/com/android/sched/vfs/PrefixedFS.java b/sched/src/com/android/sched/vfs/PrefixedFS.java index 7b8bc3f..c85178f 100644 --- a/sched/src/com/android/sched/vfs/PrefixedFS.java +++ b/sched/src/com/android/sched/vfs/PrefixedFS.java @@ -87,7 +87,13 @@ public class PrefixedFS extends BaseVFS<BaseVDir, BaseVFile> implements VFS { @Override @Nonnull OutputStream openWrite(@Nonnull BaseVFile file) throws WrongPermissionException { - return vfs.openWrite(file); + return openWrite(file, false); + } + + @Override + @Nonnull + OutputStream openWrite(@Nonnull BaseVFile file, boolean append) throws WrongPermissionException { + return vfs.openWrite(file, append); } @Override diff --git a/sched/src/com/android/sched/vfs/ReadWriteZipFS.java b/sched/src/com/android/sched/vfs/ReadWriteZipFS.java index 2ee080b..228e7f2 100644 --- a/sched/src/com/android/sched/vfs/ReadWriteZipFS.java +++ b/sched/src/com/android/sched/vfs/ReadWriteZipFS.java @@ -119,7 +119,13 @@ public class ReadWriteZipFS extends BaseVFS<BaseVDir, BaseVFile> implements VFS @Override @Nonnull OutputStream openWrite(@Nonnull BaseVFile file) throws WrongPermissionException { - return vfs.openWrite(file); + return openWrite(file, false); + } + + @Override + @Nonnull + OutputStream openWrite(@Nonnull BaseVFile file, boolean append) throws WrongPermissionException { + return vfs.openWrite(file, append); } @Override diff --git a/sched/src/com/android/sched/vfs/ReadZipFS.java b/sched/src/com/android/sched/vfs/ReadZipFS.java index eeb3a6e..8851255 100644 --- a/sched/src/com/android/sched/vfs/ReadZipFS.java +++ b/sched/src/com/android/sched/vfs/ReadZipFS.java @@ -204,6 +204,12 @@ public class ReadZipFS extends BaseVFS<ZipVDir, ZipVFile> implements VFS { throw new UnsupportedOperationException(); } + @Override + @Nonnull + OutputStream openWrite(@Nonnull ZipVFile file, boolean append) { + throw new UnsupportedOperationException(); + } + // // VElement // diff --git a/sched/src/com/android/sched/vfs/VFSToVFSWrapper.java b/sched/src/com/android/sched/vfs/VFSToVFSWrapper.java index df733f4..b0a61f1 100644 --- a/sched/src/com/android/sched/vfs/VFSToVFSWrapper.java +++ b/sched/src/com/android/sched/vfs/VFSToVFSWrapper.java @@ -170,7 +170,13 @@ public class VFSToVFSWrapper extends BaseVFS<BaseVDir, BaseVFile> implements VFS @Override @Nonnull OutputStream openWrite(@Nonnull BaseVFile file) throws WrongPermissionException { - return workVFS.openWrite(file); + return openWrite(file, false); + } + + @Override + @Nonnull + OutputStream openWrite(@Nonnull BaseVFile file, boolean append) throws WrongPermissionException { + return workVFS.openWrite(file, append); } @Override diff --git a/sched/src/com/android/sched/vfs/VFile.java b/sched/src/com/android/sched/vfs/VFile.java index 5e172d3..beef656 100644 --- a/sched/src/com/android/sched/vfs/VFile.java +++ b/sched/src/com/android/sched/vfs/VFile.java @@ -17,6 +17,9 @@ package com.android.sched.vfs; import com.android.sched.util.file.CannotDeleteFileException; +import com.android.sched.util.file.WrongPermissionException; + +import java.io.OutputStream; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; @@ -28,6 +31,9 @@ public interface VFile extends VElement, InputStreamProvider, OutputStreamProvid @Nonnull VPath getPath(); + @Nonnull + OutputStream getOutputStream(boolean append) throws WrongPermissionException; + @CheckForNull String getDigest(); diff --git a/sched/src/com/android/sched/vfs/WriteZipFS.java b/sched/src/com/android/sched/vfs/WriteZipFS.java index 2370117..b43b3d6 100644 --- a/sched/src/com/android/sched/vfs/WriteZipFS.java +++ b/sched/src/com/android/sched/vfs/WriteZipFS.java @@ -171,6 +171,16 @@ public class WriteZipFS extends BaseVFS<ZipVDir, ZipVFile> implements VFS { return new ZipEntryOutputStream(this, file.getZipEntry()); } + @Override + @Nonnull + OutputStream openWrite(@Nonnull ZipVFile file, boolean append) { + if (append) { + throw new UnsupportedOperationException(); + } else { + return openWrite(file); + } + } + // // VElement // |