diff options
author | mikaelpeltier <mikaelpeltier@google.com> | 2014-07-15 13:51:32 +0200 |
---|---|---|
committer | mikaelpeltier <mikaelpeltier@google.com> | 2014-07-18 16:37:16 +0200 |
commit | f70ac562332cdb5779a23c33c7a7a2de11964249 (patch) | |
tree | 885278a776bb7538722aa325e45df36f63581d69 /jack | |
parent | e4b975a4d1bc4c12ad02429eed2383abf37752bc (diff) | |
download | toolchain_jack-f70ac562332cdb5779a23c33c7a7a2de11964249.tar.gz toolchain_jack-f70ac562332cdb5779a23c33c7a7a2de11964249.tar.bz2 toolchain_jack-f70ac562332cdb5779a23c33c7a7a2de11964249.zip |
Use OutputVDir into dex writers
Change-Id: Ia960137182622d2dcd12b9a31d5681f7fed35a43
Diffstat (limited to 'jack')
-rw-r--r-- | jack/src/com/android/jack/Options.java | 6 | ||||
-rw-r--r-- | jack/src/com/android/jack/backend/dex/DexZipWriter.java | 74 |
2 files changed, 48 insertions, 32 deletions
diff --git a/jack/src/com/android/jack/Options.java b/jack/src/com/android/jack/Options.java index 91aba80e..5dd65259 100644 --- a/jack/src/com/android/jack/Options.java +++ b/jack/src/com/android/jack/Options.java @@ -36,7 +36,6 @@ import com.android.sched.util.RunnableHooks; import com.android.sched.util.codec.InputOutputVDirCodec; import com.android.sched.util.codec.OutputStreamCodec; import com.android.sched.util.codec.OutputVDirCodec; -import com.android.sched.util.codec.PathCodec; import com.android.sched.util.config.Config; import com.android.sched.util.config.ConfigPrinterFactory; import com.android.sched.util.config.ConfigurationException; @@ -140,8 +139,9 @@ public class Options { GENERATE_ONE_DEX_PER_TYPE.getValue().isTrue())); @Nonnull - public static final PropertyId<File> DEX_ZIP_OUTPUT = PropertyId.create("jack.dex.output.zip", - "Output zip archive for dex", new PathCodec()).requiredIf( + public static final PropertyId<OutputVDir> DEX_ZIP_OUTPUT = PropertyId.create( + "jack.dex.output.zip", "Output zip archive for dex", + new OutputVDirCodec(Existence.MAY_EXIST, Container.ZIP)).requiredIf( DEX_OUTPUT_CONTAINER_TYPE.is(Container.ZIP)); @Nonnull diff --git a/jack/src/com/android/jack/backend/dex/DexZipWriter.java b/jack/src/com/android/jack/backend/dex/DexZipWriter.java index 41c24e2d..13c3b600 100644 --- a/jack/src/com/android/jack/backend/dex/DexZipWriter.java +++ b/jack/src/com/android/jack/backend/dex/DexZipWriter.java @@ -16,7 +16,7 @@ package com.android.jack.backend.dex; -import com.android.jack.JackFileException; +import com.android.jack.JackIOException; import com.android.jack.Options; import com.android.jack.dx.dex.file.DexFile; import com.android.jack.ir.ast.JSession; @@ -31,13 +31,18 @@ import com.android.sched.schedulable.Produce; import com.android.sched.schedulable.RunnableSchedulable; import com.android.sched.schedulable.Support; import com.android.sched.util.config.ThreadConfig; +import com.android.sched.util.log.LoggerFactory; +import com.android.sched.vfs.OutputVDir; +import com.android.sched.vfs.OutputVFile; import com.android.sched.vfs.VPath; -import java.io.File; -import java.io.FileOutputStream; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.IOException; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.annotation.Nonnull; @@ -55,43 +60,54 @@ public class DexZipWriter extends DexWriter implements RunnableSchedulable<JSess private static final String DEX_NAME = "classes.dex"; @Nonnull - private final File outputFile = ThreadConfig.get(Options.DEX_ZIP_OUTPUT); + private final OutputVDir outputVDir = ThreadConfig.get(Options.DEX_ZIP_OUTPUT); + + @Nonnull + private final Logger logger = LoggerFactory.getLogger(); @Override public void run(@Nonnull JSession session) throws Exception { DexFile dexFile = getDexFile(session); + OutputVFile vFile = outputVDir.createOutputVFile(new VPath(DEX_NAME, '/')); + OutputStream osDex = new BufferedOutputStream(vFile.openWrite()); - ZipOutputStream zos = null; try { - zos = new ZipOutputStream(new FileOutputStream(outputFile)); - ZipEntry entry = new ZipEntry(DEX_NAME); - zos.putNextEntry(entry); if (emitOneDexPerType) { - mergeDexPerType(dexFile, zos); + mergeDexPerType(dexFile, osDex); } else { - dexFile.writeTo(zos, null, false); - } - zos.closeEntry(); - for (Resource resource : session.getResources()) { - writeResource(resource, zos); + + dexFile.writeTo(osDex, null, false); } } catch (IOException e) { - throw new JackFileException( - "Could not write Dex archive to output '" + outputFile.getAbsolutePath() + "'", e); + throw new JackIOException("Could not write Dex file to output '" + vFile + "'", e); } finally { - if (zos != null) { - zos.close(); + try { + osDex.close(); + } catch (IOException e) { + logger.log(Level.WARNING, "Failed to close output stream on '" + vFile + "'", e); } } - } - - private void writeResource(@Nonnull Resource resource, @Nonnull ZipOutputStream zos) - throws IOException { - VPath path = resource.getPath(); - ZipEntry resourceEntry = new ZipEntry(path.getPathAsString('/')); - zos.putNextEntry(resourceEntry); - BytesStreamSucker sucker = new BytesStreamSucker(resource.getVFile().openRead(), zos); - sucker.suck(); + for (Resource resource : session.getResources()) { + OutputVFile resourceVFile = outputVDir.createOutputVFile(resource.getPath()); + InputStream is = new BufferedInputStream(resource.getVFile().openRead()); + OutputStream os = new BufferedOutputStream(resourceVFile.openWrite()); + try { + BytesStreamSucker sucker = new BytesStreamSucker(is, os); + sucker.suck(); + } finally { + try { + is.close(); + } catch (IOException e) { + logger.log(Level.WARNING, + "Failed to close input stream on '" + resource.getVFile() + "'", e); + } + try { + os.close(); + } catch (IOException e) { + logger.log(Level.WARNING, "Failed to close output stream on '" + resourceVFile + "'", e); + } + } + } } } |