Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Retrieve target folder during generation
Retrieve target folder during generation [message #894755] Tue, 10 July 2012 11:49 Go to next message
Niels Brouwers is currently offline Niels BrouwersFriend
Messages: 80
Registered: July 2009
Member
Hi all,

is there a way to retrieve the target folder during generation? With target folder I mean the root folder to which all files are generated, configured in the launch configuration.

I would like to use this to provide a warning to the user in case a file is generated to another location, such that he can manually remove it from the old location. Please note that both locations are determined at forehand.

Thanks!


Kind regards,
Niels Brouwers.
Re: Retrieve target folder during generation [message #895364 is a reply to message #894755] Thu, 12 July 2012 15:05 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

Technically, this information is in the "targetFolder" attribute of your Java launcher, you could create a Java service to access this value. In one of our projects, we saved it in a properties file next to the model during the launch of the generation and we retrieve the value from the generator to give it to our Java service;

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau & @acceleo
Google+: stephane.begaudeau & acceleo
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo
Re: Retrieve target folder during generation [message #896086 is a reply to message #894755] Tue, 17 July 2012 08:39 Go to previous messageGo to next message
Niels Brouwers is currently offline Niels BrouwersFriend
Messages: 80
Registered: July 2009
Member
Hi Stephane,

thanks for answer. Eventually I ended up with using system systems properties to temporarily storing the target folder.

I have overridden generator's 'generate' method to store the target folder in a system property using System.setProperty() and retrieve this property in a Java service wrapper using System.getProperty(). This actually works fine!

Thanks for the help.

Kind regards,
Niels Brouwers.


Kind regards,
Niels Brouwers.
Re: Retrieve target folder during generation [message #1785253 is a reply to message #896086] Wed, 11 April 2018 15:18 Go to previous message
Thomas Petrou is currently offline Thomas PetrouFriend
Messages: 12
Registered: April 2018
Junior Member
Hello all,

I have solved this one by creating a static field in the Generate.java folder.

I am seting it to the target folder when registering my ecore model.

This is how it is set in Generate.java
* USed to find the name of the target folder so we can copy non mtls.
*
* @generated NOT
*/
public static String currentTargetFolder = "Not Defined Yet";

/**
* This allows clients to instantiates a generator with all required information.
*
* @param modelURI
* URI where the model on which this generator will be used is located.
* @param targetFolder
* This will be used as the output folder for this generation : it will be the base path
* against which all file block URLs will be resolved.
* @param arguments
* If the template which will be called requires more than one argument taken from the model,
* pass them here.
* @throws IOException
* This can be thrown in three scenarios : the module cannot be found, it cannot be loaded, or
* the model cannot be loaded.
* @generated NOT
*/
public GenerateMaziDocs(URI modelURI, File targetFolder,
List<? extends Object> arguments) throws IOException {
MYECOREDSL.doSetup();
initialize(modelURI, targetFolder, arguments);
currentTargetFolder = this.getTargetFolder().getAbsolutePath();
}


This is how i am accessing it in the java wrapper
Generate.currentTargetFolder


Hope it makes sense.

Posting in the case someone can see some side effects or help others

Thanks
Thomas
Previous Topic:Error while generating A UML code
Next Topic:How to get the location of the currently executing template in java wrapper
Goto Forum:
  


Current Time: Thu Nov 14 18:55:54 GMT 2024

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

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

Back to the top