Ruben Laguna’s blog

Eclipse #201116 contentMergeViewers Discarded

I filled
Bug 201116 – Compare will silently discard additional contentMergeViewers associated with the same file extension a couple of days ago. As Szymon Brandys says eclipse should allow the user to switch between the differente merge viewer available for a given extension. He proposes two solutions:

1) Having a mechanishm inside the compare view to do the switch
2) or having a preference page to do the same

I feel more inclined towards the second solution, as I’m used to change the defautl editor for .xml, etc though the preference page General → Editors → File Associations. Having a similar preference page would fit me. I’m trying to figure out how to integrate a preference page to org.eclipse.compare and send it back to eclipse.org to include it in the next release.

Updating the Java Compare Plugin

I received some comments about my java compare plugin about my plugin ignoring preferences for text font and formatter settings. I didn’t address those at the beginning because I didn’t notice so as soon as I realized that was missing I put my hands at work.

The java formatter settings was easy just modifying the old

final Properties options = new Properties();
final CodeFormatter codeFormatter = ToolFactory	.createCodeFormatter(options);

with


final Map options = JavaCore.getOptions();
final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);

That’s easy. The font issue was also easy, just adding the following snippet to the plugin.xml did the trick:

   <extension
         point="org.eclipse.ui.themes">
      <fontDefinition
            categoryId="org.eclipse.compare.contentmergeviewer.TextMergeViewer"
            defaultsTo="org.eclipse.jdt.internal.ui.compare.JavaMergeViewer"
            id="com.rubenlaguna.eclipse.javacompare.JavaFormattingMergeViewer"
            label="Java compare text font (ignore formatting changes)">
         <description>
            The Java compare text font is used by Java compare/merge tools when the ignore formatting changes plugin is loaded.
         </description>
      </fontDefinition>     
   </extension>

Because JavaFormattingMergeViewer extends JavaMergeViewer whick in turns extends TextMergeViewer the code to manager fonts, etc is already in place it’s just a matter of setting it properly in the plugin.xml.

Avahi and .local Domain Troubleshooting

I got the “avahi-daemon disabled because there is a unicast .local domain” but I have no .local domain so I was a little bit confused.


~$ sudo /etc/init.d/avahi-daemon restart

  • Restarting Avahi mDNS/DNS-SD Daemon: avahi-daemon
  • avahi-daemon disabled because there is a unicast .local domain

After a while I realized that my ISP is playing tricks with the DNS. It will never return a “DNS lookup failed”, it always resolve any dns name you pass to it. If the name is assigned it will return the proper IP but if the name is not assigned it will return the IP of the ISP portal. (Nice trick to get more page hits in their home page).

So in order to make avahi work I changed my dns server to OpenDNS ones. But avahi give me the same “…unicast .local domain” error. Then I found that I have to delete the “/var/run/avahi-daemon/disabled-for-unicast-local” first. Otherwise the “/etc/init.d/avahi-daemon” init script won’t notice that change in DNS.

Hope this helps.

Eclipse Compare. Ignoring Java Formatting Changes Not Only Whitespace.

I met some difficulties dealing with the default eclipse java compare. I got involved on a project where everybody likes to commit code to CVS formatted their way, so comparing between CVS revisions is almost impossible.

So I decided to start investigating about Eclipse plugin development to make a Java Compare Viewer that not only ignores whitespace but also all java formatting changes. The result is the following

*Before *ignore java formatting plugin:
comparebefore.png

After ignore java formatting plugin:

compareafter.png

The plugin honors the text font preferences set in General → Appearance → Colors and fonts → Text Compare → Java compare text font. Also honors the Java Formatter preferences in Java → Code Style → Formatter

You can download the plugin and source code tested in Eclipse 3.3 Europa release from here. (The source code is in src folder inside the .jar)

Or you can use Update Manager:
http://rubenlaguna.com/javacompare/update-site.

findandinstall.png

To activate/deactivate the plugin all you have to do is press the new icon in the java compare view

comparebutton.png

UPDATE: Depending on your current set of plugins this plugin may or may not work. There is an issue in Eclipse when it comes to registering contentMergeViewers, It seems that when you register more that one contentMergeViewer for a particular file extension (in this case the Eclipse JDT registers org.eclipse.jdt.internal.ui.compare.JavaContentViewerCreator and my plugin registers com.rubenlaguna.eclipse.javacompare.JavaContentViewerCreator) then the CompareUIPlugin.registerExtensions() will only record the last one. I’m trying to figure out how can I force my plugin to register last because right now depending on your configuration my plugin can register before JDT and then JDT will override my contentMergeViewer with his own. I have filed a bug report on eclipse bugzilla about this issue

How to Install Trac 0.10.4 and XmlRpcPlugin on a Non-standard Directory Location

First you need setuptools/EasyInstall:

