You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Kuiper, Arnout" <Ar...@nl.origin-it.com> on 2000/01/10 21:19:27 UTC

RE: [Ant] Status of the "init" target & properties? [PATCH]

Hi,

I patched the code for the <project ... init="..."> stuff. (Thus also +1 for
me;-)

The patch does the following:
-Removal of the hack to allow tasks outside a target.
-Execute the target specified in the projects init attribute, in all cases
and always first. This will only be done when the target exists. When no
init attribute is specified, nothing is executed.

Implications for existing code: No tasks outside targets are allowed
anymore. This can better be done now, than later in the future, when more
projects depend on it. If we keep the backward compatibility in, we will
never get rid of it.

So to fix old buildfiles:

-Add the init="init" attribute to the project tag.
-When tasks exist outside a target, put them in a init-target.

The patch includes 3 files:
Project.java (Added initTarget attribute)
ProjectHelper.java (Changed "init" into Project.initTarget + removed old
hack)
build.xml (Updated the buildfile for Ant to reflect changes in <project
...>)

Regards,

  Arnout


Index: Project.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tools/ant/src/main/org/apache/tools/ant/Project.java
,v
retrieving revision 1.22
diff -r1.22 Project.java
105a106,107
>     private String initTarget;
> 
212a215,232
>     }
> 
>     /**
>      * Sets the name of the init-target of this project.
>      *
>      * @param initTarget the name of the init-target
>      */
>     public void setInitTarget(String initTarget) {
> 	this.initTarget = initTarget;
>     }
> 
>     /**
>      * Gets the name of the init-target of this project.
>      *
>      * @return the name of the init-target
>      */
>     public String getInitTarget() {
> 	return initTarget;
Index: ProjectHelper.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tools/ant/src/main/org/apache/tools/ant/ProjectHelpe
r.java,v
retrieving revision 1.10
diff -r1.10 ProjectHelper.java
106a107
> 	project.setInitTarget(root.getAttribute("init"));
138,139c139,142
< 	// Hack - all tasks outside init target will be added to init
< 	// ( will be removed when / if build.xml will start using init )
---
> 	String initName = project.getInitTarget();
> 	if (initName.equals("")) {
> 	    return;
> 	}
142,144c145,146
< 	initTarget.setName( "init" );
< 	project.addTarget( "init", initTarget );
< 	configureTasks( project, initTarget, root );
---
> 	initTarget.setName( initName );
> 	project.addTarget( initName, initTarget );
151c153
< 	    if( targetName.equals("init") ) 
---
> 	    if( targetName.equals(initName) ) 
174c176
< 	    if( targetName.equals("init") ) 
---
> 	    if( targetName.equals(project.getInitTarget()) ) 
213,218c215,216
< 		// special case - no target in a target.
< 		// hack to allow this method to set "init" target
< 		// using root element
< 		if( ! taskType.equals( "target" ) ) {
< 		    // XXX
< 		    // put in some sanity checking
---
> 		// XXX
> 		// put in some sanity checking
220c218
< 		    Task task = project.createTask(taskType);
---
> 		Task task = project.createTask(taskType);
222,223c220,221
< 		    // get the attributes of this element and reflect them
< 		    // into the task
---
> 		// get the attributes of this element and reflect them
> 		// into the task
225,228c223,225
< 		    NamedNodeMap nodeMap = element.getAttributes();
< 		    configureTask(project, task, nodeMap);
< 		    target.addTask(task);
< 		}
---
> 		NamedNodeMap nodeMap = element.getAttributes();
> 		configureTask(project, task, nodeMap);
> 		target.addTask(task);
Index: build.xml
===================================================================
RCS file: /home/cvspublic/jakarta-tools/ant/build.xml,v
retrieving revision 1.12
diff -r1.12 build.xml
3c3,7
< <project name="Ant" default="main" basedir=".">
---
> <project name="Ant" default="main" basedir="." init="init">
>   <target name="init">
>     <property name="src.dir" value="src/main"/>
>     <property name="build.dir" value="build"/>
>     <property name="dist.dir" value="${user.home}/opt"/>
5,10c9,10
<   <property name="src.dir" value="src/main"/>
<   <property name="build.dir" value="build"/>
<   <property name="dist.dir" value="${user.home}/opt"/>
< 
<   <property name="classpath" value="lib/projectx-tr2.jar"/>
<   <property name="manifest" value="src/etc/manifest"/>
---
>     <property name="classpath" value="lib/projectx-tr2.jar"/>
>     <property name="manifest" value="src/etc/manifest"/>
12c12,13
<   <property name="build.compiler" value="classic"/>
---
>     <property name="build.compiler" value="classic"/>
>   </target>

> -----Original Message-----
> From: rubys@us.ibm.com [mailto:rubys@us.ibm.com]
> Sent: maandag 10 januari 2000 18:37
> To: tomcat-dev@jakarta.apache.org
> Subject: Re: [Ant] Status of the "init" target & properties?
> 
> 
> 
> 
> >> Anyway, I proposed a small change that should make everyone happy
> >>
> >> <project ... init="...">
> >>
> >> and, if found, the "init" attribute will indicate what 
> target should be
> >> used to initialize. This allows me to be happy since we 
> are not having
> >> anything hidden and you to be happy since you get the init target
> >> functionality.
> >
> >+0 - but I don't have the time to do this right now.
> >Anything is fine as long as the build works, and probably we can keep
> >it as it is till we solve the properties.
> 
> It looks like the impact would be pretty minimal, at least on 
> the jakarta-*
> projects.  Most targets seem to have a depends="init,..." 
> attribute on them
> anyway.  I'll take a look into the change and then rebuild 
> everything from
> scratch, and if all goes well, check it in.
> 
> - Sam Ruby
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
>