beckje01 / grails-code-coverage

Git Repo of the Grails Code Coverage plugin.
http://grails.org/plugin/code-coverage
16 stars 26 forks source link

Invalid class name exception on db-migration files #38

Open robertoschwald opened 9 years ago

robertoschwald commented 9 years ago

Environment: code-coverage 2.0.3-3 Grails 2.4.4 Fork mode disabled in test

I use database-migration files of name

<date>_purpose.groovy

e.g. 
2015-01-01_justASample.groovy

This leads to coverage errors on all of those files (see below). I'm unable to exclude those files in the config to get rid of the error. Tried with

coverage {
  exclusions = [
    '*201*', // migrations
    '**/20*',
    '**/20*/**'
  ]
}
[java] [cobertura-instrument] Cobertura 2.0.3 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
     [java] [cobertura-instrument] 2015-02-10 14:06:19,181 [main ] WARN  net.sourceforge.cobertura.instrument.CoberturaInstrumenter  - Unable to instrument file /testapp/target/classes/2015-01-09_justASample/z$_run_closure1.class
     [java] [cobertura-instrument] java.lang.IllegalArgumentException: Invalid class name (must be a fully qualified class name in internal form): 2015-01-09_justASample/z$_run_closure1.class
     [java] [cobertura-instrument]  at org.objectweb.asm.util.CheckMethodAdapter.checkInternalName(Unknown Source)
     [java] [cobertura-instrument]  at org.objectweb.asm.util.CheckMethodAdapter.checkInternalName(Unknown Source)
     [java] [cobertura-instrument]  at org.objectweb.asm.util.CheckClassAdapter.visit(Unknown Source)
     [java] [cobertura-instrument]  at org.objectweb.asm.ClassVisitor.visit(Unknown Source)
     [java] [cobertura-instrument]  at net.sourceforge.cobertura.instrument.pass1.DetectDuplicatedCodeClassVisitor.visit(DetectDuplicatedCodeClassVisitor.java:205)
     [java] [cobertura-instrument]  at org.objectweb.asm.ClassReader.accept(Unknown Source)
     [java] [cobertura-instrument]  at org.objectweb.asm.ClassReader.accept(Unknown Source)
     [java] [cobertura-instrument]  at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:153)
     [java] [cobertura-instrument]  at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:121)
     [java] [cobertura-instrument]  at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:234)
     [java] [cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:298)
     [java] [cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:307)
     [java] [cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:399)
     [java] [cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.main(Main.java:421)
beckje01 commented 9 years ago

We use the following exclusions does this work for you?

"changelog*", "2012-*", "load_*", "remove_*", "2013-*", "2014-*", "2015-*" // migrations
robertoschwald commented 9 years ago

No, it doesn't work. Even used your exclusion list in BuildConfig.groovy, but error is the same. db-migration files and changelog.groovy are in the default grails-app/migrations dir.

robertoschwald commented 9 years ago

Now I switched on Grails forked mode for test env (was set to false in grails.project.fork as you've written it is not supported in the coverage plugin for now), and it seems the exclusion works then, but after the unit test, I get:

Using grailsw
Base Directory: /testapp
|Loading Grails 2.4.4
|Configuring classpath
|Downloading: org/grails/plugins/audit-logging/1.0.4.EXP-SNAPSHOT/maven-metadata.xml
.
|Environment set to test
    [mkdir] Created dir: /testapp/target/work/plugin-classes
..
|Compiling 10 source files
  [groovyc] Compiling 10 source files to /testapp/target/work/plugin-build-classes

..
|Compiling 217 source files
  [groovyc] Compiling 217 source files to /testapp/target/work/plugin-classes
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
.    [mkdir] Created dir: /testapp/target/test-classes
.
|Compiling 4 source files
  [groovyc] Compiling 4 source files to /testapp/target/test-classes
.....
|Compiling 1 source files
  [groovyc] Compiling 1 source file to /testapp/target/work/plugin-classes
...    [mkdir] Created dir: /testapp/target/classes
.
|Compiling 318 source files
  [groovyc] Compiling 318 source files to /testapp/target/classes

...........................
|Running without daemon...
objc[10429]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
| Compiling 1 source files
| Compiling 1 source files.
| Compiling 1 source files..
| Compiling 1 source files...
| Compiling 1 source files....
| Compiling 25 source files
| Compiling 25 source files.
| Compiling 25 source files..
| Compiling 25 source files..
| Compiling 25 source files..
| Compiling 25 source files...
| Compiling 25 source files....
| Compiling 25 source files.....
| Instrumenting classes for coverage
| Instrumenting classes for coverage.
| Instrumenting classes for coverage..
| Instrumenting classes for coverage...
INFO: Found ASM 3: /Users/builduser/.grails/wrapper/2.4.4/grails-2.4.4/lib/asm/asm/jars/asm-3.3.1.jar.
      Possibly because grails-core (grails-plugin-databinding) uses it.
      Removing from instrumentation classpath!
| Instrumenting classes for coverage....
| Instrumenting classes for coverage.....
| Compiling 49 source files
| Compiling 49 source files.
| Running 60 unit tests...
| Running 60 unit tests... 1 of 60
...
| Tests PASSED - view reports in /testapp/target/test-reports
Feb 10, 2015 5:05:22 PM net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler loadCoverageData
SEVERE: Cobertura: Error reading from object stream.
java.lang.ClassNotFoundException: net.sourceforge.cobertura.coveragedata.PackageData
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
robertoschwald commented 9 years ago

This is how the test is performed:

grails test-app unit: -echoOut -coverage -nopost --non-interactive --plain-output --stacktrace --verbose

when disabling forked mode, "Invalid class name" error for all migration files reoccurs.