summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Lamarche <benoitlamarche@google.com>2014-11-12 12:11:38 +0100
committerBenoit Lamarche <benoitlamarche@google.com>2014-11-12 12:11:38 +0100
commitd3140c3902cd59af9b1393b3e29be55bf0bda345 (patch)
treee0a11fa994d23430935080a959ba039f478857b2
parent857eccf2866f32268038b836fd4f4c9205cb7680 (diff)
downloadtoolchain_jack-d3140c3902cd59af9b1393b3e29be55bf0bda345.zip
toolchain_jack-d3140c3902cd59af9b1393b3e29be55bf0bda345.tar.gz
toolchain_jack-d3140c3902cd59af9b1393b3e29be55bf0bda345.tar.bz2
Add codec for InputOutputZipVDir
Change-Id: Ia4dd84240ca3e834dc4ae02336a143587110afe4
-rw-r--r--jack/src/com/android/jack/Options.java8
-rw-r--r--sched/src/com/android/sched/util/codec/DirectDirInputOutputVDirCodec.java70
-rw-r--r--sched/src/com/android/sched/util/codec/InputOutputVDirCodec.java41
-rw-r--r--sched/src/com/android/sched/util/codec/OutputVDirCodec.java2
-rw-r--r--sched/src/com/android/sched/util/codec/ZipInputOutputVDirCodec.java90
-rw-r--r--sched/src/com/android/sched/util/config/cli/TokenIterator.java3
6 files changed, 167 insertions, 47 deletions
diff --git a/jack/src/com/android/jack/Options.java b/jack/src/com/android/jack/Options.java
index b18345b..1269332 100644
--- a/jack/src/com/android/jack/Options.java
+++ b/jack/src/com/android/jack/Options.java
@@ -38,8 +38,8 @@ import com.android.jack.transformations.renamepackage.PackageRenamer;
import com.android.jack.util.filter.AllMethods;
import com.android.jack.util.filter.Filter;
import com.android.sched.util.RunnableHooks;
+import com.android.sched.util.codec.DirectDirInputOutputVDirCodec;
import com.android.sched.util.codec.DirectDirOutputVDirCodec;
-import com.android.sched.util.codec.InputOutputVDirCodec;
import com.android.sched.util.codec.ZipOutputVDirCodec;
import com.android.sched.util.config.Config;
import com.android.sched.util.config.ConfigPrinterFactory;
@@ -136,9 +136,9 @@ public class Options {
@Nonnull
public static final PropertyId<InputOutputVDir> INTERMEDIATE_DEX_DIR = PropertyId.create(
"jack.dex.intermediate.output.dir", "Intermediate dex output folder",
- new InputOutputVDirCodec(Existence.MAY_EXIST)).requiredIf(GENERATE_INTERMEDIATE_DEX.getValue()
- .isTrue().and(DEX_OUTPUT_CONTAINER_TYPE.is(Container.DIR)
- .or(DEX_OUTPUT_CONTAINER_TYPE.is(Container.ZIP))));
+ new DirectDirInputOutputVDirCodec(Existence.MAY_EXIST)).requiredIf(
+ GENERATE_INTERMEDIATE_DEX.getValue().isTrue().and(DEX_OUTPUT_CONTAINER_TYPE.is(Container.DIR)
+ .or(DEX_OUTPUT_CONTAINER_TYPE.is(Container.ZIP))));
@Nonnull
public static final PropertyId<OutputVDir> DEX_OUTPUT_DIR = PropertyId.create(
diff --git a/sched/src/com/android/sched/util/codec/DirectDirInputOutputVDirCodec.java b/sched/src/com/android/sched/util/codec/DirectDirInputOutputVDirCodec.java
new file mode 100644
index 0000000..d30c369
--- /dev/null
+++ b/sched/src/com/android/sched/util/codec/DirectDirInputOutputVDirCodec.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2014 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.util.codec;
+
+
+import com.android.sched.util.file.Directory;
+import com.android.sched.util.file.FileOrDirectory.Existence;
+import com.android.sched.util.file.FileOrDirectory.Permission;
+import com.android.sched.vfs.DirectDir;
+import com.android.sched.vfs.InputOutputVDir;
+
+import java.io.IOException;
+
+import javax.annotation.Nonnull;
+
+/**
+ * This {@link StringCodec} is used to create an instance of {@link InputOutputVDir} backed by a
+ * filesystem directory.
+ */
+public class DirectDirInputOutputVDirCodec extends InputOutputVDirCodec
+ implements StringCodec<InputOutputVDir> {
+
+ public DirectDirInputOutputVDirCodec(@Nonnull Existence existence) {
+ super(existence);
+ }
+
+ @Override
+ @Nonnull
+ public String getUsage() {
+ StringBuilderAppender sb = new StringBuilderAppender(", ");
+
+ sb.append("a path to a directory (must ");
+
+ sb.append(existence == Existence.MUST_EXIST, "exist");
+ sb.append(existence == Existence.NOT_EXIST, "not exist");
+
+ sb.append((permissions & Permission.READ) != 0, "be readable");
+ sb.append((permissions & Permission.WRITE) != 0, "be writable");
+
+ sb.append(")");
+
+ return sb.toString();
+ }
+
+ @Override
+ @Nonnull
+ public InputOutputVDir checkString(@Nonnull CodecContext context, @Nonnull final String string)
+ throws ParsingException {
+ try {
+ return new DirectDir(
+ new Directory(string, context.getRunnableHooks(), existence, permissions, change));
+ } catch (IOException e) {
+ throw new ParsingException(e);
+ }
+ }
+}
diff --git a/sched/src/com/android/sched/util/codec/InputOutputVDirCodec.java b/sched/src/com/android/sched/util/codec/InputOutputVDirCodec.java
index f3354f7..2746470 100644
--- a/sched/src/com/android/sched/util/codec/InputOutputVDirCodec.java
+++ b/sched/src/com/android/sched/util/codec/InputOutputVDirCodec.java
@@ -18,28 +18,19 @@ package com.android.sched.util.codec;
import com.android.sched.util.config.ConfigurationError;
-import com.android.sched.util.file.Directory;
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.log.LoggerFactory;
-import com.android.sched.vfs.DirectDir;
import com.android.sched.vfs.InputOutputVDir;
-import java.io.IOException;
-import java.util.logging.Logger;
-
import javax.annotation.Nonnull;
/**
* This {@link StringCodec} is used to create an instance of {@link InputOutputVDir}.
*/
-public class InputOutputVDirCodec extends FileOrDirCodec
+abstract class InputOutputVDirCodec extends FileOrDirCodec
implements StringCodec<InputOutputVDir> {
- @Nonnull
- private final Logger logger = LoggerFactory.getLogger();
-
public InputOutputVDirCodec(@Nonnull Existence existence) {
super(existence, Permission.READ | Permission.WRITE);
}
@@ -59,36 +50,6 @@ public class InputOutputVDirCodec extends FileOrDirCodec
}
@Override
- @Nonnull
- public String getUsage() {
- StringBuilderAppender sb = new StringBuilderAppender(", ");
-
- sb.append("a path to a directory (must ");
-
- sb.append(existence == Existence.MUST_EXIST, "exist");
- sb.append(existence == Existence.NOT_EXIST, "not exist");
-
- sb.append((permissions & Permission.READ) != 0, "be readable");
- sb.append((permissions & Permission.WRITE) != 0, "be writable");
-
- sb.append(")");
-
- return sb.toString();
- }
-
- @Override
- @Nonnull
- public InputOutputVDir checkString(@Nonnull CodecContext context, @Nonnull final String string)
- throws ParsingException {
- try {
- return new DirectDir(
- new Directory(string, context.getRunnableHooks(), existence, permissions, change));
- } catch (IOException e) {
- throw new ParsingException(e);
- }
- }
-
- @Override
public void checkValue(@Nonnull CodecContext context, @Nonnull InputOutputVDir dir) {
}
diff --git a/sched/src/com/android/sched/util/codec/OutputVDirCodec.java b/sched/src/com/android/sched/util/codec/OutputVDirCodec.java
index 6acf538..3de4284 100644
--- a/sched/src/com/android/sched/util/codec/OutputVDirCodec.java
+++ b/sched/src/com/android/sched/util/codec/OutputVDirCodec.java
@@ -28,7 +28,7 @@ import javax.annotation.Nonnull;
/**
* This {@link StringCodec} is used to create an instance of {@link OutputVDir}.
*/
-public abstract class OutputVDirCodec extends FileOrDirCodec implements StringCodec<OutputVDir> {
+abstract class OutputVDirCodec extends FileOrDirCodec implements StringCodec<OutputVDir> {
public OutputVDirCodec(@Nonnull Existence existence) {
super(existence, Permission.READ | Permission.WRITE);
diff --git a/sched/src/com/android/sched/util/codec/ZipInputOutputVDirCodec.java b/sched/src/com/android/sched/util/codec/ZipInputOutputVDirCodec.java
new file mode 100644
index 0000000..590287b
--- /dev/null
+++ b/sched/src/com/android/sched/util/codec/ZipInputOutputVDirCodec.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2014 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.util.codec;
+
+
+import com.android.sched.util.RunnableHooks;
+import com.android.sched.util.file.FileOrDirectory.Existence;
+import com.android.sched.util.file.FileOrDirectory.Permission;
+import com.android.sched.util.file.OutputZipFile;
+import com.android.sched.util.log.LoggerFactory;
+import com.android.sched.vfs.InputOutputVDir;
+import com.android.sched.vfs.InputOutputZipRootVDir;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.annotation.Nonnull;
+
+/**
+ * This {@link StringCodec} is used to create an instance of {@link InputOutputVDir} backed by a
+ * filesystem directory, which is then zipped when closed.
+ */
+public class ZipInputOutputVDirCodec extends InputOutputVDirCodec
+ implements StringCodec<InputOutputVDir> {
+
+ @Nonnull
+ private final Logger logger = LoggerFactory.getLogger();
+
+ public ZipInputOutputVDirCodec(@Nonnull Existence existence) {
+ super(existence);
+ }
+
+ @Override
+ @Nonnull
+ public String getUsage() {
+ StringBuilderAppender sb = new StringBuilderAppender(", ");
+
+ sb.append("a path to a zip archive (must ");
+
+ sb.append(existence == Existence.MUST_EXIST, "exist");
+ sb.append(existence == Existence.NOT_EXIST, "not exist");
+
+ sb.append((permissions & Permission.READ) != 0, "be readable");
+ sb.append((permissions & Permission.WRITE) != 0, "be writable");
+
+ sb.append(")");
+
+ return sb.toString();
+ }
+
+ @Override
+ @Nonnull
+ public InputOutputVDir checkString(@Nonnull CodecContext context, @Nonnull final String string)
+ throws ParsingException {
+ RunnableHooks hooks = context.getRunnableHooks();
+ try {
+ final InputOutputZipRootVDir vDir =
+ new InputOutputZipRootVDir(new OutputZipFile(string, hooks, existence, change));
+ assert hooks != null;
+ hooks.addHook(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ vDir.close();
+ } catch (IOException e) {
+ logger.log(Level.WARNING, "Failed to create zip for '" + string + "'.", e);
+ }
+ }
+ });
+ return vDir;
+ } catch (IOException e) {
+ throw new ParsingException(e.getMessage(), e);
+ }
+ }
+}
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 ae0e402..7d86978 100644
--- a/sched/src/com/android/sched/util/config/cli/TokenIterator.java
+++ b/sched/src/com/android/sched/util/config/cli/TokenIterator.java
@@ -26,7 +26,6 @@ import com.android.sched.util.file.NoSuchFileException;
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.FileOrDirLocation;
import com.android.sched.util.location.LineLocation;
import com.android.sched.util.location.Location;
@@ -221,7 +220,7 @@ public class TokenIterator {
tokenizers.push(null);
index = args.length;
- throw new CannotReadException((FileOrDirLocation) locations.peek());
+ throw new CannotReadException(locations.peek());
}
// Else, go to the next one