11var glob = require ( 'glob' ) ;
22var fs = require ( 'fs' ) ;
33var path = require ( 'path' ) ;
4+ var os = require ( 'os' ) ;
45
56require ( 'find-java-home' ) ( function ( err , home ) {
67 var dll ;
78 var dylib ;
8- var so ;
9+ var so , soFiles ;
910 var binary ;
1011
1112 if ( home ) {
1213 dll = glob . sync ( '**/jvm.dll' , { cwd : home } ) [ 0 ] ;
13- so = glob . sync ( '**/libjvm.so' , { cwd : home } ) [ 0 ] ;
1414 dylib = glob . sync ( '**/libjvm.dylib' , { cwd : home } ) [ 0 ] ;
15+ soFiles = glob . sync ( '**/libjvm.so' , { cwd : home } ) ;
16+ so = getCorrectSoForPlatform ( soFiles ) ;
17+
1518 binary = dll || dylib || so ;
1619
1720 fs . writeFileSync (
@@ -25,3 +28,38 @@ require('find-java-home')(function(err, home){
2528 ) ;
2629 }
2730} ) ;
31+
32+ function getCorrectSoForPlatform ( soFiles ) {
33+ var so = _getCorrectSoForPlatform ( soFiles ) ;
34+ return removeDuplicateJre ( so ) ;
35+ }
36+
37+ function removeDuplicateJre ( filePath ) {
38+ while ( filePath . indexOf ( 'jre/jre' ) >= 0 ) {
39+ filePath = filePath . replace ( 'jre/jre' , 'jre' ) ;
40+ }
41+ return filePath ;
42+ }
43+
44+ function _getCorrectSoForPlatform ( soFiles ) {
45+
46+ var architectureFolderNames = {
47+ 'ia32' : 'i386' ,
48+ 'x64' : 'amd64'
49+ } ;
50+
51+ if ( os . platform ( ) != 'sunos' )
52+ return soFiles [ 0 ] ;
53+
54+ var requiredFolderName = architectureFolderNames [ os . arch ( ) ] ;
55+
56+ for ( var i = 0 ; i < soFiles . length ; i ++ ) {
57+ var so = soFiles [ i ] ;
58+
59+ if ( so . indexOf ( 'server' ) > 0 )
60+ if ( so . indexOf ( requiredFolderName ) > 0 )
61+ return so ;
62+ }
63+
64+ return soFiles [ 0 ] ;
65+ }
0 commit comments