maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Fiedler" <mfied...@wernervas.com>
Subject RE: MOJO/plugin use of TestNG annocation results in an exception
Date Fri, 20 Jan 2006 20:09:31 GMT
My question is:

Why am I able to find the class using 
         ClassLoader classLoader = this.getClass().getClassLoader();
         classLoader.loadClass("org.testng.annotations.Test");
         getLog().info(org.testng.annotations.Test.class.getName());
[INFO] org.testng.annotations.Test

But getting an exception when TestNG tries to find that same class?

[INFO] Type org.testng.annotations.Test not present
 java.lang.TypeNotPresentException: Type org.testng.annotations.Test not
present


My assumption is that TestNG is not using the same classloader.  I am
next going to dig into the TestNG code, but if someone already knew the
cause I would appreciate their help.  Also, if someone could point me to
the right document, I would also be thankful.

Thank you, Michael


-----Original Message-----
From: Brett Porter [mailto:brett@apache.org] 
Sent: Friday, January 20, 2006 1:31 PM
To: Maven Developers List
Subject: Re: MOJO/plugin use of TestNG annocation results in an
exception

Sorry, I'm not sure I understand the question?

Michael Fiedler wrote:
> Hi,
> 
>  
> 
> I am invoking a TestNG test from within a plugin.  The test class has
a
> java 1.5 language annotation when the exception took place.  Changing
> the test class to a TestNG javadoc tag/annotation allowed the tests to
> run without experiencing an exception.
> 
>  
> 
> I checked to make sure the annotated interface could be found at some
> point.  It was!  It is in the dependent jar - TestNG.
> 
>  
> 
> Anyone experience this before?  Any suggestions?
> 
>  
> 
> Thank you, Michael
> 
>  
> 
>  
> 
> Code:
> 
>  
> 
>         ClassLoader classLoader = this.getClass().getClassLoader();
> 
>         getLog().info(classLoader.getClass().getName());
> 
>  
> 
>         try {
> 
>  
> classLoader.loadClass("org.testng.annotations.Test");
> 
>  
> getLog().info(org.testng.annotations.Test.class.getName());
> 
>         } catch (ClassNotFoundException e1) {
> 
>                                     getLog().error(e1.getMessage());
> 
>                                     e1.printStackTrace();
> 
>                                     throw new
> MojoFailureException(e1.getMessage());
> 
>         }
> 
>  
> 
>  
> 
> Result:
> 
> ...
> 
> [INFO] org.codehaus.classworlds.RealmClassLoader
> 
> [INFO] org.testng.annotations.Test
> 
> ...
> 
>  
> 
>  
> 
>  
> 
> Code:
> 
>                         try {
> 
>                                     getLog().info("testing class
loading
> of 'org.testng.annotations.Test'");
> 
>                                     Class otat =
> Class.forName("org.testng.annotations.Test");
> 
>  
> getLog().info(otat.getClass().getName());
> 
>  
> getLog().info(otat.getCanonicalName());
> 
>                         } catch (ClassNotFoundException e) {
> 
>                                     getLog().error(e.getMessage());
> 
>                                     e.printStackTrace();
> 
>                         }
> 
>  
> 
> ...
> 
>             TestNG testng = new TestNG(xmlSuite);
> 
>             testng.setTestJar(jarFilename);
> 
>             testng.setSourcePath(srcPath.getAbsolutePath() + ";" +
> testPath.getAbsolutePath());
> 
>             testng.setOutputDirectory(metadataDir.getAbsolutePath() +
> "/testNG");
> 
>             testng.setVerbose(1);
> 
>             testng.setGroups("Preferred");
> 
>             testng.run();
> 
>  
> 
>  
> 
> Result:
> 
> [INFO] testing class loading of 'org.testng.annotations.Test'
> 
> [INFO] java.lang.Class
> 
> [INFO] org.testng.annotations.Test
> 
>  
> 
> ===============================================
> 
> Suite of Tests
> 
> Total tests run: 0, Failures: 0, Skips: 0
> 
> ===============================================
> 
>  
> 
> [INFO]
>
------------------------------------------------------------------------
> ----
> 
> [ERROR] FATAL ERROR
> 
> [INFO]
>
------------------------------------------------------------------------
> ----
> 
> [INFO] Type org.testng.annotations.Test not present
> 
> [INFO]
>
------------------------------------------------------------------------
> ----
> 
> [INFO] Trace
> 
> java.lang.TypeNotPresentException: Type org.testng.annotations.Test
not
> present
> 
>         at
>
sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreRef
> lectionFactory.java:98)
> 
>         at
>
sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.jav
> a:107)
> 
>         at
>
sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.j
> ava:31)
> 
>         at
>
sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:3
> 51)
> 
>         at
>
sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser
> .java:175)
> 
>         at
>
sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationPars
> er.java:69)
> 
>         at
>
sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParse
> r.java:52)
> 
>         at
java.lang.reflect.Method.declaredAnnotations(Method.java:676)
> 
>         at
> java.lang.reflect.Method.getDeclaredAnnotations(Method.java:669)
> 
>         at
>
java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java:
> 179)
> 
>         at
>
org.testng.internal.jdk15.JDK15AnnotationFinder.findAnnotation(JDK15Anno
> tationFinder.java:70)
> 
>         at
>
org.testng.internal.jdk15.JDK15AnnotationFinder.findAnnotation(JDK15Anno
> tationFinder.java:92)
> 
>         at
>
org.testng.internal.TestNGClassFinder.isTestNGClass(TestNGClassFinder.ja
> va:158)
> 
>         at
>
org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:49)
> 
>         at org.testng.TestRunner.initMethods(TestRunner.java:256)
> 
>         at org.testng.TestRunner.init(TestRunner.java:192)
> 
>         at org.testng.TestRunner.init(TestRunner.java:164)
> 
>         at org.testng.TestRunner.<init>(TestRunner.java:112)
> 
>         at
>
org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunne
> r.java:325)
> 
>         at org.testng.SuiteRunner.privateRun(SuiteRunner.java:160)
> 
>         at org.testng.SuiteRunner.run(SuiteRunner.java:126)
> 
>         at org.testng.TestNG.run(TestNG.java:292)
> 
>         at com.werner.osc.m2plugin.emma.Unit2.test2(Unit2.java:310)
> 
>         at com.werner.osc.m2plugin.emma.Unit2.execute(Unit2.java:82)
> 
>         at
>
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginMa
> nager.java:432)
> 
>         at
>
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Default
> LifecycleExecutor.java:530)
> 
>         at
>
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoa
> l(DefaultLifecycleExecutor.java:485)
> 
>         at
>
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultL
> ifecycleExecutor.java:455)
> 
>         at
>
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandle
> Failures(DefaultLifecycleExecutor.java:303)
> 
>         at
>
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(
> DefaultLifecycleExecutor.java:270)
> 
>         at
>
org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifec
> ycleExecutor.java:139)
> 
>         at
> org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
> 
>         at
org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
> 
>         at org.apache.maven.cli.MavenCli.main(MavenCli.java:249)
> 
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 
>         at
>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
> a:39)
> 
>         at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
> Impl.java:25)
> 
>         at java.lang.reflect.Method.invoke(Method.java:585)
> 
>         at
> org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
> 
>         at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
> 
>         at
> org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
> 
>         at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
> 
> Caused by: java.lang.ClassNotFoundException:
org.testng.annotations.Test
> 
>         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 java.lang.ClassLoader.loadClass(ClassLoader.java:251)
> 
>         at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
> 
>         at java.lang.Class.forName0(Native Method)
> 
>         at java.lang.Class.forName(Class.java:242)
> 
>         at
>
sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreRef
> lectionFactory.java:95)
> 
>         ... 41 more
> 
>  
> 
>  
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Mime
View raw message