NoClassDefFoundError when checkstyle is running - checkstyle

I have written a new checkstyle check as a filescanner. I modeled my junits after the code I found in the checkstyle code. The junits run just fine and everything looks good.
But then, I add the check to my project.
<module name="TreeWalker">
<property name="tabWidth" value="4" />
<module name="com.onuspride.codetools.checkstyles.DuplicateClassNames"/>
</module>
and my ant task
<taskdef resource="checkstyletask.properties">
<classpath refid="classpath" />
</taskdef>
<property name="checkstyle.suppressions.file" value="checkstyle/suppressions.xml" />
<property name="translation.severity" value="error" />
<target name="checkStyle" description="TestTask to evaluate the checkstyle system.">
<checkstyle config="checkstyle/checkstyle_checks.xml">
<fileset dir="${msg.src}" includes="**/*.java" />
<formatter type="plain" />
<formatter type="xml" toFile="${msg.build.jar}/checkstyle_errors.xml" />
<classpath refid="classpath" />
</checkstyle>
</target>
the duplicateclassnames class calls several classes in the same jar. For some reason, when ant runs it, ant finds the check class, but can't find the supporting classes, when they are all in the same jar file. here's what i get in ant
[checkstyle] [class]:0: Got an exception - java.lang.NoClassDefFoundError: com/onuspride/codetools/common/classpath/criteria/ClassNameCriteriaCollector
Im stumped. Ive checkd all the dependencies of my jar, they are all in the classpath, I don't understand how it can find one class file but not another in the same jar. Ive done all my dirty little tricks and I just don't get it.
any ideas?

You can do it like following :
Create plugin project and add your custom checks there.
Make appropriate changes to plugin.xml, checkstyle_packages.xml.
Export the project as Deployable Plug-ins and fragments (Export > Plug-in Developement)
Copy the jar file to Eclipse Plugin folde, so no need to install your custom check .
You can go through this tutorial for reference
To reduce effort, download a Sample Check, the file is here under the name net.sf.eclipsecs.sample
Just replace your source in src folder. Before replacing, refer this 3 files in src/net/sf/eclipsecs/sample/checks/ directory as you will need them in your com/onuspride/codetools/checkstyles/ directory :
checkstyle-metadata.properties
checkstyle-metadata.xml
messages.properties
After replacing the code, make appropriate changes in checkstyle_packages.xml file in src/ directory.
Extending Check is described nicely there.

Related

HxCPP Add Include Paths and Linker Options

I'm trying to use an external C++ library in Haxe. I have an extern class with an #:include meta, but I can't figure out how to add the directory containing some headers to the HxCPP include path, or add linker options to add to the lbrary path and link with the libraries. I assume it will involve using #:buildXml, and I have this:
#:buildXml("
<target id=\"default\">
<cppflag value=\"-I...\" />
<flag value=\"-L...\" />
<lib base="..." />
</target>
")
, but those flags don't show up in the logged g++ command. I can't find any documentation about adding include paths, or any real examples of build XML.

Limiting Checkstyle to certain packages

I have a project with several hundred packages. It's mostly generated code from a conversion from COBOL to inline java so the vast majority of it (~11,000 files) is something I do not want to run checkstyle on. I do have a couple packages in the project that are "real" java that I have added to replace utilities that could not be generated by the code conversion and I do want to run checkstyle on those.
I'm having trouble getting the suppression to work properly.
This is the relevant fragment from the checkstyle.xml:
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">
<!--
Checkstyle configuration that checks the Google coding conventions from Google Java Style
that can be found at https://google.github.io/styleguide/javaguide.html.
Checkstyle is very configurable. Be sure to read the documentation at
http://checkstyle.sf.net (or in your downloaded distribution).
To completely disable a check, just comment it out or delete it from the file.
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
-->
<module name = "Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="SuppressionFilter">
<property name="file" value="${config_loc}/checkstyleSuppress.xml"/>
<property name="optional" value="false"/>
</module>
<module name="TreeWalker">
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format"
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message"
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
</module>
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowEscapesForControlCharacters" value="true"/>
<propert ...
I'm confident that the checkstyleSuppress.xml file is getting read because checkstyle will error out if I add a character to the file name to make it wrong.
The content of checkstyleSuppress.xml is as follows:
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress files="[/\\].+" checks=".*"/>
<suppress checks=".*" files="app[\\/]dbio[\\/].java"/>
<suppress checks=".*" files="app[\\/]dbio[\\/]internal[\\/].java"/>
<suppress checks=".*" files="app[\\/]f17*[\\/].java"/>
<suppress checks=".*" files="app[\\/]f17*[\\/]internal[\\/].java"/>
</suppressions>
What I'm trying to do is suppress all checks for anything in the app.dbio and app.f17* packages. To see if my rules are running I added the first line in the file which I thought would suppress all checks on all files.
None of these filters are suppressing anything. Checkstyle checks all files in all packages (and reports over 400,000 violations, which is a bit too many to wade through for the ones I care about! lol)
Most projects are ground up, so I have previously used checkstyle with no suppression. This is my first attempt to limit the scope of the code review and it's not going as I had hoped. I'm not sure where my issue lies here.
Any suggestions are much appreciated.
I think BeforeExecutionExclusionFileFilter is the thing you are looking for. You can provide regexp(s) which matches packages you want to exclude, they will not be checked.

Logback configuration: factoring out reusable parts

