File: zzz.R.in

package info (click to toggle)
rjava 1.0-11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,184 kB
  • sloc: java: 13,223; ansic: 5,479; sh: 3,776; xml: 325; makefile: 250; perl: 33
file content (53 lines) | stat: -rw-r--r-- 2,722 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
.onLoad <- function(libname, pkgname) {
   ## we can skip all the detection logic if forced - assuming the user has loaded JVM already
   if (!nzchar(Sys.getenv("RJAVA_FORCE_LOAD"))) {
      ## On OS X with Oracle Java we may need to work around Oracle bug:
      ## https://bugs.openjdk.java.net/browse/JDK-7131356
      use.dynload <- FALSE
      @USE_DYNLOAD_TRUE@use.dynload <- TRUE
      if (length(grep("^darwin", R.version$os))) {
         jh <- Sys.getenv("JAVA_HOME")
         if (nzchar(jh) && !dir.exists(jh)) {
             warning("JAVA_HOME is set incorrectly! Ingoring.")
             jh <- ""
         }
         if (!nzchar(jh) && file.exists("/usr/libexec/java_home"))
               jh <- system("/usr/libexec/java_home", intern=TRUE)[1L]
         if (!nzchar(jh)) {
            if (use.dynload)
               stop("Cannot find Java. Install Java run-time and use R CMD javareconf.\nAs a last resort you can set JAVA_HOME appropriately.")
            warning("Cannot find Java. Install Java run-time and use R CMD javareconf.\nAs a last resort you can set JAVA_HOME if you know the correct value.")
         }
         if (file.exists(file.path(jh, "jre/lib"))) jh <- file.path(jh, "jre")
         dlp <- Sys.getenv("DYLD_LIBRARY_PATH")
         if (nzchar(dlp)) dlp <- paste0(":", dlp)
         ## pre-load JLI due to Oracle bug
         if (file.exists(jli <- file.path(jh, "lib/jli/libjli.dylib")))
            dyn.load(jli, FALSE)
         ## this is mandatory - we need the JVM
         if (file.exists(jvm <- file.path(jh, "lib/server/libjvm.dylib"))) {
            dyn.load(jvm, FALSE)
            Sys.setenv(DYLD_LIBRARY_PATH=paste0(file.path(jh, "lib/server"), dlp))
         } else {
            warning("Cannot find JVM library '", jvm, "'\nInstall Java and/or check JAVA_HOME (if in doubt, do NOT set it, it will be detected)")
            if (use.dynload) stop("JVM could not be found")
         }
      } else if (use.dynload) {
         jh <- Sys.getenv("JAVA_HOME")
         if (nzchar(jh) && !dir.exists(jh)) {
            warning("JAVA_HOME is set incorrectly! Ingoring.")
            jh <- ""
         }
         if (!nzchar(jh))
            stop("JAVA_HOME is requied for dynamically loaded JVM, but is not set.\nRe-run R CMD javareconf or set JAVA_HOME correctly.")
         if (file.exists(file.path(jh, "jre/lib"))) jh <- file.path(jh, "jre")
         if (!file.exists(jvm <- file.path(jh, "lib/server/libjvm.so")))
            stop("Cannot find ", jvm,", re-configure R or use valid JAVA_HOME")
         dyn.load(jvm, FALSE)
      }
   } ## RJAVA_FORCE_LOAD

   library.dynam("rJava", pkgname, libname)
   # pass on to the system-independent part
   .jfirst(libname, pkgname)
}