diff options
author | Jean-Philippe Lesot <jplesot@google.com> | 2015-02-26 19:06:48 +0100 |
---|---|---|
committer | Jean-Philippe Lesot <jplesot@google.com> | 2015-02-26 19:06:48 +0100 |
commit | 5d34a7cbd1f21cd27192736b0dcb0f3dee86ae4e (patch) | |
tree | 1375a324558d95c0b02d2fea80f7cb962349282d | |
parent | 43c55378c7a96f6478e75389ba325a9988bb7831 (diff) | |
download | toolchain_jack-5d34a7cbd1f21cd27192736b0dcb0f3dee86ae4e.zip toolchain_jack-5d34a7cbd1f21cd27192736b0dcb0f3dee86ae4e.tar.gz toolchain_jack-5d34a7cbd1f21cd27192736b0dcb0f3dee86ae4e.tar.bz2 |
First take of Jack API. WIP.
Change-Id: Iff2b57d5ca7720b62ee8ac06172204036e981657
9 files changed, 353 insertions, 0 deletions
diff --git a/jack-api/src/com/android/jack/api/AbortException.java b/jack-api/src/com/android/jack/api/AbortException.java new file mode 100644 index 0000000..814d129 --- /dev/null +++ b/jack-api/src/com/android/jack/api/AbortException.java @@ -0,0 +1,43 @@ +/* + * 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; + +import javax.annotation.Nonnull; + +/** + * A {@link RuntimeException} that should be fatal and cause Jack to abort. It should not be caught, + * should have a cause {@link ReportableException} and no message. + */ +public class AbortException extends Exception { + private static final long serialVersionUID = 1L; + + public AbortException() { + super(); + } + + public AbortException(@Nonnull String message) { + super(message); + } + + public AbortException(@Nonnull String message, @Nonnull Throwable cause) { + super(message, cause); + } + + public AbortException(@Nonnull Throwable cause) { + super(cause); + } +} diff --git a/jack-api/src/com/android/jack/api/JackConfig.java b/jack-api/src/com/android/jack/api/JackConfig.java new file mode 100644 index 0000000..ee4ec3e --- /dev/null +++ b/jack-api/src/com/android/jack/api/JackConfig.java @@ -0,0 +1,23 @@ +/* + * 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; + +/** + * STOPSHIP + */ +public interface JackConfig { +} diff --git a/jack-api/src/com/android/jack/api/JackConfigProvider.java b/jack-api/src/com/android/jack/api/JackConfigProvider.java new file mode 100644 index 0000000..b65830f --- /dev/null +++ b/jack-api/src/com/android/jack/api/JackConfigProvider.java @@ -0,0 +1,44 @@ +/* + * 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; + +import java.util.Collection; + +import javax.annotation.Nonnull; + +/** + * STOPSHIP + */ +public interface JackConfigProvider { + @Nonnull + static final String CLASS_NAME = "com.android.jack.api.impl.JackConfigProviderImpl"; + + @Nonnull + <T extends JackConfig> T getConfig(@Nonnull Class<T> cls); + + @Nonnull + Collection<Class<? extends JackConfig>> getSupportedConfigs(); + + @Nonnull + String getCompilerCodeName(); + @Nonnull + String getCompilerVersion(); + @Nonnull + String getCompilerBuildId(); + @Nonnull + String getCompilerCodeBase(); +} diff --git a/jack-api/src/com/android/jack/api/UnrecoverableException.java b/jack-api/src/com/android/jack/api/UnrecoverableException.java new file mode 100644 index 0000000..4d5a934 --- /dev/null +++ b/jack-api/src/com/android/jack/api/UnrecoverableException.java @@ -0,0 +1,44 @@ +/* + * 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; + +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. + */ +public class UnrecoverableException extends Exception { + private static final long serialVersionUID = 1L; + + public UnrecoverableException() { + super(); + } + + public UnrecoverableException(@Nonnull String message) { + super(message); + } + + public UnrecoverableException(@Nonnull String message, @Nonnull Throwable cause) { + super(message, cause); + } + + public UnrecoverableException(@Nonnull Throwable cause) { + super(cause); + } +} diff --git a/jack-api/src/com/android/jack/api/arzon/ArzonCompiler.java b/jack-api/src/com/android/jack/api/arzon/ArzonCompiler.java new file mode 100644 index 0000000..e4a3463 --- /dev/null +++ b/jack-api/src/com/android/jack/api/arzon/ArzonCompiler.java @@ -0,0 +1,28 @@ +/* + * 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/arzon/ArzonConfig.java b/jack-api/src/com/android/jack/api/arzon/ArzonConfig.java new file mode 100644 index 0000000..b8c84a8 --- /dev/null +++ b/jack-api/src/com/android/jack/api/arzon/ArzonConfig.java @@ -0,0 +1,32 @@ +/* + * 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.JackConfig; + +import javax.annotation.Nonnull; + +/** + * STOPSHIP + */ +public interface ArzonConfig extends JackConfig { + @Nonnull + ArzonConfig setProperty(@Nonnull String key, @Nonnull String value); + + @Nonnull + ArzonCompiler build(); +} diff --git a/jack-api/src/com/android/jack/api/brest/BrestCompiler.java b/jack-api/src/com/android/jack/api/brest/BrestCompiler.java new file mode 100644 index 0000000..645e366 --- /dev/null +++ b/jack-api/src/com/android/jack/api/brest/BrestCompiler.java @@ -0,0 +1,27 @@ +/* + * 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.brest; + +import com.android.jack.api.AbortException; +import com.android.jack.api.UnrecoverableException; + +/** + * STOPSHIP + */ +public interface BrestCompiler { + void run() throws AbortException, UnrecoverableException; +} diff --git a/jack-api/src/com/android/jack/api/brest/BrestConfig.java b/jack-api/src/com/android/jack/api/brest/BrestConfig.java new file mode 100644 index 0000000..02dded8 --- /dev/null +++ b/jack-api/src/com/android/jack/api/brest/BrestConfig.java @@ -0,0 +1,32 @@ +/* + * 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.brest; + +import com.android.jack.api.JackConfig; + +import javax.annotation.Nonnull; + +/** + * STOPSHIP + */ +public interface BrestConfig extends JackConfig { + @Nonnull + BrestConfig setProperty(@Nonnull String key, @Nonnull String value); + + @Nonnull + BrestCompiler build(); +} diff --git a/jack-api/src/com/android/jack/api/example/Main.java b/jack-api/src/com/android/jack/api/example/Main.java new file mode 100644 index 0000000..3673889 --- /dev/null +++ b/jack-api/src/com/android/jack/api/example/Main.java @@ -0,0 +1,80 @@ +package com.android.jack.api.example; + + +import com.android.jack.api.AbortException; +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.BrestConfig; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; + +/** + * + */ +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 { + ClassLoader loader = + URLClassLoader.newInstance(new URL[] {new File( + "/Users/jplesot/Android/ub-jack/toolchain/jack/jack/dist/jack.jar").toURI().toURL()}, + Main.class.getClassLoader()); + + Class<? extends JackConfigProvider> confProviderClass = + Class.forName(JackConfigProvider.CLASS_NAME, true, loader).asSubclass( + JackConfigProvider.class); + + JackConfigProvider confProvider = confProviderClass.getConstructor().newInstance(); + + System.out.println("Jack version: " + confProvider.getCompilerVersion() + " '" + + confProvider.getCompilerCodeName() + "' (" + confProvider.getCompilerBuildId() + " " + + confProvider.getCompilerCodeBase() + ")"); + + System.out.println("Supported configs: "); + for (Class<? extends JackConfig> cls : confProvider.getSupportedConfigs()) { + System.out.print(cls.getSimpleName() + " "); + } + 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(); + try { + arzonCompiler.run(); + } catch (AbortException e) { + e.printStackTrace(); + } catch (UnrecoverableException e) { + e.printStackTrace(); + } + + BrestConfig brest = confProvider.getConfig(BrestConfig.class); + brest.setProperty("c.a.n.brest", "toto"); + try { + brest.build().run(); + } catch (AbortException e) { + e.printStackTrace(); + } catch (UnrecoverableException e) { + e.printStackTrace(); + } + } +} |