From: gmungoc Date: Mon, 6 Jul 2020 14:59:53 +0000 (+0100) Subject: JAL-1424 slight tidying of reporting X-Git-Tag: Develop-2_11_2_0-d20201215~24^2~27 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=84e5ae1a30d64a331fb0d3b28422d590e469a4ad;p=jalview.git JAL-1424 slight tidying of reporting --- diff --git a/utils/MessageBundleChecker.java b/utils/MessageBundleChecker.java index c870f6d..5b48226 100644 --- a/utils/MessageBundleChecker.java +++ b/utils/MessageBundleChecker.java @@ -1,3 +1,4 @@ + /* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors @@ -127,8 +128,18 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner */ private void doMain(String srcPath) throws IOException { - System.out.println("Scanning " + srcPath - + " for calls to MessageManager\n"); + System.out.println( + "Scanning " + srcPath + " for calls to MessageManager\n"); + System.out.println("Please note this is not a perfect check:"); + System.out.println( + "- message keys constructed dynamically can't be checked"); + System.out + .println("- message keys passed as variables can't be checked"); + System.out.println( + "- references in commented out code are not filtered out"); + System.out.println( + "Verify 'missing' keys manually by a source code search\n"); + sourcePath = srcPath; loadMessages(); File dir = new File(srcPath); @@ -159,16 +170,16 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner { System.out.println("\nScanned " + javaCount + " source files"); System.out.println( - "Messages.properties has " + messages.size() - + " keys"); + "Messages.properties has " + messages.size() + " keys"); if (!invalidKeys.isEmpty()) { System.out.println("Found " + invalidKeys.size() - + " possibly invalid parameter call" + + " possibly invalid unmatched keys in source code" + (invalidKeys.size() > 1 ? "s" : "")); } - System.out.println("Keys not found, assumed constructed dynamically:"); + System.out.println( + "Keys not found in source code, assumed constructed dynamically:"); int dynamicCount = 0; for (String key : messageKeys) { @@ -182,7 +193,7 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner if (dynamicCount < messageKeys.size()) { System.out.println((messageKeys.size() - dynamicCount) - + " keys not found, possibly unused"); + + " keys not found, possibly unused, or used indirectly (check code manually!)"); for (String key : messageKeys) { if (!isDynamic(key)) @@ -286,9 +297,8 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner */ private void inspectSourceLines(String path, int lineNo, String line) { - String lineNos = String - .format("%d-%d", lineNo, lineNo + bufferSize - - 1); + String lineNos = String.format("%d-%d", lineNo, + lineNo + bufferSize - 1); for (String method : METHODS) { int pos = line.indexOf(method); @@ -328,10 +338,14 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner if (METHOD3 == method) { - System.out.println(String.format("Dynamic key at %s line %s %s", - path.substring(sourcePath.length()), lineNos, line)); String key = messageKey.substring(1, messageKey.length() - 1); - dynamicKeys.add(key); + if (!dynamicKeys.contains(key)) + { + System.out.println(String.format( + "Dynamic key \"" + key + "\" at %s line %s %s", + path.substring(sourcePath.length()), lineNos, line)); + dynamicKeys.add(key); + } continue; } @@ -356,11 +370,12 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner if (!this.messages.containsKey(messageKey)) { - System.out.println(String.format( - "Unmatched key '%s' at line %s of %s", messageKey, lineNos, - path.substring(sourcePath.length()))); if (!invalidKeys.contains(messageKey)) { + // report each key the first time found only + System.out.println(String.format( + "Unmatched key '%s' at line %s of %s", messageKey, + lineNos, path.substring(sourcePath.length()))); invalidKeys.add(messageKey); } } @@ -399,8 +414,8 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner */ int commaPos = key.indexOf(","); int bracePos = key.indexOf(")"); - int endPos = commaPos == -1 ? bracePos : (bracePos == -1 ? commaPos - : Math.min(commaPos, bracePos)); + int endPos = commaPos == -1 ? bracePos + : (bracePos == -1 ? commaPos : Math.min(commaPos, bracePos)); if (endPos == -1 && key.length() > 1 && key.endsWith("\"")) { endPos = key.length(); @@ -417,8 +432,8 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner void loadMessages() throws IOException { messages = new Properties(); - FileReader reader = new FileReader(new File(sourcePath, - "../resources/lang/Messages.properties")); + FileReader reader = new FileReader( + new File(sourcePath, "../resources/lang/Messages.properties")); messages.load(reader); reader.close();