From ff89d4ffe6f473c71404e78537ffe7a3e1aa6651 Mon Sep 17 00:00:00 2001 From: Christoph Rueger Date: Mon, 28 Oct 2024 20:33:40 +0100 Subject: [PATCH] JarViewer: remove background jobs this fixes all the race conditions where update methods was called multiple times by different threads and created temp folders multiple times. Now only one temp folder per opened jar is created. Also did not notice a performance problem when opening the jar. Signed-off-by: Christoph Rueger --- .../bndtools/jareditor/internal/JARPrintPage.java | 8 ++++++-- .../jareditor/internal/JARTreeEntryPart.java | 15 ++++++++------- .../bndtools/jareditor/internal/JARTreePage.java | 15 ++++++++++----- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/bndtools.jareditor/src/bndtools/jareditor/internal/JARPrintPage.java b/bndtools.jareditor/src/bndtools/jareditor/internal/JARPrintPage.java index a7e6fff363..4417a57efc 100644 --- a/bndtools.jareditor/src/bndtools/jareditor/internal/JARPrintPage.java +++ b/bndtools.jareditor/src/bndtools/jareditor/internal/JARPrintPage.java @@ -43,6 +43,7 @@ import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; +import aQute.bnd.exceptions.Exceptions; import aQute.bnd.osgi.Jar; import aQute.bnd.print.JarPrinter; @@ -393,10 +394,13 @@ private void update() { return; } loading = true; - JAREditor.background("Printing ZIP file", monitor -> print(uri), text -> { + try { + String text = print(uri); styledText.setText(text); styledText.setFocus(); - }); + } catch (Exception e) { + throw Exceptions.duck(e); + } } diff --git a/bndtools.jareditor/src/bndtools/jareditor/internal/JARTreeEntryPart.java b/bndtools.jareditor/src/bndtools/jareditor/internal/JARTreeEntryPart.java index d554ba09c3..eca924d87f 100644 --- a/bndtools.jareditor/src/bndtools/jareditor/internal/JARTreeEntryPart.java +++ b/bndtools.jareditor/src/bndtools/jareditor/internal/JARTreeEntryPart.java @@ -38,6 +38,7 @@ import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.Section; +import aQute.bnd.exceptions.Exceptions; import aQute.lib.hex.Hex; import aQute.lib.io.ByteBufferOutputStream; import aQute.lib.io.IO; @@ -201,13 +202,13 @@ private void update() { lastModified.setText(""); if (resource instanceof IFile) { IFile node = (IFile) resource; - JAREditor.background("Loading " + resource.getName(), mon -> { - try (InputStream in = limitRead ? new LimitedInputStream(node.getContents(), READ_LIMIT) - : node.getContents()) { - return IO.copy(in, new ByteBufferOutputStream()) - .toByteBuffer(); - } - }, this::setContent); + try (InputStream in = limitRead ? new LimitedInputStream(node.getContents(), READ_LIMIT) + : node.getContents()) { + setContent(IO.copy(in, new ByteBufferOutputStream()) + .toByteBuffer()); + } catch (Exception e) { + throw Exceptions.duck(e); + } } else { setContent(""); } diff --git a/bndtools.jareditor/src/bndtools/jareditor/internal/JARTreePage.java b/bndtools.jareditor/src/bndtools/jareditor/internal/JARTreePage.java index bd479299e0..48351e9e28 100644 --- a/bndtools.jareditor/src/bndtools/jareditor/internal/JARTreePage.java +++ b/bndtools.jareditor/src/bndtools/jareditor/internal/JARTreePage.java @@ -8,6 +8,7 @@ import org.eclipse.core.resources.IFolder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.graphics.Image; @@ -20,6 +21,8 @@ import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.plugin.AbstractUIPlugin; +import aQute.bnd.exceptions.Exceptions; + public class JARTreePage extends FormPage { private Image titleImg; @@ -101,19 +104,21 @@ private void update() { if (loading.getAndIncrement() > 1) return; - JAREditor.background("Reading zip file", monitor -> { + try { IFolder folder; do { - folder = getFolder(uri, monitor); + folder = getFolder(uri, new NullProgressMonitor()); loading.getAndDecrement(); } while (loading.getAndSet(0) > 0); - return folder; - }, folder -> { + if (closed) return; setFolder(folder); tree.setFormInput(folder); - }); + } catch (CoreException e) { + throw Exceptions.duck(e); + } + } private void setFolder(IFolder folder) {