Skip to content

Commit dc29642

Browse files
committed
Changed java home detection process on windows to be inline with macos and added some additional log outputs
1 parent 33e0f13 commit dc29642

File tree

3 files changed

+137
-36
lines changed

3 files changed

+137
-36
lines changed

Diff for: client/src/com/apm/client/config/RunConfig.as

+3-31
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.apm.client.config
1919
import com.apm.client.config.processes.LoadProjectDefinitionProcess;
2020
import com.apm.client.config.processes.LoadUserSettingsProcess;
2121
import com.apm.client.config.processes.LoadWindowsEnvironmentVariablesProcess;
22+
import com.apm.client.config.processes.LoadWindowsJavaHomeProcess;
2223
import com.apm.client.logging.Log;
2324
import com.apm.client.processes.ProcessQueue;
2425
import com.apm.data.project.ProjectDefinition;
@@ -105,6 +106,7 @@ package com.apm.client.config
105106
if (isWindows)
106107
{
107108
_loadQueue.addProcess( new LoadWindowsEnvironmentVariablesProcess( this ) );
109+
_loadQueue.addProcess( new LoadWindowsJavaHomeProcess( this ) );
108110
}
109111

110112
// General
@@ -155,41 +157,10 @@ package com.apm.client.config
155157
if (isWindows)
156158
{
157159
javaBinPath = "bin\\java.exe";
158-
if (javaHome == null)
159-
{
160-
// Try to locate a java install
161-
// Normally have a directory "Java/jdkx.x.x_x"
162-
// - so iterate over subdirectories checking for the java exe
163-
164-
var javaDirectoryCandidates:Array = [
165-
new File( "C:\\Program Files\\Java" ),
166-
new File( "C:\\Program Files (x86)\\Java" )
167-
];
168-
169-
for each (var candidate:File in javaDirectoryCandidates)
170-
{
171-
if (candidate.exists && candidate.getDirectoryListing().length > 0)
172-
{
173-
for each (var javaCandidate:File in candidate.getDirectoryListing())
174-
{
175-
if (javaCandidate.resolvePath( javaBinPath ).exists)
176-
{
177-
javaHome = javaCandidate.nativePath;
178-
break;
179-
}
180-
}
181-
}
182-
}
183-
}
184160
}
185161
else if (isMacOS)
186162
{
187163
javaBinPath = "bin/java";
188-
// if (javaHome == null)
189-
// {
190-
// // Try default java install - this will likely fail
191-
// javaHome = "/usr";
192-
// }
193164
}
194165
else
195166
{
@@ -225,6 +196,7 @@ package com.apm.client.config
225196
}
226197

227198

199+
228200
//
229201
// UTILITIES
230202
//

Diff for: client/src/com/apm/client/config/processes/LoadWindowsEnvironmentVariablesProcess.as

+13-5
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ package com.apm.client.config.processes
6363
{
6464
var processStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
6565
processStartupInfo.executable = new File( "C:\\Windows\\System32\\cmd.exe" );
66-
66+
6767
var processArgs:Vector.<String> = new Vector.<String>();
6868
processArgs.push( "/c" );
6969
processArgs.push( "set" );
70-
70+
7171
processStartupInfo.arguments = processArgs;
7272

7373
if (!processStartupInfo.executable.exists)
7474
{
75-
// TODO:: Error?
75+
Log.d( TAG, "ERROR: cmd.exe not available - cannot get environment" );
7676
complete();
7777
}
7878

@@ -95,8 +95,16 @@ package com.apm.client.config.processes
9595

9696
private function onOutputData( event:ProgressEvent ):void
9797
{
98-
var data:String = _process.standardOutput.readUTFBytes( _process.standardOutput.bytesAvailable );
99-
processEnvironmentVariables( data );
98+
try
99+
{
100+
var data:String = _process.standardOutput.readUTFBytes( _process.standardOutput.bytesAvailable );
101+
processEnvironmentVariables( data );
102+
}
103+
catch (e:Error)
104+
{
105+
Log.d( TAG, "ERROR: " + e.message );
106+
Log.e( TAG, e );
107+
}
100108
}
101109

102110

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* __ __ __
3+
* ____/ /_ ____/ /______ _ ___ / /_
4+
* / __ / / ___/ __/ ___/ / __ `/ __/
5+
* / /_/ / (__ ) / / / / / /_/ / /
6+
* \__,_/_/____/_/ /_/ /_/\__, /_/
7+
* / /
8+
* \/
9+
* http://distriqt.com
10+
*
11+
* @author Michael (https://github.com/marchbold)
12+
* @created 28/5/21
13+
*/
14+
package com.apm.client.config.processes
15+
{
16+
import com.apm.client.config.RunConfig;
17+
import com.apm.client.logging.Log;
18+
import com.apm.client.processes.ProcessBase;
19+
20+
import flash.desktop.NativeProcess;
21+
import flash.desktop.NativeProcessStartupInfo;
22+
import flash.events.IOErrorEvent;
23+
import flash.events.NativeProcessExitEvent;
24+
import flash.events.ProgressEvent;
25+
import flash.filesystem.File;
26+
27+
28+
public class LoadWindowsJavaHomeProcess extends ProcessBase
29+
{
30+
////////////////////////////////////////////////////////
31+
// CONSTANTS
32+
//
33+
34+
private static const TAG:String = "LoadWindowsJavaHomeProcess";
35+
36+
37+
////////////////////////////////////////////////////////
38+
// VARIABLES
39+
//
40+
41+
private var _config:RunConfig;
42+
private var _data:String = "";
43+
44+
45+
////////////////////////////////////////////////////////
46+
// FUNCTIONALITY
47+
//
48+
49+
public function LoadWindowsJavaHomeProcess( config:RunConfig )
50+
{
51+
_config = config;
52+
}
53+
54+
55+
private function isJavaHomeValid():Boolean
56+
{
57+
try
58+
{
59+
if (_config.env[ "JAVA_HOME" ] == null) return false;
60+
if (_config.getJava().exists)
61+
return true;
62+
}
63+
catch (e:Error)
64+
{
65+
}
66+
return false;
67+
}
68+
69+
70+
override public function start( completeCallback:Function = null, failureCallback:Function = null ):void
71+
{
72+
super.start( completeCallback, failureCallback );
73+
Log.d( TAG, "start()" );
74+
75+
if (!isJavaHomeValid())
76+
{
77+
var javaBinPath:String = "bin\\java.exe";
78+
var javaHome:String = null;
79+
80+
// Try to locate a java install
81+
// Normally have a directory "Java/jdkx.x.x_x"
82+
// - so iterate over subdirectories checking for the java exe
83+
84+
var javaDirectoryCandidates:Array = [
85+
new File( "C:\\Program Files\\Java" ),
86+
new File( "C:\\Program Files (x86)\\Java" )
87+
];
88+
89+
for each (var candidate:File in javaDirectoryCandidates)
90+
{
91+
if (candidate.exists && candidate.getDirectoryListing().length > 0)
92+
{
93+
for each (var javaCandidate:File in candidate.getDirectoryListing())
94+
{
95+
if (javaCandidate.resolvePath( javaBinPath ).exists)
96+
{
97+
javaHome = javaCandidate.nativePath;
98+
break;
99+
}
100+
}
101+
}
102+
}
103+
104+
if (javaHome != null)
105+
{
106+
_config.env[ "JAVA_HOME" ] = javaHome;
107+
}
108+
complete();
109+
110+
111+
}
112+
else
113+
{
114+
complete();
115+
}
116+
}
117+
118+
119+
}
120+
121+
}

0 commit comments

Comments
 (0)