clang-format everything, whitespace-only changes

This commit is contained in:
eyedeekay
2024-03-05 16:31:28 -05:00
parent 6ed3aae543
commit f225bbb35e
7 changed files with 80 additions and 64 deletions

View File

@ -88,7 +88,7 @@ public class I2PBrowser extends I2PGenericUnsafeBrowser {
* *
* @since 0.0.16 * @since 0.0.16
*/ */
public I2PBrowser() { } public I2PBrowser() {}
/** /**
* Construct an I2PBrowser class which automatically determines which browser * Construct an I2PBrowser class which automatically determines which browser
@ -96,9 +96,7 @@ public class I2PBrowser extends I2PGenericUnsafeBrowser {
* *
* @since 0.0.18 * @since 0.0.18
*/ */
public I2PBrowser(String browserPath) { public I2PBrowser(String browserPath) { this.BROWSER = browserPath; }
this.BROWSER = browserPath;
}
public void setBrowser(String browserPath) { this.BROWSER = browserPath; } public void setBrowser(String browserPath) { this.BROWSER = browserPath; }
@ -194,7 +192,7 @@ public class I2PBrowser extends I2PGenericUnsafeBrowser {
/** /**
* Stop all running processes managed by the browser manager. * Stop all running processes managed by the browser manager.
* *
* @return true if successful, false if not * @return true if successful, false if not
*/ */
public boolean stop() { public boolean stop() {
@ -285,8 +283,7 @@ public class I2PBrowser extends I2PGenericUnsafeBrowser {
if (useSystray) { if (useSystray) {
Runtime.getRuntime().addShutdownHook(new Thread() { Runtime.getRuntime().addShutdownHook(new Thread() {
@Override @Override
public void run() { public void run() {}
}
}); });
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -61,23 +61,23 @@ public class I2PChromium extends I2PChromiumProfileUnpacker {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
list = Arrays.asList(chromiumPathsWindows()); list = Arrays.asList(chromiumPathsWindows());
getProperties().setProperty("chromium.paths.windows", getProperties().setProperty("chromium.paths.windows",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
list = Arrays.asList(chromiumPathsUnix()); list = Arrays.asList(chromiumPathsUnix());
getProperties().setProperty("chromium.paths.linux", getProperties().setProperty("chromium.paths.linux",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
list = Arrays.asList(chromiumPathsOSX()); list = Arrays.asList(chromiumPathsOSX());
getProperties().setProperty("chromium.paths.osx", getProperties().setProperty("chromium.paths.osx",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
list = Arrays.asList(chromiumBinsWindows()); list = Arrays.asList(chromiumBinsWindows());
getProperties().setProperty("chromium.bins.windows", getProperties().setProperty("chromium.bins.windows",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
list = Arrays.asList(chromiumBinsUnix()); list = Arrays.asList(chromiumBinsUnix());
getProperties().setProperty("chromium.bins.linux", getProperties().setProperty("chromium.bins.linux",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
list = Arrays.asList(chromiumBinsUnix()); list = Arrays.asList(chromiumBinsUnix());
getProperties().setProperty("chromium.bins.osx", getProperties().setProperty("chromium.bins.osx",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
try (OutputStream fos = new FileOutputStream( try (OutputStream fos = new FileOutputStream(
new File(runtimeDirectory(""), "browser.config"))) { new File(runtimeDirectory(""), "browser.config"))) {
getProperties().store(fos, "Chromium Configuration Section"); getProperties().store(fos, "Chromium Configuration Section");
@ -87,7 +87,8 @@ public class I2PChromium extends I2PChromiumProfileUnpacker {
} }
private String[] chromiumPathsUnix() { private String[] chromiumPathsUnix() {
String chromiumPathsProp = getProperties().getProperty("chromium.paths.unix"); String chromiumPathsProp =
getProperties().getProperty("chromium.paths.unix");
if (chromiumPathsProp != null) if (chromiumPathsProp != null)
if (!chromiumPathsProp.equals("")) if (!chromiumPathsProp.equals(""))
return chromiumPathsProp.split(","); return chromiumPathsProp.split(",");
@ -126,7 +127,8 @@ public class I2PChromium extends I2PChromiumProfileUnpacker {
return exePath; return exePath;
} }
private String[] chromiumPathsOSX() { private String[] chromiumPathsOSX() {
String chromiumPathsProp = getProperties().getProperty("chromium.paths.osx"); String chromiumPathsProp =
getProperties().getProperty("chromium.paths.osx");
if (chromiumPathsProp != null) if (chromiumPathsProp != null)
if (!chromiumPathsProp.equals("")) if (!chromiumPathsProp.equals(""))
return chromiumPathsProp.split(","); return chromiumPathsProp.split(",");
@ -149,7 +151,8 @@ public class I2PChromium extends I2PChromiumProfileUnpacker {
} }
private String[] chromiumPathsWindows() { private String[] chromiumPathsWindows() {
String chromiumPathsProp = getProperties().getProperty("chromium.paths.windows"); String chromiumPathsProp =
getProperties().getProperty("chromium.paths.windows");
if (chromiumPathsProp != null) if (chromiumPathsProp != null)
if (!chromiumPathsProp.equals("")) if (!chromiumPathsProp.equals(""))
return chromiumPathsProp.split(","); return chromiumPathsProp.split(",");
@ -182,7 +185,8 @@ public class I2PChromium extends I2PChromiumProfileUnpacker {
}; };
} }
private String[] chromiumBinsWindows() { private String[] chromiumBinsWindows() {
String chromiumPathsProp = getProperties().getProperty("chromium.bins.windows"); String chromiumPathsProp =
getProperties().getProperty("chromium.bins.windows");
if (chromiumPathsProp != null) if (chromiumPathsProp != null)
if (!chromiumPathsProp.equals("")) if (!chromiumPathsProp.equals(""))
return chromiumPathsProp.split(","); return chromiumPathsProp.split(",");
@ -766,7 +770,7 @@ public class I2PChromium extends I2PChromiumProfileUnpacker {
/** /**
* Stop all running processes managed by the browser manager. * Stop all running processes managed by the browser manager.
* *
* @return true if successful, false if not * @return true if successful, false if not
*/ */
public boolean stop() { public boolean stop() {

View File

@ -74,9 +74,7 @@ public class I2PCommonBrowser {
* *
* @return the properties of the object * @return the properties of the object
*/ */
public Properties getProperties() { public Properties getProperties() { return prop; }
return prop;
}
/** /**
* Validates the user directory. * Validates the user directory.
@ -95,7 +93,8 @@ public class I2PCommonBrowser {
logger.info("user.home: " + userHomeFile.getAbsolutePath()); logger.info("user.home: " + userHomeFile.getAbsolutePath());
if (!userDirFile.getAbsolutePath().contains("Program Files")) { if (!userDirFile.getAbsolutePath().contains("Program Files")) {
if (!userDirFile.getAbsolutePath().equals(userHomeFile.getAbsolutePath())) { if (!userDirFile.getAbsolutePath().equals(
userHomeFile.getAbsolutePath())) {
logger.info("user.dir is not inconvenient"); logger.info("user.dir is not inconvenient");
if (userDirFile.exists()) { if (userDirFile.exists()) {
logger.info("user.dir exists"); logger.info("user.dir exists");
@ -127,7 +126,8 @@ public class I2PCommonBrowser {
defaultPathFile.mkdirs(); defaultPathFile.mkdirs();
} }
if (!defaultPathFile.isDirectory()) { if (!defaultPathFile.isDirectory()) {
logger.info("default path exists and is not a directory, get it out of the way"); logger.info(
"default path exists and is not a directory, get it out of the way");
logger.info(defaultPathFile.getAbsolutePath()); logger.info(defaultPathFile.getAbsolutePath());
} }
System.setProperty("user.dir", defaultPathFile.getAbsolutePath()); System.setProperty("user.dir", defaultPathFile.getAbsolutePath());
@ -169,7 +169,8 @@ public class I2PCommonBrowser {
*/ */
protected boolean isOSX() { protected boolean isOSX() {
String osName = System.getProperty("os.name").toLowerCase(); String osName = System.getProperty("os.name").toLowerCase();
return osName.contains("osx") || osName.contains("mac") || osName.contains("apple") || osName.contains("darwin"); return osName.contains("osx") || osName.contains("mac") ||
osName.contains("apple") || osName.contains("darwin");
} }
/** /**
@ -229,7 +230,8 @@ public class I2PCommonBrowser {
/** /**
* Returns the runtime directory path based on the given override parameter. * Returns the runtime directory path based on the given override parameter.
* *
* @param override the name of the environment variable to override the runtime * @param override the name of the environment variable to override the
* runtime
* directory * directory
* @return the runtime directory path as a string * @return the runtime directory path as a string
*/ */
@ -272,7 +274,8 @@ public class I2PCommonBrowser {
* @return true if the directory is valid, false otherwise * @return true if the directory is valid, false otherwise
*/ */
private boolean isDirectoryValid(String directory) { private boolean isDirectoryValid(String directory) {
return directory != null && !directory.isEmpty() && new File(directory).exists(); return directory != null && !directory.isEmpty() &&
new File(directory).exists();
} }
/** /**
@ -285,7 +288,8 @@ public class I2PCommonBrowser {
* @return the profile directory, or null if it could not be created * @return the profile directory, or null if it could not be created
* @since 0.0.19 * @since 0.0.19
*/ */
protected String profileDirectory(String envVar, String browser, String base, boolean app) { protected String profileDirectory(String envVar, String browser, String base,
boolean app) {
String profileDir = System.getenv(envVar); String profileDir = System.getenv(envVar);
if (profileDir != null && !profileDir.isEmpty()) { if (profileDir != null && !profileDir.isEmpty()) {
File profileDirFile = new File(profileDir); File profileDirFile = new File(profileDir);
@ -306,9 +310,11 @@ public class I2PCommonBrowser {
* @param app description of parameter * @param app description of parameter
* @return description of return value * @return description of return value
*/ */
protected String profileDir(String file, String browser, String base, boolean app) { protected String profileDir(String file, String browser, String base,
boolean app) {
String appString = app ? ".app" : ""; String appString = app ? ".app" : "";
String profileDirName = String.format("i2p.%s.profile.%s%s", browser, base, appString); String profileDirName =
String.format("i2p.%s.profile.%s%s", browser, base, appString);
File profileDir = new File(file, profileDirName); File profileDir = new File(file, profileDirName);
return profileDir.getAbsolutePath(); return profileDir.getAbsolutePath();
} }
@ -322,11 +328,12 @@ public class I2PCommonBrowser {
* @return true if the profile was successfully unpacked, false otherwise * @return true if the profile was successfully unpacked, false otherwise
*/ */
protected boolean unpackProfile(String profileDirectory, String browser, protected boolean unpackProfile(String profileDirectory, String browser,
String base) { String base) {
logger.info("Unpacking base profile to " + profileDirectory); logger.info("Unpacking base profile to " + profileDirectory);
try { try {
final InputStream resources = this.getClass().getClassLoader().getResourceAsStream( final InputStream resources =
"i2p." + browser + "." + base + ".profile.zip"); this.getClass().getClassLoader().getResourceAsStream(
"i2p." + browser + "." + base + ".profile.zip");
if (resources == null) { if (resources == null) {
logger.info("Could not find resources"); logger.info("Could not find resources");
return false; return false;
@ -366,8 +373,8 @@ public class I2PCommonBrowser {
} }
/** /**
* Copy a directory from sourceDir to destDir, excluding certain files based on * Copy a directory from sourceDir to destDir, excluding certain files based
* browser and base. * on browser and base.
* *
* @param sourceDir directory to be copied from * @param sourceDir directory to be copied from
* @param destDir directory to be copied to * @param destDir directory to be copied to
@ -375,13 +382,16 @@ public class I2PCommonBrowser {
* @param base the base name * @param base the base name
* @throws IOException if an I/O error occurs during copying * @throws IOException if an I/O error occurs during copying
*/ */
protected void copyDirectory(File sourceDir, File destDir, String browser, String base) throws IOException { protected void copyDirectory(File sourceDir, File destDir, String browser,
destDir = new File(destDir.toString().replace("i2p." + browser + "." + base + ".profile", "")); String base) throws IOException {
destDir = new File(destDir.toString().replace(
"i2p." + browser + "." + base + ".profile", ""));
if (!destDir.exists()) { if (!destDir.exists()) {
destDir.mkdir(); destDir.mkdir();
} }
for (String file : sourceDir.list()) { for (String file : sourceDir.list()) {
copyDirectoryCompatibilityMode(new File(sourceDir, file), new File(destDir, file), browser, base); copyDirectoryCompatibilityMode(new File(sourceDir, file),
new File(destDir, file), browser, base);
} }
} }
@ -394,8 +404,10 @@ public class I2PCommonBrowser {
* @param base the base * @param base the base
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
private void copyDirectoryCompatibilityMode(File sourceDirectory, File destinationDirectory, String browser, private void copyDirectoryCompatibilityMode(File sourceDirectory,
String base) throws IOException { File destinationDirectory,
String browser, String base)
throws IOException {
if (sourceDirectory.isDirectory()) { if (sourceDirectory.isDirectory()) {
copyDirectory(sourceDirectory, destinationDirectory, browser, base); copyDirectory(sourceDirectory, destinationDirectory, browser, base);
} else { } else {
@ -426,9 +438,10 @@ public class I2PCommonBrowser {
* copied to * copied to
* @throws IOException if an I/O error occurs during the file copy process * @throws IOException if an I/O error occurs during the file copy process
*/ */
private void copyFile(File sourceFile, File destinationFile) throws IOException { private void copyFile(File sourceFile, File destinationFile)
throws IOException {
try (InputStream in = new FileInputStream(sourceFile); try (InputStream in = new FileInputStream(sourceFile);
OutputStream out = new FileOutputStream(destinationFile)) { OutputStream out = new FileOutputStream(destinationFile)) {
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int length; int length;
while ((length = in.read(buffer)) > 0) { while ((length = in.read(buffer)) > 0) {
@ -466,9 +479,7 @@ public class I2PCommonBrowser {
* @return true if the proxy is ready, false if it is not. * @return true if the proxy is ready, false if it is not.
* @since 0.0.1 * @since 0.0.1
*/ */
public boolean waitForProxy() { public boolean waitForProxy() { return waitForProxy(CONFIGURED_TIMEOUT); }
return waitForProxy(CONFIGURED_TIMEOUT);
}
/** /**
* Waits for an HTTP proxy on port 4444 to be ready. * Waits for an HTTP proxy on port 4444 to be ready.
@ -546,9 +557,7 @@ public class I2PCommonBrowser {
* *
* @param time * @param time
*/ */
public void setProxyTimeoutTime(int time) { public void setProxyTimeoutTime(int time) { CONFIGURED_TIMEOUT = time; }
CONFIGURED_TIMEOUT = time;
}
/** /**
* Joins the elements of the given string array into a single string. * Joins the elements of the given string array into a single string.

View File

@ -59,23 +59,23 @@ public class I2PFirefox extends I2PFirefoxProfileUnpacker {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
list = Arrays.asList(firefoxPathsWindows()); list = Arrays.asList(firefoxPathsWindows());
getProperties().setProperty("firefox.paths.windows", getProperties().setProperty("firefox.paths.windows",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
list = Arrays.asList(firefoxPathsUnix()); list = Arrays.asList(firefoxPathsUnix());
getProperties().setProperty("firefox.paths.linux", getProperties().setProperty("firefox.paths.linux",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
list = Arrays.asList(firefoxPathsOSX()); list = Arrays.asList(firefoxPathsOSX());
getProperties().setProperty("firefox.paths.osx", getProperties().setProperty("firefox.paths.osx",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
list = Arrays.asList(firefoxBinsWindows()); list = Arrays.asList(firefoxBinsWindows());
getProperties().setProperty("firefox.bins.windows", getProperties().setProperty("firefox.bins.windows",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
list = Arrays.asList(firefoxBinsUnix()); list = Arrays.asList(firefoxBinsUnix());
getProperties().setProperty("firefox.bins.linux", getProperties().setProperty("firefox.bins.linux",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
list = Arrays.asList(firefoxBinsUnix()); list = Arrays.asList(firefoxBinsUnix());
getProperties().setProperty("firefox.bins.osx", getProperties().setProperty("firefox.bins.osx",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
try (OutputStream fos = new FileOutputStream( try (OutputStream fos = new FileOutputStream(
new File(runtimeDirectory(""), "browser.config"))) { new File(runtimeDirectory(""), "browser.config"))) {
getProperties().store(fos, "Firefox Configuration Section"); getProperties().store(fos, "Firefox Configuration Section");
@ -147,7 +147,8 @@ public class I2PFirefox extends I2PFirefoxProfileUnpacker {
return exePath; return exePath;
} }
public String[] firefoxPathsWindows() { public String[] firefoxPathsWindows() {
String firefoxPathsProp = getProperties().getProperty("firefox.paths.windows"); String firefoxPathsProp =
getProperties().getProperty("firefox.paths.windows");
if (firefoxPathsProp != null) if (firefoxPathsProp != null)
if (!firefoxPathsProp.equals("")) if (!firefoxPathsProp.equals(""))
return firefoxPathsProp.split(","); return firefoxPathsProp.split(",");
@ -180,7 +181,8 @@ public class I2PFirefox extends I2PFirefoxProfileUnpacker {
}; };
} }
private String[] firefoxBinsWindows() { private String[] firefoxBinsWindows() {
String firefoxPathsProp = getProperties().getProperty("firefox.bins.windows"); String firefoxPathsProp =
getProperties().getProperty("firefox.bins.windows");
if (firefoxPathsProp != null) if (firefoxPathsProp != null)
if (!firefoxPathsProp.equals("")) if (!firefoxPathsProp.equals(""))
return firefoxPathsProp.split(","); return firefoxPathsProp.split(",");
@ -829,7 +831,7 @@ public class I2PFirefox extends I2PFirefoxProfileUnpacker {
/** /**
* Stop all running processes managed by the browser manager. * Stop all running processes managed by the browser manager.
* *
* @return true if successful, false if not * @return true if successful, false if not
*/ */
public boolean stop() { public boolean stop() {

View File

@ -39,7 +39,8 @@ public class I2PFirefoxProfileChecker extends I2PCommonBrowser {
return; return;
} }
profileChecker.logger.info("Profile directory: " + profileDirectory); profileChecker.logger.info("Profile directory: " + profileDirectory);
boolean isProfileValid = profileChecker.validateProfileDirectory(profileDirectory); boolean isProfileValid =
profileChecker.validateProfileDirectory(profileDirectory);
if (isProfileValid) { if (isProfileValid) {
profileChecker.logger.info("Profile directory is valid"); profileChecker.logger.info("Profile directory is valid");
} else { } else {
@ -65,7 +66,8 @@ public class I2PFirefoxProfileChecker extends I2PCommonBrowser {
*/ */
public boolean validateProfileDirectory(String profileDirectory) { public boolean validateProfileDirectory(String profileDirectory) {
File profileDir = new File(profileDirectory); File profileDir = new File(profileDirectory);
if (!profileDir.exists() || !profileDir.isDirectory() || !profileDir.canRead() || !profileDir.canWrite()) { if (!profileDir.exists() || !profileDir.isDirectory() ||
!profileDir.canRead() || !profileDir.canWrite()) {
return false; return false;
} }
if (!validateFile(profileDir + "/prefs.js")) { if (!validateFile(profileDir + "/prefs.js")) {
@ -129,7 +131,8 @@ public class I2PFirefoxProfileChecker extends I2PCommonBrowser {
*/ */
private boolean undoHomepage(File fileToBeModified) { private boolean undoHomepage(File fileToBeModified) {
String oldStringToFind = "\"browser.startup.homepage\", true"; String oldStringToFind = "\"browser.startup.homepage\", true";
String newStringToReplace = "\"browser.startup.homepage\", \"http://127.0.0.1:7657\""; String newStringToReplace =
"\"browser.startup.homepage\", \"http://127.0.0.1:7657\"";
try (Scanner scanner = new Scanner(fileToBeModified)) { try (Scanner scanner = new Scanner(fileToBeModified)) {
while (scanner.hasNextLine()) { while (scanner.hasNextLine()) {
String line = scanner.nextLine(); String line = scanner.nextLine();
@ -153,7 +156,7 @@ public class I2PFirefoxProfileChecker extends I2PCommonBrowser {
* @return true if the value was successfully undone, false otherwise * @return true if the value was successfully undone, false otherwise
*/ */
public boolean undoValue(String oldString, String newString, public boolean undoValue(String oldString, String newString,
File fileToBeModified) { File fileToBeModified) {
String oldContent = ""; String oldContent = "";
BufferedReader reader = null; BufferedReader reader = null;
FileWriter writer = null; FileWriter writer = null;
@ -190,7 +193,8 @@ public class I2PFirefoxProfileChecker extends I2PCommonBrowser {
*/ */
public boolean validateFile(String filePath) { public boolean validateFile(String filePath) {
File file = new File(filePath); File file = new File(filePath);
if (!file.exists() || !file.isFile() || !file.canRead() || !file.canWrite()) { if (!file.exists() || !file.isFile() || !file.canRead() ||
!file.canWrite()) {
return false; return false;
} }
return true; return true;

View File

@ -67,7 +67,7 @@ public class I2PGenericUnsafeBrowser extends I2PCommonBrowser {
list = Arrays.asList(browsers()); list = Arrays.asList(browsers());
getProperties().setProperty("generic.bins.unix", getProperties().setProperty("generic.bins.unix",
list.stream().collect(Collectors.joining(","))); list.stream().collect(Collectors.joining(",")));
try (OutputStream fos = new FileOutputStream( try (OutputStream fos = new FileOutputStream(
new File(runtimeDirectory(""), "browser.config"))) { new File(runtimeDirectory(""), "browser.config"))) {
getProperties().store(fos, "Chromium Configuration Section"); getProperties().store(fos, "Chromium Configuration Section");
@ -406,7 +406,7 @@ public class I2PGenericUnsafeBrowser extends I2PCommonBrowser {
} }
/** /**
* Stop all running processes managed by the browser manager. * Stop all running processes managed by the browser manager.
* *
* @return true if successful, false if not * @return true if successful, false if not
*/ */
public boolean stop() { public boolean stop() {

View File

@ -20,5 +20,5 @@ import javax.script.*;
* @since 1.0.6 * @since 1.0.6
*/ */
public class I2PLibreWolf { public class I2PLibreWolf {
//TODO: provide a librewolf updater here. // TODO: provide a librewolf updater here.
} }