Increase the maximum number of javadoc warnings when compiling with Ant - eclipse

I recently upgraded my development environment from Java 7 to Java 8, which now finds a large number of previously-undetected javadoc issues.
By default, Ant (invoked via Eclipse Mars) limits its warnings (and I assume errors) to 100:
Is there any parameter to force Ant to display all javadoc warnings instead of limiting to 100?
I attempted to use the -Xmaxwarns 1000 parameter via the compilerarg element, but it appears that the current Ant version in Eclipse Mars (Ant 1.9.4) javadoc task does not support the compilerarg element (it is only supported in the javac task):
<!-- Generate the API documentation. -->
<target name="javadoc" depends="clean" description="Generate the API documentation.">
<!-- Create the build directory structure used by javadoc. -->
<mkdir dir="${build.folder}" />
<mkdir dir="${docs.folder}" />
<!-- Run javadoc. -->
<javadoc destdir="${docs.folder}/api" author="true" version="true" use="true" windowtitle="${documentation.title}">
<compilerarg value="-Xmaxerrs 1000 -Xmaxwarns 1000" />
<classpath>
...
Java 8 javadoc does support these parameters (support was added in Java 7 b100):
C:\>javadoc -X
-Xmaxerrs <number> Set the maximum number of errors to print
-Xmaxwarns <number> Set the maximum number of warnings to print
Provided by standard doclet:
-Xdocrootparent <url> Replaces all appearances of #docRoot followed
by /.. in doc comments with <url>
-Xdoclint Enable recommended checks for problems in javadoc comments
-Xdoclint:(all|none|[-]<group>)
Enable or disable specific checks for problems in javadoc comments,
where <group> is one of accessibility, html, missing, reference, or syntax.
These options are non-standard and subject to change without notice.
Conclusion: It appears that the Ant javadoc task is the limiting factor here, and if it supported the compilerarg flag, it would be possible to adjust the limit on errors and warnings.

As you noted, -Xmaxwarns affects how many warnings the javadoc program outputs.
-Xmaxwarns can be passed to the javadoc program with nested <arg> elements:
<javadoc ...>
<arg value="-Xmaxwarns"/>
<arg value="200"/>
</javadoc>
In my own test case, I was able to increase the reported warnings above 100:
[javadoc] Generating Javadoc
...
[javadoc] 112 warnings

Related

phpcs with VScode - how do I disable the line length warning?

I am working on some legacy code, and VScode is highlighting a lot of lines because of some warnings like Line exceeds 85 characters, contains 91 characters. It's pretty annoying, and I'd like to raise that limit to at least 120 chars, or even disable it completely.
My vertical ruler is already set to 120.
How can I move or remove that limit? I've been looking everywhere but I can't find a a working answer... this is my project's settings.json
{
"editor.wordWrapColumn": 120
}
Edit phpcs settings in VS Code and make sure "PHP Sniffer: Standard" is blank (so that it looks for your custom ruleset file).
Create file "phpcs.xml" in your project root, containing a ruleset like:
<?xml version="1.0"?>
<ruleset name="MyRuleset">
<!-- Scan all files in directory -->
<file>.</file>
<!-- Ignore Composer dependencies -->
<exclude-pattern>vendor/</exclude-pattern>
<!-- Show colors in console -->
<arg value="-colors"/>
<!-- Show sniff codes in all reports -->
<arg value="ns"/>
<!-- Use PSR-12 as a base -->
<rule ref="PSR12"/>
<rule ref="Generic.Files.LineLength.TooLong">
<severity>0</severity>
</rule>
</ruleset>

Checkstyle Error in eclipse: cannot initialize module FilesFilter - Unable to instantiate FilesFilter

I am using checkstyle 5.7
I have written a custom FilesFilter as explained in the checkstyle documentation below,
http://checkstyle.sourceforge.net/writingfilters.html
As suggested in the documentation, I have written a java file and added an entry for it under "Checker" module in my config xml file.
So, this custom filter is supposed to ignore all files containing string "Test" in it's file name.
<module name="com.mycompany.myproject.filters.FilesFilter">
<property name="files" value="Test" />
</module>
Due to this entry in the config file, the check style is not loading in eclipse and gives following error,
cannot initialize module FilesFilter - Unable to instantiate
FilesFilter
Please help.
I think there is no straight solution for this yet. Or may be there is, if you are prepared to invest hours of your time.
Here's what I did as a workaround.
In eclipse, to disable checkstyles for a package (e.g. Test package in my case),
Go to, Project -> Properties -> Checkstyle
On Checkstyle Main tab, there is section "Exclude from checking.." with a set of check boxes.
Select the check box "files from packages:".
Click the "Change.." button in the right hand corner or just double click on "files from packages:"
Select the package you want Checkstyle to ignore. In my case I selected com/myproject/test/ package, and that was it. Checkstyle ignores all files in the test package.
If you are using Checkstyle as an ANT task, you may use excludes option as explained in the following code,
<target name="applyCheckStyle" depends="build" description="--> apply check style to all java files, excluding test package.">
<checkstyle config="${checkstyle.config}">
<fileset dir="${src.dir}" includes="**/*.java" excludes="**/test/**" />
<formatter type="plain" />
<formatter type="xml" toFile="${build.dir}/checkstyle_errors.xml" />
</checkstyle>
</target>
This worked for me :)

