Bug 18692 - [ExternalTools] Including XML files in ANT does not work anymore in F2
Summary: [ExternalTools] Including XML files in ANT does not work anymore in F2
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Ant (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P1 critical (vote)
Target Milestone: 2.1   Edit
Assignee: Simon Arsenault CLA
QA Contact:
URL:
Whiteboard:
Keywords: investigate, ui
: 18681 18817 19122 (view as bug list)
Depends on: 20819
Blocks:
  Show dependency tree
 
Reported: 2002-06-03 08:25 EDT by Markus Kohler CLA
Modified: 2004-12-21 17:54 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Kohler CLA 2002-06-03 08:25:52 EDT
I use the following heade in my build.xml file :

<?xml version="1.0"  encoding="iso-8859-1"?>
<!DOCTYPE project   [
<!ENTITY common SYSTEM "file:./common.xml">
]>

I use this to include a file common.xml that is located within the same
directory as the build.xml file. 

This used to work until build M5.
Comment 1 Rodrigo Peretti CLA 2002-06-03 17:01:04 EDT
Go to Run->External Tools->Configure and select the script you want to run. 
Click on edit. In the working directory option, select the desired location. 
That should solve your problem.
Comment 2 Rodrigo Peretti CLA 2002-06-03 17:01:34 EDT
*** Bug 18817 has been marked as a duplicate of this bug. ***
Comment 3 Rodrigo Peretti CLA 2002-06-03 17:04:17 EDT
*** Bug 18681 has been marked as a duplicate of this bug. ***
Comment 4 Markus Kohler CLA 2002-06-04 02:57:37 EDT
Hi,
I tried the approach using the "External Tools" menu. 
I can now execute the Ant default target. :-)

Unfortunately trying to add the the ant targets variable does not work, because the
included .xml file cannot be found. 
Comment 5 Markus Kohler CLA 2002-06-04 03:05:38 EDT
A Workaround ist to specify the ant target variable directly without using the
menu. 
 
Comment 6 Rodrigo Peretti CLA 2002-06-04 10:15:21 EDT
Markus, just to make sure I follow what happened. You can now execute your 
script. The only problem is that if you try to use the External Tools UI to 
select a target that belongs to the other script, it is not available but you 
can workaround the problem by editing the command line manually. Is that 
correct?
Moving to Platform UI for comments. If the above is true the suggestion is 
defer and investigate after 2.0.
Comment 7 Rodrigo Peretti CLA 2002-06-04 10:15:47 EDT
I meant Platform UI - Sorry.
Comment 8 Markus Kohler CLA 2002-06-04 10:36:09 EDT
Hi,
Actually when I'm trying to use the "Edit external Tools" UI, I can specify my 
ant target by entering directly  "${ant_target:jar}" (that wasn't easy to find 
out). If I try to use the "Browse Variables" button and select the  "Ant 
targets" to get the list of available targets for my build.xml file, I get the 
error message that the file ./common.xml cannot be found. This is the file my 
build.xml includes.
It seems to me that actually the build.xml file has been parsed to find out the 
available target's but that at this point the working directory is not used. 

 
Comment 9 Rodrigo Peretti CLA 2002-06-04 14:17:17 EDT
*** Bug 19122 has been marked as a duplicate of this bug. ***
Comment 10 Nick Edgar CLA 2002-06-05 09:09:56 EDT
Rodrigo, is the failure to resolve the included path a UI or Core Ant problem?
Comment 11 Rodrigo Peretti CLA 2002-06-05 10:10:50 EDT
Probably UI. It seems related to parsing the script to get the the target 
information.
Comment 12 Nick Edgar CLA 2002-06-05 14:31:15 EDT
Should consider for F3 since this is a regression from previous behaviour.
Comment 13 Nick Edgar CLA 2002-06-06 21:24:07 EDT
Marked for F3 since this is a regression.
Comment 14 Nick Edgar CLA 2002-06-07 15:46:00 EDT
Bumping up priority - this affects many people.
Comment 15 Simon Arsenault CLA 2002-06-10 14:40:54 EDT
Markus, can you include the build.xml and common.xml you are using (or a simple 
example to reproduce this problem)?
Comment 16 Simon Arsenault CLA 2002-06-11 14:17:26 EDT
Ryan changed ant build file parser to resolve correctly relative path by using 
the directory of the ant build file as the base directory.

Checked by Simon and Tod
Comment 17 Markus Kohler CLA 2002-06-16 03:34:48 EDT
Sorry for the late reply. I was on vacation.

