Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Invoke .emf from Ant programatically ?
Invoke .emf from Ant programatically ? [message #1257401] Wed, 26 February 2014 11:34 Go to next message
Shrikanth NC is currently offline Shrikanth NCFriend
Messages: 31
Registered: February 2014
Member
I tried AntRunner of eclipse ant core,

***************************************************************************

AntRunner runner = new org.eclipse.ant.core.AntRunner();
runner.setBuildFileLocation("C:\\epsilon\\workspace\\ISUpdate\\model\\build.xml");
runner.setArguments("-Dmessage=Building -verbose");
try {
System.out.println(runner.getAvailableTargets());
} catch (CoreException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
runner.start(null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

*******************************************************************************

Also tried regular ant api

**********************************************************************
File buildFile = new File(
"C:\\epsilon\\workspace\\ISUpdate\\model\\build.xml");
Project antProject = new Project();
antProject.setUserProperty("ant.file", buildFile.getAbsolutePath());
antProject.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
antProject.addReference("ant.ProjectHelper", helper);
helper.parse(antProject, buildFile);
String target = "main";
System.out.println(antProject.getJavaVersion());
antProject.executeTarget(target);


********************************************************************************

But I am unable generate

In the AntRunner api i am getting core exception and BUILD FAILED
In the later it says unable to find epsilon.eugenia tag

***********************************************************************
My Ant script :

- <project default="main">
- <target name="main">
<epsilon.eugenia src="new_file.emf" />
</target>
</project>

************************************************************************

Kindly help : How to generate code from emfatic file programatically either through ant or eugenia source code!
Re: Invoke .emf from Ant programatically ? [message #1257722 is a reply to message #1257401] Wed, 26 February 2014 18:26 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1472
Registered: July 2009
Location: York, UK
Senior Member

Hi,

Does this help? http://www.eclipse.org/forums/index.php/mv/msg/512479/1111540/#msg_1111540

Cheers,
Dimitris
Re: Invoke .emf from Ant programatically ? [message #1258213 is a reply to message #1257722] Thu, 27 February 2014 06:55 Go to previous messageGo to next message
Shrikanth NC is currently offline Shrikanth NCFriend
Messages: 31
Registered: February 2014
Member
Thank You but no it doesn't fit into my situation.

My exact requirement :

1. When someone clicks menu item ( say update ) from my rcp application.
2. I wish to trigger updated emfatic file using ant / any other
3. That overwrites new diagram code
4. Hence my palette gets updated with new elements automatically, the next time i restart my rcp application

Problem :

I hard code 'wc.setAttribute(IExternalToolConstants.ATTR_LOCATION, "C:\\epsilon\\workspace\\is\\model\\build.xml");'

in RunAntAction class.

Also tried using AntRunner of eclipse core

Both throwing this exception,

org.eclipse.core.runtime.CoreException: C:\epsilon\workspace\is\model\build.xml:3: java.lang.NullPointerException
at org.eclipse.ant.core.AntRunner.handleInvocationTargetException(AntRunner.java:452)
at org.eclipse.ant.core.AntRunner.run(AntRunner.java:384)
at org.eclipse.epsilon.examples.runant.RunAntAction.run(RunAntAction.java:37)

***********************************************************************************

In short i want to generate diagram code using emfatic file in an standalone java program.

Using above examples it introduces eclipse workspace/IFile dependencies.


Kindly help, Thanks for your support!
Re: Invoke .emf from Ant programatically ? [message #1258788 is a reply to message #1258213] Thu, 27 February 2014 19:12 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1472
Registered: July 2009
Location: York, UK
Senior Member

Hi,

I don't think it's possible to do what you're describing from an RCP/standalone application as Eugenia inherently requires these Eclipse dependencies.

Cheers,
Dimitris

[Updated on: Thu, 27 February 2014 19:13]

Report message to a moderator

Re: Invoke .emf from Ant programatically ? [message #1263283 is a reply to message #1258788] Tue, 04 March 2014 10:42 Go to previous messageGo to next message
Shrikanth NC is currently offline Shrikanth NCFriend
Messages: 31
Registered: February 2014
Member
<project default="main">
<target name="main">
<epsilon.eugenia src="new_file.emf"/>
</target>
</project>

is it possible to invoke it from command prompt ? ( Assuming Separate Ant is installed )

Thanks,
Shrikanth NC

[Updated on: Tue, 04 March 2014 10:43]

Report message to a moderator

Re: Invoke .emf from Ant programatically ? [message #1266297 is a reply to message #1263283] Fri, 07 March 2014 08:38 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1472
Registered: July 2009
Location: York, UK
Senior Member

Hi,

To be able to invoke this from the command line you'll need to assemble a fat jar containing Epsilon, Eugenia, EMF and GMF (see [1] for a starting point) and add it to ANT's classpath. Please feel free to open an enhancement request for this using the link below.

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=epsilon

Cheers,
Dimitris

[1] https://dev.eclipse.org/svnroot/modeling/org.eclipse.epsilon/trunk/standalone/org.eclipse.epsilon.standalone/build-jars.xml
Re: Invoke .emf from Ant programatically ? [message #1266332 is a reply to message #1266297] Fri, 07 March 2014 09:42 Go to previous messageGo to next message
Shrikanth NC is currently offline Shrikanth NCFriend
Messages: 31
Registered: February 2014
Member
I am half way there. Now ant is able to recognize epsilon.eugenia ( 'abc' in my case ) task as well as classnotdef exception doesnt occur after adding almost all jars Very Happy

But now I am stuck with new problem,

Using the following ant build.xml (below)

<project default="main">

<path id="libraries">
<fileset dir="C:\Users\shrikanth_n_c\Desktop\Libraries\EMF\">
<include name="*.jar"/>
</fileset>
<fileset dir="C:\epsilon\plugins\">
<include name="*.jar"/>
</fileset>
<fileset dir="C:\epsilon\plugins\org.apache.ant_1.8.4.v201303080030\lib\">
<include name="*.jar"/>
</fileset>
</path>

<target name="main">
<taskdef name="abc" classname="org.eclipse.epsilon.workflow.tasks.eugenia.EugeniaTask" classpathref="libraries" />
<abc src="new_file.emf" />
</target>
</project>

I am invoking build.xml from command prompt using

java -jar C:\eclipse\plugins\org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar -application org.eclipse.ant.core.antRunner -buildfile C:\epsilon\workspace\is\model\build.xml

I am getting following message,

Buildfile: C:\epsilon\workspace\is\model\build.xml

main:

BUILD FAILED
C:\epsilon\workspace\is\model\build.xml:17: java.lang.IllegalStateException: Wor
kbench has not been created yet.
at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:93)
at org.eclipse.epsilon.workflow.tasks.eugenia.EugeniaTask.executeImpl(Eu
geniaTask.java:139)
at org.eclipse.epsilon.workflow.tasks.EpsilonTask.execute(EpsilonTask.ja
va:40)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
at org.eclipse.ant.internal.core.ant.EclipseDefaultExecutor.executeTarge
ts(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRu
nner.java:672)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRu
nner.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.ant.core.AntRunner.run(AntRunner.java:513)
at org.eclipse.ant.core.AntRunner.start(AntRunner.java:600)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandl
e.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runAppli
cation(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(Ec
lipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.ja
va:354)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.ja
va:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)

Total time: 1 second
An error has occurred. See the log file
C:\Users\shrikanth_n_c\workspace\.metadata\.log.

Kindly help me to proceed!

Thanks,
Shrikanth NC
  • Attachment: .log
    (Size: 71.14KB, Downloaded 56 times)

[Updated on: Fri, 07 March 2014 09:53]

Report message to a moderator

Re: Invoke .emf from Ant programatically ? [message #1267722 is a reply to message #1266332] Sun, 09 March 2014 12:50 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1472
Registered: July 2009
Location: York, UK
Senior Member

The discussion has moved to https://bugs.eclipse.org/bugs/show_bug.cgi?id=429848
Re: Invoke .emf from Ant programatically ? [message #1751727 is a reply to message #1266297] Thu, 12 January 2017 22:55 Go to previous messageGo to next message
Lina Ochoa is currently offline Lina OchoaFriend
Messages: 8
Registered: January 2017
Junior Member
Hi,

I am currently having the same problem with an ANT file execution. The content of the ANT file is the following:

<?xml version="1.0"?>
<project name="ProjectName" default="main" basedir=".">
	<epsilon.emf.register file="../../metamodels/MM.ecore"/>
	
	<epsilon.emf.loadModel name="M1"  
		aliases="M1"
		modelFile="../../models/M1.coco2afm"
		metamodelUri="MetamodelURI1"
		read="true" store="true"/>
				
	<epsilon.emf.loadModel name="M2"
		modelFile="../../models/M2.xmi"
		metamodelUri="MetamodelURI2"
		read="true" store="true"/>
	
	<target name="main">
		<epsilon.etl src="../../transformations/M2M.etl">
			<model ref="M1"/>
			<model ref="M2"/>
		</epsilon.etl>
	</target>
</project>


When I manually run the ANT file with the JRE of the workspace it works perfect. However, when I run it programatically I obtained an error.

The Java code for executing the ANT file:
File file = new File(pathAnt);
Project project = new Project();
project.init();
		
DefaultLogger logger = new DefaultLogger();
logger.setErrorPrintStream(System.err);
logger.setOutputPrintStream(System.err);
logger.setMessageOutputLevel(Project.MSG_INFO);
		
project.setProperty("ant.file", file.getAbsolutePath());
project.addBuildListener(logger);
project.fireBuildStarted();
		
ProjectHelper helper = ProjectHelper.getProjectHelper();
project.addReference("ant.projectHelper", helper);
helper.parse(project, file);
project.executeTarget(project.getDefaultTarget());


And the obtained error:
Problem: failed to create task or type epsilon.emf.register
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.


I tried to access the URL posted in an early post but the link is broken. Is there any additional solution or guide that I can follow?

Thank you for your help and time.
Re: Invoke .emf from Ant programatically ? [message #1751804 is a reply to message #1751727] Sat, 14 January 2017 10:45 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1472
Registered: July 2009
Location: York, UK
Senior Member

Hi,

This happens because ANT is not aware of any 3rd party tasks (e.g. Epsilon tasks) unless they are explicitly declared. To make epsilon.emf.register work you need to either add the following line to your Java program, or use a taskdef [1] inside your ANT script

getProject().addTaskDefinition("epsilon.emf.register", RegisterTask.class);


You will need to do the same for any other Epsilon tasks you may want to use in your ANT script. The mappings of all Epsilon and Epsilon/EMF tasks are available under:

https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/plugins/org.eclipse.epsilon.workflow/ant/org/eclipse/epsilon/workflow/tasks/tasks.xml
https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/plugins/org.eclipse.epsilon.workflow.emf/src/org/eclipse/epsilon/workflow/tasks/emf/tasks.xml

[2] could also be of interest.

Cheers,
Dimitris

[1] https://ant.apache.org/manual/develop.html
[2] http://stackoverflow.com/questions/12891893/how-to-include-ant-contrib-jar-dynamically-in-ant

[Updated on: Sat, 14 January 2017 11:27]

Report message to a moderator

Re: Invoke .emf from Ant programatically ? [message #1751889 is a reply to message #1751804] Mon, 16 January 2017 14:34 Go to previous messageGo to next message
Lina Ochoa is currently offline Lina OchoaFriend
Messages: 8
Registered: January 2017
Junior Member
Than you for your help. I have finally followed your standalone example, available in the Epsilon git repository:

https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/examples/org.eclipse.epsilon.examples.workflow.standalone

Everything works fine now except for one thing. I am using Xtext and one of the models involved in the transformation has a ".coco2afm" extension. When I manually execute the transformation, these type of models are identified as Ecore models. However, when executing the workflow with Ant I obtain the following error:

Caused by: org.xml.sax.SAXParseExceptionpublicId: file:/C:/Path/runtime-EclipseApplication/CoCoPreviewV2.0/models/pruebasEscalabilidad/M0.coco2afm; systemId: file:/C:/Path/runtime-EclipseApplication/CoCoPreviewV2.0/models/pruebasEscalabilidad/M0.coco2afm; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException[ErrorHandlerWrapper.java:203]
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError[ErrorHandlerWrapper.java:177]
	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError[XMLErrorReporter.java:441]
	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError[XMLErrorReporter.java:368]
	at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError[XMLScanner.java:1437]
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next[XMLDocumentScannerImpl.java:999]
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next[XMLDocumentScannerImpl.java:606]
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument[XMLDocumentFragmentScannerImpl.java:510]
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse[XML11Configuration.java:848]
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse[XML11Configuration.java:777]
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse[XMLParser.java:141]
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse[AbstractSAXParser.java:1213]
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse[SAXParserImpl.java:649]
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse[SAXParserImpl.java:333]
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load[XMLLoadImpl.java:175]
	... 23 more


I suppose it is trying to find and XML file which is in fact an instance of my DSL (plain text). I think it is an issue of third party dependencies. However, I would like to know if you have in mind which are those needed dependencies both of Epsilon and Xtext.

I have also followed with no success the guidelines defined in:

https://www.eclipse.org/forums/index.php/t/369157/

And I have added the following Xtex dependencies:

org.eclipse.xtext.satandalone.jar
org.eclipse.xtext.jar
org.eclipse.xtext.builder.jar
org.eclipse.xtext.builder.standalone.jar
org.eclipse.xtext.ecore.jar
org.eclipse.xtext.java.jar
org.eclipse.xtext.m2e.jar


Thank you again for your help.

[Updated on: Mon, 16 January 2017 14:52]

Report message to a moderator

Re: Invoke .emf from Ant programatically ? [message #1751913 is a reply to message #1751889] Mon, 16 January 2017 18:38 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1472
Registered: July 2009
Location: York, UK
Senior Member

Hi Lina,

To use an Xtext-based model in your Epsilon program, you need to parse it into a Resource using standard Xtext code and then wrap the resource into an InMemoryEmfModel.

Cheers,
Dimitris

[1] http://download.eclipse.org/epsilon/javadoc/org/eclipse/epsilon/emc/emf/InMemoryEmfModel.html
Re: Invoke .emf from Ant programatically ? [message #1752115 is a reply to message #1751913] Thu, 19 January 2017 01:35 Go to previous messageGo to next message
Lina Ochoa is currently offline Lina OchoaFriend
Messages: 8
Registered: January 2017
Junior Member
Hi Dimitris,

Thank you for all your help, it was very useful and accurate. Finally the ANT file was correctly executed. Just in case someone else needs the complete solution, these are the steps to follow:

When you want to programatically execute an ANT file with epsilon transformations, (and maybe you have Xtext files):

  1. Develop your Xtext grammar, execute the mwe2 file, and generate "Model", "Edit", and "Editor" code from the genmodel file.
  2. Generate a runnable JAR from the Xtext project based on the steps provided in https://www.eclipse.org/forums/index.php/t/369157/
  3. Create your Epsilon standalone project based on the following example https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/examples/org.eclipse.epsilon.examples.workflow.standalone
  4. Include the required dependencies (see Note 1 below)
  5. Implement the Ant Executor (see Note 2 below)
  6. Implement the Xtext model reader (see Note 3 below)


Note 1 (Required dependencies):

  • ant.jar
  • ant-launcher.jar
  • mydsl.jar (obtained from step 2)
  • epsilon-1.X-workflow-emf-src.jar
  • epsilon-1.X-workflow-src.jar
  • org.eclipse.emf.jar
  • org.eclipse.emf.common.jar
  • org.eclipse.emf.ecore.jar
  • org.eclipse.emf.ecore.xmi.jar
  • org.eclipse.emf.jar
  • org.eclipse.xsd.jar
  • org.eclipse.epsilon.*.jar (depending on your project needs)


Note 2 (ANT executor):
File file = new File(pathAnt);
Project project = new Project();
project.init();
		
DefaultLogger logger = new DefaultLogger();
logger.setErrorPrintStream(System.err);
logger.setOutputPrintStream(System.err);
logger.setMessageOutputLevel(Project.MSG_INFO);
		
project.setProperty("ant.file", file.getAbsolutePath());
project.addBuildListener(logger);
project.fireBuildStarted();
		
ProjectHelper helper = ProjectHelper.getProjectHelper();
project.addReference("ant.projectHelper", helper);
helper.parse(project, file);
project.executeTarget(project.getDefaultTarget());


Note 3 (Xtext model reader):
This code is based on https://wiki.eclipse.org/Xtext/FAQ#How_do_I_load_my_model_in_a_standalone_Java_application.C2.A0.3F and https://www.eclipse.org/epsilon/doc/articles/in-memory-emf-model/.

StandaloneSetup setup = new StandaloneSetup();
setup.setPlatformUri("../");
Injector injector = new CoCo2AfmStandaloneSetupGenerated().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet =  injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
URI uri = URI.createURI("ModelURI");
Resource resource = resourceSet.getResource(uri, true);
		
InMemoryEmfModel emfModel = new InMemoryEmfModel(resource);
emfModel.loadModel();
emfModel.setModelFile("ModelPath");
emfModel.setName("ModelName");


Additional Note:
If you have problems to modify a model (although you have set store=true), use the storeModel task after executing the transformation (it happens to me).

<epsilon.storeModel model="ModelName"/>

[Updated on: Thu, 19 January 2017 18:31]

Report message to a moderator

Re: Invoke .emf from Ant programatically ? [message #1752165 is a reply to message #1752115] Thu, 19 January 2017 11:44 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1472
Registered: July 2009
Location: York, UK
Senior Member

Hi Lina,

Many thanks for summarising your solution - this is brilliant!

Cheers,
Dimitris
Re: Invoke .emf from Ant programatically ? [message #1752198 is a reply to message #1752165] Thu, 19 January 2017 18:32 Go to previous message
Lina Ochoa is currently offline Lina OchoaFriend
Messages: 8
Registered: January 2017
Junior Member
Dimitris, thank you so much for your help.
Previous Topic:Append documentation for Template object missing in table 7.2 of Epsilon book
Next Topic:Getting links with EGL
Goto Forum:
  


Current Time: Fri Aug 18 11:18:57 GMT 2017

Powered by FUDForum. Page generated in 0.02690 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software