com.puppycrawl.tools.checkstyle.Definitions Java Examples

The following examples show how to use com.puppycrawl.tools.checkstyle.Definitions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java    From diff-check with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Loads properties from a File.
 * @param file
 *        the properties file
 * @return the properties in file
 * @throws CheckstyleException
 *         when could not load properties file
 */
private static Properties loadProperties(File file)
        throws CheckstyleException {
    final Properties properties = new Properties();

    try (InputStream stream = Files.newInputStream(file.toPath())) {
        properties.load(stream);
    }
    catch (final IOException ex) {
        final LocalizedMessage loadPropertiesExceptionMessage = new LocalizedMessage(1,
                Definitions.CHECKSTYLE_BUNDLE, LOAD_PROPERTIES_EXCEPTION,
                new String[] {file.getAbsolutePath()}, null, Main.class, null);
        throw new CheckstyleException(loadPropertiesExceptionMessage.getMessage(), ex);
    }

    return properties;
}
 
Example #2
Source File: Main.java    From diff-check with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Loops over the files specified checking them for errors. The exit code
 * is the number of errors found in all the files.
 * @param args the command line arguments.
 * @throws IOException if there is a problem with files access
 * @noinspection CallToPrintStackTrace, CallToSystemExit
 **/
public static void main(String... args) throws IOException {
    int errorCounter = 0;
    boolean cliViolations = false;
    // provide proper exit code based on results.
    final int exitWithCliViolation = -1;
    int exitStatus = 0;

    try {
        //parse CLI arguments
        final CommandLine commandLine = parseCli(args);

        // show version and exit if it is requested
        if (commandLine.hasOption(OPTION_V_NAME)) {
            System.out.println("Checkstyle version: "
                    + Main.class.getPackage().getImplementationVersion());
            exitStatus = 0;
        }
        else {
            List<File> filesToProcess = Collections.emptyList();

            if (commandLine.hasOption(OPTION_GIT_DIR_NAME)) {
                filesToProcess = getGitDiffFilesToProcess(getExclusions(commandLine), commandLine);
                if (CollectionUtils.isEmpty(filesToProcess)) {
                    System.out.println("There is no file need to check");
                    return;
                }
            } else {
                filesToProcess = getFilesToProcess(getExclusions(commandLine),
                        commandLine.getArgs());
            }

            // return error if something is wrong in arguments
            final List<String> messages = validateCli(commandLine, filesToProcess);
            cliViolations = !messages.isEmpty();
            if (cliViolations) {
                exitStatus = exitWithCliViolation;
                errorCounter = 1;
                messages.forEach(System.out::println);
            }
            else {
                errorCounter = runCli(commandLine, filesToProcess);
                exitStatus = errorCounter;
            }
        }
    }
    catch (ParseException pex) {
        // something wrong with arguments - print error and manual
        cliViolations = true;
        exitStatus = exitWithCliViolation;
        errorCounter = 1;
        System.out.println(pex.getMessage());
        printUsage();
    }
    catch (CheckstyleException ex) {
        exitStatus = EXIT_WITH_CHECKSTYLE_EXCEPTION_CODE;
        errorCounter = 1;
        ex.printStackTrace();
    }
    finally {
        // return exit code base on validation of Checker
        // two ifs exist till https://github.com/hcoles/pitest/issues/377
        if (errorCounter != 0) {
            if (!cliViolations) {
                final LocalizedMessage errorCounterMessage = new LocalizedMessage(1,
                        Definitions.CHECKSTYLE_BUNDLE, ERROR_COUNTER,
                        new String[] {String.valueOf(errorCounter)}, null, Main.class, null);
                System.out.println(errorCounterMessage.getMessage());
            }
        }
        if (exitStatus != 0) {
            System.exit(exitStatus);
        }
    }
}
 
Example #3
Source File: AssertionsAuditListener.java    From nohttp with Apache License 2.0 4 votes vote down vote up
private void recordLocalizedMessage(String message, String... args) {
	recordMessage(new LocalizedMessage(0, Definitions.CHECKSTYLE_BUNDLE, message,
			args, null, LocalizedMessage.class, null).getMessage());
}
 
Example #4
Source File: AssertionsAuditListener.java    From spring-javaformat with Apache License 2.0 4 votes vote down vote up
private void recordLocalizedMessage(String message, String... args) {
	recordMessage(new LocalizedMessage(0, Definitions.CHECKSTYLE_BUNDLE, message, args, null,
			LocalizedMessage.class, null).getMessage());
}