actually all you need to reproduce the bug is the header I already specified and
then a line to include the file : "&common". The solution described by Simon 
sounds to be correct. 
I will verify this as soon as I get the new build. 
Comment 18 Markus Kohler CLA 2002-06-19 03:13:22 EDT
It works for me in F3. 

Thanks,
Markus
Comment 19 Nick Edgar CLA 2002-06-19 09:38:53 EDT
Verified by Markus.
Comment 20 Matthew Conway CLA 2002-06-19 12:39:43 EDT
It still doesn't work if you don't include the protocol (which is a valid usage)
e.g.

<?xml version="1.0"  encoding="iso-8859-1"?>
<!DOCTYPE project   [
<!ENTITY common SYSTEM "../common.xml">
]>
Comment 21 Simon Arsenault CLA 2002-06-19 12:47:30 EDT
Reopening problem report because of Matthew's comment above.

Matthew, did you mean "../common.xml" or "./common.xml"? (note the dot count)
What platform and build are you running on?
Comment 22 Matthew Conway CLA 2002-06-19 12:56:40 EDT
Either . or .. should fail depending on your setup - its the lack of the "file:"
protocol that causes the failue, i.e. on my my machine its actually
"../../Build/ant/common.xml", and fails unless I prefix with "file:"

But to preserve the example it should be "." =)

I'm running build F3 on Windows NT

Comment 23 Simon Arsenault CLA 2002-06-19 14:10:29 EDT
Just to be accurate. Do you mean NT 4.0 or 2000? It works fine for me on 
Windows 2000 (without the file: prefix).
Comment 24 Matthew Conway CLA 2002-06-19 14:24:00 EDT
NT 4.0sp6
If I don't specify a protocol, when I "Run ant..." I get the error dialog:
Problems reading Ant build file
Reason:
 no protocol: ../../Build/ant/build-driver.xml

But it does work ok when I run it through Run->External Tools

Comment 25 Simon Arsenault CLA 2002-06-19 14:50:48 EDT
When you use Run Ant..., does it fail when the dialog opens, or when you hit 
Finish?

When you use Run > External Tools dialog, select your ant file tool, edit it, 
select Browse Variables, and select Ant targets, does it fail?

Are you using the ant.bat file?

Is there a space in the complete path to your project or in your project name?
Comment 26 Matthew Conway CLA 2002-06-19 15:24:14 EDT
It fails before the dialog comes up.
It also fails when trying to browse the ant targets in the External tools dialog.
There are no spaces anywhere.
Comment 27 Matthew Conway CLA 2002-06-19 15:29:24 EDT
Forget to mention that I'm not using ant.bat, I was pointing ant to a 1.5beta2
ant jars, but I tried reverting to defaults, restarted workspace, but same problems

Comment 28 Markus Kohler CLA 2002-06-20 03:12:48 EDT
Just a comment from my side, regarding the problem with the missing "file:" 
protocol. 

I think I have had problems with this before I used Eclipse. 
It might therefore be a problem that has nothing to do with Eclipse. 

As far as I can remember I tried different XML Parsers and got different 
results when trying to include .xml files.  
Comment 29 Simon Arsenault CLA 2002-06-20 08:09:25 EDT
From my limited knowledge of XML, I do recall reading the spec on entities in 
which they refered to the system id as being in a URI format. Nevertheless, on 
Windows 2000, we can use a relative path like "../../somefile.xml" and it works 
for us. The only difference I see so far is your using NT. If we can't 
reproduce here, would you be willing to assist in debugging this from your end 
today?
Comment 30 Matthew Conway CLA 2002-06-20 11:12:59 EDT
Sure - just tell me where to set my breakpoints
Comment 31 Ryan Cooper CLA 2002-06-20 11:29:26 EDT
A good start would be to set a breakpoint in AntUtil.getTargetList(IPath). 

public static AntTargetList getTargetList(IPath path) throws CoreException {
	IMemento memento = getMemento(path);
	return getTargetList(memento);	
}

The exception which causes the error dialog to pop up should be coming from 
somwhere in here. First, find out if it's coming from getMemento(IPath) or 
getTargetList(IMemento). Then, step through whichever method it is coming from 
to find out exactly what line is causing it (feel free to step through methods 
being called inside these methods as well, to whatever depth you think is 
appropriate). This will give us a hint on what the problem might be, and we can 
decide what to do once we know a bit more.
Comment 32 Matthew Conway CLA 2002-06-20 14:31:14 EDT
Well, I found where and why an exception is getting thrown - no idea why it
doesn't happen for you.

AntUtil.AntEntityResolver.resolveEntity doesn't resolve any entities that don't
begin with "file:", and instead returns null to allow the xml parser to do the
default processing.

