views:

44

answers:

2

When I run an Ant build, MyEclipse (happens for v6.0 and 7.5) formats my code. When I open the file it says it was modified on the file system and when I reload it it is formatted.

The thing that is even stranger is that it is not formatted as specified in the Code Style in my Preferences (seems like Java Sun codding rules).

As far as I could determine, there is nothing called by the Ant build to do the formatting so it MyEclipse doing it? Could it be a plugin or something?

Part of the build also includes Maven tasks so could there be a Maven plugin doing this?

I mention that I searched and deactivated all possible options in the preferences of the IDE trying to find some setting but nothing.

It is very annoying so far and could cause problems since I am working on some older projects with minimal modifications in the code and don't want to have a complete messed up version of a class just because I modified a word or something.

Has someone else encountered this?

P.S. It happens only on my PC. My colleagues don't encounter this issue.

Thank you!

EDIT: I have executed some tests:

  1. I executed the Ant script outside of eclipse (in command prompt) then opened the files with notepad. The files are untouched, no formatting occurred. If I open eclipse nothing happens to the files.
  2. I opened eclipse and changed the files on the disk using notepad (added some spaces and saved them). Eclipse says the files are changed on the file system and asks to reload them. I say Yes he opens the files. The files are unchanged. No formatting occurs.
  3. I run Ant from eclipse. Eclipse says files have changed and asks to reload them. I say Yes and when the files are opened they are formatted. WTF??!?!!

Is there a config that says to run some tasks after ant builds or something? I could not find anything.

A: 

Eclipse can format on save if you choose, and you can elect to have it save automatically any modified files before a build. There is nothing in myeclipse that would cause the code to be formatted on load. I would look through your plugins.

Jalopy has an ANT plugin that will format code

Romain Hippeau
@Romain Hippeau: I also read about Jalopy but could not find any reference to it in the project. I looked at all taskdefs from the ant build. Nothing.
StupidLearner
@StupidLearner There are also others, some commercial some not. From the question it is not clear if the code is being formatted on a save or on a build. maybe you could open a file save it and then open it with another editor outside of eclipse to see if it changed. That would tell you if it is during the build or during the save. maybe you could open the file from outside the editor before you opened it with eclipse also.
Romain Hippeau
@StupidLearner Any news on this ? Did you find out where it was happening ?
Romain Hippeau
@Romain Hippeau: see my edited question
StupidLearner
A: 

Did you check the "Save actions"?

Preferences" menu, Java > Editor > Save actions.

One of the possible actions is to format your code when you save. You can have these preferences on a global or per project context.

Although it's strange that the code gets changed when you run your Ant script.

Fernando
@Fernando: Thanks... I already checked that. It does not happen on save. It happens after I run the Ant build and there is nothing special about that script. My colleagues use it and it does not happen for them. It must be something with my configs. But which ones?
StupidLearner
That's strange... Maybe some Maven task is doing it then. Check the tasks xml and compare it with your colleagues or something.
Fernando