cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertdzeig...@apache.org
Subject svn commit: r746145 - /cayenne/main/trunk/framework/maven-cayenne-modeler-plugin/src/main/java/org/apache/cayenne/tools/CayenneModelerMojo.java
Date Fri, 20 Feb 2009 05:20:52 GMT
Author: robertdzeigler
Date: Fri Feb 20 05:20:48 2009
New Revision: 746145

URL: http://svn.apache.org/viewvc?rev=746145&view=rev
Log:
CAY-1158: cayenne-modeler:run plugin should open a (configured) project file, with suitable
defaults

Modified:
    cayenne/main/trunk/framework/maven-cayenne-modeler-plugin/src/main/java/org/apache/cayenne/tools/CayenneModelerMojo.java

Modified: cayenne/main/trunk/framework/maven-cayenne-modeler-plugin/src/main/java/org/apache/cayenne/tools/CayenneModelerMojo.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/maven-cayenne-modeler-plugin/src/main/java/org/apache/cayenne/tools/CayenneModelerMojo.java?rev=746145&r1=746144&r2=746145&view=diff
==============================================================================
--- cayenne/main/trunk/framework/maven-cayenne-modeler-plugin/src/main/java/org/apache/cayenne/tools/CayenneModelerMojo.java
(original)
+++ cayenne/main/trunk/framework/maven-cayenne-modeler-plugin/src/main/java/org/apache/cayenne/tools/CayenneModelerMojo.java
Fri Feb 20 05:20:48 2009
@@ -19,7 +19,12 @@
 
 package org.apache.cayenne.tools;
 
+import java.io.File;
+import java.util.List;
+
 import org.apache.cayenne.modeler.Main;
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -33,10 +38,54 @@
  * @goal run
  */
 public class CayenneModelerMojo extends AbstractMojo {
-	public void execute() throws MojoExecutionException, MojoFailureException {
 
-		// Start up the modeler.
-		Main.main(new String[] {});
+    /**
+     * Name of the model file to open.  
+     *
+     * @parameter expression="${modeler.modelFile} 
+     */
+    private File modelFile;
+
+    /**
+     * Project instance.
+     * @parameter default-value="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+
+    private File lookupModelFile() {
+        if (modelFile != null) {
+            return modelFile;
+        }
+        
+        //try to locate cayenne.xml at top level of a resource directory.
+        for(Object o : project.getResources()) {
+            Resource r = (Resource) o;
+            File f = new File(r.getDirectory(),"cayenne.xml");
+            if (f.exists()) {
+                return f;
+            }
+        }
+        
+        //failing that, try for WEB-INF/cayenne.xml in the maven-conventional webapp directory,
src/main/webapp
+        File f = new File(project.getBasedir().getAbsolutePath(),
+                            "src" + File.separator + 
+                            "main" + File.separator + 
+                            "webapp" + File.separator + 
+                            "WEB-INF" + File.separator +
+                            "cayenne.xml");
+        return f;
+    }
+
+	public void execute() throws MojoExecutionException, MojoFailureException {
+        File f = lookupModelFile();
+        //start the modeler with the provided model file, if it exists.
+        if (f.exists() && !f.isDirectory()) {
+            Main.main(new String[] {f.getAbsolutePath()});
+        } else {
+            Main.main(new String[] {});
+        }
 
 		// Block until the modeler finishes executing.
 		try {



Mime
View raw message