Thus, one level up the stack from this call,
org.apache.crimson.parser.ExternalEntity.getInputSource(org.xml.sax.EntityResolver)
line: 92) does a "new URL(filename) which throws a MalformedURLException.

You could probably fix this by handling it in your entity resolver.  Not sure
why the parser doesn't do something more intelligent - it might if in
org.eclipse.ui.externaltools.internal.core.AntUtil.createReadRoot, line: 85, you
constructed an InputSource like so: InputSource(reader, basedir) - this would
then use basedir for resolving relative URLs


Hope this helps, let me know if I can do anything else

BTW, is there an easy way to have all the platform jars/source available when
debugging a runtime workbench?

Comment 33 Matthew Conway CLA 2002-06-20 14:33:10 EDT
Forgot to mention, here are the files I'm using if you want to try and duplicate
the problem again.  Both should be in the same directory.

build.xml:

<!DOCTYPE project [
   <!ENTITY common SYSTEM "common.xml">
]>

<project name="bug" default="all">

	<target name="all" depends="hello">
		<echo message="In All"/>
	</target>

	&common;

</project>


common.xml:

<target name="hello">
	<echo message="Hello world!"/>
</target>


Comment 34 Rodrigo Peretti CLA 2002-06-20 14:38:51 EDT
Matthew, 2 questions:
1) What VM are you using?
2) Are you using xerces shipped with Eclipse or another version (just check 
the Ant classpath in Window->Preferences->External Tools->Ant)?
Comment 35 Simon Arsenault CLA 2002-06-20 14:46:53 EDT
Matthew, thanks for looking into this. In AntUtil, line 85 we construct the 
InputSource. You suggest passing the baseDir as a parameter - in my version of 
InputSource there is no two parameter constructor. If you look at line 86, we 
do set the baseDir for the InputSource (using setSystemId())...do you see that 
call in the code?
Comment 36 Matthew Conway CLA 2002-06-20 14:49:45 EDT
> java -version
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

Ant Preferences shows that I'm using the xerces shipped with eclipse
Comment 37 Matthew Conway CLA 2002-06-20 14:54:14 EDT
Sorry, yes, was just working on some JDOM code which has a build(reader,
basePath) method, so I guess I was thinking of that - you are doing the correct
thing in your code by using setSystemId

Comment 38 Rodrigo Peretti CLA 2002-06-20 14:56:17 EDT
Simon, could you test against JDK 1.4? Any possibility it could be a conflict 
between XML parsers? (sorry if this is a bogus question)
Comment 39 Matthew Conway CLA 2002-06-20 15:06:25 EDT
Actually, I think it is using the parser from jdk 1.4 - Or at least the classes
it is using are coming from the 1.4 rt.jar (as shown in java package explorer
when I switch to java perspective after debugging)
I guess I should have guessed from the package name - org.apache.crimson is the
parser that comes with the jdk, xerces is org.apache.xerces



Comment 40 Rodrigo Peretti CLA 2002-06-20 15:38:35 EDT
So maybe we should handle it (dealing with relative paths) in our 
EntityResolver implementation and not leaving the job for the default 
implementation.
Comment 41 Simon Arsenault CLA 2002-06-20 15:46:30 EDT
We could do that, but it would only fix the UI portion. Matthew, I'm assuming 
if you do Run > External Tools > <<your xml file>>, it fails also? During the 
run, we do not open the XML file at the UI level, therefore we do not go thru 
our entity resolver. If it fails during run, then Ant runner has the same 
problem? Matthew, if it does fail, can you put a break point in 
AntFileRunner.execute method and see if the error is the same?
Comment 42 Matthew Conway CLA 2002-06-20 16:48:30 EDT
Actually, if I do Run > External Tools > <<your xml file>>, it works just fine.
 Its just the UI parsing of the ant build file that is broken.



Comment 43 Simon Arsenault CLA 2002-06-21 14:05:36 EDT
We will not be fixing this problem for release 2.0 (it's too late). The 
workaround is to use the "file:" protocol. This problem will be fixed post 2.0 
(see bug 20819).
Comment 44 Simon Arsenault CLA 2002-06-25 14:06:21 EDT
Reopening to change resolution to LATER instead of WONTFIX.
Comment 45 Simon Arsenault CLA 2002-06-25 14:07:10 EDT
Change resolution to LATER instead of WONTFIX.
Comment 46 Randy Giffen CLA 2002-08-01 10:37:01 EDT
reopened for investigation
Comment 47 Simon Arsenault CLA 2002-08-08 14:03:49 EDT
This is fixed in the 2.0.1 code stream (see bug 20819). The report (bug 22273) 
was created to port the fix to the 2.1 code stream.