leumas95
leumas95

Reputation: 395

Dynamic Acceleo Project Plugin

I want to run an Acceleo Project from an Installed Plugin,

i.e. I have written a plugin that uses Acceleo and I want it to run an Acceleo template from a project that is in the workspace.

Currently, I have an Acceleo project which I run from my Eclipse Plugin programmatically:

try {
final File outputDir = new File("C:/outputDir/");
List<String> arguments = new ArrayList<String>();
/*fc is an instance of a EMF Compare Comparison object
 * the nsURI for it is http://www.eclipse.org/emf/compare
 */
Generate generator = new Generate(fc, outputDir, arguments);                                 
            generator.doGenerate(new BasicMonitor());
} catch (IOException e) {
e.printStackTrace();
}

The template is simple at the moment:

[comment encoding = UTF-8 /]
[module generate('http://www.eclipse.org/emf/compare')]
[template public generateElement(comparison : Comparison)]
[comment @main/]
[file ('update.sql', false, 'UTF-8')]
/*SQL UPDATE SCRIPT TEST*/
[comparison.getDifferences().toString() /]
[/file]
[/template]

This generates perfectly.

The issue is that I need to deploy the plugin but I still need end users to be able to modify the templates. The end goal is to have the Acceleo project in the end users' workspace and let my plugin call it at runtime, but no matter how I set it up, I have to include the Acceleo project in my Plugin Feature.

Things I have attempted:

I am running:

Upvotes: 0

Views: 370

Answers (2)

Uisleandro
Uisleandro

Reputation: 41

I'm doing this way: "taking argument data from the generated structure and treating it as input data". In other words, you can pass data through your models:

The model is your input, so if you want to have a compiled and configurable Acceleo plugin you should maybe have a "configuration element" on your entrance model (if you are using UML it can be a "configuration class"), in this case you'll be able to have a "blackbox m2t transformation" and also some information (through your entrance model) from which you can take decisions. You can add these elements (with the default values) from a previous m2m transformation. If you know a little bit of "eclipse rcp" maybe you can create this configuration element and add it to your entrance model (as text) programmatically and then running your "argumented transformation" or else you can just ask the user to to the task manually. Maybe this solution won't solve all your problems, but based on this you can, at least, give to the end user various transformation options.

After writing this answer, i find this interesting, and maybe better than my proposal: Acceleo M2T - Write timestamp into a generated file

Upvotes: 0

D-FENS
D-FENS

Reputation: 1521

What you are trying to achieve is probably defined incorrectly. Acceleo compiles the templates into Java code and creates executable classes from them. If you want your end users to modify the templates, then they will need to compile code afterwards, i.e. they would need the build infrastructure.

I would suggest that you parameterize the SQL queries and compile the templates. You can create a utility Java class exposing a function "getSQL...()" and call it from your template. This utility class can read the SQL from .properties or other source as you please.

Then you compile and release your binary acceleo project and teach the users what they need to configure at runtime.

Upvotes: 0

Related Questions