1 /*
2 * (C) Copyright 2006-2014 Nuxeo SA (http://nuxeo.com/) and contributors.
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the GNU Lesser General Public License
6 * (LGPL) version 2.1 which accompanies this distribution, and is available at
7 * http://www.gnu.org/licenses/lgpl-2.1.html
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * Contributors:
15 * bstefanescu
16 */
17 package org.nuxeo.build.ant;
18
19 import java.io.File;
20
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Task;
23
24 /**
25 * TODO NXBT-258
26 */
27 public class RenameTask extends Task {
28
29 protected File from;
30
31 protected File to;
32
33 public void setFrom(File from) {
34 this.from = from;
35 }
36
37 public void setTo(File to) {
38 this.to = to;
39 }
40
41 @Override
42 public void execute() throws BuildException {
43 String fromName = from.getName();
44 if (fromName.endsWith("*")) {
45 String prefix = fromName.substring(0, fromName.length() - 1);
46 File dir = from.getParentFile();
47 File[] files = dir.listFiles();
48 for (int k = 0; k < files.length; k++) {
49 File f = files[k];
50 if (f.getName().startsWith(prefix)) {
51 f.renameTo(to);
52 return;
53 }
54 }
55 } else {
56 from.renameTo(to);
57 }
58 }
59
60 }