rsiccho / workspacemechanic

Automatically exported from code.google.com/p/workspacemechanic
0 stars 0 forks source link

Backlash escaping with preference tasks. #26

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
As reported by richboss

I encountered a problem with how Workspace Mechanic handles escaping
backslashes, illustrated by the following example.

The *.epf-File for Workspace Mechanic contains a line like this:

/instance/org.eclipse.jdt.ui/
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0"
encoding\="UTF-8" standalone\="no"?><templates> ............ </
templates>

When applied, this leads to a line like this in the Eclipse settings
(org.eclipse.jdt.ui.prefs):

org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\\\="1.0"
encoding\\\="UTF-8" standalone\\\="no"?><templates> ............ </
templates>

The problem is, each single (escaping) backslash ist transformed to
triple backslashes. Double backslashes would be transformed to five
backslashes, and so on. This doesn't work.

Original issue reported on code.google.com by konigsb...@gmail.com on 18 Aug 2010 at 3:39

GoogleCodeExporter commented 9 years ago
Rich, sorry I've been away from this for so long. Can you give an example of 
the preference set, and the file exported? (Rather than a partial example?)

Original comment by konigsb...@gmail.com on 14 Feb 2011 at 4:44

GoogleCodeExporter commented 9 years ago
Hi Robert,

yeah, long time. It took me a while to reconstruct the issue myself :)

Let's say I want to set a Code Template for a Java Class body. Start Workspace 
Mechanic preference recording, go to Window Preferences > Java > Code Style > 
Code Templates > Code > Class body. Press Edit... Insert random pattern FOO 
BAR. Press OK and OK again. Stop recording in Workspace Mechanic, insert Title 
and Description and save to file. 

The resulting FooBar.epf looks normal and looks like the one I gave in the bug 
report. I'm trying to attach the zipped FooBar.epf to this comment.

But if you try to apply the recorded preference to Workspace Mechanic, it 
doesn't work. Firstly, the Mechanic complains and wants to repair the setting 
immediately, even when no change has happened inbetween. Secondly, after having 
ostensively repaired the issue, the Class body pattern is empty, no FOO BAR 
anywhere to be seen. The reason why this is so can be found in the following 
settings file in the eclipse workspace: 
.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.ui.prefs. 
There all the single backslashes have been converted to triple ones. This 
doesn't work at all.

Feel free to ask if you need anything more to reproduce the bug.

Cheers,
Richard

Original comment by richb...@gmail.com on 16 Feb 2011 at 4:30

Attachments:

GoogleCodeExporter commented 9 years ago
I will attach a task, which will lead to problems when importing.

As file it looks like the following (when recorded with the preference 
recorder): 
/instance/org.eclipse.team.core/ignore_files=.vlt\ntrue\n
When the task is imported the file within the .metadata of the workspace looks 
like
ignore_files=.vlt\\ntrue\\n
Instead it should look like: ignore_files=.vlt\ntrue\n
This is also the case, if I change that preference manually.

Somehow the escape characters are not handled correctly, when the task is 
applied.
This makes WorkspaceMechanic almost useless for a lot of tasks, since in a lot 
of preferences there are escaping sequences.

Original comment by konra...@gmx.de on 21 Jun 2011 at 9:37

Attachments:

GoogleCodeExporter commented 9 years ago
You can for example call 
StringEscapeUtils.unescapeJava 
(http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/StringEscapeUtil
s.html#unescapeJava%28java.lang.String%29) before calling 
IEclipsePreferences.put (PreferenceReconcilerTask.java, line 294)
That would solve this issue.

Original comment by konra...@gmx.de on 21 Jun 2011 at 9:43

GoogleCodeExporter commented 9 years ago
One additional remark: This seems to apply only to RECONCILE tasks.

Original comment by konra...@gmx.de on 21 Jun 2011 at 12:01

GoogleCodeExporter commented 9 years ago
It seems it is because preferences files are always considered as properties 
ones (by Eclipse, when recording modifications, when reading a LASTMOD task), 
except when reading a RECONCILE task.

Here is a proposal of fix :
https://github.com/bguerin/workspacemechanic/commit/e8ef84970ba881dd7e41d2d0d652
f5f4cf187c42

Original comment by benoit.g...@gmail.com on 4 Mar 2012 at 6:28

GoogleCodeExporter commented 9 years ago
I think this is fixed at head. I've changed the way RECONCILE tasks are parsed.

Original comment by konigsb...@gmail.com on 23 Jun 2012 at 3:47