jvanzyl 2002/11/24 09:59:30
Modified: src/java/org/apache/maven/jelly/tags/project MavenTag.java
Log:
refactoring
Revision Changes Path
1.13 +71 -31
jakarta-turbine-maven/src/java/org/apache/maven/jelly/tags/project/MavenTag.java
Index: MavenTag.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jelly/tags/project/MavenTag.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- MavenTag.java 15 Nov 2002 19:47:26 -0000 1.12
+++ MavenTag.java 24 Nov 2002 17:59:30 -0000 1.13
@@ -59,8 +59,10 @@
import java.io.File;
import org.apache.maven.MavenUtils;
-import org.apache.maven.app.Maven;
import org.apache.maven.MavenConstants;
+import org.apache.maven.app.Maven;
+import org.apache.maven.jelly.MavenJellyContext;
+import org.apache.maven.project.Project;
import org.apache.commons.jelly.MissingAttributeException;
import org.apache.commons.jelly.TagSupport;
@@ -71,21 +73,27 @@
/**
* A way of running maven as a Jelly tag
*
- * @author Bob McWhirter
- * @author Jason van Zyl
- * @author St�phane Mor
- * @task get rid of 'throws Exception'
+ * @author <a href="mailto:[EMAIL PROTECTED]">bob mcwhirter</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
+ *
+ * @version $Id$
+ *
+ * @todo get rid of 'throws Exception'
*/
-public class MavenTag extends TagSupport
+public class MavenTag
+ extends TagSupport
{
/** maven project descriptor */
private File descriptor;
+
/** project base directory */
private File basedir;
+
/** goals to execute */
private String goals;
+
/** whether to ignore exceptions */
- private boolean ignore;
+ private boolean ignoreFailures;
/**
* Process the tag. Set up a new maven instance with the same maven home
@@ -95,33 +103,35 @@
* @param output for providing xml output
* @throws Exception if anything goes wrong. FIXME
*/
- public void doTag(XMLOutput output) throws Exception
+ public void doTag(XMLOutput output)
+ throws Exception
{
- if (basedir == null)
+ if (getBasedir() == null)
{
throw new MissingAttributeException("basedir");
}
- if (descriptor == null)
+ if (getDescriptor() == null)
{
throw new MissingAttributeException("descriptor");
}
-
- Maven parent = (Maven)
getContext().getVariable(MavenConstants.MAVEN_OBJECT);
-
+
try
{
- Maven maven = getMaven(output, parent);
-
+ //[ model for embedding maven ]
+ Maven maven = getMaven(output, MavenUtils.getProject(getDescriptor(),
getBasedir()));
+ // How come no verfication of the project?
+ maven.runtimeInitialization();
maven.attainGoals();
}
catch (Exception e)
{
- if (ignore)
+ if (getIgnoreFailures())
{
return;
}
+ e.printStackTrace();
e.fillInStackTrace();
throw e;
@@ -136,28 +146,36 @@
* @param parent the maven project that is currently executing
* @throws Exception when any error occurs
*/
- private Maven getMaven(XMLOutput output, Maven parent) throws Exception
+ protected Maven getMaven(XMLOutput output, Project project)
+ throws Exception
{
+ Maven parent = (Maven)
getContext().getVariable(MavenConstants.MAVEN_OBJECT);
+
+
+ // Use the descriptor file to get the base directory.
+ File basedir = new File(project.getFile().getParent());
+ System.out.println("basedir: " + basedir);
+ System.out.println("descriptor: " + project.getFile());
+
Maven maven = new Maven();
+ maven.setProject(project);
+
+ MavenJellyContext c = MavenUtils.createContext(basedir);
+
+ maven.setContext(c);
maven.setMavenHome(parent.getMavenHome());
- maven.setDir(getBasedir());
- maven.setProject(MavenUtils.getProject(getDescriptor(), getBasedir()));
+ maven.setDir(basedir);
maven.setXMLOutput(output, parent.isDebug());
- if (this.goals != null)
- {
- StringTokenizer tokens = new StringTokenizer(this.goals, ",");
-
- while (tokens.hasMoreTokens())
- {
- maven.addGoalName(tokens.nextToken().trim());
- }
- }
+ addGoals(maven);
- maven.runtimeInitialization();
return maven;
}
+ // ------------------------------------------------------------
+ // A C C E S S O R S
+ // ------------------------------------------------------------
+
/**
* Setter for the descriptor property
*
@@ -223,8 +241,30 @@
*
* @param ignore whether exceptions should be silently ignored
*/
- public void setIgnoreFailures(boolean ignore)
+ public void setIgnoreFailures(boolean ignoreFailures)
{
- this.ignore = ignore;
+ this.ignoreFailures = ignoreFailures;
}
+
+ public boolean getIgnoreFailures()
+ {
+ return ignoreFailures;
+ }
+
+ // ------------------------------------------------------------
+ // I N S T A N C E M E T H O D S
+ // ------------------------------------------------------------
+
+ protected void addGoals(Maven maven)
+ {
+ if (goals != null)
+ {
+ StringTokenizer tokens = new StringTokenizer(this.goals, ",");
+
+ while (tokens.hasMoreTokens())
+ {
+ maven.addGoalName(tokens.nextToken().trim());
+ }
+ }
+ }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>