Skip to content

Commit

Permalink
JarViewer: remove background jobs
Browse files Browse the repository at this point in the history
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 <chrisrueger@gmail.com>
  • Loading branch information
chrisrueger committed Oct 28, 2024
1 parent 3bdbe71 commit ff89d4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ff89d4f

Please sign in to comment.