当前位置: 首页>>代码示例>>Java>>正文


Java AuditListener类代码示例

本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.AuditListener的典型用法代码示例。如果您正苦于以下问题:Java AuditListener类的具体用法?Java AuditListener怎么用?Java AuditListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuditListener类属于com.puppycrawl.tools.checkstyle.api包,在下文中一共展示了AuditListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: realExecute

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
/**
 * Helper implementation to perform execution.
 * @param checkstyleVersion Checkstyle compile version.
 */
private void realExecute(String checkstyleVersion) {
    // Create the root module
    RootModule rootModule = null;
    try {
        rootModule = createRootModule();

        // setup the listeners
        final AuditListener[] listeners = getListeners();
        for (AuditListener element : listeners) {
            rootModule.addListener(element);
        }
        final SeverityLevelCounter warningCounter =
            new SeverityLevelCounter(SeverityLevel.WARNING);
        rootModule.addListener(warningCounter);

        processFiles(rootModule, warningCounter, checkstyleVersion);
    }
    finally {
        destroyRootModule(rootModule);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:26,代码来源:CheckstyleAntTask.java

示例2: fireErrors

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
/**
 * Notify all listeners about the errors in a file.
 *
 * @param fileName the audited file
 * @param errors the audit errors from the file
 */
@Override
public void fireErrors(String fileName, SortedSet<LocalizedMessage> errors) {
    final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
    boolean hasNonFilteredViolations = false;
    for (final LocalizedMessage element : errors) {
        final AuditEvent event = new AuditEvent(this, stripped, element);
        if (filters.accept(event)) {
            hasNonFilteredViolations = true;
            for (final AuditListener listener : listeners) {
                listener.addError(event);
            }
        }
    }
    if (hasNonFilteredViolations && cache != null) {
        cache.remove(fileName);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:Checker.java

示例3: testSetupChildListener

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testSetupChildListener() throws Exception {
    final Checker checker = new Checker();
    final PackageObjectFactory factory = new PackageObjectFactory(
        new HashSet<String>(), Thread.currentThread().getContextClassLoader());
    checker.setModuleFactory(factory);

    final Configuration config = new DefaultConfiguration(
        DebugAuditAdapter.class.getCanonicalName());
    checker.setupChild(config);

    final List<AuditListener> listeners =
        (List<AuditListener>) Whitebox.getInternalState(checker, "listeners");
    assertTrue("Invalid child listener class",
        listeners.get(listeners.size() - 1) instanceof DebugAuditAdapter);

}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:CheckerTest.java

示例4: fireErrors

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
/**
 * Notify all listeners about the errors in a file.
 *
 * @param fileName the audited file
 * @param errors the audit errors from the file
 */
@Override
public void fireErrors(String fileName, SortedSet<LocalizedMessage> errors) {
    final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
    boolean hasNonFilteredViolations = false;
    for (final LocalizedMessage element : errors) {
        final AuditEvent event = new AuditEvent(this, stripped, element);
        if (filters.accept(event)) {
            hasNonFilteredViolations = true;
            for (final AuditListener listener : listeners) {
                listener.addError(event);
            }
        }
    }
    if (hasNonFilteredViolations && cacheFile != null) {
        cacheFile.remove(fileName);
    }
}
 
开发者ID:checkstyle,项目名称:checkstyle,代码行数:24,代码来源:Checker.java

示例5: testSetupChildListener

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testSetupChildListener() throws Exception {
    final Checker checker = new Checker();
    final PackageObjectFactory factory = new PackageObjectFactory(
        new HashSet<>(), Thread.currentThread().getContextClassLoader());
    checker.setModuleFactory(factory);

    final Configuration config = new DefaultConfiguration(
        DebugAuditAdapter.class.getCanonicalName());
    checker.setupChild(config);

    final List<AuditListener> listeners =
        (List<AuditListener>) Whitebox.getInternalState(checker, "listeners");
    assertTrue("Invalid child listener class",
        listeners.get(listeners.size() - 1) instanceof DebugAuditAdapter);
}
 
开发者ID:checkstyle,项目名称:checkstyle,代码行数:18,代码来源:CheckerTest.java

示例6: getListeners

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
/**
 * Return the list of listeners set in this task.
 * @return the list of listeners.
 */
private AuditListener[] getListeners() {
    final int formatterCount = Math.max(1, formatters.size());

    final AuditListener[] listeners = new AuditListener[formatterCount];

    // formatters
    try {
        if (formatters.isEmpty()) {
            final OutputStream debug = new LogOutputStream(this, Project.MSG_DEBUG);
            final OutputStream err = new LogOutputStream(this, Project.MSG_ERR);
            listeners[0] = new DefaultLogger(debug, AutomaticBean.OutputStreamOptions.CLOSE,
                    err, AutomaticBean.OutputStreamOptions.CLOSE);
        }
        else {
            for (int i = 0; i < formatterCount; i++) {
                final Formatter formatter = formatters.get(i);
                listeners[i] = formatter.createListener(this);
            }
        }
    }
    catch (IOException ex) {
        throw new BuildException(String.format(Locale.ROOT, "Unable to create listeners: "
                + "formatters {%s}.", formatters), ex);
    }
    return listeners;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:31,代码来源:CheckstyleAntTask.java

示例7: createListener

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
/**
 * Creates a listener for the formatter.
 * @param task the task running
 * @return a listener
 * @throws IOException if an error occurs
 */
public AuditListener createListener(Task task) throws IOException {
    final AuditListener listener;
    if (type != null
            && E_XML.equals(type.getValue())) {
        listener = createXmlLogger(task);
    }
    else {
        listener = createDefaultLogger(task);
    }
    return listener;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:CheckstyleAntTask.java

示例8: fireAuditStarted

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
/** Notify all listeners about the audit start. */
private void fireAuditStarted() {
    final AuditEvent event = new AuditEvent(this);
    for (final AuditListener listener : listeners) {
        listener.auditStarted(event);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:8,代码来源:Checker.java

示例9: fireAuditFinished

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
/** Notify all listeners about the audit end. */
private void fireAuditFinished() {
    final AuditEvent event = new AuditEvent(this);
    for (final AuditListener listener : listeners) {
        listener.auditFinished(event);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:8,代码来源:Checker.java

示例10: fireFileStarted

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
/**
 * Notify all listeners about the beginning of a file audit.
 *
 * @param fileName
 *            the file to be audited
 */
@Override
public void fireFileStarted(String fileName) {
    final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
    final AuditEvent event = new AuditEvent(this, stripped);
    for (final AuditListener listener : listeners) {
        listener.fileStarted(event);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:15,代码来源:Checker.java

示例11: fireFileFinished

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
/**
 * Notify all listeners about the end of a file audit.
 *
 * @param fileName
 *            the audited file
 */
@Override
public void fireFileFinished(String fileName) {
    final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
    final AuditEvent event = new AuditEvent(this, stripped);
    for (final AuditListener listener : listeners) {
        listener.fileFinished(event);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:15,代码来源:Checker.java

示例12: setup

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
@Before
public void setup() throws CheckstyleException {
    baos = new ByteArrayOutputStream();
    final AuditListener listener = new DefaultLogger(baos, OutputStreamOptions.NONE);

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

    checker = new Checker();
    checker.setModuleClassLoader(Checker.class.getClassLoader());
    checker.configure(configuration);
    checker.addListener(listener);
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:16,代码来源:CheckstyleTest.java

示例13: innerProcess

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
private void innerProcess(@NotNull Review review, @NotNull AuditListener auditListener) {
    List<File> files = review.getFiles(new JavaFilter(), new IOFileTransformer());
    Checker checker = createChecker(auditListener);
    try {
        checker.process(files);
    } catch (CheckstyleException e) {
        throw new ReviewException("Unable to process files with Checkstyle", e);
    }
    checker.destroy();
}
 
开发者ID:TouK,项目名称:sputnik,代码行数:11,代码来源:CheckstyleProcessor.java

示例14: createChecker

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
@NotNull
private Checker createChecker(@NotNull AuditListener auditListener) {
    try {
        Checker checker = new Checker();
        ClassLoader moduleClassLoader = Checker.class.getClassLoader();
        String configurationFile = getConfigurationFilename();
        Properties properties = System.getProperties();// loadProperties(new File(System.getProperty(CHECKSTYLE_PROPERTIES_FILE)));
        checker.setModuleClassLoader(moduleClassLoader);
        checker.configure(ConfigurationLoader.loadConfiguration(configurationFile, new PropertiesExpander(properties)));
        checker.addListener(auditListener);
        return checker;
    } catch (CheckstyleException e) {
        throw new ReviewException("Unable to create Checkstyle checker", e);
    }
}
 
开发者ID:TouK,项目名称:sputnik,代码行数:16,代码来源:CheckstyleProcessor.java

示例15: testCheckstyleTruePositive

import com.puppycrawl.tools.checkstyle.api.AuditListener; //导入依赖的package包/类
/**
 * Test checkstyle for true positive.
 * @throws Exception If something goes wrong
 */
@Test
public void testCheckstyleTruePositive() throws Exception {
    final AuditListener listener = Mockito.mock(AuditListener.class);
    final Collector collector = new ChecksTest.Collector();
    Mockito.doAnswer(collector).when(listener)
        .addError(Mockito.any(AuditEvent.class));
    this.check("/Invalid.java", listener);
    final String[] violations = StringUtils.split(
        IOUtils.toString(
            this.getClass().getResourceAsStream(
                String.format("%s/violations.txt", this.dir)
            )
        ),
        "\n"
    );
    for (final String line : violations) {
        final String[] sectors = StringUtils.split(line, ":");
        final Integer pos = Integer.valueOf(sectors[0]);
        final String needle = sectors[1].trim();
        MatcherAssert.assertThat(
            collector.has(pos, needle),
            Matchers.describedAs(
                String.format(
                    "Line no.%d ('%s') not reported by %s: '%s'",
                    pos,
                    needle,
                    this.dir,
                    collector.summary()
                ),
                Matchers.is(true)
            )
        );
    }
}
 
开发者ID:teamed,项目名称:qulice,代码行数:39,代码来源:ChecksTest.java


注:本文中的com.puppycrawl.tools.checkstyle.api.AuditListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。