in geode-core/src/main/java/org/apache/geode/internal/logging/MergeLogFiles.java [369:462]
private static List<String> findPIDs(final Collection<File> files, final PrintWriter output) {
int[] pidTable = new int[files.size()];
int[] pidTableCounter = new int[pidTable.length];
List<String> nickNames = new ArrayList<>();
char fileSeparatorChar = File.separatorChar;
for (File file : files) {
String name = file.getPath();
String slashdotslash = fileSeparatorChar + "." + fileSeparatorChar;
int startIdx = name.lastIndexOf(slashdotslash);
// get rid of the parent directories and any /./ in the path
if (startIdx > 0) {
name = name.substring(startIdx + slashdotslash.length());
}
startIdx = name.lastIndexOf(fileSeparatorChar);
// first see if there's a number at the end of the file's directory name
if (startIdx > 0) {
startIdx--;
char c = name.charAt(startIdx);
if (!('0' <= c && c <= '9')) {
startIdx = 0;
} else {
// see if this is a hydra-generated test directory name, like parReg-0504-161349
int testIdx = startIdx - 1;
while (testIdx > 0 && '0' <= name.charAt(testIdx) && name.charAt(testIdx) <= '9') {
testIdx--;
}
if (testIdx < 1 || name.charAt(testIdx) == '-') {
startIdx = 0;
}
}
}
// if there's no number in the directory name, use the file name
if (startIdx <= 0) {
startIdx = name.length() - 1;
if (startIdx > 6 && name.charAt(startIdx) == 'z' && name.charAt(startIdx - 1) == 'g'
&& name.charAt(startIdx - 2) == '.' && name.charAt(startIdx - 3) == 'g'
&& name.charAt(startIdx - 4) == 'o' && name.charAt(startIdx - 5) == 'l'
&& name.charAt(startIdx - 6) == '.') {
startIdx -= 7;
} else if (startIdx > 3 && name.charAt(startIdx) == 'g' && name.charAt(startIdx - 1) == 'o'
&& name.charAt(startIdx - 2) == 'l' && name.charAt(startIdx - 3) == '.') {
startIdx -= 4;
}
}
// find the string of numbers at the end of the test area and use it as a PID
for (int i = startIdx; i >= 0; i--) {
char c = name.charAt(i);
if (!('0' <= c && c <= '9')) {
if (i < name.length() - 1) { // have a number
// there's a number - assume it's a PID if it's not zero
String PID = name.substring(i + 1, startIdx + 1);
try {
int iPID = Integer.parseInt(PID);
if (iPID > 0) {
int p = 0;
// find the PID in the table of those seen so far, or assign it
// a new slot. increment the number of files for this PID and
// assign a nickname for the file
for (; p < pidTable.length; p++) {
if (pidTable[p] == 0) {
pidTable[p] = iPID;
pidTableCounter[p] = 1;
break;
}
if (pidTable[p] == iPID) {
pidTableCounter[p]++;
break;
}
}
Assert.assertTrue(p < pidTableCounter.length);
nickNames.add(iPID + "-" + pidTableCounter[p]);
output.println("nickname " + iPID + "-" + pidTableCounter[p] + ": " + name);
} else {
nickNames.add(null);
}
} catch (NumberFormatException nfe) {
nickNames.add(null);
}
} else {
nickNames.add(null);
}
break;
}
}
}
return nickNames;
}