Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 223064

Summary: Ant build File Not opened in the Ant Editor when use the Open File menu
Product: [Eclipse Project] Platform Reporter: Amel <nammoula>
Component: UIAssignee: Boris Bokowski <bokowski>
Status: RESOLVED DUPLICATE QA Contact:
Severity: major    
Priority: P3 CC: cocoakevin, Darin_Swanson, emoffatt, Mike_Wilson, pwebster, remy.suen
Version: 3.3Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
A comparaison in the code of Open File in Eclipse 3.2 and Eclipse 3.3
none
Ant File which is not opened with Ant Editor
none
Eclipse plugin details that show the version of Ant plugin used
none
My own "Hello, world!" Ant test build file. none

Description Amel CLA 2008-03-18 07:18:45 EDT
Created attachment 92785 [details]
A comparaison in the code of Open File in Eclipse 3.2 and Eclipse 3.3

Build ID: 3.3

Steps To Reproduce:
1.Install the Ant plugin
2.Open Ant File with Open File Menu Of Eclipse 3.3
3.


More information:
Expecting result:
The ant build file must be opened with the Ant editor, but it isn’t the case.


There is a difference between Open File in 3.3 and 3.2. I have installed the ant plugin. When I used the eclipse 3.2.1 and open an Ant file with the “Open File” Menu, this file was opened with the Ant Editor. But when I change to eclipse 3.3 and I want to open my ant file with the Open File Menu, it was opened with the Text editor!!!
I’ve debugged the Eclipse 3.3 and 3.2 codes and there is a difference in the determination of the content Type.
In eclipse 3.3, the content type is determined using the function:
Public IContentType findContentTypeFor (String filename) of the class org.eclipse.core.internal.content.ContentTypeMatcher. This function uses a policy for sorting the content types that put the content type org.eclipse.core.runtime.xml in the first position.

In eclipse 3.2, the content type is determined using the function:
public IContentType findContentTypeFor(InputStream contents, String fileName) of the class org.eclipse.core.internal.content.ContentTypeMatcher. This function uses a policy for sorting the content types that put the content type org.eclipse.ant.core.antBuildFile in the first position.

Can you please tell me how to resolve this problem in eclipse 3.3, I want my Ant build file be opened in the Ant file, when I use the Open File menu. It’s very very urgent, so thank you for response me asap.
Comment 1 Kevin Barnes CLA 2008-03-19 12:44:12 EDT
It may be helpful to attach a buildfile that causing this problem for you. If I use File/Open to open a simple HelloWorld build file, I get the Ant Editor.

Where are you getting the Ant plugin that you're installing in step 1? Are you using a different plugin from the ant plugins that ship with the SDK?
Comment 2 Amel CLA 2008-03-21 05:27:51 EDT
Created attachment 93105 [details]
Ant File which is not opened with Ant Editor
Comment 3 Amel CLA 2008-03-21 05:31:07 EDT
Created attachment 93106 [details]
Eclipse plugin details that show the version of Ant plugin used
Comment 4 Amel CLA 2008-03-21 05:38:36 EDT
Hello,
Thank you for your speedy reply.
I get the ant plugin within the installation of Eclipse SDK 3.3.0. The version of this ant plugin is 1.7.0 (see the attached file). 
I think that the problem wasn’t  in the Ant plugin, but in the Open File Menu (see my explanation in the previous message). Any way I’ve attached the ant file which I work with. (Remark: all ant files that I work with have the same problem).
If you open this file in the package view it will work (the file will be opened in the Ant Editor). But if you do “File>Open File” in the eclipse Menu it will not work.
Can you give me please the Hello_world ant build file which you work with. Thank you.

Amel
Comment 5 Mike Wilson CLA 2008-04-11 18:55:38 EDT
Why is this in Ant? It looks like it's a content type issue.

Kevin, did you try this on linux?
Comment 6 Remy Suen CLA 2008-04-11 19:10:51 EDT
Created attachment 95775 [details]
My own "Hello, world!" Ant test build file.

(In reply to comment #5)
> Kevin, did you try this on linux?

I confirm and verify that attachment 93105 [details] does not use the Ant editor on Linux if named as test.xml. However, once renamed to build.xml, the Ant editor is used. I created my own "Hello, world!" Ant build file named test2.xml and that too did not use the Ant editor to open but did once renamed as build.xml. See above.

This is on I20080408-0800.
Comment 7 Remy Suen CLA 2008-04-11 19:44:44 EDT
As Amel mentioned, back in 3.2, we used both the InputStream and the file's name to check the file's content type.

// from org.eclipse.ui.internal.editors.text.OpenExternalFileAction
// which appears to be have been deleted because I can't find it anymore
return Platform.getContentTypeManager().findContentTypeFor(stream, fileStore.getName());

Now, we simply use the name and move on.

// from the org.eclipse.ui.ide.IDE class
IContentType contentType = inferContentType ? Platform
				.getContentTypeManager().findContentTypeFor(name) : null;

(In reply to comment #0)
> Can you please tell me how to resolve this problem in eclipse 3.3, I want my
> Ant build file be opened in the Ant file, when I use the Open File menu.

Does renaming the file as build.xml help?
Comment 8 Amel CLA 2008-04-16 03:02:18 EDT
(In reply to comment #7)
> As Amel mentioned, back in 3.2, we used both the InputStream and the file's
> name to check the file's content type.
> 
> // from org.eclipse.ui.internal.editors.text.OpenExternalFileAction
> // which appears to be have been deleted because I can't find it anymore
> return Platform.getContentTypeManager().findContentTypeFor(stream,
> fileStore.getName());
> 
> Now, we simply use the name and move on.
> 
> // from the org.eclipse.ui.ide.IDE class
> IContentType contentType = inferContentType ? Platform
>                                
> .getContentTypeManager().findContentTypeFor(name) : null;
> 
> (In reply to comment #0)
> > Can you please tell me how to resolve this problem in eclipse 3.3, I want my
> > Ant build file be opened in the Ant file, when I use the Open File menu.
> 
> Does renaming the file as build.xml help?
> 

Hello,
I think that this solution will not resolve my problems as the users of my plugin want to open several ant files that can be in the same directory. Is there any other solutions?
Amel
Comment 9 Kevin Barnes CLA 2008-04-16 15:57:37 EDT
The same behavior happens on mac. If you use File/Open File you get a text editor, but if you use the Open Resource command or open the file from the package explorer you get the ant editor. Does open file check content type?
Comment 10 Remy Suen CLA 2008-04-16 16:16:07 EDT
I see two solutions to this bug.

a) We change the implementation of IDE's openEditorOnFileStore(IWorkbenchPage, IFileStore) method to query for an IContentType based on the file's name and its contents (by opening an InputStream). This analysis should return the Ant file content type properly and allow the Ant editor to be opened. I don't know if we'll be breaking any adopters' code with this.

b) We change OpenLocalFileAction to query for the content type directly. We then ask the editor registry for the corresponding editor and then open the editor that way.

(In reply to comment #8)
> I think that this solution will not resolve my problems as the users of my
> plugin want to open several ant files that can be in the same directory. Is
> there any other solutions?

I think the only way around this is to bring the files into the workspace directly.
Comment 11 Boris Bokowski CLA 2008-04-17 01:10:57 EDT
I would vote for solution a.
Comment 12 Remy Suen CLA 2008-05-07 15:05:51 EDT
Boris, I guess we can mark this as a duplicate of bug 230865?
Comment 13 Boris Bokowski CLA 2008-05-07 16:02:53 EDT
Yes.

*** This bug has been marked as a duplicate of bug 230865 ***