diff options
author | Dennis Wagelaar | 2018-04-19 15:04:09 +0000 |
---|---|---|
committer | Dennis Wagelaar | 2018-04-19 15:04:09 +0000 |
commit | b804ac89cd0348725bf4565205dfe43cdc7475a0 (patch) | |
tree | 6b98e5f49d09149f5458454c25b23534d3e25203 /plugins | |
parent | 7b4076ae59355590678d4095eb44d59280be45ab (diff) | |
download | org.eclipse.atl-b804ac89cd0348725bf4565205dfe43cdc7475a0.tar.gz org.eclipse.atl-b804ac89cd0348725bf4565205dfe43cdc7475a0.tar.xz org.eclipse.atl-b804ac89cd0348725bf4565205dfe43cdc7475a0.zip |
Add emftvm.compile Ant task.
Diffstat (limited to 'plugins')
3 files changed, 130 insertions, 1 deletions
diff --git a/plugins/org.eclipse.m2m.atl.emftvm.ant/META-INF/MANIFEST.MF b/plugins/org.eclipse.m2m.atl.emftvm.ant/META-INF/MANIFEST.MF index b059137c..9dfc4947 100644 --- a/plugins/org.eclipse.m2m.atl.emftvm.ant/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.m2m.atl.emftvm.ant/META-INF/MANIFEST.MF @@ -10,7 +10,9 @@ Require-Bundle: org.apache.ant;bundle-version="1.7.1", org.eclipse.ant.core;bundle-version="3.2.101", org.eclipse.core.resources;bundle-version="3.5.2", org.eclipse.core.runtime;bundle-version="3.5.0", - org.eclipse.m2m.atl.common + org.eclipse.m2m.atl.common, + org.eclipse.m2m.atl.emftvm.compiler, + org.eclipse.m2m.atl.engine Bundle-Activator: org.eclipse.m2m.atl.emftvm.ant.EmftvmAntPlugin Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.m2m.atl.emftvm.ant diff --git a/plugins/org.eclipse.m2m.atl.emftvm.ant/plugin.xml b/plugins/org.eclipse.m2m.atl.emftvm.ant/plugin.xml index bf130f8b..a59e2046 100644 --- a/plugins/org.eclipse.m2m.atl.emftvm.ant/plugin.xml +++ b/plugins/org.eclipse.m2m.atl.emftvm.ant/plugin.xml @@ -28,6 +28,11 @@ library="lib/emftvmAntTasks.jar" name="emftvm.newModel"> </antTask> + <antTask + class="org.eclipse.m2m.atl.emftvm.ant.CompileTask" + library="lib/emftvmAntTasks.jar" + name="emftvm.compile"> + </antTask> </extension> </plugin> diff --git a/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/CompileTask.java b/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/CompileTask.java new file mode 100644 index 00000000..e1c97327 --- /dev/null +++ b/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/CompileTask.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2018 Dennis Wagelaar. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Dennis Wagelaar - initial API and + * implementation and/or initial documentation + *******************************************************************************/ +package org.eclipse.m2m.atl.emftvm.ant; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + +import org.eclipse.m2m.atl.core.ATLCoreException; +import org.eclipse.m2m.atl.emftvm.compiler.AtlToEmftvmCompiler; +import org.eclipse.m2m.atl.engine.compiler.CompileTimeError; + +/** + * Compiles an ATL module to EMFTVM bytecode. + * + * @author <a href="mailto:dwagelaar@gmail.com">Dennis Wagelaar</a> + */ +public class CompileTask extends EMFTVMTask { + + private String module; + private String modulePath; + private String charset; + + /** + * Sets the module name. + * + * @param module + * the module to set + */ + public void setModule(String module) { + this.module = module; + } + + /** + * Returns the module name. + * + * @return the module + */ + public String getModule() { + return module; + } + + /** + * Sets the module path. + * + * @param modulePath + * the modulePath to set + */ + public void setModulePath(String modulePath) { + this.modulePath = modulePath; + } + + /** + * Returns the module path. + * + * @return the modulePath + */ + public String getModulePath() { + return modulePath; + } + + /** + * Returns the character set to be used for parsing. + * + * @return the character set to be used for parsing + */ + public String getCharset() { + return charset; + } + + /** + * Sets the character set to be used for parsing + * + * @param charset + * the character set to set + */ + public void setCharset(String charset) { + this.charset = charset; + } + + /** + * {@inheritDoc} + */ + @Override + protected void innerExecute() throws Exception { + final File atlFile = new File(modulePath + module + ".atl"); + final AtlToEmftvmCompiler compiler = new AtlToEmftvmCompiler(); + final InputStream inputStream = new FileInputStream(atlFile); + try { + final BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); + final String charset = getCharset(); + final Reader reader = charset == null || charset.isEmpty() ? new InputStreamReader(bufferedInputStream) + : new InputStreamReader(bufferedInputStream, charset); + + final CompileTimeError[] errors = compiler.compile(reader, modulePath + module + ".emftvm"); + + if (errors != null && errors.length > 0) { + final StringBuilder errorString = new StringBuilder(); + for (final CompileTimeError error : errors) { + errorString.append("\n\t").append(error.getSeverity()).append(" : ").append(error.getDescription()) + .append(" [").append(error.getLocation()).append("]"); + } + throw new ATLCoreException("Compile error" + errorString); + } + } finally { + inputStream.close(); + } + } + +} |