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 | |
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
-rwxr-xr-x | docs/manual/tasks/importurl.html | 84 | ||||
-rw-r--r-- | docs/manual/tasks/toc.html | 3 | ||||
-rw-r--r-- | src/java/net/sf/antcontrib/antcontrib.properties | 1 | ||||
-rwxr-xr-x | src/java/net/sf/antcontrib/net/URLImportTask.java | 103 |
4 files changed, 190 insertions, 1 deletions
diff --git a/docs/manual/tasks/importurl.html b/docs/manual/tasks/importurl.html new file mode 100755 index 0000000..76d40b3 --- /dev/null +++ b/docs/manual/tasks/importurl.html @@ -0,0 +1,84 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> + <head> + <title>Ant-contrib Tasks: Importurl</title> + </head> + + <body> + <h1>Importurl</h1> + + <p>The Importurl task will download a file, and import it's contents into the
+ current project. The file can be in the form of a standard ant .xml project
+ file, or a .jar/.zip file. In the case of a .jar/.zip file, the file is downloaded
+ and then decompressed. After decompression, the file 'build.xml' at the root
+ level of the jar is imported.</p>
+ <p>
+ By importing a .jar/.zip file, one can package additional resources along with
+ the build.xml file. However, you must be careful how you refer to these resources.
+ The build.xml file must follow the same rules as any other file imported with the
+ <import> task, in that references relative to the build.xml file must be
+ made with the property:
+ ant.file.<projectname>
+ where <projectname> is the name of the project being imported, as specified
+ in the project tag.
+ </p> +
+ <p>
+ This task should be compatible with older versions of ant, but has only been
+ tested with Ant 1.6.x
+ </p> + <h2>Parameters</h2> + <table border="1" cellpadding="2" cellspacing="0"> + <tr> + <th>Attribute</th> + <th>Description</th> + <th>Required</th> + </tr> + <tr> + <td valign="top">url</td> + <td valign="top">The URL of the file to import. This can be any URL which
+ is recognized by the <get> task.</td> + <td align="center" valign="top">Yes</td> + </tr> + </table> + + + <h2>Example</h2> + + + <pre>
+ <code>
+ <antcontrib:importurl url="file:/path/to/build.xml" /> + </code>
+ </pre>
+ + <pre>
+ <code>
+ <antcontrib:importurl url="http://host/path/to/build.xml" />
+ </code>
+ </pre>
+ + <pre>
+ <code>
+ <antcontrib:importurl url="http://host/path/to/common.jar" />
+ </code>
+ </pre>
+
+ The following build.xml may be packaged into a .jar with it's corresponding
+ build.properties file:
+
+ <pre>
+ <code>
+ <project name="common">
+ <property file="${ant.file.common}/build.properties" />
+ </project>
+ </code>
+ </pre>
+
+ + <hr> + <p align="center">Copyright © 2002-2006 Ant-Contrib Project. All + rights Reserved.</p> + + </body> +</html> diff --git a/docs/manual/tasks/toc.html b/docs/manual/tasks/toc.html index df60d23..ef59b1b 100644 --- a/docs/manual/tasks/toc.html +++ b/docs/manual/tasks/toc.html @@ -24,7 +24,8 @@ <h2>Network Tasks</h2> <ul> <li><a href="post_task.html" target="mainFrame">HTTP Post</a></li> - <li><a href="server_tasks.html" target="mainFrame">AntServer / RemoteAnt</a></li> + <li><a href="server_tasks.html" target="mainFrame">AntServer / RemoteAnt</a></li>
+ <li><a href="importurl.html" target="mainFrame">ImportURL</a></li> </ul> <h2>Performance Monitoring and Tasks</h2> <ul> 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);
+ }
+ }
+}
|