+
/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
*/
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);
{
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)
{
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))
*/
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);
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 (!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);
}
}
*/
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();