1 /*
2 * Copyright 2008 University Corporation for Advanced Internet Development, Inc.
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 package edu.internet2.middleware.ant.util;
18
19 import java.io.File;
20
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Task;
23
24 /**
25 * Converts a filesystem path into an absolute path.
26 *
27 * This ant task requires two attributes:
28 * <ul>
29 * <li><strong>path</strong> - the path that will be converted in to an absolute path</li>
30 * <li><strong>addProperty</strong> - name of the property that will receive the file contents as a string</li>
31 * <ul>
32 */
33 public class PathToAbsolutePath extends Task {
34
35 /** Property name to which the file URL is added. */
36 private String addProperty;
37
38 /** Path to convert into an absolute path. */
39 private String path;
40
41 /** {@inheritDoc} */
42 public void execute() throws BuildException {
43
44 if (addProperty != null && getProject().getProperty(addProperty) != null) {
45 log("Skipping " + getTaskName() + " as property " + addProperty + " has already been set.");
46 return;
47 }
48
49 if (path == null) {
50 log("Skipping " + getTaskName() + " because path was not specified.");
51 return;
52 }
53
54 getProject().setNewProperty(addProperty, new File(path).getAbsolutePath());
55 }
56
57 /**
58 * Sets the name of the property that will contain the URL to the file.
59 *
60 * @param property name of the property that will contain the URL to the file
61 */
62 public void setAddProperty(String property) {
63 addProperty = property;
64 }
65
66 /**
67 * Sets the path that will be converted into a file URL.
68 *
69 * @param path path that will be converted into a file URL
70 */
71 public void setPath(String path) {
72 this.path = path;
73 }
74 }