Skip to content

Commit

Permalink
Add dialog for R version 2.13. or later
Browse files Browse the repository at this point in the history
checks the installed R version and prompts the user if R needs to be updated
  • Loading branch information
Valentin Georgiev committed Jan 20, 2012
1 parent dd90a11 commit 6dce72d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
Expand Up @@ -62,8 +62,14 @@ public interface IRBusinessManager extends IBioclipseManager {

@Recorded
@PublishedMethod(
methodSummary = "Splits a string on newline and semicolon" +
methodSummary = "Splits a string on newline and semicolon " +
"and returns a String array of commmands"
)
public String[] parseCommand(String command);
@Recorded
@PublishedMethod(
methodSummary = "Gets the boolean " +
"noting if we have the right R version"
)
public boolean getRightRVersion();
}
Expand Up @@ -32,18 +32,20 @@
import net.bioclipse.managers.business.IBioclipseManager;
import net.bioclipse.r.RServiManager;
import net.bioclipse.statistics.model.IMatrixResource;
//import net.bioclipse.ui.business.Activator;

import org.apache.log4j.Logger;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;

import de.walware.rj.data.RObject;
import de.walware.rj.data.RStore;
import de.walware.rj.servi.RServi;

import java.util.regex.Pattern;

public class RBusinessManager implements IBioclipseManager {

private static final Logger logger = Logger.getLogger(RBusinessManager.class);
Expand All @@ -54,6 +56,7 @@ public class RBusinessManager implements IBioclipseManager {
private IPath workspacePath;
private static final String OS = System.getProperty("os.name").toString();
private RServiManager rsmanager = new RServiManager("Rconsole");
private boolean rightRVersion = true;
public static String NEWLINE = System.getProperty("line.separator");
public static String cmdparser = "(;?\r?\n|;)";
public static final String fileseparator = java.io.File.separator;
Expand Down Expand Up @@ -201,9 +204,10 @@ private boolean runRCmd(String Rcommand) {
*/
private void checkRdependencies() throws FileNotFoundException {
runRCmd("R -e \"getRversion()\" -s");
// if (!status.contains("1.14.")) {
// MessageDialog.openInformation(Viewer, "Warning", "R version warning");
// }
int st = compare(status.substring(5, (status.length() - 2)), "2.12.9");
if (st < 0) {
rightRVersion = false;
}
logger.debug(status);
if (!runRCmd("R -e \".find.package('rJava')\" -s")) {
logger.debug("Error: Package rJava not found.");
Expand Down Expand Up @@ -253,6 +257,10 @@ private void checkRdependencies() throws FileNotFoundException {
}
}

public boolean getRightRVersion(){
return this.rightRVersion;
}

private boolean installRj() throws FileNotFoundException {
if (!runRCmd("R -e \"install.packages('rj', repos='http://download.walware.de/rj-1.0')\" -s")) {
status += "Error installing rj-package, try manually from: http://www.walware.de/it/downloads/rj.mframe";
Expand Down Expand Up @@ -543,4 +551,26 @@ private String extractRError(String error) {
}
return result;
}

private static int compare(String v1, String v2) {
String s1 = normalisedVersion(v1);
String s2 = normalisedVersion(v2);
int cmp = s1.compareTo(s2);
String cmpStr = cmp < 0 ? "<" : cmp > 0 ? ">" : "==";
System.out.printf("'%s' %s '%s'%n", v1, cmpStr, v2);
return cmp;
}

public static String normalisedVersion(String version) {
return normalisedVersion(version, ".", 4);
}

public static String normalisedVersion(String version, String sep, int maxWidth) {
String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
StringBuilder sb = new StringBuilder();
for (String s : split) {
sb.append(String.format("%" + maxWidth + 's', s));
}
return sb.toString();
}
}
Expand Up @@ -12,6 +12,7 @@
import net.bioclipse.r.business.IRBusinessManager;
import net.bioclipse.scripting.ui.views.ScriptingConsoleView;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Composite;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -29,6 +30,15 @@ public RConsoleView() {
public void createPartControl(Composite parent) {
super.createPartControl(parent);
getRBusinessManager();
if (!r.getRightRVersion()){
getSite().getShell().getDisplay().asyncExec
(new Runnable() {
public void run() {
MessageDialog.openError(getSite().getShell(),"Incompatible R version","Runnig R within Bioclipse requires R version 2.13, or later!");
}
});
}

}

public String execSnippet(String command) {
Expand Down

0 comments on commit 6dce72d

Please sign in to comment.