Author: robertdzeigler
Date: Sat Feb 21 10:56:33 2009
New Revision: 746483
URL: http://svn.apache.org/viewvc?rev=746483&view=rev
Log:
CAY-1158 cayenne-modeler:run plugin should open a (configured) project file,
with suitable defaults
Code clean up + make it so the plugin can find cayenne.xml in WEB-INF even if a
project uses a non-default webapp structure.
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=746483&r1=746482&r2=746483&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
Sat Feb 21 10:56:33 2009
@@ -21,13 +21,17 @@
import java.io.File;
import java.util.List;
+import java.util.Properties;
+import org.apache.cayenne.conf.Configuration;
import org.apache.cayenne.modeler.Main;
+import org.apache.maven.model.Plugin;
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;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
* Maven mojo to start up the Cayenne modeler from the command-line.
@@ -56,32 +60,52 @@
private File lookupModelFile() {
if (modelFile != null) {
- return modelFile;
+ if (modelFile.isDirectory()) {
+ return new File(modelFile,Configuration.DEFAULT_DOMAIN_FILE);
+ } else {
+ 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");
+ File f = new
File(r.getDirectory(),Configuration.DEFAULT_DOMAIN_FILE);
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;
+ //failing that, try for WEB-INF/DEFAULT_DOMAIN_FILE
+ //but only if we're using the war plugin
+ for(Object o : project.getBuildPlugins()) {
+ Plugin plugin = (Plugin) o;
+ //means we're using the war plugin.
+ if
(plugin.getKey().equals("org.apache.maven.plugins:maven-war-plugin")) {
+ //check to see if the default loc. is overridden.
+ Xpp3Dom conf = (Xpp3Dom)plugin.getConfiguration();
+ String path;
+
+ if (conf != null && (conf =
conf.getChild("warSourceDirectory")) != null) {
+ path = conf.getValue().trim();
+ } else {
+ path = "src" + File.separator + "main" + File.separator +
"webapp";
+ }
+
+ return new File(project.getBasedir().getAbsolutePath(),
+ path + File.separator +
+ "WEB-INF" + File.separator +
+ Configuration.DEFAULT_DOMAIN_FILE);
+ }
+ }
+
+ return null;
}
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()) {
+ if (f != null && f.exists() && !f.isDirectory()) {
Main.main(new String[] {f.getAbsolutePath()});
} else {
Main.main(new String[] {});