Skip to content

Commit

Permalink
Added support for querying file verison information on win32 slave no…
Browse files Browse the repository at this point in the history
…des.
  • Loading branch information
burcadoruciprian committed Feb 12, 2018
1 parent 3c4ba35 commit 8ffb3d5
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/main/java/caphyon/jenkins/advinst/AdvinstInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.net.URLConnection;

import javax.servlet.ServletException;

import com.sun.jna.platform.win32.VerRsrc.VS_FIXEDFILEINFO;
import com.sun.jna.platform.win32.VersionUtil;

Expand Down Expand Up @@ -175,7 +174,9 @@ private boolean registerAdvinst(final FilePath advinstPath, final Secret license
if (null == licenseID)
return true;

final VersionNumber advinstVersion = getFileVerison(advinstPath.sibling("advinst.exe"));
final FilePath advinstExe = advinstPath.sibling("advinst.exe");
final VersionNumber advinstVersion = new VersionNumber(
node.getChannel().call(new GetWin32FileVersion(advinstExe.getRemote())));

String registerCommand = "/RegisterCI";
if (advinstVersion.isOlderThan(kAdvinstRegVersionSwitch)) {
Expand All @@ -194,16 +195,6 @@ private boolean registerAdvinst(final FilePath advinstPath, final Secret license
return retcode == 0;
}

private VersionNumber getFileVerison(final FilePath advinstPath) {

VS_FIXEDFILEINFO verInfo = VersionUtil.getFileVersionInfo(advinstPath.getRemote());

final String verString = String.format("%d.%d.%d.%d", verInfo.getProductVersionMajor(),
verInfo.getProductVersionMinor(), verInfo.getProductVersionRevision(), verInfo.getProductVersionBuild());

return new VersionNumber(verString);
}

private String getAdvinstDownloadUrl(Node node) {
String downloadUrl;

Expand Down Expand Up @@ -262,6 +253,23 @@ public String[] call() {
}
}

private static class GetWin32FileVersion extends MasterToSlaveCallable<String, InterruptedException> {
private static final long serialVersionUID = 1L;
private final String filePath;

GetWin32FileVersion(String filePath) {
this.filePath = filePath;
}

public String call() {
VS_FIXEDFILEINFO verInfo = VersionUtil.getFileVersionInfo(this.filePath);
final String verString = String.format("%d.%d.%d.%d", verInfo.getProductVersionMajor(),
verInfo.getProductVersionMinor(), verInfo.getProductVersionRevision(),
verInfo.getProductVersionBuild());
return verString;
}
}

// Extend IOException so we can throw and stop the build if installation fails
static class InstallationFailedException extends IOException {
InstallationFailedException(String message) {
Expand Down

0 comments on commit 8ffb3d5

Please sign in to comment.