[updater] catching all exceptions (IDEA-226297)

GitOrigin-RevId: bc2bcd4a650c1dfbd025b288fc0478c8c5d2bdc1
This commit is contained in:
Roman Shevchenko
2020-06-09 22:29:28 +03:00
committed by intellij-monorepo-bot
parent e20eeaa431
commit 43c1daf1eb
+42 -37
View File
@@ -12,10 +12,7 @@ import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -38,6 +35,42 @@ public class Runner {
}
public static void main(String[] args) {
initLogger();
try {
_main(args);
}
catch (Throwable t) {
logger().error("internal error", t);
System.exit(2);
}
}
private static void initLogger() {
String logDirectory = Utils.findDirectory(1_000_000L);
logPath = new File(logDirectory, "idea_updater.log").getAbsolutePath();
FileAppender update = new FileAppender();
update.setFile(logPath);
update.setLayout(new PatternLayout("%d{dd/MM HH:mm:ss} %-5p %C{1}.%M - %m%n"));
update.setThreshold(Level.ALL);
update.setAppend(true);
update.activateOptions();
FileAppender updateError = new FileAppender();
updateError.setFile(new File(logDirectory, ERROR_LOG_FILE_NAME).getAbsolutePath());
updateError.setLayout(new PatternLayout("%d{dd/MM HH:mm:ss} %-5p %C{1}.%M - %m%n"));
updateError.setThreshold(Level.ERROR);
updateError.setAppend(false);
updateError.activateOptions();
logger = Logger.getLogger("com.intellij.updater");
logger.addAppender(updateError);
logger.addAppender(update);
logger.setLevel(Level.ALL);
logger.info("--- Updater started ---");
}
private static void _main(String[] args) {
String jarFile = getArgument(args, "jar");
if (jarFile == null) {
jarFile = resolveJarFile();
@@ -51,7 +84,6 @@ public class Runner {
String patchFile = args[5];
checkCaseSensitivity(newFolder);
initLogger();
boolean binary = hasArgument(args, "zip_as_binary");
boolean strict = hasArgument(args, "strict");
@@ -94,17 +126,17 @@ public class Runner {
else if (args.length >= 2 && ("install".equals(args[0]) || "apply".equals(args[0])) ||
args.length >= 3 && ("batch-install".equals(args[0]))) {
String destPath = args[1];
checkCaseSensitivity(destPath);
Path destDirectory = null;
Path destDirectory = Paths.get(destPath);
try {
destDirectory = Paths.get(destPath).toRealPath();
destDirectory = destDirectory.toRealPath();
}
catch (InvalidPathException | IOException e) {
logger().error(e);
}
initLogger();
checkCaseSensitivity(destDirectory.toString());
logger().info("args: " + Arrays.toString(args));
logger().info("destination: " + destPath + " (" + destDirectory + "), case-sensitive: " + ourCaseSensitiveFs);
@@ -121,7 +153,7 @@ public class Runner {
boolean backup = !hasArgument(args, "no-backup");
boolean success;
if (destDirectory == null || !Files.isDirectory(destDirectory)) {
if (!Files.isDirectory(destDirectory, LinkOption.NOFOLLOW_LINKS)) {
ui.showError("Invalid target directory: " + destPath);
success = false;
}
@@ -172,33 +204,6 @@ public class Runner {
return map;
}
private static void initLogger() {
if (logger == null) {
String logDirectory = Utils.findDirectory(1_000_000L);
logPath = new File(logDirectory, "idea_updater.log").getAbsolutePath();
FileAppender update = new FileAppender();
update.setFile(logPath);
update.setLayout(new PatternLayout("%d{dd/MM HH:mm:ss} %-5p %C{1}.%M - %m%n"));
update.setThreshold(Level.ALL);
update.setAppend(true);
update.activateOptions();
FileAppender updateError = new FileAppender();
updateError.setFile(new File(logDirectory, ERROR_LOG_FILE_NAME).getAbsolutePath());
updateError.setLayout(new PatternLayout("%d{dd/MM HH:mm:ss} %-5p %C{1}.%M - %m%n"));
updateError.setThreshold(Level.ERROR);
updateError.setAppend(false);
updateError.activateOptions();
logger = Logger.getLogger("com.intellij.updater");
logger.addAppender(updateError);
logger.addAppender(update);
logger.setLevel(Level.ALL);
logger.info("--- Updater started ---");
}
}
public static List<String> extractArguments(String[] args, String paramName) {
List<String> result = new ArrayList<>();
String prefix = paramName + '=';