@@ -124,42 +124,77 @@ const checkConnection = async (host, port, timeout = 2000) => {
124
124
} )
125
125
}
126
126
127
- const resolveRuntimeDependency = runtimeDependency => {
127
+ const resolveRuntimeDependency = ( runtimeDependency = { } ) => {
128
128
const { name, version, type } = runtimeDependency
129
129
if ( name === 'Java' ) {
130
130
if ( 'JAVA_HOME' in process . env ) {
131
- console . log ( 'found java' , process . env [ 'JAVA_HOME' ] )
132
131
const JAVA_HOME = process . env [ 'JAVA_HOME' ]
133
- // windows: const JAVA_EXE = `${JAVA_HOME}/bin/java.exe`
132
+ const JAVA_BIN = path . join (
133
+ JAVA_HOME ,
134
+ 'bin' ,
135
+ process . platform === 'win32' ? 'java.exe' : 'java'
136
+ )
137
+ return fs . existsSync ( JAVA_BIN ) ? JAVA_BIN : undefined
134
138
} else {
135
139
// MAC:
136
140
if ( process . platform === 'darwin' ) {
137
141
if ( fs . existsSync ( '/Library/Java/JavaVirtualMachines/' ) ) {
138
142
const vms = fs . readdirSync ( '/Library/Java/JavaVirtualMachines/' )
139
143
// /Contents/Home/bin/java
140
- console . log ( 'found vms' , vms )
144
+ // console.log('found vms', vms)
141
145
}
142
146
// alternative tests
143
147
// /usr/bin/java
144
148
// /usr/libexec/java_home -V
145
149
// execute 'which java'
146
150
const javaPath = '/usr/bin/java'
147
- return javaPath
151
+ return fs . existsSync ( javaPath ) ? javaPath : undefined
148
152
}
149
- console . log ( 'JAVA_HOME not set' )
150
153
// console.log(process.env.PATH.includes('java'))
151
154
}
152
155
return undefined
153
156
}
154
157
return undefined
155
158
}
156
159
160
+ const resolvePackagePath = ( flag , release ) => {
161
+ // NOTE order important
162
+ // more specific matcher
163
+ const PACKAGE_PATH = release . extractedPackagePath
164
+ if ( flag . includes ( '%PACKAGE_PATH/*%' ) ) {
165
+ if ( ! PACKAGE_PATH ) throw new Error ( 'cannot resolve %PACKAGE_PATH%' )
166
+ // console.log('rewrite path in flag', flag)
167
+ const files = fs . readdirSync ( PACKAGE_PATH )
168
+ const subdirs = files . filter (
169
+ f => fs . lstatSync ( path . join ( PACKAGE_PATH , f ) ) . isDirectory
170
+ )
171
+ if ( subdirs . length === 0 ) {
172
+ throw new Error ( 'cannot resolve path for flag' , flag )
173
+ }
174
+ if ( subdirs . length > 1 ) {
175
+ console . warn ( 'WARNING: ambiguous paths found for' , flag , subdirs )
176
+ }
177
+ const PACKAGE_SUBDIR = subdirs [ 0 ]
178
+ flag = flag . replace (
179
+ '%PACKAGE_PATH/*%' ,
180
+ path . join ( PACKAGE_PATH , PACKAGE_SUBDIR )
181
+ )
182
+ }
183
+ // less specific matcher
184
+ if ( flag . includes ( '%PACKAGE_PATH%' ) ) {
185
+ if ( ! PACKAGE_PATH ) throw new Error ( 'cannot resolve %PACKAGE_PATH%' )
186
+ flag = flag . replace ( '%PACKAGE_PATH%' , PACKAGE_PATH )
187
+ }
188
+ return flag
189
+ }
190
+
157
191
module . exports = {
158
192
checkConnection,
159
193
getShippedGridUiPath,
160
194
getCachePath,
161
195
getUserDataPath,
162
196
getPluginCachePath,
163
197
getBinaryUpdater,
164
- resolveRuntimeDependency
198
+ resolveRuntimeDependency,
199
+ resolvePackagePath
165
200
}
0 commit comments