View Javadoc
1   package de.fhdw.wtf.mojo;
2   
3   import java.io.File;
4   import java.net.URI;
5   import java.net.URISyntaxException;
6   import java.util.Iterator;
7   import java.util.concurrent.ExecutionException;
8   
9   import org.apache.maven.plugin.AbstractMojo;
10  import org.apache.maven.plugin.MojoExecutionException;
11  import org.apache.maven.plugin.MojoFailureException;
12  
13  import de.fhdw.wtf.common.ast.Model;
14  import de.fhdw.wtf.common.exception.editor.CheckException;
15  import de.fhdw.wtf.common.exception.editor.MultipleCheckExceptions;
16  import de.fhdw.wtf.common.exception.walker.CyclicDependencyException;
17  import de.fhdw.wtf.common.exception.walker.CyclicPartDefinitionException;
18  import de.fhdw.wtf.facade.ModelManager;
19  import de.fhdw.wtf.generator.java.generatorModel.GeneratorModel;
20  
21  /**
22   * A Maven Mojo, which generates the full WTF Stack: Java-Classes and Persitstence into the current project.
23   * 
24   * @goal generate
25   * @phase process-sources
26   * 
27   */
28  public class FullGenerate extends AbstractMojo {
29  	
30  	/**
31  	 * A file to represent the root of the java sources.
32  	 * 
33  	 * @parameter property="basedir"
34  	 */
35  	private File root;
36  	
37  	@Override
38  	public void execute() throws MojoExecutionException, MojoFailureException {
39  		this.getLog().info("Starting generation");
40  		try {
41  			if (this.root == null) {
42  				this.getLog().error("Root Path is null");
43  				this.root = new File(".");
44  			}
45  			this.getLog().info("Execution Path is " + this.root.getPath());
46  			final URI modelUri =
47  					new URI("file://" + this.root.getPath().replace('\\', '/') + "/src/main/resources/models/model.wtf");
48  			final String outputDir = this.root.getPath() + "/src/main/java";
49  			final String dbProprties = this.root.getPath() + "/src/main/resources/config/oracledb.properties";
50  			this.getLog().debug("Model File URI: " + modelUri.toString());
51  			this.getLog().debug("Output Director: " + outputDir);
52  			this.getLog().debug("Database Properties in: " + dbProprties);
53  			
54  			final ModelManager modelManager = ModelManager.getInstance();
55  			this.getLog().info("Parsing Model");
56  			try {
57  				final Model modelFromFile = modelManager.getModelFromFile(modelUri);
58  				final GeneratorModel genModel = modelManager.generateJava(modelFromFile, outputDir);
59  				modelManager.generatePersistence(modelFromFile, genModel, dbProprties);
60  			} catch (final MultipleCheckExceptions e) {
61  				final Iterator<CheckException> i = e.iterator();
62  				while (i.hasNext()) {
63  					final CheckException current = i.next();
64  					this.getLog().error(current);
65  				}
66  			} catch (final CyclicDependencyException | InterruptedException | CyclicPartDefinitionException
67  					| ExecutionException e1) {
68  				this.getLog().error(e1);
69  			}
70  		} catch (final URISyntaxException e) {
71  			this.getLog().error(e);
72  		}
73  		
74  	}
75  }