public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/JRI.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>flintstones.group</groupId>
<artifactId>flintstones.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>flintstones.engine.R</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] R</name>
</project>
+50
View File
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.engine.R</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1779484362552</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,26 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: R
Bundle-SymbolicName: flintstones.engine.R
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flinstones.engine.R
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.e4.core.di,
org.eclipse.e4.core.contexts,
org.eclipse.e4.ui.model.workbench,
javax.inject,
org.eclipse.core.jobs,
org.eclipse.e4.core.services,
org.eclipse.equinox.registry,
org.eclipse.swt,
javax.annotation
Import-Package: flintstones.entity.domain.messages,
flintstones.entity.problemelement.messages
Bundle-ClassPath: lib/JRI.jar,
.
Export-Package: flintstones.engine.R,
flintstones.engine.R.provider,
flintstones.engine.R.provider.internal,
org.rosuda.JRI
Service-Component: component.xml
Bundle-ActivationPolicy: lazy
@@ -0,0 +1,8 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
lib/,\
lib/JRI.jar,\
component.xml
jars.compile.order = .
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="flintstones.engine.R.provider">
<implementation class="flintstones.engine.R.provider.internal.REngineProviderContextFunction"/>
<property name="service.context.key" type="String" value="flintstones.engine.R.provider.IREngineProvider"/>
<service>
<provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
</service>
</scr:component>
Binary file not shown.
@@ -0,0 +1,60 @@
package flintstones.engine.R;
import javax.script.ScriptException;
import org.rosuda.JRI.Rengine;
import flintstones.engine.R.engine.IEngine;
/**
* R engine for ASE
*
* @author Sinbad²
* @version 3.0
*/
public class R implements IEngine {
public static final String ID = "R"; //$NON-NLS-1$
private Rengine rengine;
private String name;
private R() {
super();
name = ID;
rengine = null;
}
/**
* Build R engine
*
* @param rengine
* JRI Rengine
*/
public R(Rengine rengine) {
this();
assert rengine != null;
this.rengine = rengine;
}
@Override
public String getName() {
return name;
}
@Override
public Object getEngine() {
return rengine;
}
@Override
public Object eval(String script) throws ScriptException {
return rengine.eval(script);
}
@Override
public void end() {
rengine.end();
}
}
@@ -0,0 +1,37 @@
package flintstones.engine.R.engine;
import javax.script.ScriptException;
public interface IEngine {
/**
* Return engine name
*
* @return Engine name
*/
String getName();
/**
* Return engine
*
* @return Engine
*/
Object getEngine();
/**
* Evaluate script
*
* @param script
* Script to eval
* @return Evaluation result
* @throws ScriptException
*/
Object eval(String script) throws ScriptException;
/**
* End engine
*/
void end();
}
@@ -0,0 +1,20 @@
package flintstones.engine.R.provider;
import flintstones.engine.R.engine.IEngine;
public interface IREngineProvider {
public static final String R = "R"; //$NON-NLS-1$
public static final String R_STATUS = "R_STATUS"; //$NON-NLS-1$
public static final String R_MANUAL = "R_MANUAL"; //$NON-NLS-1$
public static final String R_VERSION = "R_VERSION";
public static final String R_PATHS = "R_PATHS"; //$NON-NLS-1$
/**
* Return R engine instance
*
* @return R engine instance
*/
IEngine getEngine();
}
@@ -0,0 +1,173 @@
package flintstones.engine.R.provider.internal;
import java.io.File;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
import org.rosuda.JRI.Rengine;
import flintstones.engine.R.engine.IEngine;
import flintstones.engine.R.R;
import flintstones.engine.R.provider.IREngineProvider;
public class REngineDefaultProvider implements IREngineProvider {
private static final String VERSION = "--vanilla"; //$NON-NLS-1$
private static final String JRI_IGNORE_FLAG = "jri.ignore.ule"; //$NON-NLS-1$
private static final String JRI_IGNORE_FLAG_VALUE = "yes"; //$NON-NLS-1$
private static final String R_HOME = "R_HOME"; //$NON-NLS-1$
private static final String BINARIES_DIRECTORY = "bin"; //$NON-NLS-1$
private static final String LIBRARIES_DIRECTORY = "library"; //$NON-NLS-1$
private static final String R_VERSION_CMD = "R.version.string"; //$NON-NLS-1$
private static final String R_JRI_CMD = "system.file(\"jri\",package=\"rJava\")"; //$NON-NLS-1$
@Inject
private IEclipseContext context;
private IEclipseContext topContext;
private R engine;
private Job job;
@PostConstruct
private void initialize() {
System.out.println("initialize");
getTopContext();
//saveRConfigurationInstructions();
saveRStatus();
createEngineJob(R);
}
private void getTopContext() {
/*IEclipseContext parent = context;
do {
topContext = parent;
parent = topContext.getParent();
} while (parent != null);*/
MApplication application = context.get(MApplication.class);
topContext = application.getContext();
}
@Override
public IEngine getEngine() {
try {
job.join();
} catch (InterruptedException e) {
// Nothing to do
}
return (flintstones.engine.R.engine.IEngine) topContext.get(R);
}
private void saveRStatus() {
String status = checkDependenciesStatus();
topContext.set(R_STATUS, status);
}
private String checkDependenciesStatus() {
System.setProperty(JRI_IGNORE_FLAG, JRI_IGNORE_FLAG_VALUE);
try {
if (!Rengine.jriLoaded) {
return "Invalid jri";
}
if (!Rengine.versionCheck()) {
return "Invalid jri version";
}
if (System.getenv(R_HOME) == null) {
return "R_HOME not detected";
}
if (!validateR_HOME()) {
return "Invalid R_HOME";
}
} catch (UnsatisfiedLinkError error) {
return "Invalid jri";
}
return null;
}
private boolean validateR_HOME() {
String home = System.getenv(R_HOME);
File dir = new File(home);
if (!dir.exists()) {
return false;
}
if (!dir.canRead()) {
return false;
}
if (!dir.isDirectory()) {
return false;
}
List<String> files = Arrays.asList(dir.list());
if (!files.contains(BINARIES_DIRECTORY) || !files.contains(LIBRARIES_DIRECTORY)) {
return false;
}
return true;
}
private void createEngineJob(String scriptName) {
job = new Job(scriptName) {
@Override
protected IStatus run(IProgressMonitor monitor) {
createEngine();
return (topContext.get(scriptName) != null)
? Status.OK_STATUS
: Status.CANCEL_STATUS;
}
};
job.schedule();
}
private void createEngine() {
Rengine rengine = getRengine();
topContext.set(R, (rengine != null)
? new R(rengine)
: null);
}
private Rengine getRengine() {
Rengine result = null;
if (topContext.get(R_STATUS) == null) {
result = new Rengine(new String[] { VERSION }, false, null);
if (!result.waitForR()) {
result = null;
} else {
String rVersion = result.eval(R_VERSION_CMD).asString();
String rJRI = result.eval(R_JRI_CMD).asString();
String rHome = System.getenv(R_HOME);
topContext.set(R_VERSION, rVersion);
topContext.set(
R_PATHS,
MessageFormat.format(
"{0}\n\nJRI:\n{1}\n\nR_HOME:\n{2}", //$NON-NLS-1$
rVersion,
rJRI,
rHome));
}
}
return result;
}
public void end() {
if (engine != null) {
engine.end();
}
}
}
@@ -0,0 +1,25 @@
package flintstones.engine.R.provider.internal;
import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
import flintstones.engine.R.provider.IREngineProvider;
public class REngineProviderContextFunction extends ContextFunction {
@Override
public Object compute (IEclipseContext context, String contextKey) {
IREngineProvider rEngineProvider = ContextInjectionFactory.make(REngineDefaultProvider.class, context);
MApplication application = context.get(MApplication.class);
IEclipseContext applicationContext = application.getContext();
applicationContext.set(IREngineProvider.class, rEngineProvider);
return rEngineProvider;
}
}