Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

147: UI freeze while task :"Reporting PIT results" with huge projects #200

Merged
merged 5 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bundles/org.pitest.pitclipse.ui/icons/expandall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,58 @@

package org.pitest.pitclipse.ui.view.mutations;

import java.net.URL;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.part.ViewPart;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.pitest.pitclipse.runner.model.MutationsModel;

public class PitMutationsView extends ViewPart implements MutationsView {

private static final int TREE_STYLE = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL;
private TreeViewer viewer;

public static final String EXPAND_ALL_BUTTON_TEXT = "Expand All";
public static final String COLLAPSE_ALL_BUTTON_TEXT = "Collapse All";

private static final ImageDescriptor EXPAND_ALL = getBundleImage("expandall.png");
private static final ImageDescriptor COLLAPSE_ALL = getBundleImage("collapseall.png");

@Override
public void createPartControl(Composite parent) {
createTreeViewer(parent);

IActionBars actionBars = getViewSite().getActionBars();
IToolBarManager toolBar = actionBars.getToolBarManager();

final Action expandAllAction = new Action(EXPAND_ALL_BUTTON_TEXT) {
@Override
public void run() {
viewer.expandAll();
}
};
expandAllAction.setImageDescriptor(EXPAND_ALL);
toolBar.add(expandAllAction);

final Action collapseAllAction = new Action(COLLAPSE_ALL_BUTTON_TEXT) {
@Override
public void run() {
viewer.collapseAll();
}
};
collapseAllAction.setImageDescriptor(COLLAPSE_ALL);
toolBar.add(collapseAllAction);
}

private void createTreeViewer(Composite parent) {
Expand Down Expand Up @@ -61,8 +98,16 @@ private ViewUpdater(MutationsModel mutations) {

@Override
public void run() {
// better not to expand the view to avoid UI freeze
// see https://github.com/pitest/pitclipse/issues/147
viewer.setInput(mutations);
viewer.expandAll();
}
}

private static ImageDescriptor getBundleImage(String file) {
Bundle bundle = FrameworkUtil.getBundle(PitMutationsView.class);
URL url = FileLocator.find(bundle, new Path("icons/" + file), null);
return ImageDescriptor.createFromURL(url);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum PageObjects {
private final PackageExplorer packageExplorer;
private final WindowsMenu windowsMenu;
private final RunMenu runMenu;
private final PitMutationsView pitMutationsView;
private final PitMutationsViewPageObject pitMutationsView;
private final BuildProgress buildProgress;
private final AbstractSyntaxTree abstractSyntaxTree;
private final SourceMenu sourceMenu;
Expand All @@ -42,7 +42,7 @@ private PageObjects() {
windowsMenu = new WindowsMenu(bot);
runMenu = new RunMenu(bot);
pitSummaryView = new PitSummaryView(bot);
pitMutationsView = new PitMutationsView(bot);
pitMutationsView = new PitMutationsViewPageObject(bot);
buildProgress = new BuildProgress(bot);
abstractSyntaxTree = new AbstractSyntaxTree();
sourceMenu = new SourceMenu(bot);
Expand Down Expand Up @@ -86,7 +86,7 @@ public RefactorMenu getRefactorMenu() {
return refactorMenu;
}

public PitMutationsView getPitMutationsView() {
public PitMutationsViewPageObject getPitMutationsView() {
return pitMutationsView;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@

import junit.framework.AssertionFailedError;

public class PitMutationsView {
public class PitMutationsViewPageObject {

private final SWTWorkbenchBot bot;

public PitMutationsView(SWTWorkbenchBot bot) {
public PitMutationsViewPageObject(SWTWorkbenchBot bot) {
this.bot = bot;
}

Expand All @@ -53,13 +53,18 @@ public List<PitMutation> getMutations() {
return mutationsFrom(mutationTree);
}

private SWTBotTree mutationTreeRoot() {
public SWTBotTree mutationTreeRoot() {
SWTBotView mutationsView = getView();
SWTBotTree mutationTree = mutationsView.bot().tree();
return mutationTree;
}

public SWTBotView getView() {
SWTBotView mutationsView = bot.viewByTitle("PIT Mutations");
mutationsView.show();
// Make sure the 'PIT Mutations' view is opened
bot.waitUntil(new ViewOpenedCondition(bot, "PIT Mutations"));
SWTBotTree mutationTree = mutationsView.bot().tree();
return mutationTree;
return mutationsView;
}

private ImmutableList<PitMutation> mutationsFrom(SWTBotTree mutationTree) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package org.pitest.pitclipse.ui.tests;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.pitest.pitclipse.ui.behaviours.pageobjects.PitMutationsViewPageObject;
import org.pitest.pitclipse.ui.behaviours.steps.PitMutation;
import org.pitest.pitclipse.ui.behaviours.steps.PitclipseSteps;
import org.pitest.pitclipse.ui.view.mutations.PitMutationsView;

/**
* @author Lorenzo Bettini
Expand All @@ -25,14 +32,14 @@ public class PitclipsePitMutationsViewTest extends AbstractPitclipseSWTBotTest {
@BeforeClass
public static void setupJavaProject() throws CoreException {
importTestProject(TEST_PROJECT);
openEditor(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT);
openEditor(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT);
openEditor(BAR_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT);
openEditor(BAR_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT);
}

@Test
public void selectMutationOpensTheClassAtTheRightLineNumber() throws CoreException {
openEditor(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT);
openEditor(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT);
openEditor(BAR_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT);
openEditor(BAR_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT);
runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT);
coverageReportGenerated(2, 80, 0, 6, 0);
PitclipseSteps pitclipseSteps = new PitclipseSteps();
Expand All @@ -45,4 +52,19 @@ public void selectMutationOpensTheClassAtTheRightLineNumber() throws CoreExcepti
pitclipseSteps.doubleClickMutationInMutationsView(mutation);
pitclipseSteps.mutationIsOpened(BAR_CLASS + ".java", 7);
}

@Test
public void expandAndCollapse() throws CoreException {
runTest(BAR_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT);
final PitMutationsViewPageObject pitMutationsView = new PitMutationsViewPageObject(bot);
SWTBotTree mutationTreeRoot = pitMutationsView.mutationTreeRoot();
final SWTBotTreeItem firstItem = mutationTreeRoot.getAllItems()[0];
assertFalse("should be collapsed", firstItem.isExpanded());
bot.toolbarButtonWithTooltip
(PitMutationsView.EXPAND_ALL_BUTTON_TEXT).click();
assertTrue("should be expanded", firstItem.isExpanded());
bot.toolbarButtonWithTooltip
(PitMutationsView.COLLAPSE_ALL_BUTTON_TEXT).click();
assertFalse("should be collapsed", firstItem.isExpanded());
}
}