Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » [Modisco 0.9] How to Discover Model and Generate Code programmatically? (Help needed for stepping from Modisco 0.8 to 0.9)
[Modisco 0.9] How to Discover Model and Generate Code programmatically? [message #684276] Wed, 15 June 2011 10:30 Go to next message
Thanasis Naskos is currently offline Thanasis Naskos
Messages: 22
Registered: March 2011
Junior Member
Hi,

I need some help Discovering Model and Generating Code programmatically in Modisco 0.9!

In Modisco 0.8 was using those two methods to do my job:
public void modelDiscovery(String projectName, String savePath){
		try {
			IProject project = 
				ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
			IJavaProject javaProject = JavaCore.create(project);
			DiscoverJavaModelFromJavaProject javaDiscoverer = new DiscoverJavaModelFromJavaProject();
			Map<DiscoveryParameter, Object> parameters = new HashMap<DiscoveryParameter, Object>();
			parameters.put(DefaultDiscoverer.PARAMETER_SILENT_MODE, true);
			javaDiscoverer.discoverElement(javaProject, parameters);
			//Resource output = (Resource) parameters.get(DefaultDiscoverer.PARAMETER_TARGET_RESOURCE);
			//Tools.saveModel(output, savePath);
		} catch (Exception e) {
			System.err.println("Error: " + e.getMessage());
		}
	}


public void generateJava(String javaModelFilepath, String generatedCodeFolderPath){
		Generate_JavaStructures javaGenerator = null;
		
		try {
			javaGenerator = new Generate_JavaStructures(URI.createFileURI(javaModelFilepath),
					new File(generatedCodeFolderPath),
					//new File(""),
					new ArrayList<Object>());
			javaGenerator.doGenerate(null);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


But in Modisco 0.9 are not working any more...
Is there anyone can help me?

Thanks
Thanasis
Re: [Modisco 0.9] How to Discover Model and Generate Code programmatically? [message #684434 is a reply to message #684276] Wed, 15 June 2011 15:11 Go to previous messageGo to next message
Thanasis Naskos is currently offline Thanasis Naskos
Messages: 22
Registered: March 2011
Junior Member
Hi me Smile,

I've found it!

Model Discovery:

Adding to manifest
Require-Bundle:
 org.eclipse.gmt.modisco.java;bundle-version="0.9.0",
 org.eclipse.modisco.java.discoverer;bundle-version="0.9.0",
 org.eclipse.modisco.infra.discovery.core;bundle-version="0.9.0",

public void modelDiscovery(String projectName, String savePath){
		try {
			IProject project = 
				ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
			IJavaProject javaProject = JavaCore.create(project);
			DiscoverJavaModelFromJavaProject javaDiscoverer = new DiscoverJavaModelFromJavaProject();
			javaDiscoverer.discoverElement(javaProject, new NullProgressMonitor());
			Resource javaResource = javaDiscoverer.getTargetModel();
			FileOutputStream fout = new FileOutputStream(new File(savePath));
			javaResource.save(fout, null);
			fout.close();

		} catch (Exception e) {
			System.err.println("Error: " + e.getMessage());
		}
	}



Code Generation:

Adding to manifest
Import-Package:
 org.eclipse.gmt.modisco.java.generation.files,
 org.eclipse.acceleo.engine.service,

public void generateJava(String javaModelFilepath, String generatedCodeFolderPath){
		try {
			GenerateJavaExtended javaGenerator = new GenerateJavaExtended(URI.createFileURI(javaModelFilepath),
					new File(generatedCodeFolderPath),
					new ArrayList<Object>());
			javaGenerator.doGenerate(null);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
Re: [Modisco 0.9] How to Discover Model and Generate Code programmatically? [message #689366 is a reply to message #684434] Mon, 27 June 2011 14:03 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
Registered: July 2009
Senior Member
Hi,

thanks for your interest in our MoDisco components. We're glad you made it work with new 0.9 API.
However, we are curious to understand what problems you encountered with old API. It has been deprecated but we tried to maintain its good working : for instance the JUNIT test org.eclipse.gmt.modisco.java.discoverer.tests.SimpleBlackBoxDiscovery.testJavaModelDiscoveryFromJavaProject() makes nearly the same invocation of oegm.DiscoverJavaModelFromJavaProject class as you have done.

Is it possible for you to explain which kind of problem you had (compilation, errors at execution, ...) ?

Fabien.


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Ch√Ęteau de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Re: [Modisco 0.9] How to Discover Model and Generate Code programmatically? [message #689420 is a reply to message #689366] Mon, 27 June 2011 16:00 Go to previous message
Thanasis Naskos is currently offline Thanasis Naskos
Messages: 22
Registered: March 2011
Junior Member
Hi,
I didn't have any problem with the previous version, everything was working as a charm... I've just changed my code because as you said the old methods are deprecated...
Previous Topic:MoDisco team is organizing an Eclipse DemoCamp for Indigo next week
Next Topic:Infinite (?) execution when trying to discover KDM code model from ADempiere
Goto Forum:
  


Current Time: Wed Oct 22 12:34:30 GMT 2014

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

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