protected static Configuration getConfiguration() throws CheckstyleException {
    if (configuration == null) {
      configuration =
          ConfigurationLoader.loadConfiguration(
              XML_NAME, new PropertiesExpander(System.getProperties()));
    }

    return configuration;
  }
Exemplo n.º 2
0
 /**
  * Check one file.
  *
  * @param name The name of the check
  * @param listener The listener
  * @throws Exception If something goes wrong inside
  */
 private void check(final String name, final AuditListener listener) throws Exception {
   final Checker checker = new Checker();
   final InputSource src =
       new InputSource(
           this.getClass().getResourceAsStream(String.format("%s/config.xml", this.dir)));
   checker.setClassLoader(Thread.currentThread().getContextClassLoader());
   checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
   checker.configure(
       ConfigurationLoader.loadConfiguration(src, new PropertiesExpander(new Properties()), true));
   final List<File> files = new ArrayList<File>(0);
   files.add(
       new File(this.getClass().getResource(String.format("%s%s", this.dir, name)).getFile()));
   checker.addListener(listener);
   checker.process(files);
   checker.destroy();
 }
Exemplo n.º 3
0
  @Before
  public void setup() throws CheckstyleException {
    baos = new ByteArrayOutputStream();
    AuditListener listener = new DefaultLogger(baos, false);

    InputSource inputSource =
        new InputSource(
            CheckstyleTest.class.getClassLoader().getResourceAsStream("checkstyle-logging.xml"));
    Configuration configuration =
        ConfigurationLoader.loadConfiguration(
            inputSource, new PropertiesExpander(System.getProperties()), false);

    checker = new Checker();
    checker.setModuleClassLoader(Checker.class.getClassLoader());
    checker.configure(configuration);
    checker.addListener(listener);
  }