You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by um...@apache.org on 2001/12/05 02:15:57 UTC
cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs AvailableTest.java TarTest.java
umagesh 01/12/04 17:15:57
Modified: src/etc/testcases/taskdefs available.xml tar.xml
src/main/org/apache/tools/ant/taskdefs Available.java
Tar.java Tstamp.java
src/testcases/org/apache/tools/ant/taskdefs
AvailableTest.java TarTest.java
Log:
setFoo(String) replaced with setFoo(ExtendedEnumeratedAttribute) for certain attributes of these tasks:
Available.java
Tar.java
Tstamp.java
setFoo(String) has been deprecated for the affected attributes.
Revision Changes Path
1.8 +5 -0 jakarta-ant/src/etc/testcases/taskdefs/available.xml
Index: available.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/available.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- available.xml 2001/05/03 11:16:50 1.7
+++ available.xml 2001/12/05 01:15:57 1.8
@@ -98,4 +98,9 @@
file="../this_dir_should_never_exist" type="dir"/>
</target>
+ <target name="test19">
+ <available property="test"
+ file="available.xml" type="Foo"/>
+ </target>
+
</project>
1.6 +5 -1 jakarta-ant/src/etc/testcases/taskdefs/tar.xml
Index: tar.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/tar.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- tar.xml 2001/11/21 15:45:26 1.5
+++ tar.xml 2001/12/05 01:15:57 1.6
@@ -26,7 +26,11 @@
basedir="."
includes="test5dir"/>
</target>
-
+
+ <target name="test6">
+ <tar tarfile="blah" longfile="Foo"/>
+ </target>
+
<target name="cleanup">
<delete file="test4.tar"/>
<delete file="test5.tar"/>
1.29 +55 -22 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java
Index: Available.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- Available.java 2001/11/28 09:21:37 1.28
+++ Available.java 2001/12/05 01:15:57 1.29
@@ -61,6 +61,7 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.condition.Condition;
+import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.util.FileUtils;
@@ -69,6 +70,7 @@
* Will set the given property if the requested resource is available at runtime.
*
* @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a>
+ * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public class Available extends Task implements Condition {
@@ -78,7 +80,7 @@
private String file;
private Path filepath;
private String resource;
- private String type;
+ private FileDir type;
private Path classpath;
private AntClassLoader loader;
private String value = "true";
@@ -101,7 +103,7 @@
public void setFilepath(Path filepath) {
createFilepath().append(filepath);
}
-
+
public Path createFilepath() {
if (this.filepath == null) {
this.filepath = new Path(project);
@@ -131,7 +133,20 @@
this.resource = resource;
}
+ /**
+ * @deprecated setType(String) is deprecated and is replaced with
+ * setType(Available.FileDir) to make Ant's Introspection
+ * mechanism do the work and also to encapsulate operations on
+ * the type in its own class.
+ */
public void setType(String type) {
+ log("DEPRECATED - The setType(String) method has been deprecated."
+ + " Use setType(Available.FileDir) instead.");
+ this.type = new FileDir();
+ this.type.setValue(type);
+ }
+
+ public void setType(FileDir type) {
this.type = type;
}
@@ -144,7 +159,7 @@
this.project.setProperty(property, value);
}
}
-
+
public boolean eval() throws BuildException {
if (classname == null && file == null && resource == null) {
throw new BuildException("At least one of (classname|file|resource) is required", location);
@@ -154,9 +169,6 @@
if (file == null){
throw new BuildException("The type attribute is only valid when specifying the file attribute.");
}
- if (!type.equalsIgnoreCase("file") && !type.equalsIgnoreCase("dir")){
- throw new BuildException("Type must be one of either dir or file");
- }
}
if (classpath != null) {
@@ -168,7 +180,7 @@
log("Unable to load class " + classname + " to set property " + property, Project.MSG_VERBOSE);
return false;
}
-
+
if ((file != null) && !checkFile()) {
if (type != null) {
log("Unable to find " + type + " " + file + " to set property " + property, Project.MSG_VERBOSE);
@@ -177,7 +189,7 @@
}
return false;
}
-
+
if ((resource != null) && !checkResource(resource)) {
log("Unable to load resource " + resource + " to set property " + property, Project.MSG_VERBOSE);
return false;
@@ -197,7 +209,7 @@
String[] paths = filepath.list();
for(int i = 0; i < paths.length; ++i) {
log("Searching " + paths[i], Project.MSG_DEBUG);
- /*
+ /*
** filepath can be a list of directory and/or
** file names (gen'd via <fileset>)
**
@@ -218,11 +230,11 @@
if (type == null) {
log("Found: " + path, Project.MSG_VERBOSE);
return true;
- } else if (type.equalsIgnoreCase("dir")
+ } else if (type.isDir()
&& path.isDirectory()) {
log("Found directory: " + path, Project.MSG_VERBOSE);
return true;
- } else if (type.equalsIgnoreCase("file")
+ } else if (type.isFile()
&& path.isFile()) {
log("Found file: " + path, Project.MSG_VERBOSE);
return true;
@@ -230,16 +242,16 @@
// not the requested type
return false;
}
-
+
FileUtils fileUtils = FileUtils.newFileUtils();
File parent = fileUtils.getParentFile(path);
// ** full-pathname specified == parent dir of path in list
- if (parent != null && parent.exists()
+ if (parent != null && parent.exists()
&& file.equals(parent.getAbsolutePath())) {
if (type == null) {
log("Found: " + parent, Project.MSG_VERBOSE);
return true;
- } else if (type.equalsIgnoreCase("dir")) {
+ } else if (type.isDir()) {
log("Found directory: " + parent, Project.MSG_VERBOSE);
return true;
}
@@ -249,25 +261,25 @@
// ** simple name specified == path in list + name
if (path.exists() && path.isDirectory()) {
- if (checkFile(new File(path, file),
+ if (checkFile(new File(path, file),
file + " in " + path)) {
return true;
}
}
-
+
// ** simple name specified == parent dir + name
if (parent != null && parent.exists()) {
- if (checkFile(new File(parent, file),
+ if (checkFile(new File(parent, file),
file + " in " + parent)) {
return true;
}
}
-
+
// ** simple name specified == parent of parent dir + name
if (parent != null) {
File grandParent = fileUtils.getParentFile(parent);
if (grandParent != null && grandParent.exists()) {
- if (checkFile(new File(grandParent, file),
+ if (checkFile(new File(grandParent, file),
file + " in " + grandParent)) {
return true;
}
@@ -280,12 +292,12 @@
private boolean checkFile(File f, String text) {
if (type != null) {
- if (type.equalsIgnoreCase("dir")) {
+ if (type.isDir()) {
if( f.isDirectory()) {
log("Found directory: " + text, Project.MSG_VERBOSE);
}
return f.isDirectory();
- } else if (type.equalsIgnoreCase("file")) {
+ } else if (type.isFile()) {
if( f.isFile()) {
log("Found file: " + text, Project.MSG_VERBOSE);
}
@@ -306,7 +318,7 @@
if (cL != null) {
return (cL.getResourceAsStream(resource) != null);
} else {
- return
+ return
(ClassLoader.getSystemResourceAsStream(resource) != null);
}
}
@@ -331,6 +343,27 @@
return false;
} catch (NoClassDefFoundError e) {
return false;
+ }
+ }
+
+ public static class FileDir extends EnumeratedAttribute {
+
+ private final static String[] values = {"file", "dir"};
+
+ public String[] getValues() {
+ return values;
+ }
+
+ public boolean isDir() {
+ return "dir".equalsIgnoreCase(getValue());
+ }
+
+ public boolean isFile() {
+ return "file".equalsIgnoreCase(getValue());
+ }
+
+ public String toString() {
+ return getValue();
}
}
}
1.19 +144 -64 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java
Index: Tar.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Tar.java 2001/10/28 21:26:29 1.18
+++ Tar.java 2001/12/05 01:15:57 1.19
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -9,7 +9,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * 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
@@ -17,15 +17,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * 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", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * 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"
@@ -63,39 +63,58 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.util.SourceFileScanner;
import org.apache.tools.ant.util.MergingMapper;
import org.apache.tools.tar.TarOutputStream;
import org.apache.tools.tar.TarConstants;
import org.apache.tools.tar.TarEntry;
-import org.apache.tools.ant.types.FileSet;
/**
* Creates a TAR archive.
*
* @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
+ * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public class Tar extends MatchingTask {
- // permissable values for longfile attribute
+ /**
+ * @deprecated Tar.WARN is deprecated and is replaced with
+ * Tar.TarLongFileMode.WARN
+ */
public final static String WARN = "warn";
+ /**
+ * @deprecated Tar.FAIL is deprecated and is replaced with
+ * Tar.TarLongFileMode.FAIL
+ */
public final static String FAIL = "fail";
+ /**
+ * @deprecated Tar.TRUNCATE is deprecated and is replaced with
+ * Tar.TarLongFileMode.TRUNCATE
+ */
public final static String TRUNCATE = "truncate";
+ /**
+ * @deprecated Tar.GNU is deprecated and is replaced with
+ * Tar.TarLongFileMode.GNU
+ */
public final static String GNU = "gnu";
+ /**
+ * @deprecated Tar.OMIT is deprecated and is replaced with
+ * Tar.TarLongFileMode.OMIT
+ */
public final static String OMIT = "omit";
- private String[] validModes = new String[] {WARN, FAIL, TRUNCATE, GNU, OMIT};
-
File tarFile;
File baseDir;
-
- String longFileMode = WARN;
-
+
+ private TarLongFileMode longFileMode = new TarLongFileMode();
+
Vector filesets = new Vector();
Vector fileSetFiles = new Vector();
-
+
/**
* Indicates whether the user has been warned about long files already.
*/
@@ -106,55 +125,70 @@
filesets.addElement(fileset);
return fileset;
}
-
-
+
+
/**
* This is the name/location of where to create the tar file.
*/
public void setTarfile(File tarFile) {
this.tarFile = tarFile;
}
-
+
/**
* This is the base directory to look in for things to tar.
*/
public void setBasedir(File baseDir) {
this.baseDir = baseDir;
}
-
+
/**
* Set how to handle long files.
*
* Allowable values are
* truncate - paths are truncated to the maximum length
- * fail - patsh greater than the maximim cause a build exception
+ * fail - paths greater than the maximim cause a build exception
* warn - paths greater than the maximum cause a warning and GNU is used
* gnu - GNU extensions are used for any paths greater than the maximum.
* omit - paths greater than the maximum are omitted from the archive
+ * @deprecated setLongFile(String) is deprecated and is replaced with
+ * setLongFile(Tar.TarLongFileMode) to make Ant's Introspection
+ * mechanism do the work and also to encapsulate operations on
+ * the mode in its own class.
*/
public void setLongfile(String mode) {
- for (int i = 0; i < validModes.length; ++i) {
- if (mode.equalsIgnoreCase(validModes[i])) {
- this.longFileMode = mode;
- return;
- }
- }
- throw new BuildException("The longfile value " + mode + " is not a valid value");
+ log("DEPRECATED - The setLongfile(String) method has been deprecated."
+ + " Use setLongfile(Tar.TarLongFileMode) instead.");
+ this.longFileMode = new TarLongFileMode();
+ longFileMode.setValue(mode);
+ }
+
+ /**
+ * Set how to handle long files.
+ *
+ * Allowable values are
+ * truncate - paths are truncated to the maximum length
+ * fail - paths greater than the maximim cause a build exception
+ * warn - paths greater than the maximum cause a warning and GNU is used
+ * gnu - GNU extensions are used for any paths greater than the maximum.
+ * omit - paths greater than the maximum are omitted from the archive
+ */
+ public void setLongfile(TarLongFileMode mode) {
+ this.longFileMode = mode;
}
public void execute() throws BuildException {
if (tarFile == null) {
- throw new BuildException("tarfile attribute must be set!",
+ throw new BuildException("tarfile attribute must be set!",
location);
}
if (tarFile.exists() && tarFile.isDirectory()) {
- throw new BuildException("tarfile is a directory!",
+ throw new BuildException("tarfile is a directory!",
location);
}
if (tarFile.exists() && !tarFile.canWrite()) {
- throw new BuildException("Can not write to the specified tarfile!",
+ throw new BuildException("Can not write to the specified tarfile!",
location);
}
@@ -162,29 +196,29 @@
if (!baseDir.exists()) {
throw new BuildException("basedir does not exist!", location);
}
-
+
// add the main fileset to the list of filesets to process.
TarFileSet mainFileSet = new TarFileSet(fileset);
mainFileSet.setDir(baseDir);
filesets.addElement(mainFileSet);
}
-
+
if (filesets.size() == 0) {
- throw new BuildException("You must supply either a basdir attribute or some nested filesets.",
+ throw new BuildException("You must supply either a basdir attribute or some nested filesets.",
location);
}
-
+
// check if tr is out of date with respect to each
// fileset
boolean upToDate = true;
for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
TarFileSet fs = (TarFileSet)e.nextElement();
String[] files = fs.getFiles(project);
-
+
if (!archiveIsUpToDate(files)) {
upToDate = false;
}
-
+
for (int i = 0; i < files.length; ++i) {
if (tarFile.equals(new File(fs.getDir(project), files[i]))) {
throw new BuildException("A tar file cannot include itself", location);
@@ -204,18 +238,18 @@
try {
tOut = new TarOutputStream(new FileOutputStream(tarFile));
tOut.setDebug(true);
- if (longFileMode.equalsIgnoreCase(TRUNCATE)) {
+ if (longFileMode.isTruncateMode()) {
tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE);
}
- else if (longFileMode.equalsIgnoreCase(FAIL) ||
- longFileMode.equalsIgnoreCase(OMIT)) {
+ else if (longFileMode.isFailMode() ||
+ longFileMode.isOmitMode()) {
tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR);
}
else {
// warn or GNU
tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
}
-
+
longWarningGiven = false;
for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
TarFileSet fs = (TarFileSet)e.nextElement();
@@ -250,27 +284,27 @@
if (vPath.length() <= 0) {
return;
}
-
+
if (file.isDirectory() && !vPath.endsWith("/")) {
vPath += "/";
}
try {
if (vPath.length() >= TarConstants.NAMELEN) {
- if (longFileMode.equalsIgnoreCase(OMIT)) {
+ if (longFileMode.isOmitMode()) {
log("Omitting: "+ vPath, Project.MSG_INFO);
return;
- } else if (longFileMode.equalsIgnoreCase(WARN)) {
- log("Entry: "+ vPath + " longer than " +
+ } else if (longFileMode.isWarnMode()) {
+ log("Entry: "+ vPath + " longer than " +
TarConstants.NAMELEN + " characters.", Project.MSG_WARN);
- if (!longWarningGiven) {
+ if (!longWarningGiven) {
log("Resulting tar file can only be processed successfully"
+ " by GNU compatible tar commands", Project.MSG_WARN);
longWarningGiven = true;
}
- } else if (longFileMode.equalsIgnoreCase(FAIL)) {
+ } else if (longFileMode.isFailMode()) {
throw new BuildException(
- "Entry: "+ vPath + " longer than " +
+ "Entry: "+ vPath + " longer than " +
TarConstants.NAMELEN + "characters.", location);
}
}
@@ -280,12 +314,12 @@
if (!file.isDirectory()) {
te.setSize(file.length());
te.setMode(tarFileSet.getMode());
- }
+ }
te.setUserName(tarFileSet.getUserName());
te.setGroupName(tarFileSet.getGroup());
-
+
tOut.putNextEntry(te);
-
+
if (!file.isDirectory()) {
fIn = new FileInputStream(file);
@@ -296,8 +330,8 @@
count = fIn.read(buffer, 0, buffer.length);
} while (count != -1);
}
-
- tOut.closeEntry();
+
+ tOut.closeEntry();
} finally {
if (fIn != null)
fIn.close();
@@ -313,21 +347,21 @@
public static class TarFileSet extends FileSet {
private String[] files = null;
-
+
private int mode = 0100644;
-
+
private String userName = "";
private String groupName = "";
-
-
+
+
public TarFileSet(FileSet fileset) {
super(fileset);
}
-
+
public TarFileSet() {
super();
}
-
+
/**
* Get a list of files and directories specified in the fileset.
* @return a list of file and directory names, relative to
@@ -343,33 +377,79 @@
System.arraycopy(filesPerSe, 0, files, directories.length,
filesPerSe.length);
}
-
+
return files;
}
-
+
public void setMode(String octalString) {
this.mode = 0100000 | Integer.parseInt(octalString, 8);
}
-
+
public int getMode() {
return mode;
}
-
+
public void setUserName(String userName) {
this.userName = userName;
}
-
+
public String getUserName() {
return userName;
}
-
+
public void setGroup(String groupName) {
this.groupName = groupName;
}
-
+
public String getGroup() {
return groupName;
+ }
+
+ }
+
+ /**
+ * Valid Modes for LongFile attribute to Tar Task
+ *
+ * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
+ */
+ public static class TarLongFileMode extends EnumeratedAttribute {
+
+ // permissable values for longfile attribute
+ public final static String WARN = "warn";
+ public final static String FAIL = "fail";
+ public final static String TRUNCATE = "truncate";
+ public final static String GNU = "gnu";
+ public final static String OMIT = "omit";
+
+ private final String[] validModes = {WARN, FAIL, TRUNCATE, GNU, OMIT};
+
+ public TarLongFileMode() {
+ super();
+ setValue(WARN);
+ }
+
+ public String[] getValues() {
+ return validModes;
+ }
+
+ public boolean isTruncateMode() {
+ return TRUNCATE.equalsIgnoreCase(getValue());
+ }
+
+ public boolean isWarnMode() {
+ return WARN.equalsIgnoreCase(getValue());
+ }
+
+ public boolean isGnuMode() {
+ return GNU.equalsIgnoreCase(getValue());
+ }
+
+ public boolean isFailMode() {
+ return FAIL.equalsIgnoreCase(getValue());
+ }
+
+ public boolean isOmitMode() {
+ return OMIT.equalsIgnoreCase(getValue());
}
-
}
}
1.16 +80 -42 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
Index: Tstamp.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Tstamp.java 2001/11/30 17:35:06 1.15
+++ Tstamp.java 2001/12/05 01:15:57 1.16
@@ -58,15 +58,17 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Location;
+import org.apache.tools.ant.types.EnumeratedAttribute;
-import java.util.Vector;
+import java.util.Calendar;
import java.util.Date;
-import java.util.Locale;
import java.util.Enumeration;
-import java.util.Calendar;
-import java.util.StringTokenizer;
+import java.util.Hashtable;
+import java.util.Locale;
import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
import java.util.TimeZone;
+import java.util.Vector;
import java.text.SimpleDateFormat;
/**
@@ -76,12 +78,13 @@
* @author stefano@apache.org
* @author roxspring@yahoo.com
* @author conor@cognet.com.au
+ * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public class Tstamp extends Task {
private Vector customFormats = new Vector();
private String prefix = "";
-
+
public void setPrefix(String prefix) {
this.prefix = prefix;
if (!this.prefix.endsWith(".")) {
@@ -119,7 +122,7 @@
customFormats.addElement(cts);
return cts;
}
-
+
public class CustomFormat
{
private TimeZone timeZone;
@@ -131,22 +134,22 @@
private int offset = 0;
private int field = Calendar.DATE;
private String prefix="";
-
+
public CustomFormat(String prefix)
{
this.prefix = prefix;
}
-
+
public void setProperty(String propertyName)
{
this.propertyName = prefix + propertyName;
}
-
+
public void setPattern(String pattern)
{
this.pattern = pattern;
}
-
+
public void setLocale(String locale)
{
StringTokenizer st = new StringTokenizer( locale, " \t\n\r\f,");
@@ -177,47 +180,35 @@
public void setOffset(int offset) {
this.offset = offset;
}
-
+
+ /**
+ * @deprecated setUnit(String) is deprecated and is replaced with
+ * setUnit(Tstamp.Unit) to make Ant's Introspection
+ * mechanism do the work and also to encapsulate operations on
+ * the unit in its own class.
+ */
public void setUnit(String unit) {
- if (unit.equalsIgnoreCase("millisecond")) {
- field = Calendar.MILLISECOND;
- }
- else if (unit.equalsIgnoreCase("second")) {
- field = Calendar.SECOND;
- }
- else if (unit.equalsIgnoreCase("minute")) {
- field = Calendar.MINUTE;
- }
- else if (unit.equalsIgnoreCase("hour")) {
- field = Calendar.HOUR_OF_DAY;
- }
- else if (unit.equalsIgnoreCase("day")) {
- field = Calendar.DATE;
- }
- else if (unit.equalsIgnoreCase("week")) {
- field = Calendar.WEEK_OF_YEAR;
- }
- else if (unit.equalsIgnoreCase("month")) {
- field = Calendar.MONTH;
- }
- else if (unit.equalsIgnoreCase("year")) {
- field = Calendar.YEAR;
- }
- else {
- throw new BuildException(unit + " is not a unit supported by the tstamp task", getLocation());
- }
- }
-
+ log("DEPRECATED - The setUnit(String) method has been deprecated."
+ + " Use setUnit(Tstamp.Unit) instead.");
+ Unit u = new Unit();
+ u.setValue(unit);
+ field = u.getCalendarField();
+ }
+
+ public void setUnit(Unit unit) {
+ field = unit.getCalendarField();
+ }
+
public void execute(Project project, Date date, Location location)
{
if (propertyName == null) {
throw new BuildException("property attribute must be provided", location);
}
-
+
if (pattern == null) {
throw new BuildException("pattern attribute must be provided", location);
}
-
+
SimpleDateFormat sdf;
if (language == null) {
sdf = new SimpleDateFormat(pattern);
@@ -238,6 +229,53 @@
sdf.setTimeZone(timeZone);
}
project.setNewProperty(propertyName, sdf.format(date));
+ }
+ }
+
+ public static class Unit extends EnumeratedAttribute {
+
+ private static final String MILLISECOND = "millisecond";
+ private static final String SECOND = "second";
+ private static final String MINUTE = "minute";
+ private static final String HOUR = "hour";
+ private static final String DAY = "day";
+ private static final String WEEK = "week";
+ private static final String MONTH = "month";
+ private static final String YEAR = "year";
+
+ private final static String[] units = {
+ MILLISECOND,
+ SECOND,
+ MINUTE,
+ HOUR,
+ DAY,
+ WEEK,
+ MONTH,
+ YEAR
+ };
+
+ private Hashtable calendarFields = new Hashtable();
+
+ public Unit() {
+ calendarFields.put(MILLISECOND,
+ new Integer(Calendar.MILLISECOND));
+ calendarFields.put(SECOND, new Integer(Calendar.SECOND));
+ calendarFields.put(MINUTE, new Integer(Calendar.MINUTE));
+ calendarFields.put(HOUR, new Integer(Calendar.HOUR_OF_DAY));
+ calendarFields.put(DAY, new Integer(Calendar.DATE));
+ calendarFields.put(WEEK, new Integer(Calendar.WEEK_OF_YEAR));
+ calendarFields.put(MONTH, new Integer(Calendar.MONTH));
+ calendarFields.put(YEAR, new Integer(Calendar.YEAR));
+ }
+
+ public int getCalendarField() {
+ String key = getValue().toLowerCase();
+ Integer i = (Integer) calendarFields.get(key);
+ return i.intValue();
+ }
+
+ public String[] getValues() {
+ return units;
}
}
}
1.7 +36 -31 jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/AvailableTest.java
Index: AvailableTest.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/AvailableTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AvailableTest.java 2001/11/14 12:25:30 1.6
+++ AvailableTest.java 2001/12/05 01:15:57 1.7
@@ -56,96 +56,96 @@
import org.apache.tools.ant.BuildFileTest;
/**
- * @author Nico Seessle <ni...@seessle.de>
+ * @author Nico Seessle <ni...@seessle.de>
*/
-public class AvailableTest extends BuildFileTest {
+public class AvailableTest extends BuildFileTest {
- public AvailableTest(String name) {
+ public AvailableTest(String name) {
super(name);
- }
-
- public void setUp() {
+ }
+
+ public void setUp() {
configureProject("src/etc/testcases/taskdefs/available.xml");
}
-
+
// Nothing specified -> Fail
- public void test1() {
+ public void test1() {
expectBuildException("test1", "required argument not specified");
}
// Only property specified -> Fail
- public void test2() {
+ public void test2() {
expectBuildException("test2", "required argument not specified");
}
-
+
// Only file specified -> Fail
- public void test3() {
+ public void test3() {
expectBuildException("test3", "required argument not specified");
}
// file doesn't exist -> property 'test' == null
- public void test4() {
+ public void test4() {
executeTarget("test4");
assertTrue(project.getProperty("test") == null);
}
// file does exist -> property 'test' == 'true'
- public void test5() {
+ public void test5() {
executeTarget("test5");
assertEquals("true", project.getProperty("test"));
}
-
+
// resource doesn't exist -> property 'test' == null
- public void test6() {
+ public void test6() {
executeTarget("test6");
assertTrue(project.getProperty("test") == null);
}
// resource does exist -> property 'test' == 'true'
- public void test7() {
+ public void test7() {
executeTarget("test7");
assertEquals("true", project.getProperty("test"));
}
// class doesn't exist -> property 'test' == null
- public void test8() {
+ public void test8() {
executeTarget("test8");
assertTrue(project.getProperty("test") == null);
}
// class does exist -> property 'test' == 'true'
- public void test9() {
+ public void test9() {
executeTarget("test9");
assertEquals("true", project.getProperty("test"));
}
-
+
// All three specified and all three exist -> true
- public void test10() {
+ public void test10() {
executeTarget("test10");
assertEquals("true", project.getProperty("test"));
}
// All three specified but class missing -> null
- public void test11() {
+ public void test11() {
executeTarget("test11");
assertNull(project.getProperty("test"));
}
// Specified property-name is "" -> true
- public void test12() {
+ public void test12() {
executeTarget("test12");
assertNull(project.getProperty("test"));
assertEquals("true", project.getProperty(""));
}
// Specified file is "" -> invalid files do not exist
- public void test13() {
+ public void test13() {
executeTarget("test13");
assertNull(project.getProperty("test"));
}
// Specified file is "" actually a directory, so it should pass
- public void test13b() {
+ public void test13b() {
executeTarget("test13b");
assertEquals("true", project.getProperty("test"));
}
@@ -154,34 +154,39 @@
/*
* returns non null IBM JDK 1.3 Linux
*/
-// public void test14() {
+// public void test14() {
// executeTarget("test14");
// assertEquals(project.getProperty("test"), null);
// }
-
+
// Specified class is "" -> can not exist
- public void test15() {
+ public void test15() {
executeTarget("test15");
assertNull(project.getProperty("test"));
}
// Specified dir is "" -> this is the current directory and should
// always exist
- public void test16() {
+ public void test16() {
executeTarget("test16");
assertEquals("true", project.getProperty("test"));
}
- // Specified dir is "../taskdefs" -> should exist since it's the
+ // Specified dir is "../taskdefs" -> should exist since it's the
// location of the buildfile used...
- public void test17() {
+ public void test17() {
executeTarget("test17");
assertEquals("true", project.getProperty("test"));
}
// Specified dir is "../this_dir_should_never_exist" -> null
- public void test18() {
+ public void test18() {
executeTarget("test18");
assertNull(project.getProperty("test"));
+ }
+
+ // Invalid type specified
+ public void test19() {
+ expectBuildException("test19", "Invalid value for type attribute.");
}
}
1.6 +17 -13 jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java
Index: TarTest.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TarTest.java 2001/11/14 12:25:30 1.5
+++ TarTest.java 2001/12/05 01:15:57 1.6
@@ -56,42 +56,46 @@
import org.apache.tools.ant.BuildFileTest;
/**
- * @author Nico Seessle <ni...@seessle.de>
+ * @author Nico Seessle <ni...@seessle.de>
*/
-public class TarTest extends BuildFileTest {
-
- public TarTest(String name) {
+public class TarTest extends BuildFileTest {
+
+ public TarTest(String name) {
super(name);
- }
-
- public void setUp() {
+ }
+
+ public void setUp() {
configureProject("src/etc/testcases/taskdefs/tar.xml");
}
-
- public void test1() {
+
+ public void test1() {
expectBuildException("test1", "required argument not specified");
}
- public void test2() {
+ public void test2() {
expectBuildException("test2", "required argument not specified");
}
- public void test3() {
+ public void test3() {
expectBuildException("test3", "required argument not specified");
}
- public void test4() {
+ public void test4() {
expectBuildException("test4", "tar cannot include itself");
}
public void test5() {
executeTarget("test5");
- java.io.File f
+ java.io.File f
= new java.io.File("src/etc/testcases/taskdefs/test5.tar");
if (!f.exists()) {
fail("Tarring a directory failed");
}
+ }
+
+ public void test6() {
+ expectBuildException("test6", "Invalid value specified for longfile attribute.");
}
public void tearDown() {
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs AvailableTest.java TarTest.java
Posted by Stefan Bodewig <bo...@apache.org>.
On 5 Dec 2001, <um...@apache.org> wrote:
> setFoo(String) replaced with setFoo(ExtendedEnumeratedAttribute)
> for certain attributes of these tasks: Available.java Tar.java
> Tstamp.java
Thanks!
Stefan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>