Added an ant task to convert a variable containing a local path to a file URL.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 27 May 2005 22:23:24 +0000 (22:23 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 27 May 2005 22:23:24 +0000 (22:23 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1584 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/utils/ant/URLConvert.java [new file with mode: 0644]

diff --git a/src/edu/internet2/middleware/shibboleth/utils/ant/URLConvert.java b/src/edu/internet2/middleware/shibboleth/utils/ant/URLConvert.java
new file mode 100644 (file)
index 0000000..c8fb947
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package edu.internet2.middleware.shibboleth.utils.ant;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+/**
+ * @author Walter Hoehn
+ */
+public class URLConvert extends Task {
+
+       private String addProperty;
+       private String path;
+
+       public void execute() throws BuildException {
+
+               if (addProperty != null && getProject().getProperty(addProperty) != null) {
+                       log("Skipping " + getTaskName() + " as property " + addProperty + " has already been set.");
+                       return;
+               }
+
+               if (path == null) {
+                       log("Skipping " + getTaskName() + " because path was not specified.");
+                       return;
+               }
+
+               File file = new File(path);
+               try {
+                       URL url = file.getAbsoluteFile().toURI().toURL();
+
+                       if (addProperty != null && url != null) {
+                               getProject().setNewProperty(addProperty, url.toString());
+                       }
+               } catch (MalformedURLException e) {
+                       log("Skipping " + getTaskName() + " because path (" + path + ") could not be converted to a URL.");
+                       return;
+               }
+
+       }
+
+       public void setAddProperty(String addproperty) {
+
+               this.addProperty = addproperty;
+       }
+
+       public void setPath(String path) {
+
+               this.path = path;
+       }
+
+}