/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Prepares new key names for Resources.java.
* 6987827: security/util/Resources.java needs improvement
*
*
* java NewResourcesNames $(
* egrep -q '(ResourcesMgr.getString|rb.getString)' $a && echo $a
* done)
*
* Before running this tool, run the following two commands to make sure there
* are only these 2 types of calls into the resources:
* cat $a | perl -ne 'print if /\bResourcesMgr\b/'; done |
* grep -v ResourcesMgr.getString
* cat $a | perl -ne 'print if /\brb\b/'; done |
* grep -v rb.getString
*/
class NewResourcesNames {
// Max length of normalized names
};
// Load all names inside resources files
// Modify the callers. There are two patterns:
// 1. ResourcesMgr.getString("
// used by most JAAS codes
// 2. rb.getString("
// used by tools
}
// Special case 1: KeyTool's enum definition of commands and options
// Special case 2: PolicyFile called this 4 times
"ResourcesMgr.getString(POLICY+\""));
// During the calls above, you can read sth like:
//
// Working on com/sun/security/auth/PolicyParser.java
// GOOD match is 17
//
// This means a " exists right after getString(. Sometimes you see
//
// Working on sun/security/tools/KeyTool.java
// BAD!! pmatch != match: 212 != 209
// Working on sun/security/provider/PolicyFile.java
// BAD!! pmatch != match: 14 != 10
//
// which is mismatch. There are only two such special cases list above.
// For KeyTool, there are 3 calls for showing help. For PolicyTool, 3
// for name prefixed with POLICY. They are covered in the two special
// cases above.
// Names used but not defined. This is mostly error, except for
// special case 2 above. So it's OK to see 3 entries red here
err("FATAL: Undefined names");
}
}
}
// Names defined but not used. Mostly this is old entries not removed.
// When soemone remove a line of code, he dares not remove the entry
// in case it's also used somewhere else.
}
}
}
}
/**
* Loads the three resources files. Saves names into a Map.
*/
// Name vs Resource
// This is to check that word parsing is identical to Java thinks
throw new Exception("Expected and found do not match");
}
}
}
return allnames;
}
/**
* Special case treat for enums description in KeyTool
*/
int match = 0;
while (true) {
if (s == null) {
break;
}
match++;
if (stage == 1) {
} else {
}
} else {
}
} else {
}
}
return names;
}
/**
* Loads a resources using JRE and returns the names
*/
boolean dup = false;
// Check if normalize() creates dup entries. This is crucial.
dup = true;
}
}
return keys;
}
/**
* Rewrites a file using a pattern. The name string should be right after
* the pattern. Note: pattern ignores whitespaces. Returns names found.
*/
throws Exception {
int match = 0;
// The bare XXX.getString is also matched. Sometimes getString is
// called but does not use literal strings. This is harder to solve.
int pmatch = 0;
// The non-whitespace chars read since, used to check for pattern
int hlen = 0;
while (true) {
if (ch < 0) break;
hlen++;
pmatch++;
}
}
match++;
history = new StringBuilder();
hlen = 0;
// Save a name
// Save things after the second ". Maybe it's an end, maybe
// it's just literal string concatenation.
boolean in = true; // inside name string
while (true) {
if (in) {
if (n == '\\') {
switch (second) {
"I don't know this escape: %s%c",
}
} else if (n == '"') {
in = false;
// Maybe string concat? say bytes until clear
tail = new StringBuilder();
} else {
}
} else {
if (n == '"') { // string concat, in again
in = true;
} else if (n == ',' || n == ')') { // real end
break;
// string concat
} else {
throw new Exception("Not a correct concat");
}
}
}
} else {
}
}
// Check pheadlen > 0. Don't want to mess with rewrite for resources
} else {
}
return names;
}
/**
* Normalize a string. Rules:
*
* 1. If all spacebar return "nSPACE", n is count
* 2. If consisting at least one alphanumeric:
* a. All alphanumeric remain
* b. All others in a row goes to a single ".", even if at head or tail
* 3. Otherwise:
* a. "****\n\n" to "STARNN", special case
* b. the English name if first char in *,.\n():'"
*
* Current observations show there's no dup, Hurray! Otherwise, add more
* special cases.
*/
boolean needDot = false;
// All spacebar case
int n = 0;
for (char c: s.toCharArray()) {
if (c == ' ') n++;
else n = -10000;
}
if (n == 1) return "SPACE";
else if (n > 1) return "" + n + "SPACE";
int dotpos = -1;
for (int i=0; i<s.length(); i++) {
char c = s.charAt(i);
c == '{' || c == '}') {
if (needDot) {
// Rememeber the last dot, we want shorter form nice
// "." only added when an alphanumeric is seen. This makes
// sure sb is empty when there's no alphanumerics at all
}
needDot = false;
} else {
needDot = true;
}
}
// No alphanemeric?
return "STARNN";
}
for (char c: s.toCharArray()) {
switch (c) {
case '*': return "STAR";
case ',': return "COMMA";
case '.': return "PERIOD";
case '\n': return "NEWLINE";
case '(': return "LPARAM";
case ')': return "RPARAM";
case ':': return "COLON";
case '\'': case '"': return "QUOTE";
}
}
}
// tail "." only added when there are alphanumerics
} else {
return res;
}
}
}
}