Bug 209273 - dev-util/eclipse-sdk-3.4 : junit4 doesn't works due to hamcrest problem
Bug#: 209273 Product:  Gentoo Linux Version: unspecified Platform: AMD64
OS/Version: Linux Status: NEW Severity: major Priority: P2
Resolution:  Assigned To: java@gentoo.org Reported By: mambro87@gmail.com
Component: Java
URL: 
Summary: dev-util/eclipse-sdk-3.4 : junit4 doesn't works due to hamcrest problem
Keywords:  
Status Whiteboard: 
Opened: 2008-02-07 17:30 0000
Description:   Opened: 2008-02-07 17:30 0000
When i try to start a junit4 test in eclipse i get this error:

java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
        at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
        at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        ... 19 more

I've tried to download the official eclipse package from eclipse's website and
unpack it in my home. It works fine. This problem happens only with the eclipse
installation from portage.

This is my eclipse-sdk installation

[I] dev-util/eclipse-sdk
     Available versions:  
        (3.2)   3.2.1-r2
        (3.3)   (~)3.3.1.1
        {branding cairo doc elibc_FreeBSD gnome opengl seamonkey}
     Installed versions:  3.2.1-r2(3.2)(19:08:24 03/02/2008)(cairo gnome opengl
-branding -elibc_FreeBSD -seamonkey)
                          3.3.1.1(3.3)(14:53:43 07/02/2008)(-doc
-elibc_FreeBSD)

This is hamcrest
[I] dev-java/hamcrest-core
     Available versions:  (~)1.1 {elibc_FreeBSD source}
     Installed versions:  1.1(18:23:57 07/02/2008)(-elibc_FreeBSD -source)
     Homepage:            http://code.google.com/p/hamcrest/
     Description:         Library of matchers for building test expressions.

This is my emerge --info

Portage 2.1.3.19 (default-linux/amd64/2007.0/desktop, gcc-4.1.2,
glibc-2.6.1-r0, 2.6.23-gentoo-r6 x86_64)
=================================================================
System uname: 2.6.23-gentoo-r6 x86_64 Intel(R) Core(TM)2 Duo CPU E6750 @
2.66GHz
Timestamp of tree: Thu, 07 Feb 2008 13:30:01 +0000
ccache version 2.4 [enabled]
app-shells/bash:     3.2_p17-r1
dev-java/java-config: 1.3.7, 2.0.33-r1
dev-lang/python:     2.4.4-r6
dev-python/pycrypto: 2.0.1-r6
dev-util/ccache:     2.4-r7
sys-apps/baselayout: 1.12.10-r5
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.61-r1
sys-devel/automake:  1.5, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10
sys-devel/binutils:  2.18-r1
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   1.5.24
virtual/os-headers:  2.6.23-r3
ACCEPT_KEYWORDS="amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config
/usr/kde/3.5/shutdown /usr/share/X11/xkb /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf
/etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/
/etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/terminfo
/etc/texmf/web2c /etc/udev/rules.d"
CXXFLAGS="-march=nocona -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="ccache distlocks metadata-transfer parallel-fetch sandbox sfperms
strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://distfiles.gentoo.org
http://distro.ibiblio.org/pub/linux/distributions/gentoo"
LANG="it_IT@.UTF-8@euro"
LC_ALL="it_IT.UTF-8@euro"
LINGUAS="it"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress
--force --whole-file --delete --delete-after --stats --timeout=180
--exclude=/distfiles --exclude=/local --exclude=/packages
--filter=H_**/files/digest-*"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/portage/local/mambro"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="3dnow 3dnowext X aac aalib acl acpi alsa amd64 audiofile bash-completion
berkdb bitmap-fonts bluetooth bzip2 cairo cddb cdr cli cracklib crypt cups dbus
dri dv dvd dvdr dvdread emboss encode esd evo exif fam fbcon ffmpeg firefox
flac foomaticdb fortran ftp gdbm gif gnome gnutls gphoto2 gpm gstreamer gtk hal
iconv icq imagemagick ipod isdnlog jabber jack java javascript jikes joystick
jpeg kdexdeltas kerberos ldap libcaca libnotify lm_sensors mad mhash midi
mikmod mmx mp3 mpeg mplayer msn mudflap musicbrainz mysql ncurses nls nptl
nptlonly nsplugin offensive ogg openal opengl openmp oss pam pcre pda pdf perl
php plotutils png ppds pppd python qt3support quicktime readline reflection
samba sdl session sox spell spl sse sse2 ssl svg symlink tcpd tetex theora tiff
tk truetype truetype-fonts type1-fonts unicode usb vim-syntax vorbis wxwindows
x264 xine xml xorg xosd xv xvid zlib" ALSA_CARDS="hda-intel"
ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file
hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route
share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias
authn_anon authn_dbm authn_default authn_file authz_dbm authz_default
authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs
dav_lock deflate dir disk_cache env expires ext_filter file_cache filter
headers include info log_config logio mem_cache mime mime_magic negotiation
rewrite setenvif speling status unique_id userdir usertrack vhost_alias"
ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux"
LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses
text" LINGUAS="it" USERLAND="GNU" VIDEO_CARDS="vesa nv nvidia"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LDFLAGS,
PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS


