Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » Maven build with ant task ecore2Java
Maven build with ant task ecore2Java [message #972025] Mon, 05 November 2012 09:48 Go to next message
Artem G. is currently offline Artem G.
Messages: 10
Registered: October 2012
Junior Member
Hey folks,

I'm trying right now to generate model java code from an ecore model and I'm able to du this with an ant task:
java -jar /Applications/eclipse/plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar -application org.eclipse.ant.core.antRunner -nosplash -buildfile build.xml


Ant task:
<?xml version="1.0" encoding="UTF-8"?>
<project default="codegen" basedir="..">
	<dirname property="antfile.dir" file="${ant.file}"/>
    
  <!-- Global properties -->
	<property name="main.directory" location="${antfile.dir}/.."/>
	<property name="output.directory" location="${main.directory}"/>
	<property name="source.directory" value="src"/>
	<property name="genJDKLevel" value="5.0"/>
	
	<target name="codegen">

	  <!-- A macrodef makes it easier to generate code for multiple models in one script. -->
		<macrodef name="ecore2Java">
			<attribute name="modelName"/>
			<element name="settings"/>
			<sequential>
				<emf.Ecore2Java
					model="${main.directory}/ecore2java/model/@{modelName}.ecore"
					genModel="${output.directory}/emf/@{modelName}.genmodel"
					modelProject="${output.directory}"
					modelProjectFragmentPath="${source.directory}"
					modelPluginID="@{modelName}.model"
					copyright="This is my code."
					jdkLevel="${genJDKLevel}">
					<settings/>
				</emf.Ecore2Java>
			</sequential>
		</macrodef>

		<!-- Generating the code for the library model -->
		<ecore2Java modelName="library">
			<settings>
				<arg line="-package http:///library.ecore org.examples Library"/>
			</settings>
		</ecore2Java>
		
	</target>
</project>


So now my question is, how to run this particular ant task from maven. Should I use pde-maven-plugin or can I use tycho-eclipserun-plugin, what is the best solution? I saw some similar topics in forum but no answer for this question.

Thanks for help,
Artem.
Re: Maven build with ant task ecore2Java [message #973252 is a reply to message #972025] Tue, 06 November 2012 07:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26062
Registered: July 2009
Senior Member
Artem,

Sorry I have no experience with Maven. Posting to eclipse.tools.emf is
more likely to reach the eyes of someone who does. Your question seems
generally to be "How do I run something I can run as an Eclipse ant task
if I want to run that in Maven". It might also be better to ask this on
a Maven-specific forum. Perhaps this helps:
http://www.sonatype.org/m2eclipse

On 05/11/2012 10:48 AM, Artem G. wrote:
> Hey folks,
>
> I'm trying right now to generate model java code from an ecore model
> and I'm able to du this with an ant task:
> java -jar
> /Applications/eclipse/plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
> -application org.eclipse.ant.core.antRunner -nosplash -buildfile
> build.xml
>
> Ant task:
> <?xml version="1.0" encoding="UTF-8"?>
> <project default="codegen" basedir="..">
> <dirname property="antfile.dir" file="${ant.file}"/>
> <!-- Global properties -->
> <property name="main.directory" location="${antfile.dir}/.."/>
> <property name="output.directory" location="${main.directory}"/>
> <property name="source.directory" value="src"/>
> <property name="genJDKLevel" value="5.0"/>
>
> <target name="codegen">
>
> <!-- A macrodef makes it easier to generate code for multiple
> models in one script. -->
> <macrodef name="ecore2Java">
> <attribute name="modelName"/>
> <element name="settings"/>
> <sequential>
> <emf.Ecore2Java
> model="${main.directory}/ecore2java/model/@{modelName}.ecore"
> genModel="${output.directory}/emf/@{modelName}.genmodel"
> modelProject="${output.directory}"
> modelProjectFragmentPath="${source.directory}"
> modelPluginID="@{modelName}.model"
> copyright="This is my code."
> jdkLevel="${genJDKLevel}">
> <settings/>
> </emf.Ecore2Java>
> </sequential>
> </macrodef>
>
> <!-- Generating the code for the library model -->
> <ecore2Java modelName="library">
> <settings>
> <arg line="-package http:///library.ecore org.examples
> Library"/>
> </settings>
> </ecore2Java>
>
> </target>
> </project>
>
>
> So now my question is, how to run this particular ant task from maven.
> Should I use pde-maven-plugin or can I use tycho-eclipserun-plugin,
> what is the best solution? I saw some similar topics in forum but no
> answer for this question.
>
> Thanks for help,
> Artem.
Re: Maven build with ant task ecore2Java [message #976769 is a reply to message #973252] Thu, 08 November 2012 20:59 Go to previous messageGo to next message
Artem G. is currently offline Artem G.
Messages: 10
Registered: October 2012
Junior Member
Hi Ed,

thanks for your reply. I figured out how can I do it properly with maven. Hier is my maven task:
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-maven-plugin</artifactId>
				<extensions>true</extensions>
			</plugin>
			<plugin>
	            <groupId>org.eclipse.tycho.extras</groupId>
	            <artifactId>tycho-eclipserun-plugin</artifactId>
	            <version>0.16.0</version>
	            <configuration>
			    <appArgLine>-application org.eclipse.ant.core.antRunner -nosplash -buildfile build.xml</appArgLine>
	                <dependencies>
	               <dependency>
                        <artifactId>org.eclipse.ant.core</artifactId>
                        <type>eclipse-plugin</type>
                    </dependency>
	                    <dependency>
	                        <artifactId>org.eclipse.emf.ant</artifactId>
	                        <type>eclipse-plugin</type>
	                    </dependency>
	                    <dependency>
	                        <artifactId>org.eclipse.emf.importer.ecore</artifactId>
	                        <type>eclipse-plugin</type>
	                    </dependency>
	                </dependencies>
	            </configuration>
	            <executions>
	                <execution>
	                    <goals>
	                        <goal>eclipse-run</goal>
	                    </goals>
	                    <phase>compile</phase>
	                </execution>
	            </executions>
	        </plugin>


But now I have a next problem. I have an eclipse project:
org.example.project
|-plugin.xml
|-META-INF
|-model
   |-myEcore.ecore

and if I generate a genmodel from ecore and generate model java code from this genmodel(it has /org.example.project/model-gen as "Model Directory" property) over Eclipse UI it place model code right in model-gen directory and don't create plugin.xml etc in this model-gen directory, looks like it take org.example.projects' plugin.xml etc. So but if place build.xml in org.example.project like this:
code]
org.example.project
|-build.xml
|-plugin.xml
|-META-INF
|-model
|-myEcore.ecore
[/code]
with build.xml:
				<emf.Ecore2Java
					model="${antfile.dir}/model/@{modelName}.ecore"
					genModel="${antfile.dir}/model/@{modelName}.genmodel"
					modelProject="${antfile.dir}"
					modelProjectFragmentPath="model-gen"
					modelPluginID="${modelPlugin.ID}"
					generateJavaCode="true"
					generateModelProject="false"
					generateEditProject="false"
					generateEditorProject="false"
					validateModel="true"
					copyright="This is my code."
					jdkLevel="${genJDKLevel}">
					<settings/>
				</emf.Ecore2Java>

and run, it gives me an error: The project description file (.project) for 'org.example.project' is missing. This file contains important information about the project. The project will not function properly until this file is restored.

If I change modelProject path like this:
				<emf.Ecore2Java
					model="${antfile.dir}/model/@{modelName}.ecore"
					genModel="${antfile.dir}/model/@{modelName}.genmodel"
					modelProject="${antfile.dir}/org.genetty.gendsl"
					modelProjectFragmentPath="model-gen"
					modelPluginID="${modelPlugin.ID}"
					generateJavaCode="true"
					generateModelProject="false"
					generateEditProject="false"
					generateEditorProject="false"
					validateModel="true"
					copyright="This is my code."
					jdkLevel="${genJDKLevel}">
					<settings/>
				</emf.Ecore2Java>

it generate all model code with new plugin.xml etc in org.example.project directory inside org.example.project:
org.example.project
|-build.xml
|-plugin.xml
|-META-INF
|-model
   |-myEcore.ecore
|-model-gen
  |-org.example.project
     |-plugin.xml
     |-META-INF
     |-model-gen
        |-MyEcore.java
         ....


How can I set the modelProject path to generate model code in model-gen and use existing plugin.xml?

Thank you very much for your previous message!
Artem.
Re: Maven build with ant task ecore2Java [message #977174 is a reply to message #976769] Fri, 09 November 2012 04:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26062
Registered: July 2009
Senior Member
Artem,

Comments below.

On 08/11/2012 9:59 PM, Artem G. wrote:
> Hi Ed,
>
> thanks for your reply. I figured out how can I do it properly with
> maven. Hier is my maven task:
>
> <plugin>
> <groupId>org.eclipse.tycho</groupId>
> <artifactId>tycho-maven-plugin</artifactId>
> <extensions>true</extensions>
> </plugin>
> <plugin>
> <groupId>org.eclipse.tycho.extras</groupId>
> <artifactId>tycho-eclipserun-plugin</artifactId>
> <version>0.16.0</version>
> <configuration>
> <appArgLine>-application
> org.eclipse.ant.core.antRunner -nosplash -buildfile
> build.xml</appArgLine>
> <dependencies>
> <dependency>
> <artifactId>org.eclipse.ant.core</artifactId>
> <type>eclipse-plugin</type>
> </dependency>
> <dependency>
> <artifactId>org.eclipse.emf.ant</artifactId>
> <type>eclipse-plugin</type>
> </dependency>
> <dependency>
> <artifactId>org.eclipse.emf.importer.ecore</artifactId>
> <type>eclipse-plugin</type>
> </dependency>
> </dependencies>
> </configuration>
> <executions>
> <execution>
> <goals>
> <goal>eclipse-run</goal>
> </goals>
> <phase>compile</phase>
> </execution>
> </executions>
> </plugin>
>
>
> But now I have a next problem. I have an eclipse project:
>
> org.example.project
> |-plugin.xml
> |-META-INF
> |-model
> |-myEcore.ecore
>
> and if I generate a genmodel from ecore and generate model java code
> from this genmodel(it has /org.example.project/model-gen as "Model
> Directory" property) over Eclipse UI it place model code right in
> model-gen directory and don't create plugin.xml etc in this model-gen
> directory, looks like it take org.example.projects' plugin.xml etc.
Yes, it generally won't generate one once it exists though in the latest
builds I've added support for merging of plugin.xml and MANIFEST.MF....
> So but if place build.xml in org.example.project like this:
> code]
> org.example.project
> |-build.xml
> |-plugin.xml
> |-META-INF
> |-model
> |-myEcore.ecore
> [/code]
> with build.xml:
>
> <emf.Ecore2Java
> model="${antfile.dir}/model/@{modelName}.ecore"
> genModel="${antfile.dir}/model/@{modelName}.genmodel"
> modelProject="${antfile.dir}"
> modelProjectFragmentPath="model-gen"
> modelPluginID="${modelPlugin.ID}"
> generateJavaCode="true"
> generateModelProject="false"
> generateEditProject="false"
> generateEditorProject="false"
> validateModel="true"
> copyright="This is my code."
> jdkLevel="${genJDKLevel}">
> <settings/>
> </emf.Ecore2Java>
>
> and run, it gives me an error: The project description file
> (.project) for 'org.example.project' is missing. This file contains
> important information about the project. The project will not
> function properly until this file is restored.
>
> If I change modelProject path like this:
>
> <emf.Ecore2Java
> model="${antfile.dir}/model/@{modelName}.ecore"
> genModel="${antfile.dir}/model/@{modelName}.genmodel"
> modelProject="${antfile.dir}/org.genetty.gendsl"
> modelProjectFragmentPath="model-gen"
> modelPluginID="${modelPlugin.ID}"
> generateJavaCode="true"
> generateModelProject="false"
> generateEditProject="false"
> generateEditorProject="false"
> validateModel="true"
> copyright="This is my code."
> jdkLevel="${genJDKLevel}">
> <settings/>
> </emf.Ecore2Java>
>
> it generate all model code with new plugin.xml etc in
> org.example.project directory inside org.example.project:
>
> org.example.project
> |-build.xml
> |-plugin.xml
> |-META-INF
> |-model
> |-myEcore.ecore
> |-model-gen
> |-org.example.project
> |-plugin.xml
> |-META-INF
> |-model-gen
> |-MyEcore.java
> ....
>
>
> How can I set the modelProject path to generate model code in
> model-gen and use existing plugin.xml?
It seems to me there was some trick to let it know where the project
starts. Oh yes, hunting around I find
org.eclipse.emf.codegen.ecore.Generator.EclipseHelper.findOrCreateContainerHelper(String,
String, Monitor) where adding a "/./" in the path to indicate where the
project actually starts on the path. I also see that -projects would
help (point at the folder in which the , but I'm not sure how you
specify that in Ant.

public void printGenerateUsage()
{
System.out.println("Usage arguments:");
System.out.println(" [-projects <project-root-directory>]");
System.out.println(" [-dynamicTemplates] [-forceOverwrite | -diff]");
System.out.println(" [-generateSchema] [-nonNLSMarkers]");
System.out.println(" [-codeFormatting { default | <profile-file> }
]");
System.out.println(" [-model] [-edit] [-editor] [-tests]");
System.out.println(" [-autoBuild <true|false>]");
System.out.println(" [-reconcile]");
System.out.println(" <genmodel-file>");
System.out.println(" [ <target-root-directory> ]");
System.out.println("");
System.out.println("For example:");
System.out.println("");
System.out.println(" generate result/model/Extended.genmodel");
}

Can you run under debug control to see how best to take advantage of
these "tricks"?

>
> Thank you very much for your previous message!
> Artem.
Re: Maven build with ant task ecore2Java [message #978078 is a reply to message #977174] Fri, 09 November 2012 20:41 Go to previous message
Artem G. is currently offline Artem G.
Messages: 10
Registered: October 2012
Junior Member
Hi Ed,

thank you for your reply. I was able to solve my task partially. On your advise I've downloaded codegen.ecore' source and debugged Eclipse UI to find out, what happens by clicking "Generate Model code" and codegen.ecore.Generator by invoking it from command line. My task was to exclude artefacts, could be generated from ecore from version control: genmodel and generated models java code. Unfortunately I'm not able to exclude genmodel, only models java code. If I use ant task or org.eclipse.emf.importer.ecore.Ecore2GenModel to generate a genmodel from ecore I'm not able to specify a basePackage attribute of genmodel which than used by models code generation from this genmodel, so all the generated java classes get "package <prefix>;" in java source code. This is critical for me. But if I edit ecore in Eclipse UI, related genmodel gets updates automatically -- not such a big loss.

P.S.: Your book is great and very helpful!
Previous Topic:EMF Release Notes
Next Topic:stable UML editor under Juno?
Goto Forum:
  


Current Time: Mon Sep 22 22:24:37 GMT 2014

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

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