IDEA-117059 (error reporting in updater fixed)

- setting/reading hasError flag sequenced properly
- closing ops on ZIP stream moved out of finally blocks so that informative IOExceptions would not get suppressed by cryptic induced ZipExceptions
This commit is contained in:
Roman Shevchenko
2013-11-28 20:37:11 +01:00
parent d38a23d789
commit 9859872004
5 changed files with 41 additions and 34 deletions
+9 -5
View File
@@ -70,7 +70,8 @@ public class Runner {
private static void printUsage() {
System.err.println("Usage:\n" +
"create <old_version_description> <new_version_description> <old_version_folder> <new_version_folder> <patch_file_name> [ignored=file1;file2;...] [critical=file1;file2;...] [optional=file1;file2;...]\n" +
"create <old_version_description> <new_version_description> <old_version_folder> <new_version_folder>" +
" <patch_file_name> [ignored=file1;file2;...] [critical=file1;file2;...] [optional=file1;file2;...]\n" +
"install <destination_folder>\n");
}
@@ -94,8 +95,10 @@ public class Runner {
ui);
ui.startProcess("Packing jar file '" + patchFile + "'...");
ZipOutputWrapper out = new ZipOutputWrapper(new FileOutputStream(patchFile));
FileOutputStream fileOut = new FileOutputStream(patchFile);
try {
ZipOutputWrapper out = new ZipOutputWrapper(fileOut);
ZipInputStream in = new ZipInputStream(new FileInputStream(resolveJarFile()));
try {
ZipEntry e;
@@ -110,8 +113,8 @@ public class Runner {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
try {
Properties props = new Properties();
props.put(OLD_BUILD_DESCRIPTION, oldBuildDesc);
props.put(NEW_BUILD_DESCRIPTION, newBuildDesc);
props.setProperty(OLD_BUILD_DESCRIPTION, oldBuildDesc);
props.setProperty(NEW_BUILD_DESCRIPTION, newBuildDesc);
props.store(byteOut, "");
}
finally {
@@ -120,9 +123,10 @@ public class Runner {
out.zipBytes(PATCH_PROPERTIES_ENTRY, byteOut);
out.zipFile(PATCH_FILE_NAME, tempPatchFile);
out.finish();
}
finally {
out.close();
fileOut.close();
}
}
finally {
@@ -63,6 +63,7 @@ public class SwingUpdaterUI implements UpdaterUI {
myConsole.setWrapStyleWord(true);
myConsole.setCaretPosition(myConsole.getText().length());
myConsole.setTabSize(1);
myConsole.setMargin(new Insets(2, 4, 2, 4));
myConsolePane = new JPanel(new BorderLayout());
myConsolePane.add(new JScrollPane(myConsole));
myConsolePane.setBorder(BUTTONS_BORDER);
@@ -314,18 +315,25 @@ public class SwingUpdaterUI implements UpdaterUI {
}
public void showError(final Throwable e) {
hasError.set(true);
myQueue.add(new UpdateRequest() {
public void perform() {
StringWriter w = new StringWriter();
if (!myConsolePane.isVisible()) {
w.write("Temp. directory: ");
w.write(System.getProperty("java.io.tmpdir"));
w.write("\n\n");
}
e.printStackTrace(new PrintWriter(w));
w.append("\n");
myConsole.append(w.getBuffer().toString());
if (!myConsolePane.isVisible()) {
myConsole.setCaretPosition(0);
myConsolePane.setVisible(true);
myConsolePane.setPreferredSize(new Dimension(10, 200));
myFrame.pack();
}
hasError.set(true);
}
});
}
@@ -149,11 +149,11 @@ public class UpdateZipAction extends BaseUpdateAction {
protected void doApply(final ZipFile patchFile, File toFile) throws IOException {
File temp = Utils.createTempFile();
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
final ZipOutputWrapper out = new ZipOutputWrapper(new FileOutputStream(temp));
out.setCompressionLevel(0);
FileOutputStream fileOut = new FileOutputStream(temp);
try {
final ZipOutputWrapper out = new ZipOutputWrapper(fileOut);
out.setCompressionLevel(0);
processZipFile(toFile, new Processor() {
public void process(ZipEntry entry, InputStream in) throws IOException {
String path = entry.getName();
@@ -183,9 +183,11 @@ public class UpdateZipAction extends BaseUpdateAction {
in.close();
}
}
out.finish();
}
finally {
out.close();
fileOut.close();
}
replaceUpdated(temp, toFile);
+2 -2
View File
@@ -17,12 +17,12 @@ public class Utils {
@SuppressWarnings({"SSBasedInspection"})
public static File createTempFile() throws IOException {
if (myTempDir == null) {
myTempDir = File.createTempFile("idea.updater", "tmp");
myTempDir = File.createTempFile("idea.updater.", ".tmp");
delete(myTempDir);
myTempDir.mkdirs();
}
return File.createTempFile("temp", "tmp", myTempDir);
return File.createTempFile("temp.", ".tmp", myTempDir);
}
public static File createTempDir() throws IOException {
@@ -74,14 +74,10 @@ public class ZipOutputWrapper {
}
myOut.putNextEntry(entry);
try {
byteOut.writeTo(myOut);
}
finally {
myOut.closeEntry();
}
byteOut.writeTo(myOut);
myOut.closeEntry();
}
public void zipFile(String entryPath, File file) throws IOException {
if (file.isDirectory()) {
addDirs(entryPath, true);
@@ -124,20 +120,17 @@ public class ZipOutputWrapper {
myDirs.addAll(temp);
}
public void close() throws IOException {
try {
for (String each : myDirs) {
if (!each.endsWith("/")) each += "/";
ZipEntry e = new ZipEntry(each);
e.setMethod(ZipEntry.STORED);
e.setSize(0);
e.setCrc(0);
myOut.putNextEntry(e);
myOut.closeEntry();
}
}
finally {
myOut.close();
public void finish() throws IOException {
for (String each : myDirs) {
if (!each.endsWith("/")) each += "/";
ZipEntry e = new ZipEntry(each);
e.setMethod(ZipEntry.STORED);
e.setSize(0);
e.setCrc(0);
myOut.putNextEntry(e);
myOut.closeEntry();
}
myOut.close();
}
}