Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of node-pre-gyp (latest) #257

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node-java.cbp
*.iml
*.kdev4
*/.kdev_include_paths
lib/jvm_dll_path.json
11 changes: 11 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@
},
],
]
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
"destination": "<(module_path)"
}
]
}
]
}
89 changes: 89 additions & 0 deletions install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
var pregyp = require('node-pre-gyp');
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 (!home) {
console.log('Java home not found. Can\'t continue');
}

if(home){
console.log('Java home found. Searching for applicable DLLs');

dll = glob.sync('**/jvm.dll', {cwd: home})[0];
dylib = glob.sync('**/libjvm.dylib', {cwd: home})[0];
soFiles = glob.sync('**/libjvm.so', {cwd: home});

if(soFiles.length>0)
so = getCorrectSoForPlatform(soFiles);

binary = dll || dylib || so;

var jvmDllPath = path.resolve(__dirname, './lib/jvm_dll_path.json');
var jvmDllContent = path.delimiter + path.dirname(path.resolve(home, binary));

console.log('Creating ' + jvmDllPath);

fs.writeFileSync(
jvmDllPath,
binary ? JSON.stringify(jvmDllContent) : '""'
);

if (binary) {
console.log('Setting environment path for JVM DLL');
process.env.PATH += jvmDllContent;
}

var pregypRun = new pregyp.Run();
pregypRun.parseArgv([ '--fallback-to-build' ]);

pregypRun.commands.install(pregypRun, function() {
console.log('Done installing with node-pre-gyp');
});
}
});

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()];

for (var i = 0; i < soFiles.length; i++) {
var so = soFiles[i];

if(so.indexOf('server')>0)
if(so.indexOf(requiredFolderName)>0)
return so;
}

return soFiles[0];
}
7 changes: 4 additions & 3 deletions lib/nodeJavaBridge.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

process.env.PATH += require('../build/jvm_dll_path.json');

var _ = require('lodash');
var async = require('async');
var path = require('path');
var fs = require('fs');
var binaryPath = path.resolve(path.join(__dirname, "../build/Release/nodejavabridge_bindings.node"));

process.env.PATH += require('..' + path.sep + 'lib' + path.sep + 'jvm_dll_path.json');

var binaryPath = path.resolve(path.join(__dirname, "../lib/binding/nodejavabridge_bindings.node"));
var bindings = require(binaryPath);

var java = module.exports = new bindings.Java();
Expand Down
18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,24 @@
"find-java-home": "0.1.2",
"glob": "5.0.5",
"lodash": "3.7.0",
"nan": "2.0.9"
"nan": "2.0.9",
"node-pre-gyp": "0.5.x"
},
"devDependencies": {
"chalk": "1.0.0",
"nodeunit": "0.9.1",
"when": "3.7.2"
"when": "3.7.2",
"aws-sdk": "~2.0.0-rc.15"
},
"bundledDependencies":["node-pre-gyp"],
"scripts": {
"test": "node testRunner.js",
"postinstall": "node postInstall.js"
"install": "node install.js",
"test": "node testRunner.js"
},
"main": "./index.js"
"main": "./index.js",
"binary": {
"module_name": "nodejavabridge_bindings",
"module_path": "./lib/binding/",
"host": "https://node-java.s3.amazonaws.com/"
}
}
2 changes: 1 addition & 1 deletion testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var tests = glob.sync(path.join('testAsyncOptions', '*.js'));
tests.unshift('test test8'); // Arrange to run the primary tests first, in a single process

function runTest(testArgs, done) {
var cmd = 'node_modules/.bin/nodeunit ' + testArgs;
var cmd = 'node_modules' + path.sep + '.bin' + path.sep + 'nodeunit ' + testArgs;
childProcess.exec(cmd, function (error, stdout, stderr) {
// It appears that nodeunit merges error output into the stdout
// so these three lines are probably useless.
Expand Down