Is there a way to factor out and parameterize repeating parts of Logback XML configuration? I have many different rolling file appenders configured basically the same except for the file names. I use that in conjunction with a bunch of loggers with their 'additivity' turned off so I can redirect different parts of the stack to different files. This adds up to a cumbersome and long configuration file composed of many almost identical segments.
I've used Logback's <include> feature before, but it doesn't address this reuse issue since I can't parameterize the included configuration. I'd expect such a feature to look something akin to:
<include resource="file-appender.xml">
<property name="filePath" value="/where/logs/go" />
<property name="baseLogger" value="com.mycompany.thatpartofthestack" />
</include>
But as far as I understand that's wishful thinking. Is there another way of factoring out Logback's configuration via templates, macros, functions or whatnot?
Try using variable substitution in local and/or context scope.
Perhaps the easiest way is to define variables in some resource file, say logback.properties bundled with each each application. Moreover, each application would carry a logback.xml file importing logback.properties.
<configuration debug="true">
<property resource="logback.properties" />
<!-- set root level as given by the value of the root.level variable -->
<!-- if root.level is undefined default to DEBUG -->
<root level="${root.level:-DEBUG}"/>
</configuration>
If you wish to set the root level to WARN in webapp-A, simply add the following line in logback.properties file bundled with webapp-A.
root.level=WARN
You can bundle logback.xml as a resource in a artifact common to your various applications.

How to make ccnet update multiple projects independently in a single mercurial repo?

I have a central hg repository with multiple subprojects in it. Somewhat like this:
/Hg_central
/subproject-a
/subproject-b
/...
I am trying to set up a cc.net server so that it builds a subproject ONLY if its directory has been updated.
My current problem is once one of the subprojects has been updated and built, the server will not find any modifications for the other subprojects, since mercurial has updated the whole repository. CC.NET will not build the other subprojects, unless another update has been done. I've tried using inclusionFilters without success. I also can't afford to have a seperate WorkingDirectory for each subproject. What am I missing to make this possible?
My ccnet config file is currently like this:
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
<project name="subproject-a">
<workingDirectory>G:\Hg-clone\</workingDirectory>
<triggers>
<intervalTrigger name="continuous" seconds="60" buildCondition="IfModificationExists" initialSeconds="20" />
</triggers>
<sourcecontrol type="filtered">
<inclusionFilters>
<pathFilter>
<pattern>/subproject-a/**/*</pattern>
</pathFilter>
</inclusionFilters>
<sourceControlProvider type="hg" autoGetSource="true" >
<repo>http://myserver/myproject</repo>
<multipleHeadsFail>false</multipleHeadsFail>
</sourceControlProvider>
</sourcecontrol>
<tasks>
<exec>
<executable>mybuild.bat</executable>
</exec>
</tasks>
</project>
<project name="subproject-b">
<workingDirectory>G:\Hg-clone\</workingDirectory>
<triggers>
<intervalTrigger name="continuous" seconds="60" buildCondition="IfModificationExists" initialSeconds="20" />
</triggers>
<sourcecontrol type="filtered">
<inclusionFilters>
<pathFilter>
<pattern>/subproject-b/**/*</pattern>
</pathFilter>
</inclusionFilters>
<sourceControlProvider type="hg" autoGetSource="true" >
<repo>http://myserver/myproject</repo>
<multipleHeadsFail>false</multipleHeadsFail>
</sourceControlProvider>
</sourcecontrol>
<tasks>
<exec>
<executable>mybuild.bat</executable>
</exec>
</tasks>
</project>
</cruisecontrol>
With svn this works like a charm, so i'm a bit surprised mercurial isn't.
Either way, a possible workaround is to define a single project whose purpose is to update source and all other project should have a Project trigger for that project.
HTH

copying a jar file in Apache Ant

I need to copy a jar file from one directory to another when my project is built. Placing the statement:
<copy file="${test.dir}/MyFirstTest.jar" todir="${share.path}"/>
works fine when the project is built alone, but if I clean and build the project I get a warning informing me that the ${test.dir}/ directory hasn't been created yet. If I'm understanding properly I should be able to create a 'target' and specify a dependency for this operation but I'm unsure of what dependency to specify. What series of statements do I need to use to ensure this copy will occur whether I clean and build or just build the project?
Please let me know if any further clarification is needed.
FYI I am using Netbeans 6.8 to build my project.
Assuming you have build, dist and javadoc folders do this in the clean.
<!-- Remove all output generated from this build script -->
<target name="clean" description="Clean project">
<delete dir="${build}" />
<delete dir="${dist}" />
<delete dir="${javadoc}" />
</target>
<!-- Initialize all elements needed for the Build -->
<target name="init">
<!-- Create the time stamp -->
<tstamp />
<!-- Create the build directory structure used by compile
and copy the deployment descriptors into it-->
<mkdir dir="${build}/classes" />
<mkdir dir="${dist}" />
<mkdir dir="${javadoc}" />
</target>
<!-- Write a target such as this -->
<target name="docopy" depends="init" description="do the copy">
<copy file="${test.dir}/MyFirstTest.jar" todir="${dist}"/>
</target>
When you run ant docopy It will run init first and then the docopy task.
You can create other tasks that have a depends="docopy" in it or move the copy file task to the init itself.
If I'm understanding properly I should be able to create a 'target' and specify a dependency for this operation but I'm unsure of what dependency to specify.
Well, either add a dependency to the target that actually creates ${share.path} if that makes sense or introduce a new target to create the directory if it doesn't exists. This is typically done is some kind of init target. Then, add the dependency like this:
<target name="copy-jar" depends="target-a, target-b">
<copy file="${test.dir}/MyFirstTest.jar" todir="${share.path}"/>
</target>
You could also simply try to create the directory before to copy the library:
<mkdir dir="${share.path}" failonerror="false">
<copy file="${test.dir}/MyFirstTest.jar" todir="${share.path}"/>