Reproducible: Always

Steps to Reproduce:

------- Comment #1 From Vlastimil Babka (Caster) 2008-02-07 22:05:10 0000 -------
We have junit-4.4 which normally bundles the hamcrest-core classes but ours
doesn't. And the eclipse-sdk build doesn't handle indirect deps well. Also
looked at junit.jar bundled in eclipse sources and there are also no hamcrest
classes, which means they use older version (hamcrest was added only in 4.4).

So in short, it needs to handle this indirect dep. But only Elvanor can know
how :)

------- Comment #2 From mambro 2008-03-02 18:43:51 0000 -------
Someone is working on the problem? There are some tests I can do to give a
hand?

------- Comment #3 From Jean-Noël Rivasseau 2008-03-02 20:10:12 0000 -------
Yes, I handle this bug, and actually I will probably work on this this week

If you want to help, just create a junit4 test and attach it (as I never wrote
junit tests yet). It should save me some time

------- Comment #4 From mambro 2008-03-02 20:28:12 0000 -------
Created an attachment (id=145133) [details]
class to test

------- Comment #5 From mambro 2008-03-02 20:28:44 0000 -------
Created an attachment (id=145135) [details]
test class

------- Comment #6 From mambro 2008-03-02 20:30:28 0000 -------
Remember to add junit4 library to the classpath with right-click on the project
-> Build Path -> Add Libraries -> JUnit4

Thank you

------- Comment #7 From Jean-Noël Rivasseau 2008-03-09 17:52:02 0000 -------
OK, I got to work on this today. Unfortunately I cannot reproduce, with your
test files the test works OK (note that I dont have much experience with JUnit
tests, I just right clicked on the file and chose Run as JUnit test).

This is strange because actually it should fail yes. We use the 4.4 junit
version whereas Eclipse expects 4.3, and for 4.4 we do need the hamcrest
dependency. I know how to fix this bug - only needs a test case to reproduce.
So please try to provide me with some test that actually fail right now (maybe
yours was too simplist so did not require hamcrest) and I'll fix it ASAP.

------- Comment #8 From Jean-Noël Rivasseau 2008-03-09 19:24:39 0000 -------
Can anyone reproduce this bug on x86?? ali_bush maybe?

------- Comment #9 From Alistair Bush 2008-03-11 09:36:27 0000 -------
Works for me

Steps to Reproduce

1) Ok firstly.  Had to reemerge eclipse and its dependencies as eclipse blowing
up.
2) Created project.  Added new class and new unit test.  Copied example into
each respectively.
3) Right click on test, select Run > Run Test.
4) It runs :D

