KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > ant > BulkCopyTask


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: BulkCopyTask.java 109784 2004-12-04 06:43:22Z antonio $ */
19
20 package org.apache.lenya.cms.ant;
21
22 import java.io.File JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.taskdefs.Copy;
28 import org.apache.tools.ant.types.FileSet;
29 import org.apache.tools.ant.types.Path;
30
31 /**
32  * Copies all files matching filename or a all specififed filesets from each source directory.
33  * <br/><br/>
34  * Usage:
35  * &lt;bulkCopy
36  * sourcedirs="dirOne:dirTwo"
37  * todir="WEB-INF/lib"
38  * flatten="true">
39  * &lt;fileset includes="java/lib/*"/&gt;
40  * &lt;/bulkCopy&gt;
41  * <br/><br/>
42  * The above sample copies <em>dirOne/java/lib/*</em> and <em>dirTwo/java/lib/*</em>
43  * to <em>WEB-INF/lib</em>.
44  */

45 public class BulkCopyTask extends Copy {
46     
47     private Path sourceDirs;
48     
49     /**
50      * @see org.apache.tools.ant.taskdefs.Copy#execute()
51      */

52     public void execute() throws BuildException {
53                 
54         final StringTokenizer JavaDoc sourceDirTokens = new StringTokenizer JavaDoc(sourceDirs.toString(), File.pathSeparator);
55             
56         while (sourceDirTokens.hasMoreTokens()) {
57             final String JavaDoc sourceDir = sourceDirTokens.nextToken();
58             
59             for(int i=0; i<getFileSets().size(); i++)
60                 ((FileSet) getFileSets().get(i)).setDir(new File JavaDoc(sourceDir));
61             
62             super.execute();
63         }
64     }
65
66     /**
67      * @param sourceDirs Colon seperated list of source directories
68      */

69     public void setSourceDirs(Path sourceDirs) {
70         this.sourceDirs = sourceDirs;
71     }
72     
73     /**
74      * @return Returns the fileSet.
75      */

76     private List JavaDoc getFileSets() {
77         return super.filesets;
78     }
79 }
80
Popular Tags