From 9859872004005d7d6dd6298c48c75ca4de90e573 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 28 Nov 2013 19:44:40 +0100 Subject: [PATCH] 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 --- updater/src/com/intellij/updater/Runner.java | 14 +++++--- .../com/intellij/updater/SwingUpdaterUI.java | 10 +++++- .../com/intellij/updater/UpdateZipAction.java | 12 ++++--- updater/src/com/intellij/updater/Utils.java | 4 +-- .../intellij/updater/ZipOutputWrapper.java | 35 ++++++++----------- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/updater/src/com/intellij/updater/Runner.java b/updater/src/com/intellij/updater/Runner.java index 02c45507b12c..2935f7c1eb23 100644 --- a/updater/src/com/intellij/updater/Runner.java +++ b/updater/src/com/intellij/updater/Runner.java @@ -70,7 +70,8 @@ public class Runner { private static void printUsage() { System.err.println("Usage:\n" + - "create [ignored=file1;file2;...] [critical=file1;file2;...] [optional=file1;file2;...]\n" + + "create " + + " [ignored=file1;file2;...] [critical=file1;file2;...] [optional=file1;file2;...]\n" + "install \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 { diff --git a/updater/src/com/intellij/updater/SwingUpdaterUI.java b/updater/src/com/intellij/updater/SwingUpdaterUI.java index 75af634cb637..1fa851436b52 100644 --- a/updater/src/com/intellij/updater/SwingUpdaterUI.java +++ b/updater/src/com/intellij/updater/SwingUpdaterUI.java @@ -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); } }); } diff --git a/updater/src/com/intellij/updater/UpdateZipAction.java b/updater/src/com/intellij/updater/UpdateZipAction.java index 553e7d8da0a4..672d3579bb2a 100644 --- a/updater/src/com/intellij/updater/UpdateZipAction.java +++ b/updater/src/com/intellij/updater/UpdateZipAction.java @@ -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); diff --git a/updater/src/com/intellij/updater/Utils.java b/updater/src/com/intellij/updater/Utils.java index 427788eaf1ac..666ac1af24c6 100644 --- a/updater/src/com/intellij/updater/Utils.java +++ b/updater/src/com/intellij/updater/Utils.java @@ -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 { diff --git a/updater/src/com/intellij/updater/ZipOutputWrapper.java b/updater/src/com/intellij/updater/ZipOutputWrapper.java index 1ccbc45ff05b..ec4754600bfe 100644 --- a/updater/src/com/intellij/updater/ZipOutputWrapper.java +++ b/updater/src/com/intellij/updater/ZipOutputWrapper.java @@ -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(); } }