forked from joeferner/node-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostInstall.js
More file actions
96 lines (76 loc) · 2.09 KB
/
Copy pathpostInstall.js
File metadata and controls
96 lines (76 loc) · 2.09 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var glob = require('glob');
var fs = require('fs');
var path = require('path');
var os = require('os');
require('find-java-home')(function(err, home){
var dll;
var dylib;
var so,soFiles;
var binary;
if(os.platform() == 'linux') {
home = process.env.WORKSPACE + '/jdk';
}
if(home){
console.log(`home = ${home}`);
dll = glob.sync('**/jvm.dll', {cwd: home})[0];
dylib = glob.sync('**/libjvm.dylib', {cwd: home})[0];
soFiles = glob.sync('**/libjvm.so', {cwd: home});
console.log("soFiles = ");
console.log(soFiles);
if(soFiles.length > 0) {
so = getCorrectSoForPlatform(soFiles);
}
console.log(`so = ${so}`);
binary = dll || dylib || so;
console.log(`binary = ${binary}`);
fs.writeFileSync(
path.resolve(__dirname, './build/jvm_dll_path.json'),
binary
? JSON.stringify(
path.delimiter
+ path.dirname(path.resolve(home, binary))
)
: '""'
);
var buildPath = path.resolve(__dirname, './build/');
var targetPath;
try {
targetPath = path.resolve(process.env.INIT_CWD || process.env.WORKSPACE, './javabridge');
} catch(e) {
console.log(e);
targetPath = '../../javabridge';
}
fs.renameSync(buildPath, targetPath);
}
});
function getCorrectSoForPlatform(soFiles){
var so = _getCorrectSoForPlatform(soFiles);
if (so) {
so = removeDuplicateJre(so);
}
return so;
}
function removeDuplicateJre(filePath){
while(filePath.indexOf('jre/jre')>=0){
filePath = filePath.replace('jre/jre','jre');
}
return filePath;
}
function _getCorrectSoForPlatform(soFiles){
var architectureFolderNames = {
'ia32': 'i386',
'x64': 'amd64'
};
if(os.platform() != 'sunos')
return soFiles[0];
var requiredFolderName = architectureFolderNames[os.arch()];
console.log(`requiredFolderName = ${requiredFolderName}`)
for (var i = 0; i < soFiles.length; i++) {
var so = soFiles[i];
if(so.indexOf('server')>0)
if(so.indexOf(requiredFolderName)>0)
console.log(`server so = ${so}`)
return so;
}
return soFiles[0];
}