Search in sources :

Example 1 with MessageDispatcher

use of com.puppycrawl.tools.checkstyle.api.MessageDispatcher in project checkstyle by checkstyle.

the class TranslationCheck method checkFilesForConsistencyRegardingTheirKeys.

/**
     * Compares th the specified key set with the key sets of the given translation files (arranged
     * in a map). All missing keys are reported.
     * @param fileKeys a Map from translation files to their key sets.
     * @param keysThatMustExist the set of keys to compare with.
     */
private void checkFilesForConsistencyRegardingTheirKeys(SetMultimap<File, String> fileKeys, Set<String> keysThatMustExist) {
    for (File currentFile : fileKeys.keySet()) {
        final MessageDispatcher dispatcher = getMessageDispatcher();
        final String path = currentFile.getPath();
        dispatcher.fireFileStarted(path);
        final Set<String> currentFileKeys = fileKeys.get(currentFile);
        final Set<String> missingKeys = keysThatMustExist.stream().filter(e -> !currentFileKeys.contains(e)).collect(Collectors.toSet());
        if (!missingKeys.isEmpty()) {
            for (Object key : missingKeys) {
                log(0, MSG_KEY, key);
            }
        }
        fireErrors(path);
        dispatcher.fireFileFinished(path);
    }
}
Also used : Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) CommonUtils(com.puppycrawl.tools.checkstyle.utils.CommonUtils) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) HashMultimap(com.google.common.collect.HashMultimap) Locale(java.util.Locale) Closeables(com.google.common.io.Closeables) MessageDispatcher(com.puppycrawl.tools.checkstyle.api.MessageDispatcher) Definitions(com.puppycrawl.tools.checkstyle.Definitions) Properties(java.util.Properties) AbstractFileSetCheck(com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck) Set(java.util.Set) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) SetMultimap(com.google.common.collect.SetMultimap) List(java.util.List) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) Pattern(java.util.regex.Pattern) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) InputStream(java.io.InputStream) MessageDispatcher(com.puppycrawl.tools.checkstyle.api.MessageDispatcher) File(java.io.File)

Example 2 with MessageDispatcher

use of com.puppycrawl.tools.checkstyle.api.MessageDispatcher in project checkstyle by checkstyle.

the class TranslationCheck method logMissingTranslation.

/**
 * Logs that translation file is missing.
 *
 * @param filePath file path.
 * @param fileName file name.
 */
private void logMissingTranslation(String filePath, String fileName) {
    final MessageDispatcher dispatcher = getMessageDispatcher();
    dispatcher.fireFileStarted(filePath);
    log(1, MSG_KEY_MISSING_TRANSLATION_FILE, fileName);
    fireErrors(filePath);
    dispatcher.fireFileFinished(filePath);
}
Also used : MessageDispatcher(com.puppycrawl.tools.checkstyle.api.MessageDispatcher)

Example 3 with MessageDispatcher

use of com.puppycrawl.tools.checkstyle.api.MessageDispatcher in project checkstyle by checkstyle.

the class TranslationCheck method checkFilesForConsistencyRegardingTheirKeys.

/**
 * Compares th the specified key set with the key sets of the given translation files (arranged
 * in a map). All missing keys are reported.
 *
 * @param fileKeys a Map from translation files to their key sets.
 * @param keysThatMustExist the set of keys to compare with.
 */
private void checkFilesForConsistencyRegardingTheirKeys(Map<File, Set<String>> fileKeys, Set<String> keysThatMustExist) {
    for (Entry<File, Set<String>> fileKey : fileKeys.entrySet()) {
        final Set<String> currentFileKeys = fileKey.getValue();
        final Set<String> missingKeys = keysThatMustExist.stream().filter(key -> !currentFileKeys.contains(key)).collect(Collectors.toSet());
        if (!missingKeys.isEmpty()) {
            final MessageDispatcher dispatcher = getMessageDispatcher();
            final String path = fileKey.getKey().getAbsolutePath();
            dispatcher.fireFileStarted(path);
            for (Object key : missingKeys) {
                log(1, MSG_KEY, key);
            }
            fireErrors(path);
            dispatcher.fireFileFinished(path);
        }
    }
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) Locale(java.util.Locale) Map(java.util.Map) MessageDispatcher(com.puppycrawl.tools.checkstyle.api.MessageDispatcher) Violation(com.puppycrawl.tools.checkstyle.api.Violation) Definitions(com.puppycrawl.tools.checkstyle.Definitions) Properties(java.util.Properties) Files(java.nio.file.Files) CommonUtil(com.puppycrawl.tools.checkstyle.utils.CommonUtil) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractFileSetCheck(com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) FileText(com.puppycrawl.tools.checkstyle.api.FileText) GlobalStatefulCheck(com.puppycrawl.tools.checkstyle.GlobalStatefulCheck) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) Pattern(java.util.regex.Pattern) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) InputStream(java.io.InputStream) MessageDispatcher(com.puppycrawl.tools.checkstyle.api.MessageDispatcher) SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) File(java.io.File)

Aggregations

MessageDispatcher (com.puppycrawl.tools.checkstyle.api.MessageDispatcher)3 Definitions (com.puppycrawl.tools.checkstyle.Definitions)2 AbstractFileSetCheck (com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck)2 File (java.io.File)2 InputStream (java.io.InputStream)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Locale (java.util.Locale)2 Optional (java.util.Optional)2 Properties (java.util.Properties)2 Set (java.util.Set)2 SortedSet (java.util.SortedSet)2 TreeSet (java.util.TreeSet)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Collectors (java.util.stream.Collectors)2 Log (org.apache.commons.logging.Log)2 LogFactory (org.apache.commons.logging.LogFactory)2 HashMultimap (com.google.common.collect.HashMultimap)1