ASF Bugzilla – Attachment 11682 Details for
Bug 29251
[patch] add @url to <import> task
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
implements @url support for <import> task
import-url.patch (text/plain), 5.85 KB, created by
Dave Brondsema
on 2004-05-27 18:06:21 UTC
(
hide
)
Description:
implements @url support for <import> task
Filename:
MIME Type:
Creator:
Dave Brondsema
Created:
2004-05-27 18:06:21 UTC
Size:
5.85 KB
patch
obsolete
>Index: src/main/org/apache/tools/ant/helper/ProjectHelper2.java >=================================================================== >RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v >retrieving revision 1.47 >diff -u -r1.47 ProjectHelper2.java >--- src/main/org/apache/tools/ant/helper/ProjectHelper2.java 24 May 2004 15:09:57 -0000 1.47 >+++ src/main/org/apache/tools/ant/helper/ProjectHelper2.java 27 May 2004 18:01:17 -0000 >@@ -159,12 +159,6 @@ > buildFileName = buildFile.toString(); > // } else if (source instanceof InputStream ) { > } else if (source instanceof URL) { >- if (handler.getCurrentAntHandler() != elementHandler) { >- throw new BuildException( >- "Source " + source.getClass().getName() >- + " not supported by this plugin for " >- + " non task xml"); >- } > url = (URL) source; > buildFileName = url.toString(); > // } else if (source instanceof InputSource ) { >Index: src/main/org/apache/tools/ant/taskdefs/ImportTask.java >=================================================================== >RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/ImportTask.java,v >retrieving revision 1.28 >diff -u -r1.28 ImportTask.java >--- src/main/org/apache/tools/ant/taskdefs/ImportTask.java 28 Apr 2004 09:01:08 -0000 1.28 >+++ src/main/org/apache/tools/ant/taskdefs/ImportTask.java 27 May 2004 18:01:17 -0000 >@@ -26,6 +26,7 @@ > > import java.io.File; > import java.io.IOException; >+import java.net.URL; > import java.util.Vector; > > /** >@@ -45,17 +46,23 @@ > * <import file="../common-targets.xml" /> > * </pre> > * Import targets from a file in a parent directory. >- *<p> >+ *<p/> > * <pre> > * <import file="${deploy-platform}.xml" /> > * </pre> > * Import the project defined by the property deploy-platform >+ *<p/> >+ * <pre> >+ * <import url="http://${myhost}/common.xml" /> >+ * </pre> >+ * Import a project from a URL > * > * @since Ant1.6 > * @ant.task category="control" > */ > public class ImportTask extends Task { > private String file; >+ private String url; > private boolean optional; > private static final FileUtils FILE_UTILS = FileUtils.newFileUtils(); > >@@ -81,12 +88,23 @@ > } > > /** >+ * the name of the URL to import >+ * @param URL of the file >+ */ >+ public void setUrl(String url) { >+ this.url = url; >+ } >+ >+ /** > * This relies on the task order model. > * > */ > public void execute() { >- if (file == null) { >- throw new BuildException("import requires file attribute"); >+ if (file == null && url == null) { >+ throw new BuildException("import requires either file attribute or url attribute"); >+ } >+ if (file != null && url != null) { >+ throw new BuildException("import allows only one of file attribute or url attribute"); > } > if (getOwningTarget() == null > || !"".equals(getOwningTarget().getName())) { >@@ -110,26 +128,52 @@ > File buildFile = new File(getLocation().getFileName()); > buildFile = new File(buildFile.getAbsolutePath()); > >- getProject().log("Importing file " + file + " from " >- + buildFile.getAbsolutePath(), Project.MSG_VERBOSE); > > // Paths are relative to the build file they're imported from, > // *not* the current directory (same as entity includes). > >- File buildFileParent = new File(buildFile.getParent()); >- File importedFile = FILE_UTILS.resolveFile(buildFileParent, file); >- >- if (!importedFile.exists()) { >- String message = >- "Cannot find " + file + " imported from " >- + buildFile.getAbsolutePath(); >- if (optional) { >- getProject().log(message, Project.MSG_VERBOSE); >- return; >- } else { >- throw new BuildException(message); >+ Object importedFile; >+ if (file != null) { >+ getProject().log("Importing file " + file + " from " >+ + buildFile.getAbsolutePath(), Project.MSG_VERBOSE); >+ >+ File buildFileParent = new File(buildFile.getParent()); >+ importedFile = FILE_UTILS.resolveFile(buildFileParent, file); >+ >+ if (!((File)importedFile).exists()) { >+ String message = >+ "Cannot find " + file + " imported from " >+ + buildFile.getAbsolutePath(); >+ if (optional) { >+ getProject().log(message, Project.MSG_VERBOSE); >+ return; >+ } else { >+ throw new BuildException(message); >+ } > } >+ } else { >+ getProject().log("Importing url " + url + " from " >+ + buildFile.getAbsolutePath(), Project.MSG_VERBOSE); >+ >+ URL importedURL; >+ try { >+ importedURL = new URL(url); // can throw MalformedURLException >+ importedURL.openStream().close(); // can throw IOException >+ } catch (java.io.IOException e) { >+ String message = >+ "Cannot access url: " + url + " imported from " >+ + buildFile.getAbsolutePath(); >+ if (optional) { >+ getProject().log(message, Project.MSG_VERBOSE); >+ return; >+ } else { >+ throw new BuildException(message); >+ } >+ } >+ >+ importedFile = importedURL; > } >+ > > if (importStack.contains(importedFile)) { > getProject().log(
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 29251
: 11682