How do I manage an unmanaged Eclipse formatting profile?

Our project has an "Unmanaged Profile" and automatic formatting to save time. I would like to be able to change the settings for this unmanaged profile and be able to check them back for version control.

Eclipse help documents are completely useless ("You are not allowed to change such a profile, only the creator (manager) of the profile can change it.").

+6
source share
3 answers

Eclipse should put the .settings folder in the project directory when you have an unmanaged profile. The only way I found to change the settings was to go into the .settings folder inside the project and manually edit the .prefs files.

+2
source

The problem is that the managed profile is actually stored in your workspace, not in your project. Settings are inserted into your project when you make specific changes to the project, such as choosing a different profile. But the settings in the project differ from the parameters in the profile (in the work area).

Currently, Eclipse is not able to do this in reverse order. That is, it cannot accept settings from your project folder in order to create a profile in the workspace. Effectively an β€œUnmanaged Profile" is the profile into which you lost the source code.

The easiest way I found reverse engineering the profile is to create an XML profile file that you can import (in the formatting settings β†’ import button).

Redesign the settings from the project; I wrote the following program. It reads the settings from the project folder and writes them as an XML file:

import java.io.*; public class ExtractFormatter { public static void main( String args[] ) throws IOException { if (args.length < 2) throw new RuntimeException("No arguements specified; expected <project folder> <output file>"); File inFile = new File(args[0]); File outFile = new File(args[1]); BufferedReader reader = new BufferedReader(new FileReader(new File(inFile, ".settings/org.eclipse.jdt.core.prefs"))); PrintWriter writer = new PrintWriter(outFile); writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); // Retain the date from the file as a comment String line = reader.readLine(); writer.println("<!-- Exported from " + inFile + " -->"); writer.println("<!-- " + line + " -->"); writer.println("<profiles version=\"12\">"); writer.println("<profile kind=\"CodeFormatterProfile\" name=\"" + inFile.getName() + "\" version=\"12\">\")"); // Now read every setting for the formatter and write it out as an XML tag. for (line = reader.readLine(); line != null; line = reader.readLine()) { if (line.startsWith("org.eclipse.jdt.core.formatter.")) { String[] parts = line.split("=", 2); writer.println("<setting id=\"" + parts[0] + "\" value=\"" + parts[1] + "\" />"); } } writer.println("</profile>"); writer.println("</profiles>"); reader.close(); writer.close(); } } 
+4
source

I'm not sure if this will allow you to check your profile back for version control, but the following process will allow you to edit your profile on any computer on which the source was extracted.

To edit your profile, you must recreate the profile in Eclipse, which you can easily do as follows:

  • Create a new profile by clicking "Create ..."
  • Give the new profile the same name as your unmanaged profile.
  • Before clicking OK, make sure that you select an unmanaged profile in the "Initialize settings with the following profile" drop-down list.

This will allow you to recreate the profile and allow you to modify it in Eclipse as usual.

Note. This process works with Eclipse Indigo.

+3
source

All Articles