I'm forced to use very strange Java code formatter. Unfortunately I can't modify this formatter. So is it somehow possible to have my formatter active during development (e.g. on save action) and change the formatter to the "proper" one just before commit or any time with simple shortcut? Is there any eclipse function or plug-in for this purpose?
No, you cannot apply two formatters for different purposes. But you can apply two formatters to two copies of the code.
So you might try this: Apply your own formatter to your local working copy, and add an Ant builder to the builder list in your project settings. That Ant builder will be triggered together with the normal Java build on every source change. Have the Ant file of the Ant builder copy your original project recursively into a second project in the same workspace, but exclude the .settings/org.eclipse.jdt.*.pref files (which contain the Java settings). Make sure to have the "Refresh resources" option applied in the Ant Builder. Now apply the SVN formatter to the second project.
When you need to checkin, you probably still have to run Source -> Format once on the second project node manually before submitting.
Alternative: Server side SVN hook
You could also apply the formatting on the SVN server, controlled by a hook on submitting your changes. However, this requires you to be able to administrate that server.
You can have multiple Code Formatter profiles in Eclipse.
Go to Preferences > Java > Code Style > Formatter
Click on New to create a Profile and then click Edit to modify that profile. Here you can modify the formatter the way you want. Once done, you can even export it, so other members of your project can import and use this profile. Thus all your SVN commits will have the same Formatting.
Related
SITUATION: In Netbeans you can format the whole project or its folders recursively by selecting a tree node in Project window and pressing Ctrl+Shift+F.
PROBLEM: To get unified format for our team project we need to format it with fixed formatting settings before merges. Some don't use Netbeans. Opening it for this sort of operation is uncomfortable. Also imported formatting settings can be manually modified by irresponsible programmers later. Automation is required. A possibility to call this function as a part of special script is required.
QUESTION: Is there a way to call this Netbeans function from terminal (command line)?
I have a custom build-script for my site. I want to invoke this script whenever I press ctrl+b in eclipse.
I have configured a new builder seen at the top. While my own builder runs fine, eclipse also invokes "Validation" and "Script Builder". As far as I can tell these two do absolutely nothing, but take ages to complete.
I have tried to simply disable them, but eclipse just creates them again as another instance. (hence the duplicates)
I have tried to add an exclusion to * for the PHP Build Path, but that didn't do anything.
What do "Validation" and "Script Builder" do exactly? Why do they take so long and above all: how can I disable them?
The fact that these two builders are re-added after you disable them is a bug. Please file bug reports at bugs.eclipse.org. You will need to file separate bug reports as these two builders are maintained by different groups of people.
The Validation builder performs a variety of validation on artifacts in your project. You can see all validation that's performed under Validation property page in the same dialog. In that page, you can selectively disable the categories of validation that you don't want.
The Script Builder comes from PDT and presumably performs validation on the actual PHP artifacts. Outside of what you've already tried, I don't know of a way to disable it.
2 years later and I have the exact same problem with latest PDT.
This is what I did:
Validations:
Right-click project
Properties
Validation
Click checkbox "Enable project specific settings"
Click checkbox "Suspend all validators"
Script Builder:
Right-click project
Properties-
PHP Build Path
remove all folders from "Source folders on build path:"
or remove all but the ones you really want to be checked for syntax errors
Now "build" phase of PHP project is way shorter (like a half a second :)))
However, if you want to be able to navigate PHP source using Eclipse (like right-click on function and select "Open declaration" or pressing F3 on function name) then you need to leave folders in Script Builder with source you want to navigate. I had project with huge folders containing source of various frameworks and I removed those from "Source folders on build path:" and only left folder(s) with project source. That cut down build time to second or so.
I am using the most excellent ant/bin/complete-ant-cmd.pl for bash completion of ant targets and it caches its results in a file called .ant-targets-build.xml. The problem is, in my eclipse project, eclipse is a little overaggressive validating everything it believes is actually XML (which .ant-targets-build.xml isn't...its just the raw targets separated by newlines).
How do I get eclipse to relax its restrictions and treat .ant-targets-build.xml as NOT an xml file...just text or something.
Project->Properties
Check Enable project specific settings.
Click ellipsis next to XML Validator
Click on Exclude Group
Click on Add Rule
Follow wizard and create File exclusion.
One of the most annoying "features" of this dialog is that you cannot edit existing rules. If you make a mistake you will need to delete that rule and recreate it from scratch.
BTW, in your case it may be preferable to create a global workspace rule ( I usually like to keep special cases with the project ).
In any case after you finished with rule creation, right-click on a project with warnings and choose Validate. This will clear these warnings
If you decided to edit validation preferences in project and not in workspace, then add project-name/.setting/org.eclipse.wst.validation.prefs file to source control.
I have recently come across the LESS Leaner CSS a template engine for CSS based on ruby. The idea sounded neat, but in practice we need to compile the program to get CSS. This is cumbersome as we make too many changes while working on CSS and for every edit we don't want to compile.
In Eclipse, there are "Save-Actions" but it handles only formatting changes.
Is there a way on saving the file in Eclipse, to call or trigger the compilation?
Its easy to do this in Vi or Emacs.
I think all you need is to define a custom Builder for your project. That way, you can run a program or an ant script whenever certain files change.
Right click on the project -> Properties -> Builders -> New
While the Builders are a good solution, keep in mind they only work when a build is issued - either using auto-build or using a manual build which is invoked, well, manually. If you are looking for something that will operate after a save, regardless of the auto-build state you will need to write a plugin which listens to resource changes in Eclipse.
You do that by creating a workspace change listener and installing it like that:
ResourcesPlugin.getWorkspace().addResourceChangeListener(
..., IResourceChangeEvent.POST_CHANGE);
I'm sure you can take it from here :-)
In Eclipse, under Windows -> Preference -> Java -> Code Style, you can define code templates for comments and code, and you can setup a code formatter.
I'm wondering if it is possible in Eclipse to have these setting take affect every time I save a source file. Basically, instead of me highlighting everything and pressing Ctrl+Shift+F, I want Eclipse to be responsible for making sure my code is formatted properly.
Is this possible and how do you set it up?
Note On Using the Auto-Format: It's probably best to choose "Format Edited Lines" as merging changes becomes very difficult when you reformat a whole file that is in source control already that was not formatted properly. Already did this to a co-worker.
Under Preferences, choose Java --> Editor --> Save Actions. Check the Perform the selected actions on save, and check the Format source code box.
This may or may not be available in previous versions of Eclipse. I know it works in:
Version: 3.3.3.r33x_r20080129-_19UEl7Ezk_gXF1kouft<br>
Build id: M20080221-1800
I have a snapshot of the setting.
Please follow the path:
In the Preferences window, choose Java --> Editor --> Save Actions.
Check the Perform the selected actions on save, and check the Format source code box.
I strongly recommend checking your eclipse format xml descriptor into source control. That way all members of the team can use it and you don't get to and fro reformatting battles.
If you find that you do not have a Save Actions preference under Java--> Editor, it may be because you are using an older version of Eclipse. In that case you can install the Format on save plugin from here.
Then, under Preferences, choose Java --> Format on save. Select the Run Format option under Select a code formatting action