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 [message #575091] Thu, 20 May 2010 19:28 Go to next message
Konstantin Matuschek is currently offline Konstantin MatuschekFriend
Messages: 4
Registered: April 2010
Location: Munich
Junior Member
Hi all :)

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.v20 1005050326.jar!/org/eclipse/gmt/modisco/java/generation/file s/Generate_JavaStructures.emtl
at org.eclipse.emf.common.util.URI.createFileURI(URI.java:856)
at org.eclipse.gmt.modisco.java.generation.files.Generate_JavaS tructures.createTemplateURI(Generate_JavaStructures.java:185 )
at org.eclipse.gmt.modisco.java.generation.files.Generate_JavaS tructures. <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_JavaS tructures;

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 #575119 is a reply to message #575091] Fri, 21 May 2010 09:29 Go to previous message
Fabien Giquel is currently offline Fabien GiquelFriend
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
----------------------------------------------------


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Previous Topic:Pre-reqs for MoDisco
Next Topic:Issues with AutoEdit Strategies
Goto Forum:
  


Current Time: Fri Dec 19 22:49:22 GMT 2014

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

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