Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 319375 - Ant file included in org.eclipse.acceleo.module.example.uml2java\tasks don't work
Summary: Ant file included in org.eclipse.acceleo.module.example.uml2java\tasks don't ...
Status: CLOSED FIXED
Alias: None
Product: Acceleo
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 minor
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-09 08:29 EDT by Charlie Mordant CLA
Modified: 2011-10-12 05:53 EDT (History)
4 users (show)

See Also:


Attachments
Ugly Working standalone compilation-M2T generation (853.58 KB, text/plain)
2010-08-19 13:08 EDT, Charlie Mordant CLA
no flags Details
ant task calling acceleo compiler and generating java classes from template (4.07 KB, text/xml)
2011-03-15 15:10 EDT, Charlie Mordant CLA
no flags Details
abstract acceleo compiling class (14.01 KB, text/x-java-source)
2011-03-15 15:11 EDT, Charlie Mordant CLA
no flags Details
my core objects acceleo compiler (4.13 KB, text/x-java-source)
2011-03-15 15:11 EDT, Charlie Mordant CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Charlie Mordant CLA 2010-07-09 08:29:11 EDT
Build Identifier: org.eclipse.acceleo.module.example.uml2java 3.0

I try to follow the generate.readme file contained in the acceleo 3.0 example in order to generate model out of the box.
Some eclipse-plugin links are missing and finally code generation don't work.
Can you make a functionnal ant task, or, at least delete this task folder?

Reproducible: Always
Comment 1 Charlie Mordant CLA 2010-07-11 08:09:48 EDT
Hi,

I succeed to generate Java source code from an ant task, acceleo template and uml diagram.
I used your helios example to test this but here i'm locked.

I modified some files and some errors from the original ant task and source code. 
Here's the Ant task:
[CODE]<?xml version="1.0" encoding="UTF-8"?>
<project default="generateJava" name="org.eclipse.acceleo.module.example.uml2java">
	<property name="ECLIPSE_HOME" value="../../" />
	<property name="ECLIPSE_WORKSPACE" value="../" />
	<path id="org.eclipse.acceleo.module.example.uml2java.libraryclasspath">
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/bin" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.acceleo.engine_3.0.0.v201006150906.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/acceleoCompiler.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.acceleo.common_3.0.0.v201006150906.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.acceleo.parser_3.0.0.v201006150906.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.core.runtime_3.6.0.v20100505.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.emf.ecore_2.6.0.v20100614-1136.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.emf.ecore.xmi_2.5.0.v20100521-1846.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.ocl_3.0.0.v201005061704.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.ocl.ecore_3.0.0.v201005061704.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.acceleo.model_3.0.0.v201006150906.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.emf.common_2.6.0.v20100614-1136.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.emf.codegen.ecore_2.6.0.v20100614-1136.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/lpg.runtime.java_2.0.17.v201004271640.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.uml2.uml_3.0.0.v200905151700.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/ant.jar" />
		<pathelement location="../org.eclipse.acceleo.module.example.uml2java.helios/lib/org.eclipse.uml2.common_1.5.0.v200905041045.jar" />
		
		
		
		
				
		
	</path>
	<path id="org.eclipse.acceleo.module.example.uml2java.classpath">
		<path refid="org.eclipse.acceleo.module.example.uml2java.libraryclasspath" />
	</path>

	<target name="generateJava">

		<java classname="org.eclipse.acceleo.module.example.uml2java.helios.GenerateJava" classpathref="org.eclipse.acceleo.module.example.uml2java.classpath">
			<arg value="../org.eclipse.acceleo.module.example.uml2java.helios/model/example.uml" />
			<arg value="../org.eclipse.acceleo.module.example.uml2java.helios/src-gen" />
		</java>

	</target>

</project>
[/CODE]

I modified this code in generateJava:
[CODE]/*******************************************************************************
 * Copyright (c) 2008, 2010 Obeo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.acceleo.module.example.uml2java.helios;

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

import org.eclipse.acceleo.engine.event.IAcceleoTextGenerationListener;
import org.eclipse.acceleo.engine.generation.strategy.DefaultStrategy;
import org.eclipse.acceleo.engine.generation.strategy.IAcceleoGenerationStrategy;
import org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.common.util.Monitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;

/**
 * Entry point of the 'GenerateJava' generation module.
 * 
 * @generated
 */
