KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > Dirname


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant.taskdefs;
20
21 import java.io.File JavaDoc;
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.Task;
24
25 /**
26  * Determines the directory name of the specified file.
27  *
28  * This task can accept the following attributes:
29  * <ul>
30  * <li>file
31  * <li>property
32  * </ul>
33  * Both <b>file</b> and <b>property</b> are required.
34  * <p>
35  * When this task executes, it will set the specified property to the
36  * value of the specified file up to, but not including, the last path
37  * element. If file is a file, the directory will be the current
38  * directory.
39  *
40  *
41  * @since Ant 1.5
42  *
43  * @ant.task category="property"
44  */

45
46 public class Dirname extends Task {
47     private File JavaDoc file;
48     private String JavaDoc property;
49
50     /**
51      * Path to take the dirname of.
52      * @param file a <code>File</code> value
53      */

54     public void setFile(File JavaDoc file) {
55         this.file = file;
56     }
57
58     /**
59      * The name of the property to set.
60      * @param property the name of the property
61      */

62     public void setProperty(String JavaDoc property) {
63         this.property = property;
64     }
65
66
67     /**
68      * Execute this task.
69      * @throws BuildException on error
70      */

71     public void execute() throws BuildException {
72         if (property == null) {
73             throw new BuildException("property attribute required", getLocation());
74         }
75         if (file == null) {
76             throw new BuildException("file attribute required", getLocation());
77         } else {
78             String JavaDoc value = file.getParent();
79             getProject().setNewProperty(property, value);
80         }
81     }
82 }
83
84
Popular Tags