-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
44 lines (37 loc) · 1.17 KB
/
index.js
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
var fs = require('fs')
var path = require('path')
var inherits = require('inherits')
var EventEmitter = require('events').EventEmitter
var mvn = require('node-java-maven'); // NB: Only for asynchronous loading.
module.exports = ImageJ
inherits(ImageJ, EventEmitter)
function addToClasspath (java, dir) {
files = fs.readdirSync(dir)
files.forEach(function (file) {
fullPath = path.join(dir, file)
if (fs.lstatSync(fullPath).isDirectory()) addToClasspath(java, fullPath)
if (fullPath.endsWith('.jar')) java.classpath.push(fullPath)
})
}
function ImageJ (config) {
if (!(this instanceof ImageJ)) return new ImageJ(config)
var self = this
mvn(function(err, mvnResults) {
var java = require('java')
addToClasspath(java, config.imagej_dir)
java.asyncOptions = {
asyncSuffix: "Later",
syncSuffix: "",
promiseSuffix: "Promise",
promisify: require("when/node").lift
}
self.emit('booting')
if (config.headless) {
var System = java.import('java.lang.System')
System.setProperty('java.awt.headless', 'true')
}
var ImageJ = java.import('net.imagej.ImageJ')
ij = ImageJ()
self.emit('ready', ij)
})
}