source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 4.3 KB
Line 
1/*
2 * Copyright 2000,2002,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 * Task to rename files based on extension. This task has the following
19 * properties which can be set:
20 * <ul>
21 * <li>fromExtension: </li>
22 * <li>toExtension: </li>
23 * <li>srcDir: </li>
24 * <li>replace: </li>
25 * </ul>
26 */
27
28package org.apache.tools.ant.taskdefs.optional;
29
30import java.io.File;
31import org.apache.tools.ant.BuildException;
32import org.apache.tools.ant.Project;
33import org.apache.tools.ant.taskdefs.MatchingTask;
34import org.apache.tools.ant.taskdefs.Move;
35import org.apache.tools.ant.types.Mapper;
36
37/**
38 *
39 * @version 1.2
40 *
41 * @deprecated Use &lt;move&gt; instead
42 */
43public class RenameExtensions extends MatchingTask {
44
45 private String fromExtension = "";
46 private String toExtension = "";
47 private boolean replace = false;
48 private File srcDir;
49
50 private Mapper.MapperType globType;
51
52
53 /** Creates new RenameExtensions */
54 public RenameExtensions() {
55 super();
56 globType = new Mapper.MapperType();
57 globType.setValue("glob");
58 }
59
60 /**
61 * The string that files must end in to be renamed
62 *
63 * @param from the extension of files being renamed.
64 */
65 public void setFromExtension(String from) {
66 fromExtension = from;
67 }
68
69 /**
70 * The string that renamed files will end with on
71 * completion
72 *
73 * @param to the extension of the renamed files.
74 */
75 public void setToExtension(String to) {
76 toExtension = to;
77 }
78
79 /**
80 * store replace attribute - this determines whether the target file
81 * should be overwritten if present
82 *
83 * @param replace if true overwrite any target files that exist.
84 */
85 public void setReplace(boolean replace) {
86 this.replace = replace;
87 }
88
89 /**
90 * Set the source dir to find the files to be renamed.
91 *
92 * @param srcDir the source directory.
93 */
94 public void setSrcDir(File srcDir) {
95 this.srcDir = srcDir;
96 }
97
98 /**
99 * Executes the task.
100 *
101 * @throws BuildException is there is a problem in the task execution.
102 */
103 public void execute() throws BuildException {
104
105 // first off, make sure that we've got a from and to extension
106 if (fromExtension == null || toExtension == null || srcDir == null) {
107 throw new BuildException("srcDir, fromExtension and toExtension "
108 + "attributes must be set!");
109 }
110
111 log("DEPRECATED - The renameext task is deprecated. Use move instead.",
112 Project.MSG_WARN);
113 log("Replace this with:", Project.MSG_INFO);
114 log("<move todir=\"" + srcDir + "\" overwrite=\"" + replace + "\">",
115 Project.MSG_INFO);
116 log(" <fileset dir=\"" + srcDir + "\" />", Project.MSG_INFO);
117 log(" <mapper type=\"glob\"", Project.MSG_INFO);
118 log(" from=\"*" + fromExtension + "\"", Project.MSG_INFO);
119 log(" to=\"*" + toExtension + "\" />", Project.MSG_INFO);
120 log("</move>", Project.MSG_INFO);
121 log("using the same patterns on <fileset> as you\'ve used here",
122 Project.MSG_INFO);
123
124 Move move = (Move) getProject().createTask("move");
125 move.setOwningTarget(getOwningTarget());
126 move.setTaskName(getTaskName());
127 move.setLocation(getLocation());
128 move.setTodir(srcDir);
129 move.setOverwrite(replace);
130
131 fileset.setDir(srcDir);
132 move.addFileset(fileset);
133
134 Mapper me = move.createMapper();
135 me.setType(globType);
136 me.setFrom("*" + fromExtension);
137 me.setTo("*" + toExtension);
138
139 move.execute();
140 }
141
142}
Note: See TracBrowser for help on using the repository browser.