Skip to content

Commit

Permalink
Fix REPL Console without a File / Run all tests failure when launching
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Jul 7, 2017
1 parent 4b50853 commit 564a796
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import java.io.FileWriter
import java.util.ArrayList
import java.util.List
import org.apache.commons.cli.CommandLine
import org.apache.commons.cli.GnuParser
import org.apache.commons.cli.Option
import org.apache.commons.cli.OptionBuilder
import org.apache.commons.cli.Options
import org.eclipse.xtend.lib.annotations.Accessors
import org.uqbar.project.wollok.parser.OptionalGnuParser

/**
* @author jfernandes
Expand Down Expand Up @@ -52,8 +52,8 @@ class WollokLauncherParameters {
}

def parse(String[] args) {
val parser = new GnuParser
val cmdLine = parser.parse(options, args)
val parser = new OptionalGnuParser
val cmdLine = parser.parse(options, args, false)
hasRepl = cmdLine.hasOption("r")

tests = cmdLine.hasOption("t")
Expand All @@ -70,10 +70,9 @@ class WollokLauncherParameters {
throw new RuntimeException("Both RequestsPort and EventsPort should be informed")
}

parseLibraries(cmdLine)
parseLibraries(cmdLine)
parseWollokFiles(cmdLine)


if (!wollokFiles.empty && hasRepl && !wollokFiles.get(0).endsWith(".wlk")){
throw new RuntimeException("Repl can only be used with .wlk files.")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.uqbar.project.wollok.parser

import org.apache.commons.cli.GnuParser
import java.util.ListIterator
import org.apache.commons.cli.ParseException

/**
* https://stackoverflow.com/questions/6049470/can-apache-commons-cli-options-parser-ignore-unknown-command-line-options
*
* GnuParser fails if an option is not present. This is annoying when dealing with "optional options"
*
*/
class OptionalGnuParser extends GnuParser {

override protected processOption(String optionName, ListIterator it) throws ParseException {
try {
super.processOption(optionName, it)
} catch (ParseException e) {
// nothing as we want to be able to parse all options - present or not
}
}

}
2 changes: 1 addition & 1 deletion org.uqbar.project.wollok.ui.launch/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
class="org.uqbar.project.wollok.ui.tests.shortcut.WollokAllTestsLaunchShortcut"
description="Launch All Wollok Tests"
icon="icons/wollok-icon-test_16.png"
id="org.uqbar.project.wollok.ui.tests.shortcut"
id="org.uqbar.project.wollok.ui.allTests.shortcut"
label="%wollok.launch.allTests"
modes="run, debug">
<contextualLaunch>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ import org.uqbar.project.wollok.ui.tests.AbstractWollokFileOpenerStrategy

import static extension org.uqbar.project.wollok.utils.WEclipseUtils.*

/**
* Intended as an observer of REPL console: searches for a "(fileName:lineNumber)"
* pattern and creates a hyperlink to that file, opening Wollok editor.
* Reuses same behavior as test stack trace.
*
* @author dodain
* based on
*/
class WollokLinkListenerDelegate implements IPatternMatchListenerDelegate {

var IURIEditorOpener opener

IURIEditorOpener opener
TextConsole console

override connect(TextConsole console) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.IProject
import org.eclipse.core.runtime.IAdaptable
import org.eclipse.debug.ui.ILaunchShortcut
import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.IPackageFragmentRoot
import org.eclipse.jface.viewers.ISelection
import org.eclipse.jface.viewers.IStructuredSelection
Expand Down Expand Up @@ -39,6 +40,10 @@ abstract class AbstractFileLaunchShortcut implements ILaunchShortcut {
throw new RuntimeException("Launcher not found for " + currProject)
}

def void launch(IJavaProject currProject, String mode) {
throw new RuntimeException("Launcher not found for " + currProject)
}

def dispatch void doLaunch(IProject currProject, String mode) {
launch(currProject, mode)
}
Expand All @@ -47,6 +52,10 @@ abstract class AbstractFileLaunchShortcut implements ILaunchShortcut {
launch(packageRoot.javaProject.project, mode)
}

def dispatch void doLaunch(IJavaProject project, String mode) {
launch(project, mode)
}

def dispatch void doLaunch(IAdaptable adaptable, String mode) {
launch(adaptable.adapt(IFile), mode)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.uqbar.project.wollok.ui.launch.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.core.runtime.Platform
Expand Down Expand Up @@ -48,7 +46,7 @@ class WollokLaunchShortcut extends AbstractFileLaunchShortcut {
if (currFile.project.hasErrors) {
val confirm = MessageDialog.openQuestion(Display.current.activeShell,
Messages.TestLauncher_CompilationErrorTitle, Messages.TestLauncher_SeeProblemTab)
if(!confirm) return;
if(!confirm) return
}
doLaunch(currFile, mode)
}
Expand Down Expand Up @@ -127,10 +125,10 @@ class WollokLaunchShortcut extends AbstractFileLaunchShortcut {
}

class LaunchConfigurationInfo {
@Accessors String name;
@Accessors String project;
@Accessors String file;
@Accessors Iterable<String> libs;
@Accessors String name
@Accessors String project
@Accessors String file
@Accessors Iterable<String> libs

new(IFile file) {
name = file.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.uqbar.project.wollok.ui.tests.shortcut
import java.util.List
import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.IProject
import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jface.dialogs.MessageDialog
import org.eclipse.swt.widgets.Display
import org.uqbar.project.wollok.Messages
Expand Down Expand Up @@ -42,10 +43,14 @@ class WollokAllTestsLaunchShortcut extends WollokTestLaunchShortcut {
MessageDialog.openError(Display.current.activeShell, Messages.TestLauncher_NoTestToRun_Title,
Messages.TestLauncher_NoTestToRun_Message)
return;
}
}
val currFile = testFiles.head
this.doLaunch(currFile, mode)
}

override launch(IJavaProject currProject, String mode) {
launch(currProject.elementName.project, mode)
}

def List<IFile> getTestFiles(IProject project) {
project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ class WollokTestLaunchShortcut extends WollokLaunchShortcut {

override launch(IFile currFile, String mode) {
try {
// verifying there are no errors
if (!checkEclipseProject(currFile.project))
return;
activateWollokTestResultView
super.launch(currFile, mode)
} catch (CoreException e) {
Expand All @@ -46,13 +43,4 @@ class WollokTestLaunchShortcut extends WollokLaunchShortcut {
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 564a796

Please sign in to comment.