Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » Java Code Generation with MoDisco on Helios M7(Java Code Generation with MoDisco on Helios M7)
Java Code Generation with MoDisco on Helios M7 [message #534959] Thu, 20 May 2010 19:28 Go to next message
Konstantin Matuschek is currently offline Konstantin Matuschek
Messages: 4
Registered: April 2010
Location: Munich
Junior Member
Hi all Smile

I tried to get Fabien Giquel's simple from-scratch example for Java Code Genereation to work on MoDisco 0.8 and Helios M7 - you can find it in message #528592 in this thread: http://www.eclipse.org/forums/index.php?t=msg&th=166623& amp;start=0&

After adding all the required .jar's to the project, I run into the following Exception (occuring during construction of Generate_JavaStructures), and I don't have any idea how to solve it - hopefully someone has an idea:
Exception in thread "main" java.lang.IllegalArgumentException: invalid relative pathName: file:/home/user/Diplomarbeit-Eclipse/Eclipse Modeling Tools Helios M7/plugins/org.eclipse.gmt.modisco.java.generation_0.8.0.v201005050326.jar!/org/eclipse/gmt/modisco/java/generation/files/Generate_JavaStructures.emtl
	at org.eclipse.emf.common.util.URI.createFileURI(URI.java:856)
	at org.eclipse.gmt.modisco.java.generation.files.Generate_JavaStructures.createTemplateURI(Generate_JavaStructures.java:185)
	at org.eclipse.gmt.modisco.java.generation.files.Generate_JavaStructures.<init>(Generate_JavaStructures.java:166)
	at testpkg.MoDiscoTest.testMakeClass(MoDiscoTest.java:56)
	at testpkg.MoDiscoTest.main(MoDiscoTest.java:26)


The .jar's included in the build path are:
lpg.runtime.java_2.0.17.v201004102030
org.eclipse.acceleo.engine_3.0.0.v201005040937
org.eclipse.acceleo.model_3.0.0.v201005040937
org.eclipse.emf.common_2.6.0.v20100427-1455
org.eclipse.emf.ecore_2.6.0.v20100427-1455
org.eclipse.emf.ecore.xmi_2.5.0.v20100317-1336
org.eclipse.gmt.modisco.java_0.8.0.v201005050326
org.eclipse.gmt.modisco.java.generation_0.8.0.v201005050326
org.eclipse.ocl_3.0.0.v201005040140
org.eclipse.ocl.ecore_3.0.0.v201005040140


Finally the code is more or less just the code posted by Fabien with the imports needed:
package testpkg;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.gmt.modisco.java.ClassDeclaration;
import org.eclipse.gmt.modisco.java.CompilationUnit;
import org.eclipse.gmt.modisco.java.Model;
import org.eclipse.gmt.modisco.java.emf.JavaFactory;
import org.eclipse.gmt.modisco.java.generation.files.Generate_JavaStructures;

public class MoDiscoTest {

	public static void main(String[] args) {
		MoDiscoTest mdt = new MoDiscoTest();
		
		mdt.testMakeClass();
	}

	
	public void testMakeClass () {
		ResourceSet rs = new ResourceSetImpl();
		//Resource r = new XMIResourceImpl();
		Resource r = new ResourceImpl();
		rs.getResources().add(r);

		Model m = JavaFactory.eINSTANCE.createModel();
		m.setName("modelFromScratch");

		CompilationUnit cu = JavaFactory.eINSTANCE.createCompilationUnit();
		cu.setName("MyNewClass.java");
		m.getCompilationUnits().add(cu);

		org.eclipse.gmt.modisco.java.Package pkg = JavaFactory.eINSTANCE.createPackage();
		pkg.setName("newPkg");
		m.getOwnedElements().add(pkg);

		ClassDeclaration c = JavaFactory.eINSTANCE.createClassDeclaration();
		c.setName("MyNewClass");
		cu.getTypes().add(c);
		pkg.getOwnedElements().add(c);

		r.getContents().add(m);
		r.setURI(URI.createFileURI("/tmp/Diplomarbeit/testoutput/blah"));
		Generate_JavaStructures javaGenerator = null;
		try {
			javaGenerator = new Generate_JavaStructures(m,
			new File("/tmp/Diplomarbeit/testoutput2"),
			//new File(""),
			new ArrayList<Object>());
		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
		
		System.out.println("Generating Java ... ");
		
		javaGenerator.doGenerate(null);

	}

}



Thanks for any hints,
Konstantin
Re: Java Code Generation with MoDisco on Helios M7 [message #535087 is a reply to message #534959] Fri, 21 May 2010 09:29 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
Registered: July 2009
Senior Member
Hi Konstantin,

the problem comes from the generation calling context : creating a "java project" and running a class as "java application" does not work.
I have created a thread on M2T acceleo forum to kwow if it is an expected limit or a bug ( http://www.eclipse.org/forums/index.php?t=msg&goto=53508 0)

I dont know if you are familiar with plugin development. Anyway, here is the way to have your code working :
- create a "Plugin project" rather than a "Java Project"
- adding plugins dependencies to org.eclipse.gmt.modisco.java.generation, org.eclipse.emf.ecore,
org.eclipse.gmt.modisco.java
rather than setting directly the classpath
- include your testMakeClass() code in some ui action which will be launched from another eclipse workbench (e.g. you may use the "hello world" plugin creation wizard and modify the SampleAction class).
- running an "Eclipse Application" and testing the new action.

Regards,


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Re: Java Code Generation with MoDisco on Helios M7 [message #535273 is a reply to message #535087] Fri, 21 May 2010 19:12 Go to previous messageGo to next message
Konstantin Matuschek is currently offline Konstantin Matuschek
Messages: 4
Registered: April 2010
Location: Munich
Junior Member
Hi Fabien Smile

thanks for your quick an detailed answer ! I got it working now - as I'll create an eclipse plugin in the end anyway, it's no restriction to me (but as you suspected I'm not familiar with plugin development). In the thread you linked, Laurent Goubet already replied that they're trying to lift the limitation.

Thanks again,
Konstantin
Re: Java Code Generation with MoDisco on Helios M7 [message #538364 is a reply to message #535273] Mon, 07 June 2010 13:21 Go to previous messageGo to next message
Chloé is currently offline Chloé
Messages: 6
Registered: June 2010
Junior Member
Hello,

I have try to generate java code form a java model with all your advise but i am steel stuck.

I have create a plug-in (with the Hello world example) and I have replace the SampleAction code by the Konstantin's code and add all the dependencies.

When I run my plug-in (as a Eclipse Application) I have this message:
"The chosen operationis not currently available"

Do you know what is the problem?

Kind regards,
Chloé



Re: Java Code Generation with MoDisco on Helios M7 [message #538508 is a reply to message #538364] Mon, 07 June 2010 19:28 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
Registered: July 2009
Senior Member
Hi Chloé,

When launching your Eclipse Application at first time, a workspace has been created on your file system.
Could you look at the error messages in .log file in the .metadata subfolder of this workspace. I suppose you will find some "ClassNotFoundException" which will help you to understand.


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Re: Java Code Generation with MoDisco on Helios M7 [message #538637 is a reply to message #538508] Tue, 08 June 2010 09:37 Go to previous messageGo to next message
Chloé is currently offline Chloé
Messages: 6
Registered: June 2010
Junior Member
Hi, thanks for your quick answer.

I look in the .log file and actually there is a "java.lang.ClassNotFoundException" error on my SampleAction class.
And in my consol I have this message:

!ENTRY org.eclipse.ui 4 4 2010-06-08 11:28:16.798
!MESSAGE Could not create action delegate for id: plug2.actions.SampleAction
!ENTRY org.eclipse.ui 4 0 2010-06-08 11:28:16.813
!MESSAGE Action must implement IWorkbenchWindowActionDelegate


I try to find a way to fix it on the web but I don't find a solution. Some say it is the "try catch" on the code who raise problem, but I don't understand how to fix this problem.

I would like to know if, with the Konstantin's code, your plug-in run? or you do some change in the code or in the configuration of your eclipse?

Kind regards,
Chloé
Re: Java Code Generation with MoDisco on Helios M7 [message #538797 is a reply to message #538637] Tue, 08 June 2010 16:11 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
Registered: July 2009
Senior Member
Hi Chloé,

here are the steps i exactly follow :
- create "HelloWorld" plugin using the eclipse wizard
- adding dependencies in Manifest.MF to
"org.eclipse.emf.ecore"
"org.eclipse.gmt.modisco.java"
"org.eclipse.gmt.modisco.java.generation"
- take the body of Konstantin testMakeClass() method, and put it as body
of SampleAction#run(IAction action), without any other modification.


May be you have removed the inheritance "implements
IWorkbenchWindowActionDelegate" in SampleAction...?


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Re: Java Code Generation with MoDisco on Helios M7 [message #538960 is a reply to message #538797] Wed, 09 June 2010 08:06 Go to previous messageGo to next message
Chloé is currently offline Chloé
Messages: 6
Registered: June 2010
Junior Member
Hi,

It's works now, thanks a lot for all your answers.

And you are right I have remove the "implements
IWorkbenchWindowActionDelegate" in my SampleAction.

Thanks again.
Chloé
Re: Java Code Generation with MoDisco on Helios M7 [message #575133 is a reply to message #535087] Fri, 21 May 2010 19:12 Go to previous messageGo to next message
Konstantin Matuschek is currently offline Konstantin Matuschek
Messages: 4
Registered: April 2010
Location: Munich
Junior Member
Hi Fabien :)

thanks for your quick an detailed answer ! I got it working now - as I'll create an eclipse plugin in the end anyway, it's no restriction to me (but as you suspected I'm not familiar with plugin development). In the thread you linked, Laurent Goubet already replied that they're trying to lift the limitation.

Thanks again,
Konstantin
Re: Java Code Generation with MoDisco on Helios M7 [message #575148 is a reply to message #575133] Mon, 07 June 2010 13:21 Go to previous messageGo to next message
Chloé is currently offline Chloé
Messages: 6
Registered: June 2010
Junior Member
Hello,

I have try to generate java code form a java model with all your advise but i am steel stuck.

I have create a plug-in (with the Hello world example) and I have replace the SampleAction code by the Konstantin's code and add all the dependencies.

When I run my plug-in (as a Eclipse Application) I have this message:
"The chosen operationis not currently available"

Do you know what is the problem?

Kind regards,
Chloé
Re: Java Code Generation with MoDisco on Helios M7 [message #575163 is a reply to message #575148] Mon, 07 June 2010 19:28 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
Registered: July 2009
Senior Member
Hi Chloé,

When launching your Eclipse Application at first time, a workspace has been created on your file system.
Could you look at the error messages in .log file in the .metadata subfolder of this workspace. I suppose you will find some "ClassNotFoundException" which will help you to understand.
--
----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Re: Java Code Generation with MoDisco on Helios M7 [message #575189 is a reply to message #538508] Tue, 08 June 2010 09:37 Go to previous messageGo to next message
Chloé is currently offline Chloé
Messages: 6
Registered: June 2010
Junior Member
Hi, thanks for your quick answer.

I look in the .log file and actually there is a "java.lang.ClassNotFoundException" error on my SampleAction class.
And in my consol I have this message:

!ENTRY org.eclipse.ui 4 4 2010-06-08 11:28:16.798
!MESSAGE Could not create action delegate for id: plug2.actions.SampleAction
!ENTRY org.eclipse.ui 4 0 2010-06-08 11:28:16.813
!MESSAGE Action must implement IWorkbenchWindowActionDelegate

I try to find a way to fix it on the web but I don't find a solution. Some say it is the "try catch" on the code who raise problem, but I don't understand how to fix this problem.

I would like to know if, with the Konstantin's code, your plug-in run? or you do some change in the code or in the configuration of your eclipse?

Kind regards,
Chloé
Re: Java Code Generation with MoDisco on Helios M7 [message #575205 is a reply to message #538637] Tue, 08 June 2010 16:11 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
Registered: July 2009
Senior Member
Hi Chloé,

here are the steps i exactly follow :
- create "HelloWorld" plugin using the eclipse wizard
- adding dependencies in Manifest.MF to
"org.eclipse.emf.ecore"
"org.eclipse.gmt.modisco.java"
"org.eclipse.gmt.modisco.java.generation"
- take the body of Konstantin testMakeClass() method, and put it as body
of SampleAction#run(IAction action), without any other modification.


May be you have removed the inheritance "implements
IWorkbenchWindowActionDelegate" in SampleAction...?


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Re: Java Code Generation with MoDisco on Helios M7 [message #575260 is a reply to message #538797] Wed, 09 June 2010 08:06 Go to previous message
Chloé is currently offline Chloé
Messages: 6
Registered: June 2010
Junior Member
Hi,

It's works now, thanks a lot for all your answers.

And you are right I have remove the "implements
IWorkbenchWindowActionDelegate" in my SampleAction.

Thanks again.
Chloé
Previous Topic:Issues with AutoEdit Strategies
Next Topic:Generating and modifying uml class diagram
Goto Forum:
  


Current Time: Fri Oct 24 10:29:09 GMT 2014

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

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