darxriggs / codenarc-eclipse

CodeNarc integration for Eclipse
http://codenarceclipse.sourceforge.net/
Apache License 2.0
8 stars 3 forks source link

Internal error (NoClassDefFoundError for AssertionRenderer) #3

Closed igorrosenberg closed 11 years ago

igorrosenberg commented 11 years ago

Hello

On Groovy/Grails Tool Suite, Version: 3.1.0.RELEASE, Build Id: 201210061308, I have installed the plugin through http://codenarceclipse.sourceforge.net/eclipse/release

I try to run the plugin on my project's root: Groovy > check code with codenarc I get the popup dialog: "Internal error occurred" , due to a NoClassDefFoundError for AssertionRenderer (trace below)

If I try the plugin on a normal groovy class (for example a Controller), I get no issues. I think the problem cmes from some plugins included by my project. How can I exclude the plugins from codenarc analysis ?

Thanks!

java.lang.NoClassDefFoundError: org/codehaus/groovy/transform/powerassert/AssertionRenderer
    at org.codenarc.source.SourceString.<init>(SourceString.groovy:39)
    at org.codenarc.source.SourceString.<init>(SourceString.groovy)
    at sun.reflect.GeneratedConstructorAccessor138.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
    at org.codenarc.analyzer.StringSourceAnalyzer.<init>(StringSourceAnalyzer.groovy:32)
    at sun.reflect.GeneratedConstructorAccessor137.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
    at org.codenarc.eclipse.jobs.CheckCodeJob.analyzeSource(CheckCodeJob.groovy:89)
    at org.codenarc.eclipse.jobs.CheckCodeJob.this$5$analyzeSource(CheckCodeJob.groovy)
    at org.codenarc.eclipse.jobs.CheckCodeJob$this$5$analyzeSource.callCurrent(Unknown Source)
    at org.codenarc.eclipse.jobs.CheckCodeJob.checkFile(CheckCodeJob.groovy:77)
    at org.codenarc.eclipse.jobs.CheckCodeJob.this$5$checkFile(CheckCodeJob.groovy)
    at org.codenarc.eclipse.jobs.CheckCodeJob$this$5$checkFile.callCurrent(Unknown Source)
    at org.codenarc.eclipse.jobs.CheckCodeJob.checkFiles(CheckCodeJob.groovy:67)
    at org.codenarc.eclipse.jobs.CheckCodeJob.this$5$checkFiles(CheckCodeJob.groovy)
    at org.codenarc.eclipse.jobs.CheckCodeJob$this$5$checkFiles.callCurrent(Unknown Source)
    at org.codenarc.eclipse.jobs.CheckCodeJob.run(CheckCodeJob.groovy:40)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
igorrosenberg commented 11 years ago

Oh... This is the result of an API change in groovy itself... groovy 1.7.8 : org.codehaus.groovy.transform.powerassert.AssertionRenderer groovy 1.8.4 : org.codehaus.groovy.runtime.powerassert.AssertionRenderer Hence the requirement groovy 1.7 for this plugin

Out of curiosity, would it be hard to make the plugin groovy 1.8 compliant?

darxriggs commented 11 years ago

Groovy 1.7/1.8 shouldn't be a problem as long as the "assert" in SourceString.groovy:39 is true.

I am testing the plugin before each release in Eclipse 3.5 - 3.7 and 4.2 with either Groovy 1.7 or 1.8 enabled.

I could reproduce the issue you mentioned with GGTS 3.1.0. If Groovy 1.7 is enabled, the error is: Assertion failed: assert source | "". If Groovy 1.8 is enabled, the error is: java.lang.NoClassDefFoundError: org/codehaus/groovy/transform/powerassert/AssertionRenderer.

darxriggs commented 11 years ago

Some Groovy files in a project may be empty. For example auto-generated ones from Grails plugins like _Install.groovy and _Upgrade.groovy. CodeNarc asserts that the source to be analyzed is not empty. So this part of the plugin's CheckCodeJob.groovy will fail.

GroovyCompilationUnit unit = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(file)
String source = new String(unit.contents)

def analyzer = new StringSourceAnalyzer(source)

Requires a fix from my side.

darxriggs commented 11 years ago

Released version 0.18.1.