Skip to content

Commit

Permalink
Issue checkstyle#3110: Bugfix Checker.java removed hardcoded msgs add…
Browse files Browse the repository at this point in the history
…ed new method
  • Loading branch information
MANISH-K-07 committed Mar 16, 2024
1 parent 4ffb2fa commit 25969b7
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/main/java/com/puppycrawl/tools/checkstyle/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ public class Checker extends AbstractAutomaticBean implements MessageDispatcher,
/** The audit event filters. */
private final FilterSet filters = new FilterSet();

/** Message used by finishLocalSetup method. */
private final LocalizedMessage finishLocalSetupMsg = new LocalizedMessage(
Definitions.CHECKSTYLE_BUNDLE, getClass(),
"Checker.finishLocalSetup");

/** The basedir to strip off in file names. */
private String basedir;

Expand Down Expand Up @@ -313,8 +308,8 @@ private void processFiles(List<File> files) throws CheckstyleException {
}

// We need to catch all exceptions to put a reason failure (file name) in exception
throw new CheckstyleException("Exception was thrown while processing "
+ filePath, ex);
throw new CheckstyleException(
getLocalizedMessage("Checker.processFilesException", filePath), ex);
}
catch (Error error) {
if (fileName != null && cacheFile != null) {
Expand Down Expand Up @@ -445,8 +440,7 @@ protected void finishLocalSetup() throws CheckstyleException {

if (moduleFactory == null) {
if (moduleClassLoader == null) {
final String finishLocalSetupMessage = finishLocalSetupMsg.getMessage();
throw new CheckstyleException(finishLocalSetupMessage);
throw new CheckstyleException(getLocalizedMessage("Checker.finishLocalSetup"));
}

final Set<String> packageNames = PackageNamesLoader
Expand Down Expand Up @@ -486,8 +480,9 @@ protected void setupChild(Configuration childConf)
}
}
catch (final CheckstyleException ex) {
throw new CheckstyleException("cannot initialize module " + name
+ " - " + ex.getMessage(), ex);
throw new CheckstyleException(
getLocalizedMessage(
"Checker.setupChildModule", name, (Object)ex.getMessage()), ex);
}
if (child instanceof FileSetCheck) {
final FileSetCheck fsc = (FileSetCheck) child;
Expand All @@ -507,8 +502,8 @@ else if (child instanceof AuditListener) {
addListener(listener);
}
else {
throw new CheckstyleException(name
+ " is not allowed as a child in Checker");
throw new CheckstyleException(
getLocalizedMessage("Checker.setupChildNotAllowed", name));
}
}

Expand Down Expand Up @@ -620,8 +615,8 @@ public final void setModuleClassLoader(ClassLoader moduleClassLoader) {
public void setCharset(String charset)
throws UnsupportedEncodingException {
if (!Charset.isSupported(charset)) {
final String message = "unsupported charset: '" + charset + "'";
throw new UnsupportedEncodingException(message);
throw new UnsupportedEncodingException(
getLocalizedMessage("Checker.setCharset", charset));
}
this.charset = charset;
}
Expand Down Expand Up @@ -653,4 +648,19 @@ public void clearCache() {
}
}

/**
* Extracts localized messages from properties files.
*
* @param messageKey the key pointing to localized message in respective properties file.
* @param args the arguments of message in respective properties file.
* @return a string containing extracted localized message
*/
private String getLocalizedMessage(String messageKey, Object... args) {
final LocalizedMessage localizedMessage = new LocalizedMessage(
Definitions.CHECKSTYLE_BUNDLE, getClass(),
messageKey, args);

return localizedMessage.getMessage();
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Checker.finishLocalSetup=if no custom moduleFactory is set, moduleClassLoader must be specified
Checker.processFilesException=Exception was thrown while processing {0}
Checker.setCharset=unsupported charset: ''{0}''
Checker.setupChildModule=cannot initialize module {0} - {1}
Checker.setupChildNotAllowed={0} is not allowed as a child in Checker
DefaultLogger.addException=Error auditing {0}
DefaultLogger.auditFinished=Audit done.
DefaultLogger.auditStarted=Starting audit...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Checker.finishLocalSetup=wenn kein Brauch moduleFactory eingestellt ist, moduleClassLoader \
muss angegeben werden
Checker.processFilesException=Während der Verarbeitung wurde eine Ausnahme ausgelöst {0}
Checker.setCharset=Nicht unterstützter Zeichensatz: ''{0}''
Checker.setupChildModule=Modul kann nicht initialisiert werden {0} - {1}
Checker.setupChildNotAllowed={0} ist als Kind nicht erlaubt Checker
DefaultLogger.addException=Fehler beim Prüfen von {0}
DefaultLogger.auditFinished=Prüfung beendet.
DefaultLogger.auditStarted=Beginne Prüfung...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Checker.finishLocalSetup=si no hay costumbre moduleFactory Está establecido, \
moduleClassLoader debe ser especificado
Checker.processFilesException=Se lanzó una excepción durante el procesamiento {0}
Checker.setCharset=juego de caracteres no soportado: ''{0}''
Checker.setupChildModule=no se puede inicializar el módulo {0} - {1}
Checker.setupChildNotAllowed={0} No está permitido como niña en Checker
DefaultLogger.addException=Error auditando {0}
DefaultLogger.auditFinished=Auditoría concluida.
DefaultLogger.auditStarted=Comenzando auditoría...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Checker.finishLocalSetup=jos ei ole tapaa moduleFactory on asetettu, moduleClassLoader \
on täsmennettävä
Checker.processFilesException=Poikkeus tehtiin käsittelyn aikana {0}
Checker.setCharset=ei-tuettu merkkisarja: ''{0}''
Checker.setupChildModule=moduulia ei voi alustaa {0} - {1}
Checker.setupChildNotAllowed={0} ei saa lapsena sisään Checker
DefaultLogger.addException=Virhe {0}:n tarkistuksessa
DefaultLogger.auditFinished=Tarkistus valmis.
DefaultLogger.auditStarted=Aloitetaan tarkistus...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Checker.finishLocalSetup=si pas de coutume moduleFactory est réglé, \
moduleClassLoader il faut préciser
Checker.processFilesException=Une exception a été levée lors du traitement {0}
Checker.setCharset=jeu de caractères non pris en charge: ''{0}''
Checker.setupChildModule=impossible d initialiser le module {0} - {1}
Checker.setupChildNotAllowed={0} n'est pas autorisé en tant qu'enfant à Checker
DefaultLogger.addException=Une erreur est survenue {0}
DefaultLogger.auditFinished=Vérification terminée.
DefaultLogger.auditStarted=Début de la vérification...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Checker.finishLocalSetup=習慣がなければ moduleFactory 設定されています, \
moduleClassLoader 指定する必要があります
Checker.processFilesException=処理中に例外がスローされました {0}
Checker.setCharset=サポートされていない文字セット: ''{0}''
Checker.setupChildModule=モジュールを初期化できません {0} - {1}
Checker.setupChildNotAllowed={0} では子供として許可されていません Checker
DefaultLogger.addException={0} を監査中のエラー
DefaultLogger.auditFinished=監査が完了しました。
DefaultLogger.auditStarted=監査を開始しています...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Checker.finishLocalSetup=se não houver costume moduleFactory está definido, \
moduleClassLoader deve ser especificado
Checker.processFilesException=Exceção foi lançada durante o processamento {0}
Checker.setCharset=conjunto de caracteres não suportado: ''{0}''
Checker.setupChildModule=não é possível inicializar o módulo {0} - {1}
Checker.setupChildNotAllowed={0} não é permitido quando criança Checker
DefaultLogger.addException=Erro ao auditar {0}
DefaultLogger.auditFinished=Auditoria completa.
DefaultLogger.auditStarted=Iniciando a auditoria...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Checker.finishLocalSetup=если нет обычая moduleFactory установлен, \
moduleClassLoader должно быть указано
Checker.processFilesException=Исключение возникло при обработке {0}
Checker.setCharset=неподдерживаемая кодировка: ''{0}''
Checker.setupChildModule=не могу инициализировать модуль {0} - {1}
Checker.setupChildNotAllowed={0} не разрешен в качестве вложенного модуля в Checker
DefaultLogger.addException=Ошибка проверки {0}
DefaultLogger.auditFinished=Проверка завершена.
DefaultLogger.auditStarted=Начинаем проверку...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Checker.finishLocalSetup=özel değilse moduleFactory ayarlandı, moduleClassLoader belirtilmeli
Checker.processFilesException=İşlenirken istisna atıldı {0}
Checker.setCharset=desteklenmeyen karakter kümesi: ''{0}''
Checker.setupChildModule=modül başlatılamıyor {0} - {1}
Checker.setupChildNotAllowed={0} çocukken girilmesine izin verilmiyor Checker
DefaultLogger.addException={0} denetlenirken hata oluştu
DefaultLogger.auditFinished=Denetleme tamamlandı.
DefaultLogger.auditStarted=Denetleme başlıyor...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Checker.finishLocalSetup=如果没有定制 moduleFactory 已设置, moduleClassLoader 必须指定
Checker.processFilesException=处理时抛出异常 {0}
Checker.setCharset=不支持的字符集: ''{0}''
Checker.setupChildModule=无法初始化模块 {0} - {1}
Checker.setupChildNotAllowed={0} 不允许作为Checker的子模块
DefaultLogger.addException=检查错误: {0}
DefaultLogger.auditFinished=检查完成。
DefaultLogger.auditStarted=开始检查……
Expand Down

0 comments on commit 25969b7

Please sign in to comment.