costin 99/12/11 15:00:23
Modified: ant/src/main/org/apache/tools/ant/taskdefs
defaults.properties
Added: ant/src/main/org/apache/tools/ant/taskdefs Property.java
Taskdef.java Tstamp.java
Log:
Added Property, Taskdef - to replace the built-in tags.
Added tstamp.
Revision Changes Path
1.12 +3 -0 jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
Index: defaults.properties
===================================================================
RCS file: /home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- defaults.properties 1999/12/10 22:30:38 1.11
+++ defaults.properties 1999/12/11 23:00:22 1.12
@@ -16,3 +16,6 @@
gzip=org.apache.tools.ant.taskdefs.GZip
replace=org.apache.tools.ant.taskdefs.Replace
java=org.apache.tools.ant.taskdefs.Java
+tstamp=org.apache.tools.ant.taskdefs.Tstamp
+property=org.apache.tools.ant.taskdefs.Property
+taskdef=org.apache.tools.ant.taskdefs.Taskdef
1.1 jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Property.java
Index: Property.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.*;
import java.io.*;
import java.util.*;
/**
* Will set a Project property. Used to be a hack in ProjectHelper
*
* @author costin@dnt.ro
*/
public class Property extends Task {
String name;
String value;
String file;
String resource;
public void execute() throws BuildException {
try {
if(name!=null)
project.setProperty( name, value);
if( file!=null)
loadFile( file );
if( resource!=null)
loadResource( resource );
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void setName( String name) {
this.name=name;
}
public void setValue(String v) {
value=v;
}
public void setFile(String v) {
file=v;
}
public void setResource(String v) {
resource=v;
}
private void loadFile( String name ) {
Properties props = new Properties();
project.log("Loading " + name, project.MSG_VERBOSE);
try {
if( new File(name).exists() )
props.load(new FileInputStream( name ));
} catch(Exception ex) {
ex.printStackTrace();
}
addProperties( props );
}
private void loadResource( String name ) {
Properties props = new Properties();
project.log("Resource Loading " + name,
project.MSG_VERBOSE);
try {
InputStream is=this.getClass().getResourceAsStream(name);
if(is!=null)
props.load(is);
} catch (Exception ex) {
ex.printStackTrace();
}
addProperties( props );
}
private void addProperties( Properties props) {
Enumeration e=props.keys();
while( e.hasMoreElements() ) {
String name=(String)e.nextElement();
String value=(String)props.getProperty(name);
project.setProperty( name, value);
}
}
}
1.1 jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Taskdef.java
Index: Taskdef.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.*;
import java.io.*;
import java.util.*;
/**
* Define a new task - name and class
*
* @author costin@dnt.ro
*/
public class Taskdef extends Task {
String name;
String value;
public void execute() throws BuildException {
try {
if (name==null || value==null ) {
String msg = "name or class attributes of taskdef element "
+ "are undefined";
throw new BuildException(msg);
}
try {
Class taskClass = Class.forName(value);
project.addTaskDefinition(name, taskClass);
} catch (ClassNotFoundException cnfe) {
String msg = "taskdef class " + value +
" cannot be found";
throw new BuildException(msg);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void setName( String name) {
this.name=name;
}
public void setClass(String v) {
value=v;
}
}
1.1 jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
Index: Tstamp.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.*;
import java.io.*;
import java.util.*;
/**
* Will set TSTAMP and DSTAMP
*
* @author costin@dnt.ro
*/
public class Tstamp extends Task {
public void execute() throws BuildException {
try {
Calendar d=Calendar.getInstance();
StringBuffer tstamp=new StringBuffer();
tstamp.append( d.get(Calendar.YEAR));
if(d.get(Calendar.MONTH) < 9) tstamp.append("0");
tstamp.append( 1+d.get(Calendar.MONTH));
if( d.get(Calendar.DAY_OF_MONTH) < 10 ) tstamp.append("0");
tstamp.append(d.get(Calendar.DAY_OF_MONTH));
project.setProperty( "DSTAMP" , tstamp.toString());
if( d.get(Calendar.HOUR_OF_DAY) < 10 ) tstamp.append("0");
tstamp.append( d.get(Calendar.HOUR_OF_DAY));
if( d.get(Calendar.MINUTE) < 10 ) tstamp.append("0");
tstamp.append(d.get(Calendar.MINUTE));
project.setProperty( "TSTAMP" , tstamp.toString());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
|