From 4e347a681e78a2c860e581608b0c6b0018ba3d2f Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 19 Mar 2003 10:48:01 +0000 Subject: [PATCH] Make 's basedir optional. PR: 18046 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274288 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ docs/manual/OptionalTasks/cab.html | 24 +++++++++++-- .../tools/ant/taskdefs/optional/Cab.java | 35 +++++++++++-------- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 184a5de74..8fe91d57e 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -169,6 +169,9 @@ Other changes: * Support for HP's NonStop (Tandem) OS has been added. +* 's basedir attribute is now optional if you specify nested + filesets. Bugzilla Report 18046. + Changes from Ant 1.5.2 to Ant 1.5.3 =================================== diff --git a/docs/manual/OptionalTasks/cab.html b/docs/manual/OptionalTasks/cab.html index 583e6d85a..307949732 100644 --- a/docs/manual/OptionalTasks/cab.html +++ b/docs/manual/OptionalTasks/cab.html @@ -39,7 +39,7 @@ supports all attributes of <fileset> basedir the directory to start archiving files from. - Yes + No verbose @@ -91,6 +91,13 @@ supports all attributes of <fileset> No +

Parameters specified as nested elements

+

fileset

+ +

The cab task supports any number of nested <fileset> +elements to specify the files to be included in the archive.

+

Examples

 <cab cabfile="${dist}/manual.cab"
@@ -121,8 +128,21 @@ manual.cab in the ${dist} directory. Only html files under the
 directory api are archived, and files with the name todo.html are
 excluded. Output from the cabarc tool is displayed in the build
 output.

+ +
+<cab cabfile="${dist}/manual.cab"
+     verbose="yes">
+  <fileset
+       dir="htdocs/manual"
+       includes="api/**/*.html"
+       excludes="**/todo.html"
+  />
+</cab>
+
+

is equivalent to the example above.

+
-

Copyright © 2000-2002 Apache Software Foundation. All rights +

Copyright © 2000-2003 Apache Software Foundation. All rights Reserved.

diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java index 235f41bc9..dd564a408 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -143,14 +143,17 @@ public class Cab extends MatchingTask { * for side-effects to me... */ protected void checkConfiguration() throws BuildException { - if (baseDir == null) { - throw new BuildException("basedir attribute must be set!", getLocation()); + if (baseDir == null && filesets.size() == 0) { + throw new BuildException("basedir attribute or at least one " + + "nested filest is required!", + getLocation()); } - if (!baseDir.exists()) { + if (baseDir != null && !baseDir.exists()) { throw new BuildException("basedir does not exist!", getLocation()); } if (cabFile == null) { - throw new BuildException("cabfile attribute must be set!" , getLocation()); + throw new BuildException("cabfile attribute must be set!", + getLocation()); } } @@ -175,7 +178,7 @@ public class Cab extends MatchingTask { boolean upToDate = true; for (int i = 0; i < files.size() && upToDate; i++) { String file = files.elementAt(i).toString(); - if (new File(baseDir, file).lastModified() > + if (fileUtils.resolveFile(baseDir, file).lastModified() > cabFile.lastModified()) { upToDate = false; } @@ -220,16 +223,16 @@ public class Cab extends MatchingTask { protected Vector getFileList() throws BuildException { Vector files = new Vector(); - if (filesets.size() == 0) { + if (baseDir != null) { // get files from old methods - includes and nested include appendFiles(files, super.getDirectoryScanner(baseDir)); - } else { - // get files from filesets - for (int i = 0; i < filesets.size(); i++) { - FileSet fs = (FileSet) filesets.elementAt(i); - if (fs != null) { - appendFiles(files, fs.getDirectoryScanner(getProject())); - } + } + + // get files from filesets + for (int i = 0; i < filesets.size(); i++) { + FileSet fs = (FileSet) filesets.elementAt(i); + if (fs != null) { + appendFiles(files, fs.getDirectoryScanner(getProject())); } } @@ -264,7 +267,9 @@ public class Cab extends MatchingTask { try { Process p = Execute.launch(getProject(), new String[] {"listcab"}, null, - baseDir, true); + baseDir != null ? baseDir + : getProject().getBaseDir(), + true); OutputStream out = p.getOutputStream(); // Create the stream pumpers to forward listcab's stdout and stderr to the log