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 | package org.apache.tools.ant.taskdefs;
|
---|
19 |
|
---|
20 | import java.io.File;
|
---|
21 | import java.io.IOException;
|
---|
22 | import org.apache.tools.ant.BuildException;
|
---|
23 | import org.apache.tools.ant.Project;
|
---|
24 | import org.apache.tools.ant.Task;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Copies a file.
|
---|
28 | *
|
---|
29 | *
|
---|
30 | * @since Ant 1.1
|
---|
31 | *
|
---|
32 | * @deprecated The copyfile task is deprecated since Ant 1.2. Use
|
---|
33 | * copy instead.
|
---|
34 | */
|
---|
35 |
|
---|
36 | public class Copyfile extends Task {
|
---|
37 |
|
---|
38 | private File srcFile;
|
---|
39 | private File destFile;
|
---|
40 | private boolean filtering = false;
|
---|
41 | private boolean forceOverwrite = false;
|
---|
42 |
|
---|
43 | public void setSrc(File src) {
|
---|
44 | srcFile = src;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public void setForceoverwrite(boolean force) {
|
---|
48 | forceOverwrite = force;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public void setDest(File dest) {
|
---|
52 | destFile = dest;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public void setFiltering(String filter) {
|
---|
56 | filtering = Project.toBoolean(filter);
|
---|
57 | }
|
---|
58 |
|
---|
59 | public void execute() throws BuildException {
|
---|
60 | log("DEPRECATED - The copyfile task is deprecated. Use copy instead.");
|
---|
61 |
|
---|
62 | if (srcFile == null) {
|
---|
63 | throw new BuildException("The src attribute must be present.",
|
---|
64 | getLocation());
|
---|
65 | }
|
---|
66 |
|
---|
67 | if (!srcFile.exists()) {
|
---|
68 | throw new BuildException("src " + srcFile.toString()
|
---|
69 | + " does not exist.", getLocation());
|
---|
70 | }
|
---|
71 |
|
---|
72 | if (destFile == null) {
|
---|
73 | throw new BuildException("The dest attribute must be present.",
|
---|
74 | getLocation());
|
---|
75 | }
|
---|
76 |
|
---|
77 | if (srcFile.equals(destFile)) {
|
---|
78 | log("Warning: src == dest", Project.MSG_WARN);
|
---|
79 | }
|
---|
80 |
|
---|
81 | if (forceOverwrite
|
---|
82 | || srcFile.lastModified() > destFile.lastModified()) {
|
---|
83 | try {
|
---|
84 | getProject().copyFile(srcFile, destFile, filtering, forceOverwrite);
|
---|
85 | } catch (IOException ioe) {
|
---|
86 | String msg = "Error copying file: " + srcFile.getAbsolutePath()
|
---|
87 | + " due to " + ioe.getMessage();
|
---|
88 | throw new BuildException(msg);
|
---|
89 | }
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|