public class GenerateJava extends AbstractAcceleoGenerator {

	/**
	 * The name of the module.
	 * 
	 * @generated
	 */
	public static final String MODULE_FILE_NAME = "generateJava";

	/**
	 * The name of the templates that are to be generated.
	 * 
	 * @generated
	 */
	public static final String[] TEMPLATE_NAMES = { "generateClass", "generateInterface", };

	/**
	 * Allows the public constructor to be used. Note that a generator created this way cannot be used to
	 * launch generations before one of {@link #initialize(EObject, File, List)} or
	 * {@link #initialize(URI, File, List)} is called.
	 * <p>
	 * The main reason for this constructor is to allow clients of this generation to call it from another
	 * Java file, as it allows for the retrieval of {@link #getProperties()} and
	 * {@link #getGenerationListeners()}.
	 * </p>
	 * 
	 * @generated
	 */
	public GenerateJava() {
    // Empty implementation
  }

	/**
	 * Constructor.
	 * 
	 * @param modelURI
	 *            is the URI of the model.
	 * @param targetFolder
	 *            is the output folder
	 * @param arguments
	 *            are the other arguments
	 * @throws IOException
	 *             Thrown when the output cannot be saved.
	 * @generated
	 */
	public GenerateJava(URI modelURI, File targetFolder, List<? extends Object> arguments) throws IOException {
    initialize(modelURI, targetFolder, arguments);
  }

	/**
	 * Constructor.
	 * 
	 * @param model
	 *            is the root element of the model.
	 * @param targetFolder
	 *            is the output folder
	 * @param arguments
	 *            are the other arguments
	 * @throws IOException
	 *             Thrown when the output cannot be saved.
	 * @generated
	 */
	public GenerateJava(EObject model, File targetFolder, List<? extends Object> arguments)
			throws IOException {
    initialize(model, targetFolder, arguments);
  }

	/**
	 * Updates the registry used for looking up a package based namespace, in the resource set.
	 * 
	 * @param resourceSet
	 *            is the resource set
	 * @generated
	 */
	@Override
	public void registerPackages(ResourceSet resourceSet) {
    super.registerPackages(resourceSet);
    resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
    // TODO If you need additional package registrations, do them here. The following line is an example for UML.
    resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
  }

	/**
	 * Updates the registry used for looking up resources factory in the given resource set.
	 * 
	 * @param resourceSet
	 *            The resource set that is to be updated.
	 * @generated
	 */
	@Override
	public void registerResourceFactories(ResourceSet resourceSet) {
    super.registerResourceFactories(resourceSet);
    // TODO If you need additional resource factories registrations, do them here. The following line is an example for UML.
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
  }

