Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Barring copy & paste, is there a way to share Java detail formatters

We have 5-10 developers working on Eclipse with Java here in our shop, and we often are debugging classes that don't have debug-friendly toString().

Along comes Detail Formatters to save the day. Hurray! But only my day. If I want to share the joy with my fellow devs, I THINK I have to do some copying and pasting, as do they.

That sucks. We've got N different version control systems that work in Eclipse... it seems like this would be something that folks would Like To Pass Around.

Nothing in the file->export... dialog. Nothing via searching the online help. Nothing.

I managed to track at least some of the settings to /workspace/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.dbug.ui.prefs, but Have Reason To Believe there's more to it than that. Plus, the thought of putting something burried deep in a hidden folder into source control puts my teeth on edge.

Is there a better way to share detail formatters? Ideally this would be something we could just check into our code repo and disseminate that way.

EDIT: I'm using Helios, Service Release 1, build id 20100917-0705.


In addition to the javaLogicalStructures extension point (for adding logical structure to given classes), there's also one called detailPaneFactories. But this is for creating the pane the text (or whatever, thanks to this extension point) the detail formatter renders to. Neither allows extenders to list existing detail formatters (or logical structures for that matter).

The bottom of the detailPaneFactories extension does have Something Interesting To Say:

    Supplied Implementation:
    The debug platform contributes a detail pane factory providing a default 
    text source viewer detail pane. The default detail pane displays textual
    details of a selected element based on the corresponding debug model 
    presentation's implementation of computeDetail(IValue value, 
    IValueDetailListener listener). 

computeDetail sounds promising. I'll keep ya posted (unless someone else beats me to it... hurray bounties).

Hmm... org.eclipse.jdt.debug.ui.JavaDebugUtils.getPreferenceStore() sounds promising, but I'd still rather not write a plugin for this myself.

Ah... well. Here's the code org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager uses to load them:

    /**
     * Populate the detail formatters map with data from preferences.
     */
    private void populateDetailFormattersMap() {
            String[] detailFormattersList= JavaDebugOptionsManager.parseList(JDIDebugUIPlugin.getDefault().getPreferenceStore().getString(IJDIPreferencesConstants.PREF_DETAIL_FORMATTERS_LIST));
            fDetailFormattersMap= new HashMap(detailFormattersList.length / 3);
            for (int i= 0, length= detailFormattersList.length; i < length;) {
                    String typeName= detailFormattersList[i++];
                    String snippet= detailFormattersList[i++].replace('\u0000', ',');
                    boolean enabled= ! JavaDetailFormattersPreferencePage.DETAIL_FORMATTER_IS_DISABLED.equals(detailFormattersList[i++]);
                    fDetailFormattersMap.put(typeName, new DetailFormatter(typeName, snippet, enabled));
            }
    }

So the string in the preference store is just a bunch of CSVs with type-name,snippet,enabled,type-name... replace \u0000 with , in the snippets, and you're good to go.

That handles the export (hell, you could just dump the preference string whole hog).

Import wouldn't be much harder, though it'd be nice to not overwrite existing types, or given the user the option to do so, perhaps even with a diff of the two snippets in question.

OTOH, I'd really rather not rely on the inner workings of a class in *.internal.*.

like image 451
Mark Storer Avatar asked Mar 11 '11 21:03

Mark Storer


People also ask

What is the barring meaning?

: excluding by exception : excepting. … they knew that, barring a miracle, they would never be able to save the large cash outlay required …

How do you use Barring?

You use barring to indicate that the person, thing, or event that you are mentioning is an exception to your statement. Barring accidents, I believe they will succeed.

Does barring mean stopping?

As a verb, "barring" is the present participle of the verb "bar," which can mean to fasten with a bar ("they were barring up the windows to prevent escape"), to prevent or forbid ("the teachers were barring the students from leaving class before the final bell"), to confine and shut in or keep out as if with bars ("we ...

What does barring any issues mean?

1. — used to say that something will happen unless something else happens. They'll be at sea for six months, barring medical emergencies. [=they'll be at sea for six months if there are no medical emergencies] She's going to lose the election barring a miracle.


2 Answers

From the Eclipse 3.8 and 4.2 M5 - New and Noteworthy:

Detail formatters can now be exported as separate preferences.
Previously the only way to share detail formatters was to export all of your workspace settings.

detail formatter export

This closes the bug 224815 mentioned by Brian De Alwis in his answer:
"Make Detail formatters exportable" (with that patch)

like image 89
VonC Avatar answered Sep 28 '22 15:09

VonC


Although there is nothing explicit in the preferences export wizard, exporting everything will also write the detail formatters. Just search in the output file for /instance/org.eclipse.jdt.debug.ui/org.eclipse.jdt.debug.ui.detail_formatters and share only those lines.

Update: There seems to be a bug in the importer, you have to remove the /instance/ prefix from each line before importing the file.

Alternatively, as they are stored in a properties file in the workspace metadata, you can share that (although you'll probably overwrite other debug settings if you just copy the file): ${workspace}\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.debug.ui.prefs

like image 22
Dan Berindei Avatar answered Sep 28 '22 15:09

Dan Berindei