------- Comment #10 From Alistair Bush 2008-03-11 09:37:48 0000 -------
Sorry for bugspam.

Versions of junit are

equery list junit
[ Searching for package 'junit' in all categories among: ]
 * installed packages
[I--] [ ~] dev-java/junit-3.8.2-r1 (0)
[I--] [ ~] dev-java/junit-4.4-r1 (4)

------- Comment #11 From mambro 2008-04-08 15:48:19 0000 -------
I've manually added /usr/share/hamcrest-core/lib/hamcrest-core.jar to the build
path and now it works..

------- Comment #12 From Jean-Noël Rivasseau 2008-04-09 16:23:01 0000 -------
What do you mean, you added hamcrest-core.jar to the build path? You mean the
project build path?

That should still not be needed IMHO. So this is clearly a bug, but
unfortunately I cannot reproduce it.


> I've manually added /usr/share/hamcrest-core/lib/hamcrest-core.jar to the build
> path and now it works..
> 

------- Comment #13 From mambro 2008-04-09 16:33:06 0000 -------
Yes, I mean the project build path.

------- Comment #14 From Jean-Noël Rivasseau 2008-04-09 18:58:56 0000 -------
At LAST I can reproduce the bug. I had an old version of junit-4 laying around,
that actually contained the hamcrest classes embedded.

So now that I can reproduce, I can fix it :)

------- Comment #15 From Markus Kasper 2008-05-16 19:49:39 0000 -------
Hi,
same bug here on x86.
The bug occured on my laptop, but 2 other computers were not infected.
First I build on my laptop and another computer the junit package.
laptop -> /usr/share/junit-4/lib/junit.jar contains no hamcrest
other computer -> /usr/share/junit-4/lib/junit.jar contains hamcrest
( same junit-4 version, junit-4.4-r1 )

So, i checked, that both portage trees were up to date -> exact same ebuild for
junit.

and then, i upgraded sun-jdk of the other computer from 1.6.0.03 to 1.6.0.05
and in junit.jar the hamcrest disappears, and the bug was on this computer,
too.

So the problem is, with sun-jdk 1.6.0.03 hamcrest was integrated in junit.jar,
with sun-jdk 1.6.0.05 there was no integration of hamcrest in junit.jar.

Perhaps this can help you.

------- Comment #16 From Pun 2008-06-11 14:57:58 0000 -------
Same problem on x86. It started with the upgrade to sun-jdk/1.6.0.05 and can be
worked around  by manual adding /usr/share/hamcrest-core/lib/hamcrest-core.jar
to the project build path.

------- Comment #17 From Dror Levin 2008-12-07 20:24:34 0000 -------
Has there been any progress? It's been more than 6 months since you said you'll
fix it now that you can reproduce it, has something changed?
I'm still having this bug on eclipse 3.4.1 with junit 4.5.

------- Comment #18 From Alistair Bush 2008-12-10 09:25:52 0000 -------
(In reply to comment #17)
> Has there been any progress? It's been more than 6 months since you said you'll
> fix it now that you can reproduce it, has something changed?
> I'm still having this bug on eclipse 3.4.1 with junit 4.5.
> 

I think you will find the reason for there being a lack of progress, is the
difficulty of finding the solution.

This is the Workaround that ppl can use.

**********************************************
*************WORKAROUND***********************
**********************************************

Add the jar /usr/share/hamcrest-core/lib/hamcrest-core.jar to your build
classpath for any projects using junit4 tests.

it could also be possible that you need /usr/share/hamcrest/lib/*.jar or other
jars.  In which case adding them as well will work.

------- Comment #19 From Jean-Noël Rivasseau 2008-12-10 09:38:01 0000 -------
Yes, people should use the workaround for now. Due to the way Gentoo currently
packages hamcrest and JUnit, this bug is very hard to fix. At first I thought
we could fix it just by manipulating OSGi manifests, but I mailed the Eclipse
people and it looks like a patch to the Eclipse code is needed - which does not
look easy to write.