Skip to content

Commit 57be4c5

Browse files
committed
JBDS-4196 MSI installed OpenJDK detection does not work
Fix removes extra parameter from Util.writeFile call and changes the tests to fail if Util.writeFile called with wrong parameters.
1 parent eb6efbf commit 57be4c5

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

browser/model/jdk-install.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class JdkInstall extends InstallableItem {
7979
}
8080
done();
8181
}).catch((error) => {
82+
Logger.info(JdkInstall.KEY + ' - Detection failed with error');
83+
Logger.info(JdkInstall.KEY + ' - ' + error);
8284
if(Platform.OS !== 'darwin' ) {
8385
this.selectedOption = 'install';
8486
} else {
@@ -88,23 +90,35 @@ class JdkInstall extends InstallableItem {
8890
});
8991
}
9092

91-
findMsiInstalledJava() {
92-
let msiSearchScript = path.join(this.installerDataSvc.tempDir(), 'search-openjdk-msi.ps1');
93-
let data = [
93+
getMsiSearchScriptLocation() {
94+
return path.join(this.installerDataSvc.tempDir(), 'search-openjdk-msi.ps1');
95+
}
96+
97+
getMsiSearchScriptData() {
98+
return [
9499
'$vbox = Get-WmiObject Win32_Product | where {$_.Name -like \'*OpenJDK*\'};',
95100
'echo $vbox.IdentifyingNumber;',
96101
'[Environment]::Exit(0);'
97102
].join('\r\n');
98-
let args = [
103+
}
104+
105+
getMsiSearchScriptPowershellArgs(msiSearchScript) {
106+
return [
99107
'-NonInteractive',
100108
'-ExecutionPolicy',
101109
'ByPass',
102110
'-File',
103111
msiSearchScript
104112
];
113+
}
114+
115+
findMsiInstalledJava() {
116+
let msiSearchScript = this.getMsiSearchScriptLocation();
117+
let data = this.getMsiSearchScriptData();
118+
let args = this.getMsiSearchScriptPowershellArgs(msiSearchScript);
105119
let result = Promise.resolve('');
106120
if (Platform.OS !== 'darwin') {
107-
result = Util.writeFile(JdkInstall.KEY, msiSearchScript, data).then(()=>{
121+
result = Util.writeFile(msiSearchScript, data).then(()=>{
108122
return Util.executeFile('powershell', args);
109123
});
110124
}

test/unit/model/jdk-install-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ describe('JDK installer', function() {
142142
jdk.validateVersion();
143143
});
144144

145-
146-
147145
describe('on windows', function(){
148146
it('should select openjdk for installation if no java detected', function(done) {
149147
sandbox.stub(Platform,'getOS').returns('win32');
@@ -194,8 +192,10 @@ describe('JDK installer', function() {
194192
let jdk = new JdkInstall(installerDataSvc, 'url', 'file');
195193
jdk.findMsiInstalledJava.restore();
196194
return jdk.detectExistingInstall(function() {
197-
expect(Util.executeFile).to.have.been.calledOnce;
198-
expect(Util.writeFile).to.have.been.calledOnce;
195+
expect(Util.writeFile).to.have.been.calledWith(
196+
jdk.getMsiSearchScriptLocation(),jdk.getMsiSearchScriptData());
197+
expect(Util.executeFile).to.have.been.calledWith(
198+
'powershell', jdk.getMsiSearchScriptPowershellArgs(jdk.getMsiSearchScriptLocation()));
199199
done();
200200
});
201201
});

0 commit comments

Comments
 (0)