0

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?

scphantm
  • 4,293
  • 8
  • 43
  • 77
  • **I don't understand how it can find one class file but not another in the same jar** :: can you please tell which class did you find and which you did not, under what jar file. – Denim Datta Aug 27 '13 at 11:47
  • the check class is com.onuspride.codetools.checkstyles.DuplicateClassNames and the class that it can't find is, and they are contained in the same jar. com.onuspride.codetools.common.classpath.criteria.ClassNameCriteriaCollector – scphantm Aug 27 '13 at 14:08

1 Answers1

0

You can do it like following :

  1. Create plugin project and add your custom checks there.
  2. Make appropriate changes to plugin.xml, checkstyle_packages.xml.
  3. Export the project as Deployable Plug-ins and fragments (Export > Plug-in Developement)
  4. 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 :

  1. checkstyle-metadata.properties
  2. checkstyle-metadata.xml
  3. messages.properties

After replacing the code, make appropriate changes in checkstyle_packages.xml file in src/ directory.

Extending Check is described nicely there.

Denim Datta
  • 3,740
  • 3
  • 27
  • 53
  • I'll play with this, but the problem with this suggestion is your assuming I use Eclipse. Vast majority of my code is written with Wordpad or Sublime. – scphantm Aug 27 '13 at 13:55
  • Yup, tried this one out and still didn't work. Again, it doesn't have any trouble finding my check, its having trouble finding the additional classes my check requires. Those additional checks are in the same jar file. – scphantm Aug 27 '13 at 15:46