Skip to content

Commit

Permalink
Merge 160a8a6 into d8ed00e
Browse files Browse the repository at this point in the history
  • Loading branch information
lgassman committed Jun 28, 2017
2 parents d8ed00e + 160a8a6 commit 94fb88b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.uqbar.project.wollok.ui.tests
import java.util.Observable
import java.util.Observer
import javax.inject.Inject
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.emf.common.util.URI
import org.eclipse.jface.layout.GridDataFactory
import org.eclipse.jface.resource.JFaceResources
Expand All @@ -30,11 +29,13 @@ import org.eclipse.swt.widgets.Link
import org.eclipse.swt.widgets.Text
import org.eclipse.swt.widgets.ToolBar
import org.eclipse.swt.widgets.ToolItem
import org.eclipse.ui.PlatformUI
import org.eclipse.ui.part.ViewPart
import org.eclipse.ui.texteditor.ITextEditor
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtext.ui.editor.GlobalURIEditorOpener
import org.uqbar.project.wollok.ui.Messages
import org.uqbar.project.wollok.ui.console.RunInUI
import org.uqbar.project.wollok.ui.i18n.WollokLaunchUIMessages
import org.uqbar.project.wollok.ui.launch.Activator
import org.uqbar.project.wollok.ui.tests.model.WollokTestContainer
Expand Down Expand Up @@ -78,7 +79,7 @@ class WollokTestResultView extends ViewPart implements Observer {

@Inject
WollokTestLaunchShortcut testLaunchShortcut

@Inject
WollokAllTestsLaunchShortcut allTestsLaunchShortcut

Expand All @@ -87,7 +88,15 @@ class WollokTestResultView extends ViewPart implements Observer {
ToolItem showFailuresAndErrors
ToolItem runAgain
ToolItem debugAgain


def static activate() {
RunInUI.runInUI [
val view = PlatformUI.workbench.activeWorkbenchWindow.activePage.showView(WollokTestResultView.NAME)
(view as WollokTestResultView).cleanView
]
}


def canRelaunch() {
results !== null && results.container !== null && results.container.mainResource !== null
}
Expand All @@ -108,14 +117,34 @@ class WollokTestResultView extends ViewPart implements Observer {
}
}

/** this method is invoked between test executions */
def cleanView() {
bar.background = noResultColor
totalTextBox.text = ""
failedTextBox.text = ""
errorTextBox.text = ""
runAgain.enabled = false
debugAgain.enabled = false
(testTree.contentProvider as WTestTreeContentProvider).results.container = new WollokTestContainer() {
override toString() {
return ""
}

override asText() {
return ""
}
}
testTree.refresh(true)
}

def testFile() {
results.container.mainResource.toIFile
}

def toggleShowFailuresAndErrors() {
results.showFailuresAndErrorsOnly(showFailuresAndErrors.selection)
results.showFailuresAndErrorsOnly(showFailuresAndErrors.selection)
}

override createPartControl(Composite parent) {
parent.background = new Color(Display.current, new RGB(220, 220, 220))
resManager = new LocalResourceManager(JFaceResources.getResources(), parent)
Expand All @@ -127,10 +156,10 @@ class WollokTestResultView extends ViewPart implements Observer {
parent.setLayout(it)
parent.setLayoutData(new GridData => [
horizontalAlignment = GridData.FILL
verticalAlignment = GridData.FILL
grabExcessHorizontalSpace = true
grabExcessVerticalSpace = true
horizontalSpan = 2
verticalAlignment = GridData.FILL
grabExcessHorizontalSpace = true
grabExcessVerticalSpace = true
horizontalSpan = 2
])
]
createToolbar(parent)
Expand All @@ -147,7 +176,7 @@ class WollokTestResultView extends ViewPart implements Observer {

def createSeparator(Composite parent) {
val separator = new Label(parent, SWT.HORIZONTAL.bitwiseOr(SWT.SEPARATOR))
separator.layoutData = new GridData(GridData.FILL_HORIZONTAL)
separator.layoutData = new GridData(GridData.FILL_HORIZONTAL)
}

def createToolbar(Composite parent) {
Expand All @@ -157,23 +186,27 @@ class WollokTestResultView extends ViewPart implements Observer {

showFailuresAndErrors = new ToolItem(toolbar, SWT.CHECK) => [
toolTipText = Messages.WollokTestResultView_showOnlyFailuresAndErrors
val pathImage = Activator.getDefault.getImageDescriptor("platform:/plugin/org.eclipse.jdt.junit/icons/full/obj16/failures.gif")
val pathImage = Activator.getDefault.getImageDescriptor(
"platform:/plugin/org.eclipse.jdt.junit/icons/full/obj16/failures.gif")
image = resManager.createImage(pathImage)
addListener(SWT.Selection)[ this.toggleShowFailuresAndErrors ]
addListener(SWT.Selection)[this.toggleShowFailuresAndErrors]
enabled = true
]

runAgain = new ToolItem(toolbar, SWT.PUSH) => [
toolTipText = Messages.WollokTestResultView_runAgain
val pathImage = Activator.getDefault.getImageDescriptor("platform:/plugin/org.eclipse.jdt.junit/icons/full/elcl16/relaunch.gif")
val pathImage = Activator.getDefault.getImageDescriptor(
"platform:/plugin/org.eclipse.jdt.junit/icons/full/elcl16/relaunch.gif")
image = resManager.createImage(pathImage)
addListener(SWT.Selection)[this.relaunch]
enabled = false
]

debugAgain = new ToolItem(toolbar, SWT.PUSH) => [
toolTipText = Messages.WollokTestResultView_debugAgain
image = resManager.createImage(Activator.getDefault.getImageDescriptor("platform:/plugin/org.eclipse.debug.ui/icons/full/elcl16/debuglast_co.png"))
image = resManager.createImage(
Activator.getDefault.getImageDescriptor(
"platform:/plugin/org.eclipse.debug.ui/icons/full/elcl16/debuglast_co.png"))
addListener(SWT.Selection)[this.relaunchDebug]
enabled = false
]
Expand Down Expand Up @@ -238,9 +271,7 @@ class WollokTestResultView extends ViewPart implements Observer {
textOutput = new Link(
textParent,
SWT.BORDER.bitwiseOr(SWT.WRAP).bitwiseOr(SWT.MULTI).bitwiseOr(SWT.V_SCROLL)
) => [

]
) => []
textOutput.background = new Color(Display.current, 255, 255, 255)
textOutput.foreground = new Color(Display.current, 50, 50, 50)

Expand All @@ -258,7 +289,8 @@ class WollokTestResultView extends ViewPart implements Observer {
textOutput.addSelectionListener(
new SelectionAdapter() {
override widgetSelected(SelectionEvent event) {
val fileOpenerStrategy = AbstractWollokFileOpenerStrategy.buildOpenerStrategy(event.text, results.container.project)
val fileOpenerStrategy = AbstractWollokFileOpenerStrategy.buildOpenerStrategy(event.text,
results.container.project)
val ITextEditor textEditor = fileOpenerStrategy.getTextEditor(WollokTestResultView.this)
val String fileName = fileOpenerStrategy.fileName
val Integer lineNumber = fileOpenerStrategy.lineNumber
Expand All @@ -267,7 +299,7 @@ class WollokTestResultView extends ViewPart implements Observer {
}
)
}

def createResults(Composite parent) {
val panel = new Composite(parent, SWT.NONE)

Expand Down Expand Up @@ -314,6 +346,7 @@ class WollokTestResultView extends ViewPart implements Observer {
}

override update(Observable o, Object arg) {

testTree.refresh(true)
testTree.expandAll

Expand Down Expand Up @@ -372,6 +405,8 @@ class WollokTestResultView extends ViewPart implements Observer {
def dispatch getOutputText(WollokTestResult result) {
result.state.getOutputText(result)
}


}

class WTestTreeLabelProvider extends LabelProvider {
Expand All @@ -388,9 +423,7 @@ class WTestTreeLabelProvider extends LabelProvider {
}

def dispatch getText(WollokTestContainer element) {
if (element.hasSuiteName) return element.suiteName
val base = URI.createURI(ResourcesPlugin.getWorkspace.root.locationURI.toString + "/")
element.mainResource.deresolve(base).toFileString
return element.asText()
}

def dispatch getText(WollokTestResult element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.util.List
import org.eclipse.emf.common.util.URI
import org.eclipse.xtend.lib.annotations.Accessors
import static extension org.uqbar.project.wollok.utils.WEclipseUtils.*
import org.eclipse.core.resources.ResourcesPlugin

@Accessors
class WollokTestContainer {
Expand Down Expand Up @@ -38,6 +39,12 @@ class WollokTestContainer {
def getProject() {
if (this.allTests.empty) return null
this.allTests.head.testResource.toIFile.project
}
}

def asText() {
if (this.hasSuiteName) return this.suiteName
val base = URI.createURI(ResourcesPlugin.getWorkspace.root.locationURI.toString + "/")
this.mainResource.deresolve(base).toFileString
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ import org.uqbar.project.wollok.ui.console.RunInUI
class WollokTestResults extends Observable implements WollokRemoteUITestNotifier {

boolean shouldShowOnlyFailuresAndErrors = false

@Accessors
var WollokTestContainer container

override assertError(String testName, String message, StackTraceElementDTO[] stackTrace, int lineNumber, String resource) {
testByName(testName).endedAssertError(message, stackTrace, lineNumber, resource)

this.setChanged
this.notifyObservers
this.notifyObservers()
}

override testOk(String testName) {

testByName(testName).endedOk()

this.setChanged
Expand Down Expand Up @@ -73,6 +74,7 @@ class WollokTestResults extends Observable implements WollokRemoteUITestNotifier
this.notifyObservers
}


override notifyObservers(Object arg) {
RunInUI.runInUI[super.notifyObservers(arg)]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import org.eclipse.core.runtime.CoreException
import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.debug.core.ILaunch
import org.eclipse.debug.core.ILaunchConfiguration
import org.eclipse.ui.PlatformUI
import org.uqbar.project.wollok.ui.console.RunInUI
import org.uqbar.project.wollok.ui.launch.Activator
import org.uqbar.project.wollok.ui.launch.shortcut.WollokLaunchDelegate
import org.uqbar.project.wollok.ui.tests.WollokTestResultView
Expand All @@ -16,9 +14,7 @@ import org.uqbar.project.wollok.ui.tests.WollokTestResultView
class WollokTestLaunchDelegate extends WollokLaunchDelegate {

override launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
RunInUI.runInUI[
PlatformUI.workbench.activeWorkbenchWindow.activePage.showView(WollokTestResultView.NAME)
]
WollokTestResultView.activate()
super.launch(configuration, mode, launch, monitor)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.uqbar.project.wollok.ui.tests.shortcut

import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.IMarker
import org.eclipse.core.resources.IProject
import org.eclipse.core.resources.IResource
import org.eclipse.core.runtime.CoreException
import org.eclipse.jface.dialogs.MessageDialog
import org.eclipse.swt.widgets.Display
import org.eclipse.ui.PlatformUI
import org.uqbar.project.wollok.Messages
import org.uqbar.project.wollok.ui.console.RunInUI
import org.uqbar.project.wollok.ui.launch.shortcut.LaunchConfigurationInfo
import org.uqbar.project.wollok.ui.launch.shortcut.WollokLaunchShortcut
import org.uqbar.project.wollok.ui.tests.WollokTestResultView
Expand All @@ -26,22 +27,32 @@ class WollokTestLaunchShortcut extends WollokLaunchShortcut {
x.doSave
}

override doLaunch(IFile currFile, String mode) {
override launch(IFile currFile, String mode) {
try {
// verifying there are no errors
if (!checkEclipseProject(currFile.project))
return;
activateWollokTestResultView
super.doLaunch(currFile, mode)
super.launch(currFile, mode)
} catch (CoreException e) {
// TODO: i18n
MessageDialog.openError(Display.current.activeShell, Messages.TestLauncher_LauncherError_Title,
Messages.TestLauncher_LauncherError_Message)
// something went wrong
MessageDialog.openError(Display.current.activeShell, "Launcher error",
"There was a problem while opening test launcher. See error log for more details.")
// something went wrong
}
}

def activateWollokTestResultView() {
RunInUI.runInUI [
PlatformUI.workbench.activeWorkbenchWindow.activePage.showView(WollokTestResultView.NAME)
]
WollokTestResultView.activate()
}

def checkEclipseProject(IProject project) {
val severity = project.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)
if (severity == IMarker.SEVERITY_ERROR) {
MessageDialog.openError(Display.current.activeShell, Messages.TestLauncher_CompilationErrorTitle,
Messages.TestLauncher_SeeProblemTab)
return false
}
return true
}
}

0 comments on commit 94fb88b

Please sign in to comment.