summaryrefslogtreecommitdiffstats
path: root/sched
diff options
context:
space:
mode:
authorYohann Roussel <yroussel@google.com>2015-03-10 16:32:40 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-03-10 16:32:40 +0000
commitbf48e2963f127638b2d7f2fc266b9176b51d437c (patch)
tree761d300efd868c375ab8a255bd7a282875272d16 /sched
parent2a367c8fb0ebb06fa4c5ae17522899f592df221b (diff)
parentd6ccb85505c0d7a0bd6544d67f6d43e40775a76b (diff)
downloadtoolchain_jack-bf48e2963f127638b2d7f2fc266b9176b51d437c.zip
toolchain_jack-bf48e2963f127638b2d7f2fc266b9176b51d437c.tar.gz
toolchain_jack-bf48e2963f127638b2d7f2fc266b9176b51d437c.tar.bz2
Merge "Jack support for annotation processor." into ub-jack
Diffstat (limited to 'sched')
-rw-r--r--sched/src/com/android/sched/util/RunnableHooks.java10
-rw-r--r--sched/src/com/android/sched/util/codec/InputFileOrDirectoryCodec.java84
-rw-r--r--sched/src/com/android/sched/util/codec/ListCodec.java7
-rw-r--r--sched/src/com/android/sched/util/codec/ListParsingException.java2
-rw-r--r--sched/src/com/android/sched/util/codec/PairCodec.java167
-rw-r--r--sched/src/com/android/sched/util/codec/PairListToMapCodecConverter.java60
-rw-r--r--sched/src/com/android/sched/util/codec/StringValueCodec.java69
-rw-r--r--sched/src/com/android/sched/util/config/id/EnumPropertyId.java8
-rw-r--r--sched/src/com/android/sched/util/config/id/ListPropertyId.java2
9 files changed, 396 insertions, 13 deletions
diff --git a/sched/src/com/android/sched/util/RunnableHooks.java b/sched/src/com/android/sched/util/RunnableHooks.java
index c7143ab..07430fc 100644
--- a/sched/src/com/android/sched/util/RunnableHooks.java
+++ b/sched/src/com/android/sched/util/RunnableHooks.java
@@ -43,15 +43,6 @@ public class RunnableHooks {
@Nonnull
private final List<Runnable> hooks = new ArrayList<Runnable>();
- public RunnableHooks() {
- Runtime.getRuntime().addShutdownHook(new Thread(){
- @Override
- public void run() {
- runHooks();
- }
- });
- }
-
public synchronized void addHook(@Nonnull Runnable hook) {
assert !hooks.contains(hook);
@@ -65,7 +56,6 @@ public class RunnableHooks {
}
public synchronized void runHooks() {
-
for (Runnable hook : Lists.reverse(hooks)) {
hook.run();
}
diff --git a/sched/src/com/android/sched/util/codec/InputFileOrDirectoryCodec.java b/sched/src/com/android/sched/util/codec/InputFileOrDirectoryCodec.java
new file mode 100644
index 0000000..b735e50
--- /dev/null
+++ b/sched/src/com/android/sched/util/codec/InputFileOrDirectoryCodec.java
@@ -0,0 +1,84 @@
+/*
+ * 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;
+import com.android.sched.util.file.FileOrDirectory.Existence;
+import com.android.sched.util.file.FileOrDirectory.Permission;
+import com.android.sched.util.file.InputStreamFile;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+/**
+ * This {@link StringCodec} is used to create an instance of {@link FileOrDirectory}.
+ */
+public class InputFileOrDirectoryCodec extends FileOrDirCodec<FileOrDirectory> {
+
+ public InputFileOrDirectoryCodec() {
+ super(Existence.MUST_EXIST, Permission.READ);
+ }
+
+ @Override
+ @Nonnull
+ public FileOrDirectory parseString(@Nonnull CodecContext context, @Nonnull String string) {
+ try {
+ return checkString(context, string);
+ } catch (ParsingException e) {
+ throw new ConfigurationError(e);
+ }
+ }
+
+ @Override
+ @CheckForNull
+ public FileOrDirectory checkString(@Nonnull CodecContext context, @Nonnull String string)
+ throws ParsingException {
+ File file = new File(string);
+ try {
+ if (file.isFile()) {
+ return new InputStreamFile(string);
+ } else {
+ return new Directory(string, context.getRunnableHooks(), existence, permissions, change);
+ }
+ } catch (IOException e) {
+ throw new ParsingException(e.getMessage(), e);
+ }
+
+ }
+
+ @Override
+ @Nonnull
+ public String getUsage() {
+ return "a path to a file or directory (" + getUsageDetails() + ")";
+ }
+
+ @Override
+ @Nonnull
+ public String formatValue(@Nonnull FileOrDirectory data) {
+ return data.getPath();
+ }
+
+ @Override
+ public void checkValue(@Nonnull CodecContext context, @Nonnull FileOrDirectory data) {
+ }
+
+}
diff --git a/sched/src/com/android/sched/util/codec/ListCodec.java b/sched/src/com/android/sched/util/codec/ListCodec.java
index 25f5c75..4544573 100644
--- a/sched/src/com/android/sched/util/codec/ListCodec.java
+++ b/sched/src/com/android/sched/util/codec/ListCodec.java
@@ -56,13 +56,18 @@ public class ListCodec<T> implements StringCodec<List<T>> {
this.var = var;
}
- public ListCodec<T> setSeperator(@Nonnull String separator) {
+ public ListCodec<T> setSeparator(@Nonnull String separator) {
this.separator = separator;
this.regexp = Pattern.quote(separator);
return this;
}
+ @Nonnull
+ public String getSeparator() {
+ return separator;
+ }
+
public ListCodec<T> setMin(@Nonnegative int min) {
assert min < max;
assert min >= 0;
diff --git a/sched/src/com/android/sched/util/codec/ListParsingException.java b/sched/src/com/android/sched/util/codec/ListParsingException.java
index 83d988d..048b07b 100644
--- a/sched/src/com/android/sched/util/codec/ListParsingException.java
+++ b/sched/src/com/android/sched/util/codec/ListParsingException.java
@@ -30,7 +30,7 @@ public class ListParsingException extends ParsingException {
private final int index;
public ListParsingException(@Nonnegative int index, @Nonnull String message) {
- super(message);
+ super("element #" + (index + 1) + ": " + message);
this.index = index;
}
diff --git a/sched/src/com/android/sched/util/codec/PairCodec.java b/sched/src/com/android/sched/util/codec/PairCodec.java
new file mode 100644
index 0000000..4032bf8
--- /dev/null
+++ b/sched/src/com/android/sched/util/codec/PairCodec.java
@@ -0,0 +1,167 @@
+/*
+ * 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.config.ChainedException.ChainedExceptionBuilder;
+import com.android.sched.util.config.ConfigurationError;
+
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+/**
+ * This {@link StringCodec} is used to create an instance of {@link Entry}
+ */
+// STOPSHIP see https://android-review.googlesource.com/#/c/120553/17
+public class PairCodec<T, U> implements StringCodec<Entry<T, U>>{
+ @Nonnull
+ private final StringCodec<T> keyParser;
+ @Nonnull
+ private final StringCodec<U> valueParser;
+
+ @Nonnull
+ private String separator = "=";
+
+ public PairCodec(@Nonnull StringCodec<T> keyParser, @Nonnull StringCodec<U> valueParser) {
+ this.keyParser = keyParser;
+ this.valueParser = valueParser;
+ }
+
+ @Nonnull
+ public PairCodec<T, U> on(@Nonnull String separator) {
+ this.separator = separator;
+
+ return this;
+ }
+
+ @Nonnull
+ public String getSeparator() {
+ return separator;
+ }
+
+ @Override
+ @Nonnull
+ public Entry<T, U> parseString(@Nonnull CodecContext context,
+ @Nonnull String string) {
+ int endKey = string.indexOf(separator);
+ if (endKey == -1) {
+ throw new ConfigurationError("Missing '"
+ + separator + "' in '" + string + "'");
+ }
+ String key = string.substring(0, endKey);
+ String valueString = string.substring(endKey + separator.length());
+ return new AbstractMap.SimpleEntry<T, U>(keyParser.parseString(context, key),
+ valueParser.parseString(context, valueString));
+ }
+
+ @Override
+ @CheckForNull
+ public Entry<T, U> checkString(@Nonnull CodecContext context,
+ @Nonnull String string)
+ throws ParsingException {
+
+ ChainedExceptionBuilder<ParsingException> exceptions =
+ new ChainedExceptionBuilder<ParsingException>();
+
+ T keyElement = null;
+ U valueElement = null;
+ int endKey = string.indexOf(separator);
+ if (endKey == -1) {
+ exceptions.appendException(new ParsingException("Missing '"
+ + separator + "' in '" + string + "'"));
+ } else {
+ String key = string.substring(0, endKey);
+ String valueString = string.substring(endKey + separator.length());
+ try {
+ keyElement = keyParser.checkString(context, key);
+ } catch (ParsingException e) {
+ exceptions.appendException(e);
+ }
+ try {
+ valueElement = valueParser.checkString(context, valueString);
+ } catch (ParsingException e) {
+ exceptions.appendException(e);
+ }
+ }
+
+ exceptions.throwIfNecessary();
+ // If one element is null, do not compute the pair
+ if (keyElement == null || valueElement == null) {
+ return null;
+ } else {
+ return new AbstractMap.SimpleEntry<T, U>(keyElement, valueElement);
+ }
+ }
+
+ @Override
+ @Nonnull
+ public String getUsage() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("<key>" + separator + "<value>");
+ sb.append(" where <key> is ");
+ sb.append(keyParser.getUsage());
+ sb.append(" and where <value> is ");
+ sb.append(valueParser.getUsage());
+
+ return sb.toString();
+ }
+
+ @Override
+ @Nonnull
+ public List<com.android.sched.util.codec.Parser.ValueDescription> getValueDescriptions() {
+ List<com.android.sched.util.codec.Parser.ValueDescription> list =
+ new ArrayList<Parser.ValueDescription>();
+ list.addAll(keyParser.getValueDescriptions());
+ list.addAll(valueParser.getValueDescriptions());
+ return list;
+ }
+
+ @Override
+ @Nonnull
+ public String formatValue(@Nonnull Entry<T, U> data) {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(keyParser.formatValue(data.getKey()));
+ sb.append(separator);
+ sb.append(valueParser.formatValue(data.getValue()));
+ return sb.toString();
+ }
+
+ @Override
+ public void checkValue(@Nonnull CodecContext context, @Nonnull Entry<T, U> data)
+ throws CheckingException {
+ ChainedExceptionBuilder<CheckingException> exceptions =
+ new ChainedExceptionBuilder<CheckingException>();
+ try {
+ keyParser.checkValue(context, data.getKey());
+ } catch (CheckingException e) {
+ exceptions.appendException(e);
+ }
+ try {
+ valueParser.checkValue(context, data.getValue());
+ } catch (CheckingException e) {
+ exceptions.appendException(e);
+ }
+
+ exceptions.throwIfNecessary();
+ }
+
+}
diff --git a/sched/src/com/android/sched/util/codec/PairListToMapCodecConverter.java b/sched/src/com/android/sched/util/codec/PairListToMapCodecConverter.java
new file mode 100644
index 0000000..b9c9e86
--- /dev/null
+++ b/sched/src/com/android/sched/util/codec/PairListToMapCodecConverter.java
@@ -0,0 +1,60 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.annotation.Nonnull;
+
+/**
+ * A {@link ConvertCodec} allowing to convert list of {@link Entry} into a map.
+ */
+public class PairListToMapCodecConverter<T, U> extends
+ ConvertCodec<List<Entry<T, U>>, Map<T, U>> {
+ public PairListToMapCodecConverter(StringCodec<List<Entry<T, U>>> codec) {
+ super(codec);
+ }
+
+ @Override
+ @Nonnull
+ public Map<T, U> parseString(@Nonnull CodecContext context,
+ @Nonnull String string) {
+ List<Entry<T, U>> list = codec.parseString(context, string);
+ Map<T, U> map = new HashMap<T, U>(Math.round(list.size() / 0.75f),
+ 0.75f);
+ for (Entry<T, U> entry : list) {
+ map.put(entry.getKey(), entry.getValue());
+ }
+ return map;
+ }
+
+ @Override
+ @Nonnull
+ public String formatValue(@Nonnull Map<T, U> data) {
+ return codec.formatValue(new ArrayList<Map.Entry<T, U>>(data.entrySet()));
+ }
+
+ @Override
+ public void checkValue(@Nonnull CodecContext context, @Nonnull Map<T, U> data)
+ throws CheckingException {
+ codec.checkValue(context, new ArrayList<Map.Entry<T, U>>(data.entrySet()));
+ }
+} \ No newline at end of file
diff --git a/sched/src/com/android/sched/util/codec/StringValueCodec.java b/sched/src/com/android/sched/util/codec/StringValueCodec.java
new file mode 100644
index 0000000..19e13be
--- /dev/null
+++ b/sched/src/com/android/sched/util/codec/StringValueCodec.java
@@ -0,0 +1,69 @@
+/*
+ * 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 java.util.Collections;
+import java.util.List;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+/**
+ * A {@link StringCodec} performing no check nor conversion, just providing a usage.
+ */
+public class StringValueCodec implements StringCodec<String> {
+ @Nonnull
+ private final String usage;
+
+ public StringValueCodec(@Nonnull String usage) {
+ this.usage = usage;
+ }
+
+ @Override
+ @Nonnull
+ public String parseString(@Nonnull CodecContext context, @Nonnull String string) {
+ return string;
+ }
+
+ @Override
+ @CheckForNull
+ public String checkString(@Nonnull CodecContext context, @Nonnull String string) {
+ return string;
+ }
+
+ @Override
+ @Nonnull
+ public String getUsage() {
+ return usage;
+ }
+
+ @Override
+ @Nonnull
+ public List<ValueDescription> getValueDescriptions() {
+ return Collections.<ValueDescription> emptyList();
+ }
+
+ @Override
+ @Nonnull
+ public String formatValue(@Nonnull String data) {
+ return data;
+ }
+
+ @Override
+ public void checkValue(@Nonnull CodecContext context, @Nonnull String data) {
+ }
+} \ No newline at end of file
diff --git a/sched/src/com/android/sched/util/config/id/EnumPropertyId.java b/sched/src/com/android/sched/util/config/id/EnumPropertyId.java
index c209e3c..d98baef 100644
--- a/sched/src/com/android/sched/util/config/id/EnumPropertyId.java
+++ b/sched/src/com/android/sched/util/config/id/EnumPropertyId.java
@@ -20,6 +20,7 @@ import com.android.sched.util.codec.EnumCodec;
import com.android.sched.util.config.ConfigChecker;
import com.android.sched.util.config.MissingPropertyException;
import com.android.sched.util.config.PropertyIdException;
+import com.android.sched.util.config.category.Category;
import com.android.sched.util.config.expression.BooleanExpression;
import javax.annotation.Nonnull;
@@ -85,6 +86,13 @@ public class EnumPropertyId<T extends Enum<T>> extends PropertyId<T> {
return this;
}
+ @Override
+ @Nonnull
+ public EnumPropertyId<T> withCategory(@Nonnull Category category) {
+ super.withCategory(category);
+ return this;
+ }
+
@Nonnull
public BooleanExpression is(@Nonnull final T enumValue) {
return new BooleanExpression() {
diff --git a/sched/src/com/android/sched/util/config/id/ListPropertyId.java b/sched/src/com/android/sched/util/config/id/ListPropertyId.java
index 075fa00..fe4e032 100644
--- a/sched/src/com/android/sched/util/config/id/ListPropertyId.java
+++ b/sched/src/com/android/sched/util/config/id/ListPropertyId.java
@@ -80,7 +80,7 @@ public class ListPropertyId<T> extends PropertyId<List<T>> {
@Nonnull
public ListPropertyId<T> on(@Nonnull String separator) {
- getCodec().setSeperator(separator);
+ getCodec().setSeparator(separator);
return this;
}