You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Yves Martin <yv...@elca.ch> on 2005/01/27 12:53:06 UTC
Patch proposal for 1.6.3: parse a Ant project from a resource
Yves Martin <yv...@elca.ch> writes:
> Hello,
>
> I'm writing a task which aim is to parse a Ant Project with 'helper.parse(p,
> myURL)'
>
> It works well when myURL is a File on disk - but it failed with "Source not
> supported by this plugin" when it is a URL... whereas I saw some parts of
> ProjectHelper2 designed to load a URL resource.
>
> I would like to avoid to inherit from ProjectHelper2 to work-around the check
> that failed.
I would like to understand why a BuildException is thrown when trying to parse
a URL ?
I disabled that exception throwing and in fact, I just use
helper.parse(project, URL) with a URL and it works perfectly well.
If there is no "good" reason or constraint about that exception, I would be
pleased to see that part of code removed. Or simply disabled by a project
property, why not. What do you think about it ? Is it possible to get it for
release 1.6.3 (it will be a great help for me to release my build system) ?
Thanks in advance for your help
<ProjectHelper2>
public void parse(Project project, Object source, RootHandler handler)
throws BuildException {
AntXMLContext context = handler.context;
File buildFile = null;
URL url = null;
String buildFileName = null;
if (source instanceof File) {
buildFile = (File) source;
buildFile = fu.normalize(buildFile.getAbsolutePath());
context.setBuildFile(buildFile);
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 ) {
} else {
throw new BuildException("Source " + source.getClass().getName()
+ " not supported by this plugin");
}
--
Yves Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: Patch proposal for 1.6.3: parse a Ant project from a resource
Posted by Yves Martin <yv...@elca.ch>.
Peter Reilly <pe...@apache.org> writes:
> The problem is that this will not set the basedir correctly.
> (The basedir will be set to something like:
> File(url_string).getParentFile().getAbsolutePath()).
> This will cause all sorts of problems and is the reason why
> <import url="..."/> has not been implemented.
OK. It is a good reason.
My build system loads Ant project files from the disk, and I just adapt the
code to load them from a JAR resources.
I can say to you that such a code (set basedir, listener and project name) is
working with both a File and a URL in my build system context as fas as the
exception is not thrown in the ProjectHelper2:
public static Project loadAntProject(Project currentProject,
Object antproject) {
ProjectHelper helper =
(ProjectHelper) currentProject.getReference("ant.projectHelper");
Project project = new Project();
currentProject.initSubProject(project);
// Copy listeners to enable logging
Iterator listenerIt = currentProject.getBuildListeners().iterator();
while (listenerIt.hasNext()) {
BuildListener bl = (BuildListener) listenerIt.next();
currentProject.log(" Adding listener " + bl, Project.MSG_DEBUG);
project.addBuildListener(bl);
}
project.addReference("ant.projectHelper", helper);
project.setBaseDir(currentProject.getBaseDir());
helper.parse(project, antproject);
// Set project name
AntXMLContext context = null;
context = (AntXMLContext)
project.getReference("ant.parsing.context");
project.setName(context.getCurrentProjectName());
return project;
}
Isn't it possible to remove the exception 'throw' statement and document the
method to say that parsing a URL is at your own risk (I aggree to take it ;)) ?
In fact, ProjectHelper2 is not opened enough (private attributes) to be
inherited to change such a small part of code...
Please help me, comment that part of code that never occurs finally (as far as
import url is not implemented as your said) !
Many thanks in advance
--
Yves Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: Patch proposal for 1.6.3: parse a Ant project from a resource
Posted by Peter Reilly <pe...@apache.org>.
The problem is that this will not set the basedir correctly.
(The basedir will be set to something like:
File(url_string).getParentFile().getAbsolutePath()).
This will cause all sorts of problems and is the reason why
<import url="..."/> has not been implemented.
Peter
Yves Martin wrote:
>Yves Martin <yv...@elca.ch> writes:
>
>
>
>> Hello,
>>
>> I'm writing a task which aim is to parse a Ant Project with 'helper.parse(p,
>> myURL)'
>>
>> It works well when myURL is a File on disk - but it failed with "Source not
>> supported by this plugin" when it is a URL... whereas I saw some parts of
>> ProjectHelper2 designed to load a URL resource.
>>
>> I would like to avoid to inherit from ProjectHelper2 to work-around the check
>> that failed.
>>
>>
>
> I would like to understand why a BuildException is thrown when trying to parse
> a URL ?
>
> I disabled that exception throwing and in fact, I just use
> helper.parse(project, URL) with a URL and it works perfectly well.
>
> If there is no "good" reason or constraint about that exception, I would be
> pleased to see that part of code removed. Or simply disabled by a project
> property, why not. What do you think about it ? Is it possible to get it for
> release 1.6.3 (it will be a great help for me to release my build system) ?
>
> Thanks in advance for your help
>
><ProjectHelper2>
> public void parse(Project project, Object source, RootHandler handler)
> throws BuildException {
>
> AntXMLContext context = handler.context;
>
> File buildFile = null;
> URL url = null;
> String buildFileName = null;
>
> if (source instanceof File) {
> buildFile = (File) source;
> buildFile = fu.normalize(buildFile.getAbsolutePath());
> context.setBuildFile(buildFile);
> 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 ) {
> } else {
> throw new BuildException("Source " + source.getClass().getName()
> + " not supported by this plugin");
> }
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org