{
try
{
+ char[] displayHttpPw = new char[httpPassword == null ? 0
+ : httpPassword.length];
+ Arrays.fill(displayHttpPw, '*');
Cache.debug("CACHE Proxy: setting new Authenticator with httpUser='"
- + httpUser + "' httpPassword='"
- + (proxyAuthPassword == null ? "null"
- : new String(proxyAuthPassword))
- + "'"); // DELETE THIS LINE (password in logs)
+ + httpUser + "' httpPassword='" + displayHttpPw + "'");
Authenticator.setDefault(new Authenticator()
{
@Override
.getString("label.proxy_password_required");
Preferences.openPreferences(Preferences.CONNECTIONS_TAB,
message);
- Preferences.getPreferences().proxyAuthPasswordFocus();
+ Preferences.getInstance().proxyAuthPasswordHighlight(true);
}
else
{
&& getRequestingPort() == Integer
.valueOf(httpPort))
{
- char[] displayHttpPw = new char[httpPassword.length];
- Arrays.fill(displayHttpPw, '*');
Cache.debug(
"AUTHENTICATOR returning PasswordAuthentication(\""
+ httpUser + "\", '"
{
// reset the Authenticator to protect http.proxyUser and
// http.proxyPassword Just In Case
+ /* as noted above, due to bug in java this doesn't work if the sun.net.www.protocol.http.AuthCache
+ * has working credentials. No workaround for Java 11.
+ */
Cache.debug("AUTHENTICATOR setting default Authenticator to null");
Authenticator.setDefault(null);
}
}
}
- public final static int DEBUG = 10;
+ public final static int TRACE = 10;
- public final static int INFO = 20;
+ public final static int DEBUG = 20;
- public final static int WARN = 30;
+ public final static int INFO = 30;
- public final static int ERROR = 40;
+ public final static int WARN = 40;
+
+ public final static int ERROR = 50;
public static boolean println(int level, String message)
{
if (Cache.log == null)
{
- if (level >= ERROR)
+ if (level >= WARN)
System.err.println(message);
- else
+ else if (level >= INFO)
System.out.println(message);
+ // not printing debug or trace messages
return false;
}
- if (level >= WARN)
+ if (level >= ERROR)
+ {
+ Cache.log.error(message);
+ }
+ else if (level >= WARN)
{
Cache.log.warn(message);
}
{
Cache.log.info(message);
}
- else
+ else if (level >= DEBUG)
{
Cache.log.debug(message);
}
+ else
+ {
+ Cache.log.trace(message);
+ }
return true;
}
+ public static void trace(String message)
+ {
+ println(TRACE, message);
+ }
+
public static void debug(String message)
{
println(DEBUG, message);
{
println(ERROR, message);
}
-}
+}
\ No newline at end of file
{
String tempfilename = file.getName();
File tempdir = file.getParentFile();
- Cache.log.trace(
+ Cache.trace(
"BACKUPFILES [file!=null] attempting to create temp file for "
+ tempfilename + " in dir " + tempdir);
temp = File.createTempFile(tempfilename,
TEMP_FILE_EXT + newTempFileSuffix, tempdir);
- Cache.log.debug(
+ Cache.debug(
"BACKUPFILES using temp file " + temp.getAbsolutePath());
}
else
{
- Cache.log.trace(
+ Cache.trace(
"BACKUPFILES [file==null] attempting to create default temp file "
+ DEFAULT_TEMP_FILE + " with extension "
+ TEMP_FILE_EXT);
}
} catch (IOException e)
{
- Cache.log
- .error("Could not create temp file to save to (IOException)");
- Cache.log.error(e.getMessage());
- Cache.log.debug(Cache.getStackTraceString(e));
+ Cache.error("Could not create temp file to save to (IOException)");
+ Cache.error(e.getMessage());
+ Cache.debug(Cache.getStackTraceString(e));
} catch (Exception e)
{
- Cache.log.error("Exception creating temp file for saving");
- Cache.log.debug(Cache.getStackTraceString(e));
+ Cache.error("Exception creating temp file for saving");
+ Cache.debug(Cache.getStackTraceString(e));
}
this.setTempFile(temp);
}
public static void classInit()
{
Cache.initLogger();
- Cache.log.trace("BACKUPFILES classInit");
+ Cache.trace("BACKUPFILES classInit");
boolean e = Cache.getDefault(ENABLED, !Platform.isJS());
setEnabled(e);
- Cache.log.trace("BACKUPFILES " + (e ? "enabled" : "disabled"));
+ Cache.trace("BACKUPFILES " + (e ? "enabled" : "disabled"));
BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
.getSavedBackupEntry();
- Cache.log.trace("BACKUPFILES preset scheme " + bfpe.toString());
+ Cache.trace("BACKUPFILES preset scheme " + bfpe.toString());
setConfirmDelete(bfpe.confirmDelete);
- Cache.log.trace("BACKUPFILES confirm delete " + bfpe.confirmDelete);
+ Cache.trace("BACKUPFILES confirm delete " + bfpe.confirmDelete);
}
public static void setEnabled(boolean flag)
path = this.getTempFile().getCanonicalPath();
} catch (IOException e)
{
- Cache.log.error(
- "IOException when getting Canonical Path of temp file '"
- + this.getTempFile().getName() + "'");
- Cache.log.debug(Cache.getStackTraceString(e));
+ Cache.error("IOException when getting Canonical Path of temp file '"
+ + this.getTempFile().getName() + "'");
+ Cache.debug(Cache.getStackTraceString(e));
}
return path;
}
|| suffix.length() == 0)
{
// nothing to do
- Cache.log.debug("BACKUPFILES rollBackupFiles nothing to do." + ", "
+ Cache.debug("BACKUPFILES rollBackupFiles nothing to do." + ", "
+ "filename: " + (file != null ? file.getName() : "null")
+ ", " + "file exists: " + file.exists() + ", " + "enabled: "
+ enabled + ", " + "max: " + max + ", " + "suffix: '" + suffix
return true;
}
- Cache.log.trace("BACKUPFILES rollBackupFiles starting");
+ Cache.trace("BACKUPFILES rollBackupFiles starting");
String dir = "";
File dirFile;
{
dirFile = file.getParentFile();
dir = dirFile.getCanonicalPath();
- Cache.log.trace("BACKUPFILES dir: " + dir);
+ Cache.trace("BACKUPFILES dir: " + dir);
} catch (Exception e)
{
- Cache.log.error(
- "Could not get canonical path for file '" + file + "'");
- Cache.log.error(e.getMessage());
- Cache.log.debug(Cache.getStackTraceString(e));
+ Cache.error("Could not get canonical path for file '" + file + "'");
+ Cache.error(e.getMessage());
+ Cache.debug(Cache.getStackTraceString(e));
return false;
}
String filename = file.getName();
String basename = filename;
- Cache.log.trace("BACKUPFILES filename is " + filename);
+ Cache.trace("BACKUPFILES filename is " + filename);
boolean ret = true;
// Create/move backups up one
File[] backupFiles = dirFile.listFiles(bff);
int nextIndexNum = 0;
- Cache.log
- .trace("BACKUPFILES backupFiles.length: " + backupFiles.length);
+ Cache.trace("BACKUPFILES backupFiles.length: " + backupFiles.length);
if (backupFiles.length == 0)
{
// No other backup files. Just need to move existing file to backupfile_1
- Cache.log.trace(
+ Cache.trace(
"BACKUPFILES no existing backup files, setting index to 1");
nextIndexNum = 1;
}
if (reverseOrder)
{
// backup style numbering
- Cache.log.trace("BACKUPFILES rolling files in reverse order");
+ Cache.trace("BACKUPFILES rolling files in reverse order");
int tempMax = noMax ? -1 : max;
// noMax == true means no limits
// no "oldest" file to delete
previousFile = backupfile_n;
fileToBeDeleted = null;
- Cache.log.trace("BACKUPFILES No oldest file to delete");
+ Cache.trace("BACKUPFILES No oldest file to delete");
continue;
}
File replacementFile = backupfile_n;
long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
long replacementFileLMT = replacementFile.lastModified();
- Cache.log.trace("BACKUPFILES fileToBeDeleted is "
+ Cache.trace("BACKUPFILES fileToBeDeleted is "
+ fileToBeDeleted.getAbsolutePath());
- Cache.log.trace("BACKUPFILES replacementFile is "
+ Cache.trace("BACKUPFILES replacementFile is "
+ backupfile_n.getAbsolutePath());
try
.format(fileToBeDeletedLMT);
String replacementFileLMTString = sdf
.format(replacementFileLMT);
- Cache.log.warn("WARNING! I am set to delete backupfile "
+ Cache.warn("WARNING! I am set to delete backupfile "
+ fileToBeDeleted.getName()
+ " has modification time "
+ fileToBeDeletedLMTString
boolean delete = confirmNewerDeleteFile(fileToBeDeleted,
replacementFile, true);
- Cache.log.trace("BACKUPFILES "
+ Cache.trace("BACKUPFILES "
+ (delete ? "confirmed" : "not") + " deleting file "
+ fileToBeDeleted.getAbsolutePath()
+ " which is newer than "
}
else
{
- Cache.log.debug("BACKUPFILES moving "
+ Cache.debug("BACKUPFILES moving "
+ fileToBeDeleted.getAbsolutePath() + " to "
+ oldestTempFile.getAbsolutePath());
moveFileToFile(fileToBeDeleted, oldestTempFile);
}
else
{
- Cache.log.debug("BACKUPFILES going to move "
+ Cache.debug("BACKUPFILES going to move "
+ fileToBeDeleted.getAbsolutePath() + " to "
+ oldestTempFile.getAbsolutePath());
moveFileToFile(fileToBeDeleted, oldestTempFile);
} catch (Exception e)
{
- Cache.log.error(
+ Cache.error(
"Error occurred, probably making new temp file for '"
+ fileToBeDeleted.getName() + "'");
- Cache.log.error(Cache.getStackTraceString(e));
+ Cache.error(Cache.getStackTraceString(e));
}
// reset
}
bfsb.append(backupFiles[i].getName());
}
- Cache.log.trace("BACKUPFILES backupFiles: " + bfsb.toString());
+ Cache.trace("BACKUPFILES backupFiles: " + bfsb.toString());
// noMax == true means keep all backup files
if ((!noMax) && bfTreeMap.size() >= max)
{
- Cache.log.trace("BACKUPFILES noMax: " + noMax + ", " + "max: "
+ Cache.trace("BACKUPFILES noMax: " + noMax + ", " + "max: "
+ max + ", " + "bfTreeMap.size(): " + bfTreeMap.size());
// need to delete some files to keep number of backups to designated
// max.
int numToDelete = suffix.indexOf(NUM_PLACEHOLDER) > -1
? bfTreeMap.size() - max + 1
: 0;
- Cache.log.trace("BACKUPFILES numToDelete: " + numToDelete);
+ Cache.trace("BACKUPFILES numToDelete: " + numToDelete);
// the "replacement" file is the latest backup file being kept (it's
// not replacing though)
File replacementFile = numToDelete < backupFiles.length
File fileToBeDeleted = backupFiles[i];
boolean delete = true;
- Cache.log.trace(
- "BACKUPFILES fileToBeDeleted: " + fileToBeDeleted);
+ Cache.trace("BACKUPFILES fileToBeDeleted: " + fileToBeDeleted);
boolean newer = false;
if (replacementFile != null)
String replacementFileLMTString = sdf
.format(replacementFileLMT);
- Cache.log.warn("WARNING! I am set to delete backupfile '"
+ Cache.warn("WARNING! I am set to delete backupfile '"
+ fileToBeDeleted.getName()
+ "' has modification time "
+ fileToBeDeletedLMTString
{
// User has confirmed delete -- no need to add it to the list
fileToBeDeleted.delete();
- Cache.log.debug("BACKUPFILES deleting fileToBeDeleted: "
+ Cache.debug("BACKUPFILES deleting fileToBeDeleted: "
+ fileToBeDeleted);
delete = false;
}
else
{
// keeping file, nothing to do!
- Cache.log.debug("BACKUPFILES keeping fileToBeDeleted: "
+ Cache.debug("BACKUPFILES keeping fileToBeDeleted: "
+ fileToBeDeleted);
}
}
if (delete)
{
addDeleteFile(fileToBeDeleted);
- Cache.log.debug("BACKUPFILES addDeleteFile(fileToBeDeleted): "
+ Cache.debug("BACKUPFILES addDeleteFile(fileToBeDeleted): "
+ fileToBeDeleted);
}
String latestBackupFilename = dir + File.separatorChar
+ BackupFilenameParts.getBackupFilename(nextIndexNum, basename,
suffix, digits);
- Cache.log.trace("BACKUPFILES Moving old file [" + file
+ Cache.trace("BACKUPFILES Moving old file [" + file
+ "] to latestBackupFilename [" + latestBackupFilename + "]");
// using boolean '&' instead of '&&' as don't want moveFileToFile attempt to
// be conditional (short-circuit)
ret = ret & moveFileToFile(file, new File(latestBackupFilename));
- Cache.log.debug(
- "BACKUPFILES moving " + file + " to " + latestBackupFilename
- + " was " + (ret ? "" : "NOT ") + "successful");
+ Cache.debug("BACKUPFILES moving " + file + " to " + latestBackupFilename
+ + " was " + (ret ? "" : "NOT ") + "successful");
if (tidyUp)
{
- Cache.log.debug("BACKUPFILES tidying up files");
+ Cache.debug("BACKUPFILES tidying up files");
tidyUpFiles();
}
saveFile = nextTempFile(ftbd.getName(), ftbd.getParentFile());
} catch (Exception e)
{
- Cache.log.error(
+ Cache.error(
"Error when confirming to keep backup file newer than other backup files.");
e.printStackTrace();
}
for (int i = 0; i < deleteFiles.size(); i++)
{
File fileToDelete = deleteFiles.get(i);
- Cache.log.trace("BACKUPFILES about to delete fileToDelete:"
+ Cache.trace("BACKUPFILES about to delete fileToDelete:"
+ fileToDelete);
fileToDelete.delete();
- Cache.log.warn("deleted '" + fileToDelete.getName() + "'");
+ Cache.warn("deleted '" + fileToDelete.getName() + "'");
}
}
dirFile = file.getParentFile();
} catch (Exception e)
{
- Cache.log.error(
- "Could not get canonical path for file '" + file + "'");
+ Cache.error("Could not get canonical path for file '" + file + "'");
return new TreeMap<>();
}
int pos = deleteFiles.indexOf(fileToBeDeleted);
if (pos > -1)
{
- Cache.log.debug("BACKUPFILES not adding file "
+ Cache.debug("BACKUPFILES not adding file "
+ fileToBeDeleted.getAbsolutePath()
+ " to the delete list (already at index" + pos + ")");
return true;
}
else
{
- Cache.log.debug("BACKUPFILES adding file "
+ Cache.debug("BACKUPFILES adding file "
+ fileToBeDeleted.getAbsolutePath() + " to the delete list");
deleteFiles.add(fileToBeDeleted);
}
try
{
// delete destination file - not usually necessary but Just In Case...
- Cache.log.trace("BACKUPFILES deleting " + newFile.getAbsolutePath());
+ Cache.trace("BACKUPFILES deleting " + newFile.getAbsolutePath());
newFile.delete();
- Cache.log.trace("BACKUPFILES moving " + oldFile.getAbsolutePath()
+ Cache.trace("BACKUPFILES moving " + oldFile.getAbsolutePath()
+ " to " + newFile.getAbsolutePath());
Files.move(oldPath, newPath, StandardCopyOption.REPLACE_EXISTING);
ret = true;
- Cache.log.trace("BACKUPFILES move seems to have succeeded");
+ Cache.trace("BACKUPFILES move seems to have succeeded");
} catch (IOException e)
{
- Cache.log.warn("Could not move file '" + oldPath.toString() + "' to '"
+ Cache.warn("Could not move file '" + oldPath.toString() + "' to '"
+ newPath.toString() + "'");
- Cache.log.error(e.getMessage());
- Cache.log.debug(Cache.getStackTraceString(e));
+ Cache.error(e.getMessage());
+ Cache.debug(Cache.getStackTraceString(e));
ret = false;
} catch (Exception e)
{
- Cache.log.error(e.getMessage());
- Cache.log.debug(Cache.getStackTraceString(e));
+ Cache.error(e.getMessage());
+ Cache.debug(Cache.getStackTraceString(e));
ret = false;
}
return ret;