r4101 - in branches/4.3.0-log4j2: . src/main/assembly src/main/java/fr/ifremer/isisfish src/main/java/fr/ifremer/isisfish/util src/test/java/fr/ifremer/isisfish
Author: echatellier Date: 2014-08-28 16:25:25 +0200 (Thu, 28 Aug 2014) New Revision: 4101 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4101 Log: Use jri installed by R with rJava R package. Added: branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/util/RUtil.java Modified: branches/4.3.0-log4j2/pom.xml branches/4.3.0-log4j2/src/main/assembly/isisfish.bat branches/4.3.0-log4j2/src/main/assembly/isisfish.sh branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/IsisFish.java branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/util/JavadocHelper.java branches/4.3.0-log4j2/src/test/java/fr/ifremer/isisfish/AbstractIsisFishTest.java Modified: branches/4.3.0-log4j2/pom.xml =================================================================== --- branches/4.3.0-log4j2/pom.xml 2014-08-27 14:00:36 UTC (rev 4100) +++ branches/4.3.0-log4j2/pom.xml 2014-08-28 14:25:25 UTC (rev 4101) @@ -66,7 +66,15 @@ <scope>compile</scope> </dependency> + <!-- Temp update for log4j 2 detection --> <dependency> + <groupId>org.jboss.logging</groupId> + <artifactId>jboss-logging</artifactId> + <version>3.2.0.Beta1</version> + <scope>runtime</scope> + </dependency> + + <dependency> <groupId>org.nuiton</groupId> <artifactId>nuiton-profiling</artifactId> <version>3.0</version> Modified: branches/4.3.0-log4j2/src/main/assembly/isisfish.bat =================================================================== --- branches/4.3.0-log4j2/src/main/assembly/isisfish.bat 2014-08-27 14:00:36 UTC (rev 4100) +++ branches/4.3.0-log4j2/src/main/assembly/isisfish.bat 2014-08-28 14:25:25 UTC (rev 4101) @@ -5,4 +5,4 @@ rem SET PATH=%PATH%;%R_HOME%\bin\i386 echo [Script] Isis starting... -java -Xmx900M -Djri.load.classpath.libs=true -jar ${project.build.finalName}.${project.packaging} %1 %2 %3 %4 %5 %6 %7 %8 %9 > debug.txt 2>&1 +java -Xmx900M -jar ${project.build.finalName}.${project.packaging} %1 %2 %3 %4 %5 %6 %7 %8 %9 > debug.txt 2>&1 Modified: branches/4.3.0-log4j2/src/main/assembly/isisfish.sh =================================================================== --- branches/4.3.0-log4j2/src/main/assembly/isisfish.sh 2014-08-27 14:00:36 UTC (rev 4100) +++ branches/4.3.0-log4j2/src/main/assembly/isisfish.sh 2014-08-28 14:25:25 UTC (rev 4101) @@ -2,4 +2,4 @@ MEMORY="-Xmx1024M" -java $MEMORY -Djri.load.classpath.libs=true -jar ${project.build.finalName}.${project.packaging} $* &> debug.txt +java $MEMORY -jar ${project.build.finalName}.${project.packaging} $* &> debug.txt Modified: branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/IsisFish.java =================================================================== --- branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/IsisFish.java 2014-08-27 14:00:36 UTC (rev 4100) +++ branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/IsisFish.java 2014-08-28 14:25:25 UTC (rev 4101) @@ -83,6 +83,7 @@ import fr.ifremer.isisfish.ui.util.ErrorHelper; import fr.ifremer.isisfish.util.IsisCache; import fr.ifremer.isisfish.util.IsisMatrixSemanticMapper; +import fr.ifremer.isisfish.util.RUtil; import fr.ifremer.isisfish.vcs.VCS; import fr.ifremer.isisfish.vcs.VCSActionEvent; import fr.ifremer.isisfish.vcs.VCSException; @@ -120,16 +121,10 @@ } public static void main(String... args) throws Exception { - - // TODO as of 20140720, hibernate fails to detect log4j 2.0, force slf4j - System.setProperty("org.jboss.logging.provider", "slf4j"); - + // permet de faire fonctionner la compilation en webstart System.setSecurityManager(null); - // set Rtype in jni mode - System.setProperty("R.type", "jni"); - // initialisation de l'application init(args); @@ -143,6 +138,9 @@ log.info("PATH: " + System.getenv("PATH")); } + // init R way for isis + RUtil.initJri(); + // action after init config.doAction(IsisConfig.STEP_AFTER_INIT); Modified: branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/util/JavadocHelper.java =================================================================== --- branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/util/JavadocHelper.java 2014-08-27 14:00:36 UTC (rev 4100) +++ branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/util/JavadocHelper.java 2014-08-28 14:25:25 UTC (rev 4101) @@ -39,7 +39,6 @@ import java.util.List; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.reflect.MethodUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.FileUtil; Added: branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/util/RUtil.java =================================================================== --- branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/util/RUtil.java (rev 0) +++ branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/util/RUtil.java 2014-08-28 14:25:25 UTC (rev 4101) @@ -0,0 +1,137 @@ +/* + * #%L + * IsisFish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.util; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.util.List; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Utility class fo R integration with isis fish. + * + * @author Eric Chatellier + */ +public class RUtil { + + private static final Log log = LogFactory.getLog(RUtil.class); + + /** + * Try to call "R" process to get location where jri is installed. + */ + public static void initJri() { + + // set Rtype in jni mode + System.setProperty("R.type", "jni"); + + try { + ProcessBuilder pb = new ProcessBuilder("Rscript", "-e", "installed.packages()[which(installed.packages()[,1]=='rJava'),]['LibPath']"); + Process process = pb.start(); + int exitValue = process.waitFor(); + + if (exitValue == 0) { + // normal exit + parseRscriptOutput(process.getInputStream()); + } else { + // R trouvé, mais la commande R a échoué + InputStream err = process.getErrorStream(); + if (log.isErrorEnabled()) { + log.error("Can't call Rscript : " + IOUtils.toString(err)); + } + } + } catch (IOException ex) { + // Le processus n'a pas pu être lancé (R non trouvé) + if (log.isDebugEnabled()) { + log.debug("Can't find R", ex); + } + } catch (InterruptedException ex) { + if (log.isErrorEnabled()) { + log.error("Can't find R", ex); + } + } + } + + /** + * Parse valid Rscript output to find if rJava is installed and where it is installed. + * + * @param is process output + * @throws IOException + */ + protected static void parseRscriptOutput(InputStream is) throws IOException { + List<String> output = IOUtils.readLines(is); + + // 1 lignes = commande OK, mais rJava n'est pas installé + // 2 lignes = commande OK et rJava est installé + if (output.size() == 1) { + //installRJava(); + } else if (output.size() == 2) { + // get install location without "" + String location = output.get(1).trim(); + location = StringUtils.removeStart(location, "\""); + location = StringUtils.removeEnd(location, "\""); + // build full library path + location = location.replace('/', File.separatorChar); + location += File.separator + "rJava" + File.separator + "jri"; + setJavaLibraryPath(location); + } else if (log.isErrorEnabled()) { + log.error("Can't analyze Rscript output. was: "); + for (String line : output) { + log.error(line); + } + } + } + + /** + * Set runtime java library path. + * + * http://fahdshariff.blogspot.fr/2011/08/changing-java-library-path-at-runtime... + * + * @param newValue new value to set + */ + protected static void setJavaLibraryPath(String newValue) { + if (log.isInfoEnabled()) { + log.info("Adding '" + newValue + "' to java.library.path"); + } + System.setProperty("java.library.path", newValue); + + //set sys_paths to null + try { + final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths"); + sysPathsField.setAccessible(true); + sysPathsField.set(null, null); + } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) { + if (log.isErrorEnabled()) { + log.error("Cant' reset ClassLoader#sys_paths value", ex); + } + } + } +} Property changes on: branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/util/RUtil.java ___________________________________________________________________ Added: svn:eol-style + native Added: svn:keywords + Author Date Id Revision HeadURL Modified: branches/4.3.0-log4j2/src/test/java/fr/ifremer/isisfish/AbstractIsisFishTest.java =================================================================== --- branches/4.3.0-log4j2/src/test/java/fr/ifremer/isisfish/AbstractIsisFishTest.java 2014-08-27 14:00:36 UTC (rev 4100) +++ branches/4.3.0-log4j2/src/test/java/fr/ifremer/isisfish/AbstractIsisFishTest.java 2014-08-28 14:25:25 UTC (rev 4101) @@ -86,9 +86,6 @@ @BeforeClass public static void init() throws Exception { - // TODO as of 20140720, hibernate fails to detect log4j 2.0, force slf4j - System.setProperty("org.jboss.logging.provider", "slf4j"); - File mavenTestDir = getTestDirectory(); dirIsisBase = FileUtil.createTempDirectory("isisdbtest", "", mavenTestDir);
participants (1)
-
echatellier@users.forge.codelutin.com