	/**
	 * The main method.
	 * 
	 * @param args
	 *            are the arguments
	 * @generated
	 */
	public static void main(String[] args) {
    try {
      if (args.length < 2) {
        System.out.println("Arguments not valid : {model, folder}.");
      } else {
        URI modelURI = URI.createFileURI(args[0]);
        File folder = new File(args[1]);
        List<String> arguments = new ArrayList<String>();
        for (int i = 2; i < args.length; i++) {
          arguments.add(args[i]);
        }
        GenerateJava generator = new GenerateJava(modelURI, folder, arguments);
        generator.doGenerate(new BasicMonitor());
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

	/**
	 * Launches the generation.
	 * 
	 * @param monitor
	 *            This will be used to display progress information to the user.
	 * @throws IOException
	 *             Thrown when the output cannot be saved.
	 * @generated
	 */
	@Override
	public void doGenerate(Monitor monitor) throws IOException {
    /*
     * TODO if you wish to change the generation as a whole, override this.
     * The default behavior should be sufficient in most cases.
     */
    super.doGenerate(monitor);
  }

	/**
	 * If this generator needs to listen to text generation events, listeners can be returned from here.
	 * 
	 * @return List of listeners that are to be notified when text is generated through this launch.
	 * @generated
	 */
	@Override
	public List<IAcceleoTextGenerationListener> getGenerationListeners() {
    List<IAcceleoTextGenerationListener> listeners = super.getGenerationListeners();
    // TODO if you need to listen to generation event, add listeners to the list here
    return listeners;
  }

	/**
	 * If you need to change the way files are generated, this is your entry point.
	 * <p>
	 * The default is {@link org.eclipse.acceleo.engine.generation.strategy.DefaultStrategy}; it generates
	 * files on the fly. If you only need to preview the results, return a new
	 * {@link org.eclipse.acceleo.engine.generation.strategy.PreviewStrategy}. Both of these aren't aware of
	 * the running Eclipse and can be used standalone.
	 * </p>
	 * <p>
	 * If you need the file generation to be aware of the workspace (A typical example is when you wanna
	 * override files that are under clear case or any other VCS that could forbid the overriding), then
	 * return a new {@link org.eclipse.acceleo.engine.generation.strategy.WorkspaceAwareStrategy}.
	 * <b>Note</b>, however, that this <b>cannot</b> be used standalone.
	 * </p>
	 * <p>
	 * All three of these default strategies support merging through JMerge.
	 * </p>
	 */
	public IAcceleoGenerationStrategy getGenerationStrategy() {
		return new DefaultStrategy();
	}

	/**
	 * This will be called in order to find and load the module that will be launched through this launcher.
	 * We expect this name not to contain file extension, and the module to be located beside the launcher.
	 * 
	 * @return The name of the module that is to be launched.
	 * @generated
	 */
	@Override
	public String getModuleName() {
    return MODULE_FILE_NAME;
  }

	/**
	 * If the module(s) called by this launcher require properties files, return their qualified path from
	 * here.Take note that the first added properties files will take precedence over subsequent ones if they
	 * contain conflicting keys.
	 * <p>
	 * Properties need to be in source folders, the path that we expect to get as a result of this call are of
	 * the form &lt;package>.&lt;properties file name without extension>. For example, if you have a file
	 * named "messages.properties" in package "org.eclipse.acceleo.sample", the path that needs be returned by
	 * a call to {@link #getProperties()} is "org.eclipse.acceleo.sample.messages".
	 * </p>
	 * 
	 * @return The list of properties file we need to add to the generation context.
	 * @see java.util.ResourceBundle#getBundle(String)
	 * @generated
	 */
	@Override
	public List<String> getProperties() {
    List<String> propertiesFiles = super.getProperties();
    /*
     * TODO if your generation module requires access to properties files,
     * add their qualified path to the list here. Properties files are
     * expected to be in source folders, and the path here to be the
     * qualified path as if referring to a Java class. For example, if you
     * have a file named "messages.properties" in package
     * "org.eclipse.acceleo.sample", the path that needs be added to this
     * list is "org.eclipse.acceleo.sample.messages".
     */
    return propertiesFiles;
  }

	/**
	 * This will be used to get the list of templates that are to be launched by this launcher.
	 * 
	 * @return The list of templates to call on the module {@link #getModuleName()}.
	 * @generated
	 */
	@Override
	public String[] getTemplateNames() {
    return TEMPLATE_NAMES;
  }

}
[/CODE]

And finally copied the required jars in a lib folder.


Can you now update your example?
Comment 2 Laurent Goubet CLA 2010-08-02 04:19:15 EDT
Hi Charlie,

This bug is ... hard to read :/.

Do you remember exactly what you needed to change in the generated files for the ant task to work? Trying to determine the patch from the final result isn't the easiest of tasks.

If you don't remember what you changed, I'll try the hard way ^^.
Comment 3 Charlie Mordant CLA 2010-08-02 08:39:53 EDT
Sorry for the previous comment.

In order to make ant task work, you must create an acceleoCompiler class with some modified method (a part of the solution is explained in your forum in a post titled module recompilation), I posted the Java code in the last comment (just have to make a diff between  this and your original acceleoCompiler).

Then, you'll have to add more Acceleo/Eclipse librairies to make it run, just try uncommenting the task and running, your compiler will tell you which (I also posted the dependencies in the previous comment (XML Code).

Sorry, but I can't access the code here (at work and then on holidays), I'll try to be more precise in about 3 or 4 weeks.
Comment 4 Laurent Goubet CLA 2010-08-02 09:12:56 EDT
So the modifications you outline here are specifically for "running _and compiling_ Acceleo in standalone" right? Does http://wiki.eclipse.org/Acceleo/FAQ#How_can_I_compile_my_mtl_files_in_a_standalone_environment.3F cover the changes you outline here?

We'd rather keep the generated ant task free of compilation specific things.
Comment 5 Charlie Mordant CLA 2010-08-02 09:29:04 EDT
Yes, it concerns Standalone compilation (your FAQ just covers a part of the full process). 

But the Ant task is included in the Acceleo example and just doesn't work. 
The thing is that it has to be removed from this or modified in a way to work in order to avoid end user losing his hair trying to understand why this task should work and what he did wrong.
If you want, I can modify the helios example and send it to you in the nearly future .
Comment 6 Laurent Goubet CLA 2010-08-02 09:35:29 EDT
(In reply to comment #5)
> Yes, it concerns Standalone compilation (your FAQ just covers a part of the
> full process). 
> 
> But the Ant task is included in the Acceleo example and just doesn't work. 
> The thing is that it has to be removed from this or modified in a way to work
> in order to avoid end user losing his hair trying to understand why this task
> should work and what he did wrong.
> If you want, I can modify the helios example and send it to you in the nearly
> future .

That would be appreciated (just attach the patch to the helios example's ant tasks and classes), that would allow me to quickly grasp the needed changes.
Comment 7 Charlie Mordant CLA 2010-08-19 13:08:39 EDT
Created attachment 177027 [details]
Ugly Working standalone compilation-M2T generation

Here's the Ugly but functionnal standalone compilation and generation.

Enjoy, Charlie
Comment 8 Charlie Mordant CLA 2011-03-15 15:10:27 EDT
Created attachment 191239 [details]
ant task calling acceleo compiler and generating java classes from template

ant task calling acceleo compiler and generating java classes from template
Comment 9 Charlie Mordant CLA 2011-03-15 15:11:11 EDT
Created attachment 191240 [details]
abstract acceleo compiling class
Comment 10 Charlie Mordant CLA 2011-03-15 15:11:45 EDT
Created attachment 191241 [details]
my core objects acceleo compiler
Comment 11 Charlie Mordant CLA 2011-03-15 15:14:10 EDT
Hi, 

I succeed out of the box Acceleo template generation.
see "ant task calling acceleo compiler and generating java classes from template", "abstract acceleo compiling class" and "my core objects acceleo compiler" attachements.

Nevertheless, a Maven-Acceleo-Plugin would be graceful.

Regards, Charlie
Comment 12 Mariot Chauvin CLA 2011-03-15 15:36:32 EDT
Hi Charlie,

Thanks for your contribution, we will have a look !

On our side we worked also on it, see
 http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.m2t/org.eclipse.acceleo/plugins/org.eclipse.acceleo.parser/src-ant/org/eclipse/acceleo/parser/compiler/AcceleoCompiler.java?view=markup&root=Modeling_Project <http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.m2t/org.eclipse.acceleo/plugins/org.eclipse.acceleo.parser/src-ant/org/eclipse/acceleo/parser/compiler/AcceleoCompiler.java?view=markup&root=Modeling_Project> 

For the maven acceleo plugin we created
https://bugs.eclipse.org/bugs/show_bug.cgi?id=340036 to follow the progress. 
 
Mariot

(In reply to comment #11)
> Hi, 
> 
> I succeed out of the box Acceleo template generation.
> see "ant task calling acceleo compiler and generating java classes from
> template", "abstract acceleo compiling class" and "my core objects acceleo
> compiler" attachements.
> 
> Nevertheless, a Maven-Acceleo-Plugin would be graceful.
> 
> Regards, Charlie
Comment 13 Charlie Mordant CLA 2011-03-15 16:59:05 EDT
I already saw compilers (mine is done with this), but not the maven plugin. Thanks for the info ;).

Kiss from Paris, Charlie
Comment 14 Stephane Begaudeau CLA 2011-03-31 10:45:56 EDT
Ant files used to compile and generate have been fixed. Contributed on HEAD. It will be available in Acceleo 3.1M7