+
/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
*/
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");
+
sourcePath = srcPath;
loadMessages();
File dir = new File(srcPath);
*/
private void reportResults()
{
- System.out.println("\nScanned " + javaCount + " source files");
System.out.println(
- "Messages.properties has " + messages.size()
- + " keys");
+ "\nMessages.properties has " + messages.size() + " keys");
+ System.out.println("Scanned " + javaCount + " source files\n");
+
if (!invalidKeys.isEmpty())
{
System.out.println("Found " + invalidKeys.size()
- + " possibly invalid parameter call"
+ + " possibly invalid unmatched key(s) 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)
{
if (dynamicCount < messageKeys.size())
{
System.out.println((messageKeys.size() - dynamicCount)
- + " keys not found, possibly unused");
+ + " key(s) not found, possibly unused, or used indirectly (check code manually!)");
for (String key : messageKeys)
{
if (!isDynamic(key))
}
}
System.out
- .println("(Run i18nAnt.xml to compare other message bundles)");
+ .println("\nRun i18nAnt.xml to compare other message bundles");
}
/**
* @param lineNo
* @param line
*/
- private void inspectSourceLines(String path, int lineNo, String line)
+ private void inspectSourceLines(String path, int lineNo,
+ final 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);
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;
}
if (!(STRING_PATTERN.matcher(messageKey).matches()))
{
- System.out.println(String.format("Dynamic key at %s line %s %s",
- path.substring(sourcePath.length()), lineNos, line));
+// System.out.println(String.format("Dynamic key at %s line %s %s",
+// path.substring(sourcePath.length()), lineNos, line));
continue;
}
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);
}
}
messageKeys.remove(messageKey);
}
+
+ /*
+ * and a brute force scan for _any_ as yet unseen message key, to catch the
+ * cases where it is in a variable or a condition
+ */
+ if (line.contains("\""))
+ {
+ Iterator<String> it = messageKeys.iterator();
+ while (it.hasNext())
+ {
+ if (line.contains(it.next()))
+ {
+ it.remove(); // remove as 'seen'
+ }
+ }
+ }
}
/**
*/
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();
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();