Skip to content

Commit

Permalink
[FIX JENKINS-26828]
Browse files Browse the repository at this point in the history
  • Loading branch information
nfalco79 committed Dec 16, 2016
2 parents d6772ed + 9038814 commit 1db81e4
Show file tree
Hide file tree
Showing 10 changed files with 2,092 additions and 404 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 1db81e4

Please sign in to comment.