Has anyone used the ant task for Cobertura to exclude annotated java classes? - cobertura

Apparently earlier this year Cobertura added "IgnoreMethodAnnotation" to their latest code base. I've been trying to get this to work, and thanks to the lack of documentation on their site have no idea how to get their ant task to do this. Has anyone used this new feature they added? What I have below runs but the reports all still have the class that is annotated in the report.
Sample of my ant task I've tried:
<cobertura-instrument todir="build/instrumented" ignoreTrivial="true">
<classpath >
<path refid="classpath"/>
</classpath>
<ignoreMethodAnnotation annotationName="ExcludeFromCoverage"/>

Please see documentation for
Ignore Trivial and
Ignore Method Annotation

Related

Give an example of: groovyc --sourcepath

I am unable to get the --sourcepath option of groovyc to work at all. Can someone furnish a trivial example of it actually doing anything?
Ultimately I want to use "groovyc" at the command line with a directory a packaged organized tree of mixed groovy and java source. I don't want to reference each source file explicitly. And I don't want to use an ant or maven task either, on grounds of both principle (hey is there a bug here?) and because the production scenario that I might want to tweak the source in has neither but will have groovy. I know I could use unix find but must I resort to that?!
sourcepath isn't used anymore. It's only there for backwards compatibility and will be removed in the future.
The Groovy documentation is currently rewritten, you can find a snapshot including the documentation for groovyc here: https://dl.dropboxusercontent.com/u/20288797/groovy-documentation/index.html#ThegroovycAntTask-groovyc

How to exclude a package from codenarc?

I am new to Gradle and Codenarc but I found no example showing how to exclude a package from codenarc reports.
For example, I have a groovy application that uses, for instance, the package myapp.main and myapp.legacy
I want all my ruleset applied to myapp.main but none to myapp.legacy.
How can I accomplish that?
There are a couple of places where to look for such information:
The Gradle User Guide, which has a chapter for each plugin.
The Gradle Build Language Reference (specifically the CodeNarc task type).
The samples in the full Gradle distribution.
The Gradle forums.
According to 2., an include or exclude filter should do the trick. For example:
codenarcMain {
exclude "myapp/legacy/**"
}

Groovy and IntelliJ - getting code compiled

I have IntelliJ 12 and some groovy code (along with a pile of java code) in a project.
In intelliJ, i can see class A's import of some groovy code, and i have also included the library that has that code.
However, while the package itself is in one colour (for the import), the actual class being imported is in red, which implies an issue of some sort. Hovering the mouse over it reveals no issue though.
When i run a "make" or a "rebuild project" is where the problems start - i get
Groovyc: unable to resolve class com.blah.blah.blah.A
How can i resolve this?
Currently, my project setup is like so:
Under "Libraries" in (Project Structure -> Project Settings -> Libraries) I have:
the jar file with all the groovy code
the src jar file with all the groovy code
In the "Modules" section i have the - well, i don't know what to call it, the column isn't labelled - the library name from the libraries section associated with the src and class files, and the little "export" button beside it is ticked.
Incidentally, opening the class in intelliJ never shows the source code, which given the source is included struck me as weird.
Is there anything else I should need to do?
I've worked this one out, but if anybody knows why groovy cannot be in the "Resource Patterns" list and wants an upvote, do chime in
Oh, right.
I removed the !?*.groovy entry from the list of, um, entries in the File : Settings -> Compiler -> Resource Patterns thingy.
It doesn't seem to matter if "use external build" is on or off for this, but the !?*.groovy; entry cannot be there.
I wonder if anybody knows why?
I had the same problem and had to Add Framework Support and add Groovy to the project to get round this problem.
I created the project using gradle.
I just got your question in my Google results as I had a similar issue. My problem was that I was able to get the groovy code in my IntelliJ 12 project to compile ok, but it wasn't getting wired in properly when I tried to run unit tests within the IDE.
After some investigation, I uncovered that groovy and logback libraries were all set up in the project to be available in the runtime stage of the Maven build of the project, but that resulted in them not being available in the test stage. To fix this, I ended up manually updating the groovy-all and the logback libraries scope from runtime to provided under File->Project Structure->Modules->Dependencies. This allowed me to both compile and test within the IDE while including the Groovy modules as well as the Java modules.
Perhaps you had something similar going on in your project?
Six years later, I also just got this question near the top of my search results.
In my project my Unable to load class 'groovy.text.SimpleTemplateEngine' problem was actually due to a codenarc issue. I was able to resolve the issue by adding the following to build.gradle:
// codenarc version issue work-around
configurations.codenarc {
resolutionStrategy.eachDependency { DependencyResolveDetails d ->
if (d.requested.group == 'org.codehaus.groovy') {
d.useVersion '2.4.7'
}
}
}

ExcludeFromCodeCoverage Isn't Working in VS2012

I have a class in my code that I don't want showing up in code coverage numbers. I added the [ExcludeFromCodeCoverage] attribute to the class definition like this:
[ExcludeFromCodeCoverage]
public class MyClass { ... }
According to the docs (http://msdn.microsoft.com/en-us/library/system.diagnostics.codeanalysis.excludefromcodecoverageattribute.aspx) this should be all I need, but the class still shows up in code coverage analysis.
I'm using VS2012/.NET 4.5 if that matters.
Any ideas why this wouldn't work?
Here's what was going on, and here's how I fixed it.
I was using a .runsettings file to exclude certain assemblies from being included in code coverage. Seems like whenever you include a .runsettings file, you must include the following configuration:
<Attributes>
<Exclude>
<Attribute>^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
</Exclude>
</Attributes>
It doesn't seem to matter what you have in the .runsettings file - this has to be there for [ExcludeFromCodeCoverage] to work.
FYI see this article for more information on the .runsettings file: http://msdn.microsoft.com/en-us/library/jj159530.aspx
I know the approved answer is good but I wanted to add that if you start your .runsettings file from the one suggested here (https://msdn.microsoft.com/en-us/library/jj159530.aspx) you will have a pretty good base to start with (including the proposed solution here).

groovydoc for local package links

In my groovy file, I have a groovydoc link that looks like:
/**
* This links to {#link MyClassInSamePackage}
*/
def myMethod() {
}
Because the class of myMethod is the same package as MyClassInSamePackage, this should work, but it doesn't generate a link in the docs, rather it surrounds it in <code> tags. I have recently opened https://issues.apache.org/jira/browse/GROOVY-5957, but according to https://issues.apache.org/jira/browse/GROOVY-3745, it looks like this issue should be fixed (I'm using groovy 2.0.5).
Can anyone confirm (or refute) whether or not links in the same package work properly in groovydoc if the full package name is not used?
I'm using Grails 2.2 with Groovy 2.0.5 and I see the same behaviour, except that it seems that GroovyDoc's function of creating #link tags, as well as #see tags is unpredictable and sometimes its working - sometimes it's not.
It could also be a bug within my IDE (IntelliJ IDEA 12.0 Ultimate - 30 Days Trial Version), but if you see this behaviour too, maybe it's some bug within Groovydoc?
Which IDE do you use?

Resources