extension for checkstyle working

2007-10-03 Thread Michael Fortin

Hi

I've been trying to get a custom checkstyle check to work but I get an 
error that checkstyle can't find my custom check.  I wrote a a script to 
run checkstyle by hand and it works so I know my check is correct.  My 
check is in my local repository and I can see it in the maven log output 
when I turn on debug.  I looked at checkstyles source and it's throwing 
either an InstantiationException or a IllegalAccessException in 
PackageObjectFactory but I can't tell because the stack trace is clipped 
off.  Checkstyle gets it's classloader from it's current thread, could 
it a a security issue?  I followed the directions from mavens site and 
I've seen a few references to using the full class name instead of just 
the abbreviation but with no resolution.  How do I get my custom check 
to work in maven?


Any help would be greatly appreciated.


error
[ERROR] BUILD ERROR
[INFO] --
[INFO] An error has occurred in Checkstyle report generation.

Embedded error: Failed during checkstyle configuration
Unable to instantiate com.monetizeit.checkstyle.BlanklineCheckCheck

...

Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: 
cannot initialize module TreeWalker - Unable to instantiate 
com.monetizeit.checkstyle.BlanklineCheck
   at 
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:165)
   at 
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:209)
   at 
org.apache.maven.plugin.checkstyle.CheckstyleReport.executeCheckstyle(CheckstyleReport.java:723)
   at 
org.apache.maven.plugin.checkstyle.CheckstyleReport.executeReport(CheckstyleReport.java:484)

   ... 20 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: 
Unable to instantiate com.monetizeit.checkstyle.BlanklineCheck
   at 
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:152)
   at 
com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:213)
   at 
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:209)
   at 
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:144)

   ... 23 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: 
Unable to instantiate com.monetizeit.checkstyle.BlanklineCheckCheck
   at 
com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObjectFactory.java:94)
   at 
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:149)

   ... 26 more

thanks

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



problem with custom check in checkstyle plugin

2007-09-11 Thread Michael Fortin
) 

   at 
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:149) 


   ... 26 more
[INFO] 


[INFO] Total time: 33 seconds
[INFO] Finished at: Sat Sep 08 10:06:30 EDT 2007
[INFO] Final Memory: 6M/12M
[INFO] 












maven file:
...
build
   extensions
 extension
   groupIdcom.monetizeit/groupId
   artifactIdcheckstyle/artifactId
   version1.0-SNAPSHOT/version
 /extension
   /extensions
...
reporting
   plugins
 plugin
   groupIdorg.apache.maven.plugins/groupId
   artifactIdmaven-checkstyle-plugin/artifactId
   configuration
 configLocationsrc/main/config/checkstyle.xml/configLocation
 
packageNamesLocationsrc/main/config/checkstyle-packages.xml/packageNamesLocation 


   /configuration
 /plugin
   /plugins
 /reporting
...









checkstyle.xml:
?xml version=1.0 ?
!DOCTYPE module PUBLIC -//Puppy Crawl//DTD Check Configuration 
1.2//EN http://www.puppycrawl.com/dtds/configuration_1_2.dtd;

module name=Checker
 module name=NewlineAtEndOfFile /
 module name=Translation /
 module name=TreeWalker
   property name=cacheFile value=${checkstyle.cache.file} /
   module name=com.monetizeit.checkstyle.BlanklineCheck /
   module name=JavadocType /
   ...
   module name=UpperEll /

 /module
/module











checkstyle-packages.xml
?xml version=1.0 encoding=UTF-8?

!DOCTYPE checkstyle-packages PUBLIC
  -//Puppy Crawl//DTD Package Names 1.0//EN
  http://www.puppycrawl.com/dtds/packages_1_0.dtd;

checkstyle-packages
package name=com.monetizeit 
  package name=checkstyle/
/package
package name=com.puppycrawl.tools.checkstyle
  package name=checks
package name=blocks/
package name=coding/
package name=design/
package name=duplicates/
package name=header/
package name=imports/
package name=indentation/
package name=javadoc/
package name=metrics/
package name=modifier/
package name=naming/
package name=sizes/
package name=whitespace/
  /package
  package name=filters/
/package
/checkstyle-packages








BlankLineCheck.class
package com.monetizeit.checkstyle;

import com.puppycrawl.tools.checkstyle.api.*;

/**
*
* @author Michael Fortin
* @version $Id$
*/
public class BlanklineCheck extends Check
{
   private static final int[] ints = new int[]{
   TokenTypes.LITERAL_CASE,
   TokenTypes.LITERAL_CONTINUE,
   TokenTypes.LITERAL_DO,
   TokenTypes.LITERAL_FOR,
   TokenTypes.LITERAL_IF,
   TokenTypes.LITERAL_RETURN,
   TokenTypes.LITERAL_SWITCH,
   TokenTypes.LITERAL_TRY,
   TokenTypes.LITERAL_WHILE
   };


   public int[] getDefaultTokens()
   {
   return ints;
   }

   @Override
   public int[] getRequiredTokens()
   {
   return getDefaultTokens();
   }

   @Override
   public void visitToken(DetailAST ast)
   {

   switch (ast.getType()) {
   case TokenTypes.LITERAL_CASE:
   startsLine(ast);
   blankLineRequired(ast);
   break;

   case TokenTypes.LITERAL_CONTINUE:
   startsLine(ast);
   blankLineRequired(ast);
   break;

   case TokenTypes.LITERAL_DO:
   startsLine(ast);
   blankLineRequired(ast);
   break;

   case TokenTypes.LITERAL_FOR:
   startsLine(ast);
   blankLineRequired(ast);
   break;

   case TokenTypes.LITERAL_IF:
   startsLine(ast);
   blankLineRequired(ast);
   break;

   case TokenTypes.LITERAL_RETURN:
   startsLine(ast);
   blankLineRequired(ast);
   break;

   case TokenTypes.LITERAL_SWITCH:
   startsLine(ast);
   blankLineRequired(ast);
   break;

   case TokenTypes.LITERAL_TRY:
   startsLine(ast);
   blankLineRequired(ast);
   break;

   case TokenTypes.LITERAL_WHILE:
   startsLine(ast);
   blankLineOptional(ast);
   break;
   }

   log(ast.getLineNo(),ast.getText());
   }


   void startsLine(DetailAST ast) {

   int line = ast.getLineNo();
   DetailAST previous = ast.getPreviousSibling();
   int previousLine = previous.getLineNo();

   if(line == previousLine)
   log(line,Must start the line);
   }

   void blankLineRequired(DetailAST ast) {

   int line = ast.getLineNo();
   DetailAST previous = ast.getPreviousSibling();
   int previousLine = previous.getLineNo();

   if(line == previousLine)
   log(line,Must be preceded by a blank line);
   }

   void blankLineOptional(DetailAST ast) {

   int line = ast.getLineNo();
   DetailAST previous = ast.getPreviousSibling