diff options
author | Dennis Wagelaar | 2018-04-20 08:03:53 +0000 |
---|---|---|
committer | Dennis Wagelaar | 2018-04-20 08:03:53 +0000 |
commit | 2dfa42f0e32b7feb3e6b474f6615927ed9097f7e (patch) | |
tree | d807a4be1ad4ec76edfed9125132b39d7c52685a /plugins | |
parent | b804ac89cd0348725bf4565205dfe43cdc7475a0 (diff) | |
download | org.eclipse.atl-2dfa42f0e32b7feb3e6b474f6615927ed9097f7e.tar.gz org.eclipse.atl-2dfa42f0e32b7feb3e6b474f6615927ed9097f7e.tar.xz org.eclipse.atl-2dfa42f0e32b7feb3e6b474f6615927ed9097f7e.zip |
Add emftvm.compile Ant task.
Diffstat (limited to 'plugins')
2 files changed, 66 insertions, 6 deletions
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 index e1c97327..3951dbd8 100644 --- 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 @@ -18,6 +18,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import org.eclipse.m2m.atl.common.ATLLogger; import org.eclipse.m2m.atl.core.ATLCoreException; import org.eclipse.m2m.atl.emftvm.compiler.AtlToEmftvmCompiler; import org.eclipse.m2m.atl.engine.compiler.CompileTimeError; @@ -29,9 +30,14 @@ import org.eclipse.m2m.atl.engine.compiler.CompileTimeError; */ public class CompileTask extends EMFTVMTask { + private static final String DOT_ATL = ".atl"; + private static final String DOT_EMFTVM = ".emftvm"; + private static final double DIVISOR = 1.0E9; + private String module; private String modulePath; private String charset; + private String outputPath; /** * Sets the module name. @@ -53,7 +59,8 @@ public class CompileTask extends EMFTVMTask { } /** - * Sets the module path. + * Sets the module path. If not set, + * {@link org.apache.tools.ant.Project#getBaseDir()} is used. * * @param modulePath * the modulePath to set @@ -63,7 +70,8 @@ public class CompileTask extends EMFTVMTask { } /** - * Returns the module path. + * Returns the module path. If not set, + * {@link org.apache.tools.ant.Project#getBaseDir()} is used. * * @return the modulePath */ @@ -81,7 +89,7 @@ public class CompileTask extends EMFTVMTask { } /** - * Sets the character set to be used for parsing + * Sets the character set to be used for parsing. * * @param charset * the character set to set @@ -91,20 +99,47 @@ public class CompileTask extends EMFTVMTask { } /** + * Returns the directory path to write the output file to. If not set, + * {@link #getModulePath()} is used. + * + * @return the outputPath + */ + public String getOutputPath() { + return outputPath; + } + + /** + * Sets the directory path to write the output file to. If not set, + * {@link #getModulePath()} is used. + * + * @param outputPath + * the outputPath to set + */ + public void setOutputPath(String outputPath) { + this.outputPath = outputPath; + } + + /** * {@inheritDoc} */ @Override protected void innerExecute() throws Exception { - final File atlFile = new File(modulePath + module + ".atl"); + final long startTimeNanos = System.nanoTime(); + + final String modulePath = trimToBaseDir(getModulePath()); + final String module = getModule(); + final String inputFilePath = modulePath + module + DOT_ATL; final AtlToEmftvmCompiler compiler = new AtlToEmftvmCompiler(); - final InputStream inputStream = new FileInputStream(atlFile); + final InputStream inputStream = new FileInputStream(inputFilePath); 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 String outputPath = getOutputPath(); + final String outputFilePath = (outputPath != null ? outputPath : modulePath) + module + DOT_EMFTVM; - final CompileTimeError[] errors = compiler.compile(reader, modulePath + module + ".emftvm"); + final CompileTimeError[] errors = compiler.compile(reader, outputFilePath); if (errors != null && errors.length > 0) { final StringBuilder errorString = new StringBuilder(); @@ -114,9 +149,25 @@ public class CompileTask extends EMFTVMTask { } throw new ATLCoreException("Compile error" + errorString); } + + ATLLogger.info(String.format("Compiled %s to %s in %f seconds", inputFilePath, outputFilePath, + (System.nanoTime() - startTimeNanos) / DIVISOR)); } finally { inputStream.close(); } } + /** + * Trims <code>null</code> strings to the project's BaseDir. + * + * @param str + * the string to trim + * @return <code>str</code>, or + * {@link org.apache.tools.ant.Project#getBaseDir()} if + * <code>null</code> + */ + private String trimToBaseDir(final String str) { + return str != null ? str : getProject().getBaseDir().getPath() + File.separator; + } + } diff --git a/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/antlib.xml b/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/antlib.xml new file mode 100644 index 00000000..4533f202 --- /dev/null +++ b/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/antlib.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<antlib> + <taskdef name="emftvm.loadModel" classname="org.eclipse.m2m.atl.emftvm.ant.LoadModelTask" /> + <taskdef name="emftvm.loadMetamodel" classname="org.eclipse.m2m.atl.emftvm.ant.LoadMetamodelTask" /> + <taskdef name="emftvm.run" classname="org.eclipse.m2m.atl.emftvm.ant.RunTask" /> + <taskdef name="emftvm.saveModel" classname="org.eclipse.m2m.atl.emftvm.ant.SaveModelTask" /> + <taskdef name="emftvm.newModel" classname="org.eclipse.m2m.atl.emftvm.ant.NewModelTask" /> + <taskdef name="emftvm.compile" classname="org.eclipse.m2m.atl.emftvm.ant.CompileTask" /> +</antlib>
\ No newline at end of file |