diff options
author | mattinger <[email protected]> | 2006-08-16 03:09:30 +0000 |
---|---|---|
committer | mattinger <[email protected]> | 2006-08-16 03:09:30 +0000 |
commit | d8db18a2ac7aafc31ab08a26523e797c2b607cab (patch) | |
tree | aea8bfbcf884bb3eb85d7d1339b3a3b47e800c81 /src/java/net/sf | |
parent | 37e5a83c8db9c18975e85bbe13c4a340ff8ab7b9 (diff) |
Committing URLImportTask
git-svn-id: file:///home/sven/projects/JOGL/temp/ant-contrib/svn/ant-contrib-code/trunk/ant-contrib@18 32d7a393-a5a9-423c-abd3-5d954feb1f2f
Diffstat (limited to 'src/java/net/sf')
-rw-r--r-- | src/java/net/sf/antcontrib/antcontrib.properties | 1 | ||||
-rwxr-xr-x | src/java/net/sf/antcontrib/net/URLImportTask.java | 103 |
2 files changed, 104 insertions, 0 deletions
diff --git a/src/java/net/sf/antcontrib/antcontrib.properties b/src/java/net/sf/antcontrib/antcontrib.properties index b42b4ec..6544999 100644 --- a/src/java/net/sf/antcontrib/antcontrib.properties +++ b/src/java/net/sf/antcontrib/antcontrib.properties @@ -31,6 +31,7 @@ math=net.sf.antcontrib.math.MathTask # Net tasks
post=net.sf.antcontrib.net.PostTask
+importurl=net.sf.antcontrib.net.URLImportTask
# Peformance Tasks
stopwatch=net.sf.antcontrib.perf.StopWatchTask
diff --git a/src/java/net/sf/antcontrib/net/URLImportTask.java b/src/java/net/sf/antcontrib/net/URLImportTask.java new file mode 100755 index 0000000..4477820 --- /dev/null +++ b/src/java/net/sf/antcontrib/net/URLImportTask.java @@ -0,0 +1,103 @@ +/*
+ * Copyright (c) 2006 Ant-Contrib project. All rights reserved.
+ *
+ * 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 net.sf.antcontrib.net;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.Expand;
+import org.apache.tools.ant.taskdefs.Get;
+import org.apache.tools.ant.taskdefs.ImportTask;
+
+/***
+ * Task to import a build file from a url. The build file can be a build.xml,
+ * or a .zip/.jar, in which case we download and extract the entire archive, and
+ * import the file "build.xml"
+ * @author inger
+ *
+ */
+public class URLImportTask
+ extends Task {
+
+ private URL url;
+
+
+ public void setUrl(URL url) {
+ this.url = url;
+ }
+
+
+ public void execute()
+ throws BuildException {
+
+ if (url == null) {
+ throw new BuildException("Missing url.");
+ }
+
+ try {
+ File tempDir = File.createTempFile("urlimport", "");
+ log("Creating directory: " + tempDir.getAbsolutePath(), Project.MSG_INFO);
+ tempDir.delete();
+ tempDir.mkdirs();
+
+ log("Downloading file: " + url.toExternalForm(), Project.MSG_INFO);
+
+ File destFile = new File(tempDir, new File(url.getPath()).getName());
+ Get get = (Get) getProject().createTask("get");
+ get.setSrc(url);
+ get.setDest(destFile);
+ get.perform();
+
+ log("File: " + url.toExternalForm() + " downloaded to " + destFile.getAbsolutePath(),
+ Project.MSG_INFO);
+
+ File extractedBuildFile = null;
+ if (destFile.getName().endsWith(".jar") ||
+ destFile.getName().endsWith(".zip")) {
+ log("Extracting compressed file: " + destFile.getAbsolutePath(), Project.MSG_INFO);
+ Expand expand = (Expand) getProject().createTask("unjar");
+ expand.setSrc(destFile);
+ expand.setDest(tempDir);
+ expand.perform();
+ log("Compressed file extracted", Project.MSG_INFO);
+ extractedBuildFile = new File(tempDir, "build.xml");
+ if (! extractedBuildFile.exists()) {
+ log("No 'build.xml' exists in the extracted file.", Project.MSG_ERR);
+ throw new BuildException("Downloaded file does not contain a 'build.xml' file");
+ }
+ }
+ else {
+ extractedBuildFile = destFile;
+ }
+
+ log("Importing file: " + extractedBuildFile.getAbsolutePath(), Project.MSG_INFO);
+ ImportTask importTask = new ImportTask();
+ importTask.setProject(getProject());
+ importTask.setOwningTarget(getOwningTarget());
+ importTask.setLocation(getLocation());
+ importTask.setFile(extractedBuildFile.getAbsolutePath());
+ importTask.perform();
+ log("Import complete.", Project.MSG_INFO);
+ }
+ catch (IOException e) {
+ throw new BuildException(e);
+ }
+ }
+}
|