#CacheEvict annotation with SpEL works after Eclipse compile, but not after Ant compile

Problem
I have a class which uses Spring #CacheEvict annotations and embedded Spring Expression Language. When I allow this class to be compiled automatically by Eclipse, everything works fine. However, when I compile with an Ant task (either through Eclipse or from the command line), the resulting .class file doesn't work, and throws an Exception which seems like a red herring.
My question: How can I configure the Ant build so it generates working .class artifacts (so other developers can build my project without requiring Eclipse)? The configuration between Eclipse and Ant seem the same, but I must be missing some property somewhere.
Versions
Ant (bundled with Eclipse): org.apache.ant_1.8.3.v20120321-1730
Eclipse: Juno Service Release 1, 20120920-0800
JDK: 1.7.0_17
JUnit: 4.10 (in /lib/ of project)
O/S: Windows 7 64-bit
Spring: 3.2.2
Supporting Files
Because the problem is hard to describe without the project in front of you, I have boiled down my project to the bare minimum files needed to reproduce the issue:
/src/sample/SampleAction.java: Contains the method using the #CacheEvict annotation and SpEL.
package sample;
import org.springframework.cache.annotation.CacheEvict;
public class SampleAction {
#CacheEvict(value = "sampleCache", allEntries = true, condition = "#string.bytes != null")
public void triggerCache(String string) {
System.out.println("triggerCache(" + string + ")");
}
}
/src/sample/SampleActionTest.java: A unit test which works with Eclipse artifacts but fails with Ant artifacts.
package sample;
import org.junit.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations={"application.xml"})
public class SampleActionTest {
#Autowired
private SampleAction sampleAction;
#Test
public void testCacheMethod() {
sampleAction.triggerCache("Definitely not a null string.");
}
}
/src/sample/application.xml: Spring definition file for the caching and the action class.
<cache:annotation-driven />
<bean id="sampleAction" class="sample.SampleAction" />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="sampleCache" />
</set>
</property>
</bean>
/.settings/org.eclipse.jdt.core.prefs: Eclipse compiler settings (1.6 via 1.7.0_17):
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
/build.xml: The Ant build which cleans, compiles, and runs the unit test that fails.
<path id="classpath.main">
<fileset dir="lib" includes="*.jar" />
</path>
<path id="classpath.test">
<path refid="classpath.main" />
<pathelement location="output/classes" />
</path>
<target name="compileFailure" description="Cleans, compiles, and runs a unit test, which fails.">
<delete quiet="true" dir="output/classes" />
<mkdir dir="output/classes" />
<copy tofile="output/classes/sample/application.xml" file="src/sample/application.xml" />
<javac srcdir="src" destdir="output/classes"
classpathref="classpath.main" source="1.6" target="1.6" includeantruntime="false" />
<junit printsummary="yes">
<classpath refid="classpath.test" />
<formatter type="plain" usefile="false"/>
<test name="sample.SampleActionTest" outfile="result" />
</junit>
</target>
/lib/*.jar: Supporting libraries:
com.springsource.org.aopalliance-1.0.0.jar
commons-logging-1.1.3.jar
junit-4.10.jar
spring-aop-3.2.2.jar
spring-beans-3.2.2.jar
spring-context-3.2.2.jar
spring-context-support-3.2.2.jar
spring-core-3.2.2.jar
spring-expression-3.2.2.jar
spring-test-3.2.2.jar
This stub project is also available as a ZIP archive, including supporting JAR files for Spring and JUnit:
Minimal Eclipse Project
Steps to Reproduce
Open the "compilerDebug" project in Eclipse.
Allow Eclipse to automatically build the classes in the "sample" package. Either do a Project Clean/Build or open the Java files, edit the whitespace, and resave them. When compiled with Eclipse, output/classes/sample/SampleAction.class is 911 bytes.
Right-click on the "SampleActionTest" and choose "Run As... JUnit Test". Test passes successfully.
Open the build.xml file in the Ant view. Right-click on the "compileFailure" target and choose "Run As... Ant Build". Test fails with "EL1007E:(pos 0): Field or property 'bytes' cannot be found on null" stack trace. When compiled with Ant, output/classes/sample/SampleAction.class is 694 bytes.
Other Observations
I have tried adding compiler="org.eclipse.jdt.core.JDTCompilerAdapter" to the "javac" task, in order to force Ant to use the Eclipse compiler, but the unit test still fails after this change. SampleAction.class is 696 bytes here.
If I remove the condition from the #CacheEvict annotation, the unit test passes with both compilers.
Setting source/target levels to 1.5 or 1.7 has no effect.
Forcing the Ant task to "run in the same JRE as workspace" has no effect.
Downloading a standalone Ant distribution (1.9.1) and running the Ant build completely isolated from Eclipse has no effect.
Replacing the #CacheEvict annotation with declarative XML configuration (using aspectjtools) has no effect.
Thanks in advance for helping to prevent my inevitable insanity from troubleshooting.
Update
See answer provided below. Ant was not explicitly setting debug mode to true when compiling with javac. SpEL requires the extra debugging information to be included in the class files in order to correctly handle the annotations. Setting debug to true immediately corrected the issue.
<javac debug="true" [...] />
It seems like SpEL need java compiler to set debug information in class file to work. I had a similar problem that resolved after I enabled debugging info to be generated in maven build. Eclipse compiler does this automatically.

What should the contents of emma_ant.properties be?

I've been following this tutorial on 3. Getting Started (ANT), and it says <taskdef resource="emma_ant.properties" classpathref="emma.lib" /> but does not give any reference to the contents of emma_ant.properties. Any ideas?
Other websites such as 3.4. How do I change an EMMA property default setting? also leave things to be desired (and is based on the command prompt and not a digital file). I've found another website Using EMMA with ANT for JUnit test coverage reporting, but again it leaves the properties file to the imagination (doesn't even provide an example file).
Any ideas on how to manipulate the emma_ant.properties to Load and custom tasks for ANT?
but does not give any reference to the contents of emma_ant.properties. Any ideas?
Check for emma.jar & emma_ant.jar which you have placed in the path specified you will find emma_ant.properties
Any ideas on how to manipulate the emma_ant.properties to Load and custom tasks for ANT?
You need not to manipulate the properties file to use the tasks.
To use emma tasks you should
<!-- directory that contains emma.jar and emma_ant.jar -->
<property name="emma.dir" value="${YOUR_BASE_DIR}/lib/emma" />
<!-- Set emma.lib to refer to the list of EMMA jar files -->
<path id="emma.lib">
<fileset dir="${emma.dir}">
<include name="*.jar" />
</fileset>
</path>
and
<!-- Load <emma> custom tasks so that they can be used in ANT -->
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
and you should be able to use emma tasks.
Here are the contents of emma_ant.properties inside emma.jar
# -------------------------------------------------------------
emma: com.vladium.emma.emmaTask
emmajava: com.vladium.emma.emmajavaTask
# -------------------------------------------------------------
# end of file
Also Check out Emma Property Summary if it helps you...

How do I suppress warnings in NAnt when using the solution task?

We have a .NET 1.1 solution that we are compiling using NAnt with a "solution" task.
One of the projects throws multiple warnings for missing XML comments. I know which warnings I need to suppress (from http://bytes.com/topic/net/answers/177026-suppress-missing-xml-comment-warning-during-compile), but I can't see how. The csc task has a configuration element that can be used for this, but I can't see an equivalent for solution.
Is this even possible? How can I do it?
Replace NAnt's <solution> task by NAntContrib's <msbuild> task. You can pass solution files to MSBuild as well as project files and you can pass MSBuild properties like WarningLevel then. Find an example here.
I tend to prefer running an exec task for msbuild. This will suppress all warnings:
<exec program="${msbuild_exe_path}">
<arg line='"${solution_path}"' />
<arg line="/property:WarningLevel=0" />
<!-- SNIP -->
</exec>
More info on warning level settings: http://msdn.microsoft.com/en-us/library/13b90fz7.aspx
Getting msbuild to work on .net 1.1: http://blogs.msdn.com/b/jomo_fisher/archive/2004/11/29/271748.aspx