KickJava   Java API By Example, From Geeks To Geeks.

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


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: CopyTask.java 43062 2004-06-01 15:36:53Z michi $ */
19
20 package org.apache.lenya.cms.ant;
21
22 import java.io.File JavaDoc;
23 import java.io.FilenameFilter JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.Task;
28 import org.apache.tools.ant.types.Path;
29
30
31 public class CopyTask extends Task {
32     private Path pubsRootDirs;
33     private Path toDir;
34     private String JavaDoc excludes;
35
36     /** (non-Javadoc)
37      * @see org.apache.tools.ant.Task#execute()
38      */

39     public void execute() throws BuildException {
40         int numberOfDirectoriesCreated = 0;
41         int numberOfFilesCopied = 0;
42         TwoTuple twoTuple = new TwoTuple(numberOfDirectoriesCreated, numberOfFilesCopied);
43
44         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(pubsRootDirs.toString(), File.pathSeparator);
45
46         log("Excludes " + excludes);
47         FilenameFilter JavaDoc filter = new SCMFilenameFilter(excludes);
48
49         while (st.hasMoreTokens()) {
50             String JavaDoc pubsRootDir = st.nextToken();
51
52             if (new File JavaDoc(pubsRootDir, "publication.xml").isFile()) {
53                 CopyJavaSourcesTask.copyDir(new File JavaDoc(pubsRootDir), new File JavaDoc(toDir.toString()),
54                     twoTuple, filter);
55             } else {
56                 // FIXME: Look for publications defined by the file "publication.xml"
57
CopyJavaSourcesTask.copyContentOfDir(new File JavaDoc(pubsRootDir),
58                     new File JavaDoc(toDir.toString()), twoTuple, filter);
59             }
60         }
61
62         numberOfDirectoriesCreated = twoTuple.x;
63         numberOfFilesCopied = twoTuple.y;
64         log("Copying " + numberOfDirectoriesCreated + " directories to " + toDir);
65         log("Copying " + numberOfFilesCopied + " files to " + toDir);
66     }
67
68     /**
69      * Where the publications are located
70      *
71      * @param pubsRootDirs
72      */

73     public void setPubsRootDirs(Path pubsRootDirs) {
74         this.pubsRootDirs = pubsRootDirs;
75     }
76
77     /**
78      * Where the publications shall be copied to
79      *
80      * @param toDir
81      */

82     public void setToDir(Path toDir) {
83         this.toDir = toDir;
84     }
85
86     /**
87      * Which filenames shall be excluded
88      *
89      * @param excludes
90      */

91     public void setExcludes(String JavaDoc excludes) {
92         this.excludes = excludes;
93     }
94 }
95
Popular Tags