summaryrefslogtreecommitdiffstats
path: root/jack-api
diff options
context:
space:
mode:
authorJean-Philippe Lesot <jplesot@google.com>2015-02-27 12:11:21 +0100
committerJean-Philippe Lesot <jplesot@google.com>2015-02-27 15:08:03 +0100
commit46761f5f9b7b4f40f13ae1c26e145cf123461abb (patch)
treed611bae5490bdc683eecc1c8ce6d163ffd9270c5 /jack-api
parentf02aec7098433dfaa9a29c9f496bcc870f27bde4 (diff)
downloadtoolchain_jack-46761f5f9b7b4f40f13ae1c26e145cf123461abb.zip
toolchain_jack-46761f5f9b7b4f40f13ae1c26e145cf123461abb.tar.gz
toolchain_jack-46761f5f9b7b4f40f13ae1c26e145cf123461abb.tar.bz2
Working on Jack API
Change-Id: I1e5467956ccb3a593fcbf07d9e774eb995bd1cdb
Diffstat (limited to 'jack-api')
-rw-r--r--jack-api/src/com/android/jack/api/ConfigNotSupportedException.java (renamed from jack-api/src/com/android/jack/api/arzon/ArzonConfig.java)26
-rw-r--r--jack-api/src/com/android/jack/api/JackConfigProvider.java2
-rw-r--r--jack-api/src/com/android/jack/api/arzon/ArzonCompiler.java28
-rw-r--r--jack-api/src/com/android/jack/api/brest/AbortException.java (renamed from jack-api/src/com/android/jack/api/AbortException.java)4
-rw-r--r--jack-api/src/com/android/jack/api/brest/BrestCompiler.java2
-rw-r--r--jack-api/src/com/android/jack/api/brest/BrestConfig.java7
-rw-r--r--jack-api/src/com/android/jack/api/brest/ChainedException.java152
-rw-r--r--jack-api/src/com/android/jack/api/brest/ConfigurationException.java38
-rw-r--r--jack-api/src/com/android/jack/api/brest/UnrecoverableException.java (renamed from jack-api/src/com/android/jack/api/UnrecoverableException.java)10
-rw-r--r--jack-api/src/com/android/jack/api/example/Main.java80
10 files changed, 269 insertions, 80 deletions
diff --git a/jack-api/src/com/android/jack/api/arzon/ArzonConfig.java b/jack-api/src/com/android/jack/api/ConfigNotSupportedException.java
index b8c84a8..277e7d1 100644
--- a/jack-api/src/com/android/jack/api/arzon/ArzonConfig.java
+++ b/jack-api/src/com/android/jack/api/ConfigNotSupportedException.java
@@ -14,19 +14,29 @@
* limitations under the License.
*/
-package com.android.jack.api.arzon;
-
-import com.android.jack.api.JackConfig;
+package com.android.jack.api;
import javax.annotation.Nonnull;
/**
* STOPSHIP
*/
-public interface ArzonConfig extends JackConfig {
- @Nonnull
- ArzonConfig setProperty(@Nonnull String key, @Nonnull String value);
+public class ConfigNotSupportedException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public ConfigNotSupportedException() {
+ super();
+ }
+
+ public ConfigNotSupportedException(@Nonnull String message) {
+ super(message);
+ }
+
+ public ConfigNotSupportedException(@Nonnull String message, @Nonnull Throwable cause) {
+ super(message, cause);
+ }
- @Nonnull
- ArzonCompiler build();
+ public ConfigNotSupportedException(@Nonnull Throwable cause) {
+ super(cause);
+ }
}
diff --git a/jack-api/src/com/android/jack/api/JackConfigProvider.java b/jack-api/src/com/android/jack/api/JackConfigProvider.java
index b65830f..3d362e0 100644
--- a/jack-api/src/com/android/jack/api/JackConfigProvider.java
+++ b/jack-api/src/com/android/jack/api/JackConfigProvider.java
@@ -28,7 +28,7 @@ public interface JackConfigProvider {
static final String CLASS_NAME = "com.android.jack.api.impl.JackConfigProviderImpl";
@Nonnull
- <T extends JackConfig> T getConfig(@Nonnull Class<T> cls);
+ <T extends JackConfig> T getConfig(@Nonnull Class<T> cls) throws ConfigNotSupportedException;
@Nonnull
Collection<Class<? extends JackConfig>> getSupportedConfigs();
diff --git a/jack-api/src/com/android/jack/api/arzon/ArzonCompiler.java b/jack-api/src/com/android/jack/api/arzon/ArzonCompiler.java
deleted file mode 100644
index e4a3463..0000000
--- a/jack-api/src/com/android/jack/api/arzon/ArzonCompiler.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.jack.api.arzon;
-
-import com.android.jack.api.AbortException;
-import com.android.jack.api.UnrecoverableException;
-
-
-/**
- * STOPSHIP
- */
-public interface ArzonCompiler {
- void run() throws AbortException, UnrecoverableException;
-}
diff --git a/jack-api/src/com/android/jack/api/AbortException.java b/jack-api/src/com/android/jack/api/brest/AbortException.java
index 814d129..3c0757d 100644
--- a/jack-api/src/com/android/jack/api/AbortException.java
+++ b/jack-api/src/com/android/jack/api/brest/AbortException.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 The Android Open Source Project
+ * 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.jack.api;
+package com.android.jack.api.brest;
import javax.annotation.Nonnull;
diff --git a/jack-api/src/com/android/jack/api/brest/BrestCompiler.java b/jack-api/src/com/android/jack/api/brest/BrestCompiler.java
index 645e366..111b5af 100644
--- a/jack-api/src/com/android/jack/api/brest/BrestCompiler.java
+++ b/jack-api/src/com/android/jack/api/brest/BrestCompiler.java
@@ -16,8 +16,6 @@
package com.android.jack.api.brest;
-import com.android.jack.api.AbortException;
-import com.android.jack.api.UnrecoverableException;
/**
* STOPSHIP
diff --git a/jack-api/src/com/android/jack/api/brest/BrestConfig.java b/jack-api/src/com/android/jack/api/brest/BrestConfig.java
index 02dded8..deed8cb 100644
--- a/jack-api/src/com/android/jack/api/brest/BrestConfig.java
+++ b/jack-api/src/com/android/jack/api/brest/BrestConfig.java
@@ -25,8 +25,11 @@ import javax.annotation.Nonnull;
*/
public interface BrestConfig extends JackConfig {
@Nonnull
- BrestConfig setProperty(@Nonnull String key, @Nonnull String value);
+ static final String PROPERTY_REPORTER = "jack.reporter";
@Nonnull
- BrestCompiler build();
+ BrestConfig setProperty(@Nonnull String key, @Nonnull String value) throws ConfigurationException;
+
+ @Nonnull
+ BrestCompiler build() throws ConfigurationException;
}
diff --git a/jack-api/src/com/android/jack/api/brest/ChainedException.java b/jack-api/src/com/android/jack/api/brest/ChainedException.java
new file mode 100644
index 0000000..7a8a01c
--- /dev/null
+++ b/jack-api/src/com/android/jack/api/brest/ChainedException.java
@@ -0,0 +1,152 @@
+/*
+ * 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.jack.api.brest;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnegative;
+import javax.annotation.Nonnull;
+
+/**
+ * Abstract class to easily chain exceptions together.
+ *
+ * The exception can be managed like any other exception. In this case, the first one will be the
+ * only one used.
+ *
+ * Special management can use the {@link #iterator()} or the {@link #getNextException()} to browse
+ * all chained exceptions and dispatch them.
+ *
+ * See {@link ChainedExceptionBuilder} to build the chain of exceptions.
+ */
+public abstract class ChainedException extends Exception
+ implements Iterable<ChainedException> {
+ private static final long serialVersionUID = 1L;
+
+ @Nonnull
+ private String message;
+
+ @Nonnegative
+ private int count = 1;
+
+ @Nonnull
+ private ChainedException tail = this;
+
+ @CheckForNull
+ private ChainedException next = null;
+
+ public ChainedException(@Nonnull String message) {
+ super("");
+ this.message = message;
+ }
+
+ public ChainedException(@Nonnull String message, @Nonnull Throwable cause) {
+ super("", cause);
+ this.message = message;
+ }
+
+ public ChainedException(@Nonnull Throwable cause) {
+ super(cause);
+ this.message = cause.getMessage();
+ }
+
+ @Override
+ @Nonnull
+ public String getMessage() {
+ return message;
+ }
+
+ @Override
+ @Nonnull
+ public String getLocalizedMessage() {
+ return message;
+ }
+
+ public void setMessage(@Nonnull String message) {
+ this.message = message;
+ }
+
+ @Nonnull
+ protected ChainedException putAsLastExceptionOf(
+ @CheckForNull ChainedException head) {
+ if (head == null) {
+ this.tail = this;
+ this.next = null;
+ this.count = 1;
+
+ return this;
+ } else {
+ head.tail.next = this;
+ head.tail = this;
+ head.count++;
+
+ return head;
+ }
+ }
+
+ @CheckForNull
+ public ChainedException getNextException() {
+ return next;
+ }
+
+ @Nonnegative
+ public int getNextExceptionCount() {
+ return count;
+ }
+
+ @Override
+ @Nonnull
+ public Iterator<ChainedException> iterator() {
+ ArrayList<ChainedException> list = new ArrayList<ChainedException>(count);
+
+ ChainedException exception = this;
+ do {
+ list.add(exception);
+ exception = exception.next;
+ } while (exception != null);
+
+ return list.iterator();
+ }
+
+ /**
+ * Builder to construct a chain of exceptions.
+ */
+ public static class ChainedExceptionBuilder<T extends ChainedException> {
+ @CheckForNull
+ private T head = null;
+
+ @SuppressWarnings("unchecked")
+ public void appendException(@Nonnull T exceptions) {
+ for (ChainedException exception : exceptions) {
+ head = (T) exception.putAsLastExceptionOf(head);
+ }
+ }
+
+ public void throwIfNecessary() throws T {
+ if (head != null) {
+ throw head;
+ }
+ }
+
+ @Nonnull
+ public T getException() {
+ assert head != null;
+ return head;
+ }
+ }
+}
diff --git a/jack-api/src/com/android/jack/api/brest/ConfigurationException.java b/jack-api/src/com/android/jack/api/brest/ConfigurationException.java
new file mode 100644
index 0000000..ab98c67
--- /dev/null
+++ b/jack-api/src/com/android/jack/api/brest/ConfigurationException.java
@@ -0,0 +1,38 @@
+/*
+ * 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.jack.api.brest;
+
+import javax.annotation.Nonnull;
+
+/**
+ * All exceptions thrown from the configuration framework.
+ */
+public abstract class ConfigurationException extends ChainedException {
+ private static final long serialVersionUID = 1L;
+
+ public ConfigurationException(@Nonnull String message) {
+ super(message);
+ }
+
+ public ConfigurationException(@Nonnull String message, @Nonnull Throwable cause) {
+ super(message, cause);
+ }
+
+ public ConfigurationException(@Nonnull Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/jack-api/src/com/android/jack/api/UnrecoverableException.java b/jack-api/src/com/android/jack/api/brest/UnrecoverableException.java
index 4d5a934..5d938fa 100644
--- a/jack-api/src/com/android/jack/api/UnrecoverableException.java
+++ b/jack-api/src/com/android/jack/api/brest/UnrecoverableException.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 The Android Open Source Project
+ * 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.
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.android.jack.api;
+package com.android.jack.api.brest;
import javax.annotation.Nonnull;
/**
- * Thrown when a major problem occurred because of an event out of control. Handling this error
- * should only be reporting to the user and maybe just retry exactly the same thing as the one that
- * has thrown.
+ * Thrown when a major problem occurred because of an event out of control (e.g. an external process
+ * remove a temporary file used by Jack). Handling this error should only be reporting to the user
+ * and maybe just retry exactly the same thing as the one that has thrown.
*/
public class UnrecoverableException extends Exception {
private static final long serialVersionUID = 1L;
diff --git a/jack-api/src/com/android/jack/api/example/Main.java b/jack-api/src/com/android/jack/api/example/Main.java
index 3673889..573ed16 100644
--- a/jack-api/src/com/android/jack/api/example/Main.java
+++ b/jack-api/src/com/android/jack/api/example/Main.java
@@ -1,13 +1,29 @@
-package com.android.jack.api.example;
+/*
+ * 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.jack.api.example;
-import com.android.jack.api.AbortException;
+import com.android.jack.api.ConfigNotSupportedException;
import com.android.jack.api.JackConfig;
import com.android.jack.api.JackConfigProvider;
-import com.android.jack.api.UnrecoverableException;
-import com.android.jack.api.arzon.ArzonCompiler;
-import com.android.jack.api.arzon.ArzonConfig;
+import com.android.jack.api.brest.AbortException;
+import com.android.jack.api.brest.BrestCompiler;
import com.android.jack.api.brest.BrestConfig;
+import com.android.jack.api.brest.ConfigurationException;
+import com.android.jack.api.brest.UnrecoverableException;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
@@ -16,22 +32,9 @@ import java.net.URL;
import java.net.URLClassLoader;
/**
- *
+ * STOPSHIP
*/
public class Main {
-
- /**
- *
- * @param args
- * @throws MalformedURLException
- * @throws ClassNotFoundException
- * @throws SecurityException
- * @throws NoSuchMethodException
- * @throws IllegalArgumentException
- * @throws InstantiationException
- * @throws IllegalAccessException
- * @throws InvocationTargetException
- */
public static void main(String[] args) throws MalformedURLException, ClassNotFoundException,
SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,
IllegalAccessException, InvocationTargetException {
@@ -56,25 +59,38 @@ public class Main {
}
System.out.println();
- ArzonConfig arzonConfig = confProvider.getConfig(ArzonConfig.class);
- arzonConfig.setProperty("c.a.n.arzon", "bar").setProperty("a.b.c.d", "foo");
- ArzonCompiler arzonCompiler = arzonConfig.build();
+ BrestCompiler brestCompiler;
+ BrestConfig brestConfig;
+
+ // Get configuration object
try {
- arzonCompiler.run();
- } catch (AbortException e) {
- e.printStackTrace();
- } catch (UnrecoverableException e) {
- e.printStackTrace();
+ brestConfig = confProvider.getConfig(BrestConfig.class);
+ } catch (ConfigNotSupportedException e1) {
+ System.err.println("Brest config not supported)");
+ return;
+ }
+
+ // Configure the compiler
+ try {
+ brestConfig.setProperty(BrestConfig.PROPERTY_REPORTER, "sdk");
+ brestCompiler = brestConfig.build();
+ } catch (ConfigurationException e) {
+ System.err.println(e.getMessage());
+ return;
}
- BrestConfig brest = confProvider.getConfig(BrestConfig.class);
- brest.setProperty("c.a.n.brest", "toto");
+ // Run the compilation
try {
- brest.build().run();
+ // First
+ brestCompiler.run();
+ // Same compilation
+ brestCompiler.run();
} catch (AbortException e) {
- e.printStackTrace();
+ System.out.println("User error, see reporter");
+ return;
} catch (UnrecoverableException e) {
- e.printStackTrace();
+ System.out.println("Something out of Jack control has happen: " + e.getMessage());
+ return;
}
}
}