New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Cannot override default Checker #3515

Closed
rnveach opened this Issue Oct 25, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@rnveach
Member

rnveach commented Oct 25, 2016

The first thing we define in any configuration file is the top level module, which is usually Checker.

<module name="Checker">

I thought if I changed this to something else, I could override the default Checker and use my own custom class.
Unfortunately, it is not possible to override Checker as the CLI hardcodes Checker as the class to run.
final Checker checker = new Checker();

It was already implied this was possible here, but it is actually not.

If logic is complicated and does not satisfy already configured Checker, create a new Checker and custom Check and do whatever user want.

I think we should get the main module to run from the configuration XML so it can be customized without having to also rewrite the CLI.

Example override configuration:

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="com.company.test.CustomChecker">
</module>

Example override class:

package com.company.test;

import java.io.File;
import java.util.List;

import com.puppycrawl.tools.checkstyle.api.AuditListener;
import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.RootModule;

public class CustomChecker extends AutomaticBean implements RootModule {
    @Override
    public void destroy() {
        // example
    }

    @Override
    public int process(List<File> files) throws CheckstyleException {
        // example
        return 0;
    }

    @Override
    public void addListener(AuditListener listener) {
        // example
    }

    @Override
    public void setModuleClassLoader(ClassLoader moduleClassLoader) {
        // example
    }
}

The main module will also need an interface (or base class) for atleast the following method calls that all main modules will need to implement, as required by the CLI:

  • public int process(List files) throws CheckstyleException
  • public void setModuleClassLoader(ClassLoader moduleClassLoader)
  • public void addListener(AuditListener listener)
  • public void destroy()


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

rnveach added a commit to rnveach/checkstyle that referenced this issue Oct 25, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue Nov 5, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue Nov 5, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue Nov 6, 2016

alexgyori added a commit to alexgyori/checkstyle that referenced this issue Nov 6, 2016

alexgyori added a commit to alexgyori/checkstyle that referenced this issue Nov 6, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue Nov 9, 2016

romani added a commit that referenced this issue Nov 9, 2016

@romani romani added this to the 7.3 milestone Nov 9, 2016

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Nov 9, 2016

Member

fix is merged.

Member

romani commented Nov 9, 2016

fix is merged.

@romani romani closed this Nov 9, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment