werken 2002/06/06 11:09:26
Modified: . project.xml
src/bin maven-scripts.jelly
src/java/org/apache/maven/jelly AntBuildTag.java
MavenInitTag.java
Log:
More integration work for jelly+ant
Revision Changes Path
1.103 +6 -0 jakarta-turbine-maven/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/project.xml,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -r1.102 -r1.103
--- project.xml 6 Jun 2002 05:25:43 -0000 1.102
+++ project.xml 6 Jun 2002 18:09:25 -0000 1.103
@@ -293,6 +293,12 @@
</dependency>
<dependency>
+ <id>junit</id>
+ <version>3.7</version>
+ <url>http://junit.org/</url>
+ </dependency>
+
+ <dependency>
<id>commons-betwixt</id>
<version>1.0-dev</version>
<url>http://jakarta.apache.org/commons/sandbox/betwixt/</url>
1.3 +8 -4 jakarta-turbine-maven/src/bin/maven-scripts.jelly
Index: maven-scripts.jelly
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/bin/maven-scripts.jelly,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- maven-scripts.jelly 6 Jun 2002 06:54:36 -0000 1.2
+++ maven-scripts.jelly 6 Jun 2002 18:09:25 -0000 1.3
@@ -11,9 +11,13 @@
|| maven:target
-->
<def:script var="target_maven">
- running [maven_target] <jelly:expr value="${target}"/>
- maven.home = <jelly:expr value="${maven.home}"/>
- lib.repo = <jelly:expr value="${lib.repo}"/>
+ <maven:build target="jar" buildFile="/home/bob/maven/plugins/core/build.xml"/>
+
+ ======================================================================
+ == BUILD SUCCESSFUL
+ ==
+ == The target "<jelly:expr value="${target}"/>" has been built
+ ======================================================================
</def:script>
<!--
|| bogus maven:target
@@ -29,7 +33,7 @@
|| user-defined target
-->
<def:script var="target_user">
- <maven:build target="${target}" ignore="true"/>
+ <maven:build target="${target}"/> <!-- ignore="true"/> -->
<jelly:choose>
<jelly:when test='${target_status == "unknown_target"}'>
<jelly:jelly body="${target_unknown}"/>
1.5 +238 -34
jakarta-turbine-maven/src/java/org/apache/maven/jelly/AntBuildTag.java
Index: AntBuildTag.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jelly/AntBuildTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AntBuildTag.java 6 Jun 2002 17:05:20 -0000 1.4
+++ AntBuildTag.java 6 Jun 2002 18:09:25 -0000 1.5
@@ -58,18 +58,31 @@
import java.io.File;
import java.io.PrintStream;
+import java.io.IOException;
+import java.lang.reflect.Method;
+
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.Vector;
import java.util.Hashtable;
+import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.MissingAttributeException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.ProjectHelper;
+import org.apache.tools.ant.Target;
import org.apache.tools.ant.BuildLogger;
import org.apache.tools.ant.NoBannerLogger;
+import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Property;
+import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.ant.types.Reference;
public class AntBuildTag
extends TagSupport
@@ -141,7 +154,7 @@
public void setIgnore(String ignore)
{
- if ("true".equals(ignore))
+ if ( "true".equals( ignore ) )
{
this.ignore = true;
}
@@ -162,11 +175,12 @@
public void doTag(XMLOutput output)
throws Exception
{
+ System.err.println( "########## AntBuildTag.doTag()" );
// Check to make sure that we have a valid POM
// before processing.
if (buildFile == null
&&
- context.getVariable("ant-project") == null)
+ context.getVariable( "ant-project" ) == null )
{
throw new MissingAttributeException("buildFile");
}
@@ -177,8 +191,9 @@
/**
* Execute the Ant build using the build file specified.
*/
- public void executeBuild()
+ public void executeBuild() throws Exception
{
+ System.err.println( "########## AntBuildTag.executeBuild()" );
PrintStream err = System.err;
PrintStream out = System.out;
@@ -186,78 +201,267 @@
{
Project project = null;
- if (getBuildFile() != null)
+ if (getBuildFile() != null )
{
project = new Project();
- BuildLogger logger = new NoBannerLogger();
-
- logger.setMessageOutputLevel(Project.MSG_VERBOSE);
- logger.setOutputPrintStream(System.out);
- logger.setErrorPrintStream(System.err);
-
- project.addBuildListener(logger);
-
- project.init();
- File buildFile = new File(getBuildFile());
+ File buildFile = new File( getBuildFile() );
+
+ project.setUserProperty("ant.file" , buildFile.getAbsolutePath() );
- project.setUserProperty("ant.file",
- buildFile.getAbsolutePath());
+ Class.forName( "javax.xml.parsers.SAXParserFactory" );
- Class.forName("javax.xml.parsers.SAXParserFactory");
+ project.init();
- ProjectHelper.configureProject(project,
- buildFile);
+ ProjectHelper.configureProject( project,
+ buildFile );
+
+ Project parentProj = (Project) context.getVariable( "ant-project" );
+
+ if ( parentProj != null )
+ {
+ File baseDir = parentProj.getBaseDir();
+ String antHome = parentProj.getProperty( "ant.home" );
+
+ System.err.println( "########## property ant.home " +
parentProj.getProperty( "ant.home" ) );
+ System.err.println( "########## user-property ant.home " +
parentProj.getUserProperty( "ant.home" ) );
+
+ initializeProject( parentProj, project );
+
+ project.setBaseDir( baseDir );
+ project.setProperty( "base.dir",
+ baseDir.getAbsolutePath() );
+
+ addReferences( parentProj, project );
+
+ if ( antHome != null )
+ {
+ project.setProperty( "ant.home",
+ antHome );
+ }
+ }
}
else
{
- project = (Project) context.getVariable("ant-project");
+ project = (Project) context.getVariable( "ant-project" );
}
Hashtable projTargets = project.getTargets();
String target = getTarget();
- if (target == null)
+ if ( target == null )
{
target = project.getDefaultTarget();
}
else
{
- if (!projTargets.containsKey(getTarget()))
+ if ( ! projTargets.containsKey( getTarget() ) )
{
target = null;
}
}
- if (target != null)
+ if ( target != null )
{
try
{
- project.executeTarget(target);
- getContext().setVariable("target_status",
- "ok");
+ project.executeTarget( target );
+ getContext().setVariable( "target_status",
+ "ok" );
}
catch (BuildException e)
{
- getContext().setVariable("target_status",
- "failed");
+ getContext().setVariable( "target_status",
+ "failed" );
}
}
else
{
- getContext().setVariable("target_status",
- "unknown_target");
+ getContext().setVariable( "target_status",
+ "unknown_target" );
- if (!getIgnore())
+ if ( ! getIgnore() )
{
- throw new Exception("No target \"" + target + "\" in " +
- project.getUserProperty("ant.file"));
+ throw new Exception( "No target \"" + target + "\" in " +
project.getUserProperty( "ant.file" ) );
}
}
}
- catch (Exception e)
+ catch( Exception e )
{
e.printStackTrace();
}
+ }
+
+
+ /**
+ * Attaches the build listeners of the current project to the new
+ * project, configures a possible logfile, transfers task and
+ * data-type definitions, transfers properties (either all or just
+ * the ones specified as user properties to the current project,
+ * depending on inheritall).
+ */
+ private void initializeProject(Project project,
+ Project newProject)
+ {
+
+ System.err.println( "########## initializeProject()" );
+ Vector listeners = project.getBuildListeners();
+ final int count = listeners.size();
+ for (int i = 0; i < count; i++)
+ {
+ newProject.addBuildListener((BuildListener) listeners.elementAt(i));
+ }
+
+ Hashtable taskdefs = project.getTaskDefinitions();
+ Enumeration et = taskdefs.keys();
+ while (et.hasMoreElements())
+ {
+ String taskName = (String) et.nextElement();
+ if (taskName.equals("property"))
+ {
+ // we have already added this taskdef in #init
+ continue;
+ }
+ Class taskClass = (Class) taskdefs.get(taskName);
+ newProject.addTaskDefinition(taskName, taskClass);
+ }
+
+ Hashtable typedefs = project.getDataTypeDefinitions();
+ Enumeration e = typedefs.keys();
+ while (e.hasMoreElements())
+ {
+ String typeName = (String) e.nextElement();
+ Class typeClass = (Class) typedefs.get(typeName);
+ newProject.addDataTypeDefinition(typeName, typeClass);
+ }
+
+ // set user-defined or all properties from calling project
+ Hashtable prop1;
+
+ prop1 = project.getProperties();
+
+ e = prop1.keys();
+
+ while (e.hasMoreElements())
+ {
+ String arg = (String) e.nextElement();
+ if ("basedir".equals(arg) || "ant.file".equals(arg))
+ {
+ // basedir and ant.file get special treatment in execute()
+ continue;
+ }
+
+ String value = (String) prop1.get(arg);
+
+ newProject.setProperty(arg, value);
+ }
+
+ System.err.println( "########## initializeProject() DONE" );
+ }
+
+ /**
+ * Add the references explicitly defined as nested elements to the
+ * new project. Also copy over all references that don't override
+ * existing references in the new project if inheritrefs has been
+ * requested.
+ * @throws BuildException when the refid attribute is missing from a
+ * reference
+ */
+ private void addReferences(Project project,
+ Project newProject) throws BuildException
+ {
+ Hashtable thisReferences = (Hashtable) project.getReferences().clone();
+ Hashtable newReferences = newProject.getReferences();
+ Enumeration e;
+
+ // Now add all references that are not defined in the
+ // subproject, if inheritRefs is true
+ for (e = thisReferences.keys(); e.hasMoreElements();)
+ {
+ String key = (String) e.nextElement();
+ if (newReferences.containsKey(key))
+ {
+ continue;
+ }
+ copyReference(project, newProject,
+ key, key);
+ }
+ }
+
+ /**
+ * Try to clone and reconfigure the object referenced by oldkey in
+ * the parent project and add it to the new project with the key
+ * newkey.
+ *
+ * <p>If we cannot clone it, copy the referenced object itself and
+ * keep our fingers crossed.</p>
+ * @param oldKey the name of the reference to be cloned
+ * @param newKey the name of the cloned reference in the new project
+ */
+ private void copyReference(Project project, Project newProject,
+ String oldKey, String newKey)
+ {
+ //Object orig = project.getReference(oldKey);
+ // Changed this to make it work with ant 1.4
+ Object orig = project.getReferences().get(oldKey);
+
+ // copyReference(orig, newKey, newProject);
+
+ copyReference(newProject,
+ orig, newKey);
+ }
+
+ /**
+ * Try to clone the given reference .
+ *
+ * <p>If we cannot clone it, lets reuse the existing
+ * reference and keep our fingers crossed.</p>
+ */
+ private void copyReference(Project aProject, Object orig, String key)
+ {
+ Object copy = orig;
+ Class c = orig.getClass();
+ try
+ {
+ Method cloneM = c.getMethod("clone", new Class[0]);
+ if (cloneM != null)
+ {
+ copy = cloneM.invoke(orig, new Object[0]);
+ }
+ }
+ catch (Exception e)
+ {
+ // not Clonable
+ }
+
+
+ if (copy instanceof ProjectComponent)
+ {
+ ((ProjectComponent) copy).setProject(aProject);
+ }
+ else
+ {
+ try
+ {
+ Method setProjectM =
+ c.getMethod("setProject", new Class[] {Project.class});
+ if (setProjectM != null)
+ {
+ setProjectM.invoke(copy, new Object[] {aProject});
+ }
+ }
+ catch (NoSuchMethodException e)
+ {
+ // ignore this if the class being referenced does not have
+ // a set project method.
+ }
+ catch (Exception e2)
+ {
+ String msg = "Error setting new project instance for "
+ + "reference with new id " + key;
+ throw new BuildException(msg, e2, null);
+ }
+ }
+ aProject.addReference(key, copy);
}
}
1.7 +1 -1
jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenInitTag.java
Index: MavenInitTag.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenInitTag.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- MavenInitTag.java 6 Jun 2002 06:54:37 -0000 1.6
+++ MavenInitTag.java 6 Jun 2002 18:09:26 -0000 1.7
@@ -122,7 +122,7 @@
BuildLogger logger = new NoBannerLogger();
- logger.setMessageOutputLevel( org.apache.tools.ant.Project.MSG_VERBOSE );
+ logger.setMessageOutputLevel( org.apache.tools.ant.Project.MSG_DEBUG );
logger.setOutputPrintStream( System.out );
logger.setErrorPrintStream( System.err);
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>