001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import java.io.File;
022: import java.io.IOException;
023: import org.apache.tools.ant.BuildException;
024: import org.apache.tools.ant.Project;
025: import org.apache.tools.ant.Task;
026:
027: /**
028: * Copies a file.
029: *
030: * @since Ant 1.1
031: *
032: * @deprecated The copyfile task is deprecated since Ant 1.2. Use
033: * copy instead.
034: */
035:
036: public class Copyfile extends Task {
037:
038: private File srcFile;
039: private File destFile;
040: private boolean filtering = false;
041: private boolean forceOverwrite = false;
042:
043: /**
044: * Set the source file.
045: * @param src the source file.
046: */
047: public void setSrc(File src) {
048: srcFile = src;
049: }
050:
051: /**
052: * The forceoverwrite attribute.
053: * Default is false.
054: * @param force if true overwrite even if the destination file
055: * is newer that the source file
056: */
057: public void setForceoverwrite(boolean force) {
058: forceOverwrite = force;
059: }
060:
061: /**
062: * Set the destination file.
063: * @param dest the destination file.
064: */
065: public void setDest(File dest) {
066: destFile = dest;
067: }
068:
069: /**
070: * The filtering attribute.
071: * Default is false.
072: * @param filter if true use filtering
073: */
074: public void setFiltering(String filter) {
075: filtering = Project.toBoolean(filter);
076: }
077:
078: /**
079: * Execute the task.
080: * @throws BuildException on error
081: */
082: public void execute() throws BuildException {
083: log("DEPRECATED - The copyfile task is deprecated. Use copy instead.");
084:
085: if (srcFile == null) {
086: throw new BuildException(
087: "The src attribute must be present.", getLocation());
088: }
089:
090: if (!srcFile.exists()) {
091: throw new BuildException("src " + srcFile.toString()
092: + " does not exist.", getLocation());
093: }
094:
095: if (destFile == null) {
096: throw new BuildException(
097: "The dest attribute must be present.",
098: getLocation());
099: }
100:
101: if (srcFile.equals(destFile)) {
102: log("Warning: src == dest", Project.MSG_WARN);
103: }
104:
105: if (forceOverwrite
106: || srcFile.lastModified() > destFile.lastModified()) {
107: try {
108: getProject().copyFile(srcFile, destFile, filtering,
109: forceOverwrite);
110: } catch (IOException ioe) {
111: String msg = "Error copying file: "
112: + srcFile.getAbsolutePath() + " due to "
113: + ioe.getMessage();
114: throw new BuildException(msg);
115: }
116: }
117: }
118: }
|