Skip to content

Commit

Permalink
JENKINS-26828 Add support for installing the NodeJS windows msi
Browse files Browse the repository at this point in the history
Remove unused old method.
Update some old duplicate code from jenkins core code.
Extend version with range capabilities to check which version has only an msi installer.
  • Loading branch information
nfalco79 committed Dec 8, 2016
1 parent f6dfd26 commit 95b8e22
Show file tree
Hide file tree
Showing 10 changed files with 2,084 additions and 449 deletions.
44 changes: 44 additions & 0 deletions src/main/java/jenkins/plugins/nodejs/tools/CPU.java
@@ -0,0 +1,44 @@
package jenkins.plugins.nodejs.tools;

import java.io.IOException;
import java.util.Locale;
import java.util.Map;

import hudson.model.Node;

/**
* CPU type.
*/
public enum CPU {
i386, amd64;

/**
* Determines the CPU of the given node.
* @throws IOException
* @throws InterruptedException
* @throws DetectionFailedException
*/
public static CPU of(Node node) throws DetectionFailedException, InterruptedException, IOException {
return detect(node.toComputer().getSystemProperties());
}

/**
* Determines the CPU of the current JVM.
* @throws DetectionFailedException
*/
public static CPU current() throws DetectionFailedException {
return detect(System.getProperties());
}

private static CPU detect(Map<Object, Object> systemProperties) throws DetectionFailedException {
String arch = ((String) systemProperties.get("os.arch")).toLowerCase(Locale.ENGLISH);
if (arch.contains("amd64") || arch.contains("86_64")) {
return amd64;
}
if (arch.contains("86")) {
return i386;
}
throw new DetectionFailedException("Unknown CPU architecture: " + arch);
}

}
@@ -0,0 +1,17 @@
package jenkins.plugins.nodejs.tools;

import java.io.IOException;

/**
* Indicates the failure to detect the OS or CPU.
*/
@SuppressWarnings("serial")
public final class DetectionFailedException extends IOException {
DetectionFailedException(String message) {
super(message);
}

public DetectionFailedException(String message, Throwable cause) {
super(message, cause);
}
}
Expand Up @@ -4,13 +4,37 @@
import hudson.tools.DownloadFromUrlInstaller;

/**
* Contract to resolve parts of an URL path given some specific inputs.
*
* @author fcamblor
* @author Nikolas Falco
*/
public interface InstallerPathResolver {
String resolvePathFor(String version, NodeJSInstaller.Platform platform, NodeJSInstaller.CPU cpu);
String extractArchiveIntermediateDirectoryName(String relativeDownloadPath);
/**
* Resolve the URL path for the given parameters.
*
* @param version
* string version of an installable unit
* @param platform
* of the node where this installable is designed
* @param cpu
* of the node where this installable is designed
* @return the relative path URL for the given specifics
*/
String resolvePathFor(String version, Platform platform, CPU cpu);

/**
* Factory that return lookup for an implementation of {@link InstallerPathResolver}.
*/
public static class Factory {
/**
* Return an implementation adapt for the given installable.
*
* @param installable
* @return an instance of {@link InstallerPathResolver}
* @throws IllegalArgumentException
* in case the given installable is not supported.
*/
public static InstallerPathResolver findResolverFor(DownloadFromUrlInstaller.Installable installable){
if(isVersionBlacklisted(installable.id)){
throw new IllegalArgumentException("Provided version ("+installable.id+") installer structure not (yet) supported !");
Expand All @@ -20,8 +44,8 @@ public static InstallerPathResolver findResolverFor(DownloadFromUrlInstaller.Ins
}

public static boolean isVersionBlacklisted(String version){
NodeJSVersion nodeJSVersion = new NodeJSVersion(version);
return nodeJSVersion.isLowerThan("0.8.6") || "0.9.0".equals(version);
NodeJSVersion nodeJSVersion = NodeJSVersion.parseVersion(version);
return new NodeJSVersionRange("[0, 0.8.6)").includes(nodeJSVersion) || NodeJSVersion.parseVersion("0.9.0").equals(nodeJSVersion);
}
}
}

0 comments on commit 95b8e22

Please sign in to comment.