diff options
author | mikaelpeltier <mikaelpeltier@google.com> | 2015-01-28 11:05:23 +0100 |
---|---|---|
committer | mikaelpeltier <mikaelpeltier@google.com> | 2015-01-28 11:05:23 +0100 |
commit | dcb2f9d6906ba60f0fb7d06e886fd776a4382c58 (patch) | |
tree | d1e50909d2702c1b91a253b3207f9910c136811c /sched | |
parent | 6316950c4fbb8a625c7bbc99c5d2a75737a0544b (diff) | |
download | toolchain_jack-dcb2f9d6906ba60f0fb7d06e886fd776a4382c58.tar.gz toolchain_jack-dcb2f9d6906ba60f0fb7d06e886fd776a4382c58.tar.bz2 toolchain_jack-dcb2f9d6906ba60f0fb7d06e886fd776a4382c58.zip |
Add DirectFSCodec and ZipFSCodec
Change-Id: I235493d04a7cd286e150dc0251a73a265c845ddb
Diffstat (limited to 'sched')
-rw-r--r-- | sched/src/com/android/sched/util/codec/DirectFSCodec.java | 99 | ||||
-rw-r--r-- | sched/src/com/android/sched/util/codec/ZipFSCodec.java | 94 |
2 files changed, 193 insertions, 0 deletions
diff --git a/sched/src/com/android/sched/util/codec/DirectFSCodec.java b/sched/src/com/android/sched/util/codec/DirectFSCodec.java new file mode 100644 index 00000000..beedf8b1 --- /dev/null +++ b/sched/src/com/android/sched/util/codec/DirectFSCodec.java @@ -0,0 +1,99 @@ +/* + * 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.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.vfs.DirectFS; +import com.android.sched.vfs.VFS; + +import java.io.IOException; + +import javax.annotation.Nonnull; + +/** + * This {@link StringCodec} is used to create an instance of {@link VFS} backed by a + * filesystem directory. + */ +public class DirectFSCodec extends FileOrDirCodec implements StringCodec<VFS> { + + public DirectFSCodec() { + super(Existence.MUST_EXIST, Permission.READ | Permission.WRITE); + + assert (permissions & Permission.EXECUTE) == 0; + } + + public DirectFSCodec(@Nonnull Existence existence) { + super(existence, Permission.READ | Permission.WRITE); + } + + @Nonnull + public DirectFSCodec changeOwnerPermission() { + setChangePermission(ChangePermission.OWNER); + + return this; + } + + @Nonnull + public DirectFSCodec changeAllPermission() { + setChangePermission(ChangePermission.EVERYBODY); + + return this; + } + + @Override + public void checkValue(@Nonnull CodecContext context, @Nonnull VFS dir) { + } + + @Override + @Nonnull + public VFS parseString(@Nonnull CodecContext context, @Nonnull String string) { + try { + return checkString(context, string); + } catch (ParsingException e) { + throw new ConfigurationError(e); + } + } + + @Override + @Nonnull + public String formatValue(@Nonnull VFS directory) { + return directory.getPath(); + } + + @Override + @Nonnull + public String getUsage() { + return "a path to a directory (" + getUsageDetails() + ")"; + } + + @Override + @Nonnull + public VFS checkString(@Nonnull CodecContext context, + @Nonnull final String string) throws ParsingException { + try { + return new DirectFS(new Directory(string, + context.getRunnableHooks(), existence, permissions, change), permissions); + } catch (IOException e) { + throw new ParsingException(e); + } + } +} diff --git a/sched/src/com/android/sched/util/codec/ZipFSCodec.java b/sched/src/com/android/sched/util/codec/ZipFSCodec.java new file mode 100644 index 00000000..035a2e4c --- /dev/null +++ b/sched/src/com/android/sched/util/codec/ZipFSCodec.java @@ -0,0 +1,94 @@ +/* + * 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.util.codec; + + +import com.android.sched.util.RunnableHooks; +import com.android.sched.util.config.ConfigurationError; +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.OutputZipFile; +import com.android.sched.vfs.ReadWriteZipFS; +import com.android.sched.vfs.VFS; + +import java.io.IOException; + +import javax.annotation.Nonnull; + +/** + * This {@link StringCodec} is used to create an instance of {@link VFS} backed by a + * filesystem directory, which is then zipped when closed. + */ +public class ZipFSCodec extends FileOrDirCodec implements StringCodec<VFS> { + + public ZipFSCodec(@Nonnull Existence existence) { + super(existence, Permission.READ | Permission.WRITE); + } + + @Nonnull + public ZipFSCodec changeOwnerPermission() { + setChangePermission(ChangePermission.OWNER); + + return this; + } + + @Nonnull + public ZipFSCodec changeAllPermission() { + setChangePermission(ChangePermission.EVERYBODY); + + return this; + } + + @Override + public void checkValue(@Nonnull CodecContext context, @Nonnull VFS dir) { + } + + @Override + @Nonnull + public VFS parseString(@Nonnull CodecContext context, @Nonnull String string) { + try { + return checkString(context, string); + } catch (ParsingException e) { + throw new ConfigurationError(e); + } + } + + @Override + @Nonnull + public String formatValue(@Nonnull VFS directory) { + return directory.getPath(); + } + + @Override + @Nonnull + public String getUsage() { + return "a path to a zip archive (" + getUsageDetails() + ")"; + } + + @Override + @Nonnull + public VFS checkString(@Nonnull CodecContext context, + @Nonnull final String string) throws ParsingException { + RunnableHooks hooks = context.getRunnableHooks(); + try { + return new ReadWriteZipFS(new OutputZipFile(string, hooks, existence, change)); + } catch (IOException e) { + throw new ParsingException(e.getMessage(), e); + } + } +} |