cd $HOME/opt
wget http://peak.telecommunity.com/dist/ez_setup.py
mkdir -p $HOME/opt/easyinstall/lib/python2.4/site-packages
PYTHONPATH=$HOME/opt/easyinstall/lib/python2.4/site-packages python ez_setup.py --prefix=$HOME/opt/easyinstall

Next, trac:

cd $HOME/opt
wget http://ftp.edgewall.com/pub/trac/trac-0.10.4.tar.gz
tar xvzf trac-0.10.4.tar.gz
cd trac-0.10.4
python setup.py install --prefix=$HOME/opt/trac
cd ..
rm -rf trac-0.10.4
cd trac
PYTHONPATH=$HOME/opt/easyinstall/lib/python2.4/site-packages/:$HOME/opt/trac/lib/python2.4/site-packages/  bin/trac-admin $HOME/testtracenv initenv

Then the xmlrpcplugin:

cd $HOME/opt
wget -O xmlrpcplugin.zip  'http://trac-hacks.org/changeset/latest/xmlrpcplugin?old_path=/&filename=xmlrpcplugin&format=zip'
unzip xmlrpcplugin.zip
cd xmlrpcplugin/0.10/
PYTHONPATH=$HOME/opt/easyinstall/lib/python2.4/site-packages/ python setup.py bdist_egg
cp dist/*.egg $HOME/testtracenv/plugins
cat <<EOF >>$HOME/testtracenv/conf/trac
.ini
> [components]
> tracrpc.* = enabled
> EOF


And now you can test your installation:

cd $HOME/opt/trac
PYTHONPATH=$HOME/opt/easyinstall/lib/python2.4/site-packages/:$HOME/opt/trac/lib/python2.4/site-packages/  bin/tracd -p 8080 $HOME/testtracenv

And point your browswer to http://localhost:8080/testtracenv/xmlrpc if it returns a Forbidden: XML_RPC privileges are required to perform this operation then the installation is complete.

forbidden.png

You start using XML_RPC only need to do assign permissions for users using trac-admin, to enable xml_rpc for the anonymous user type this:

PYTHONPATH=$HOME/opt/easyinstall/lib/python2.4/site-packages/:$HOME/opt/trac/lib/python2.4/site-packages/  bin/trac-admin $HOME/testtracenv permission add anonymous XML_RPC

Hope this helps

Eclipse Error Reporting: Exception Stacktrace Details

I’m working with Eclipse 3.2.2 RCP right now and I’m getting an exception that I want to display on screen. I found in the eclipsepedia that we must use ErrorDialog to report errors:

try {
// ...
} catch (InvocationTargetException e) {
  IStatus status = new Status(IStatus.ERROR, Application.ID, 1, "Exception found.", e.getCause());
  ErrorDialog.openError(window.getShell(),"Error while loading file", null,status);						
}

But using this code snippet will only print the e.getLocalizedMessage() in the Details pane of the ErrorDialog. See screenshot

noexceptiondetails.png

If you want to see the full stacktrace of the exception in the Details pane you have to implement your own ErrorDialog. Thus taking ErrorDialog as a base and modifiying it a little bit with the guidance found here I created ExceptionDetailsErrorDialog.java.

Using ExceptionDetailsErrorDialog instead of ErrorDialog shows the following dialog:
exceptiondetails.png

Scripts to Rename Avi Files From TV Shows

If you got a lot of ill-named files like:

$ ls
S01E03.The.Sopranos.S01E03.Denial.Anger.Acceptance.avi
The.Sopranos.1x04.Meadowlands.avi
The.Sopranos.S01E01.The.Sopranos.avi
The.Sopranos.S01E02.46.Long.avi
The.Sopranos.S01E06.Pax.Soprana.avi
The_Sopranos.105.College.avi

that your divx player can’t sort properly and you want to end up with something like:

$ ls
1x01.avi  1x02.avi  1x03.avi  1x04.avi  1x05.avi  1x06.avi  

you can use the following script in this way:

cd /path/to/avi/files
../script.sh|sh

and if you want to do the same thing to srt files then:

cd /path/to/srt/files
../script.sh srt|sh

As an example the script will normalize any of the following patterns S01E03, 103,1×03, or just 03 to 1×03.

The contents of script.sh are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<span class='line'>#!/bin/bash
</span><span class='line'>ext=$1
</span><span class='line'>if [ ! $ext ]; then
</span><span class='line'>  ext="avi"
</span><span class='line'>fi
</span><span class='line'>FILES=`find . -iname "*.$ext" -printf "%p\n"`
</span><span class='line'>IFS="
</span><span class='line'>"
</span><span class='line'>for i in $FILES; do
</span><span class='line'>
</span><span class='line'>dirname=`dirname $i`
</span><span class='line'>g=`echo $i|perl -e '&lt;STDIN> =~ m/S\d?(\d)E(\d+)/i; $1 and  print $1 . "x" . $2'`
</span><span class='line'>
</span><span class='line'>if [ ! $g ]; then
</span><span class='line'>  g=`echo $i|perl -e '&lt;STDIN> =~ m/(\d)x(\d\d)/i; $1 and  print $1 . "x" . $2'`
</span><span class='line'>fi
</span><span class='line'>if [ ! $g ]; then
</span><span class='line'>g=`echo $i|perl -e '&lt;STDIN> =~ m/(\d)(\d\d)/i; $1 and print $1 . "x" . $2;'`
</span><span class='line'>fi
</span><span class='line'>if [ ! $g ]; then
</span><span class='line'>  g=`echo $i|perl -e '&lt;STDIN> =~ m/(\d\d)/i; $1 and print "1x" . $1'`
</span><span class='line'>fi
</span><span class='line'>
</span><span class='line'>if [ $g ]; then
</span><span class='line'> g="$dirname/$g.$ext"
</span><span class='line'> if [[ "$g" != "$i" ]]; then
</span><span class='line'>   echo "if [ ! -e \"$g\" ]; then mv  \"$i\" \"$g\"; fi"
</span><span class='line'> fi
</span><span class='line'>fi
</span><span class='line'>
</span><span class='line'>done</span>

The script is also available as a gist

Java Bug Producing SAAJ0511 Error

I run onto the following exception a couple of days ago:

Caused by: org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create
 or change an object in a way which is incorrect with regard to namespaces.
        at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.checkDOMNSErr
(CoreDocumentImpl.java:2421)

the following log trace was also present in the log file


SEVERE: SAAJ0511: Unable to create envelope from given source

Apparently I run onto a known java bug present in jdk1.5.0_08 up to jdk1.5.0_11. Funny, I downgraded to jdk1.5.0_07.

Cost of Life in Different Countries

I’m moving to Sweden soon and a friend of mine sent me the following link (in Spanish, sorry) about the salaries in different countries. From here, I learnt about Purchasing Power Parity and using the data from the IMF I obtained the PPP ratios from Spain, Sweden and other countries. Using this list you can translate how much worth is your money in other country. For example, roughly we can say that goods you buy in Sweden using 10000€ can be purchased in Spain for only 8058€. Or saying it in another way, if I have 10000€ in Spain I have the same purchasing power than a suede that owns 12409€. Yet another way to say it is that living in Sweden is a 19,41% more expensive than living in Spain.

Now a table with the country ranked by ther PPP ratio and the cost of life of those countries compared to Spain, negative values indicate is cheaper to life there:

Country PPP ratio 10000€ PPP Cost of life compared to Spain
Slovenia 1.30 12,962 € -28.14%
Portugal 1.24 12,383 € -22.42%
Spain 1.01 10,115 € 0.00%
United States 0.98 9,818 € 2.93%
Italy 0.97 9,665 € 4.45%
Greece 0.95 9,546 € 5.63%
Luxembourg 0.95 9,473 € 6.34%
Belgium 0.93 9,252 € 8.53%
Austria 0.92 9,215 € 8.90%
United Kingdom 0.90 8,993 € 11.09%
Finland 0.88 8,756 € 13.43%
Germany 0.87 8,726 € 13.73%
Japan 0.87 8,659 € 14.39%
France 0.86 8,630 € 14.68%
Netherlands 0.86 8,597 € 15.01%
Ireland 0.85 8,537 € 15.60%
Sweden 0.82 8,151 € 19.42%
Norway 0.64 6,355 € 37.17%

Then using the table you can quickly determine the conversion from money in Spain to money in Sweden taking into accunt the Purschasing Power Parity. (€/Spain ppp ratio)*Sweden ppp ratio. So, for 10000 euros in Spain are equivalent to (10000€ euros / 1.011484) * 0.815086 = 8058.31 € in Sweden. So with the same amount of euros in both countries 10000€ you end up with a purchasing power of 10114€ (10000×1.011484) in Spain and a purchasing power of 8150€(10000×0.815086) in Sweden. The same amount of money give you a 19.42% lower purchasing power in Sweden.

This is the table I used to obtain the PPP ratio from the using the IMF data. PPP = GDPppp 2005/GDP 2005

Country GDP 2005 GDPppp 2005 ppp
Austria 305.338 281.357 0.921461
Belgium 372.726 344.842 0.925189
Finland 195.785 171.43 0.875603
France 2127.168 1835.696 0.862977
Germany 2791.737 2436.004 0.872576
Greece 284.226 271.31 0.954557
Ireland 200.769 171.393 0.853683
Italy 1772.769 1713.399 0.96651
Luxembourg 36.621 34.692 0.947325
Netherlands 629.911 541.513 0.859666
Portugal 185.644 229.881 1.238289
Slovenia 34.407 44.597 1.296161
Spain 1127.975 1140.929 1.011484
Japan 4557.116 3946.09 0.865918
Norway 301.735 191.747 0.635481
Sweden 358.481 292.193 0.815086
United Kingdom 2230.608 2006.078 0.899341
United States 12455.83 12229.28 0.981812

Copyright © 2015 - Ruben Laguna - Powered by Octopress