Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[JENKINS-50378] Add an optional flag that allows to force the install…
…ation of a 32bit package of the NodeJS. The flag is allowed only in case a NodeJS package is available for the underlying system and 32bit architecture otherwise the build will fail.
- Loading branch information
Showing
with
188 additions
and 36 deletions.
- +1 −1 pom.xml
- +15 −10 src/main/java/jenkins/plugins/nodejs/tools/CPU.java
- +20 −12 src/main/java/jenkins/plugins/nodejs/tools/NodeJSInstaller.java
- +4 −3 src/main/java/jenkins/plugins/nodejs/tools/Platform.java
- +47 −0 src/main/java/jenkins/plugins/nodejs/tools/ToolsUtils.java
- +6 −1 src/main/resources/jenkins/plugins/nodejs/Messages.properties
- +13 −1 src/main/resources/jenkins/plugins/nodejs/Messages_it.properties
- +4 −0 src/main/resources/jenkins/plugins/nodejs/tools/NodeJSInstaller/config.jelly
- +3 −1 src/main/resources/jenkins/plugins/nodejs/tools/NodeJSInstaller/config.properties
- +8 −7 src/test/java/jenkins/plugins/nodejs/tools/NodeJSInstallerTest.java
- +67 −0 src/test/java/jenkins/plugins/nodejs/tools/ToolsUtilsTest.java
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -42,7 +42,7 @@ | ||
</licenses> | ||
|
||
<properties> | ||
<powermock.version>1.7.3</powermock.version> | ||
<jenkins.version>1.651.3</jenkins.version> | ||
</properties> | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,47 @@ | ||
package jenkins.plugins.nodejs.tools; | ||
|
||
import hudson.model.Node; | ||
import jenkins.plugins.nodejs.Messages; | ||
|
||
/*package */ class ToolsUtils { | ||
|
||
private ToolsUtils() { | ||
} | ||
|
||
public static Platform getPlatform(Node node) throws DetectionFailedException { | ||
return Platform.of(node); | ||
} | ||
|
||
public static CPU getCPU(Node node) throws DetectionFailedException { | ||
return getCPU(node, false); | ||
} | ||
|
||
public static CPU getCPU(Node node, boolean force32bit) throws DetectionFailedException { | ||
CPU nodeCPU = CPU.of(node); | ||
if (force32bit) { | ||
if (!support32Bit(nodeCPU)) { | ||
throw new DetectionFailedException(Messages.SystemTools_unsupported32bitArchitecture()); | ||
} | ||
|
||
// force 32 bit architecture | ||
if (nodeCPU == CPU.amd64) { | ||
nodeCPU = CPU.i386; | ||
} | ||
} | ||
return nodeCPU; | ||
} | ||
|
||
private static boolean support32Bit(CPU cpu) { | ||
switch (cpu) { | ||
case armv6l: | ||
// 64bit start with ARMv8 | ||
case armv7l: | ||
case i386: | ||
case amd64: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,67 @@ | ||
package jenkins.plugins.nodejs.tools; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.api.mockito.PowerMockito; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
import org.powermock.reflect.Whitebox; | ||
|
||
import hudson.model.Node; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest(CPU.class) | ||
public class ToolsUtilsTest { | ||
|
||
@Before | ||
public void setup() { | ||
CPU[] cpuValues = CPU.values(); | ||
CPU mock = PowerMockito.mock(CPU.class); | ||
for (CPU c : cpuValues) { | ||
Whitebox.setInternalState(mock, "name", c.name()); | ||
Whitebox.setInternalState(mock, "ordinal", c.ordinal()); | ||
} | ||
|
||
PowerMockito.mockStatic(CPU.class); | ||
PowerMockito.when(CPU.values()).thenReturn(cpuValues); | ||
} | ||
|
||
@Test | ||
public void nodejs_supports_32bit_64bit_on_windows_linux_mac() throws Exception { | ||
Node currentNode = mock(Node.class); | ||
|
||
when(CPU.of(currentNode)).thenReturn(CPU.amd64); | ||
CPU cpu = ToolsUtils.getCPU(currentNode, true); | ||
Assert.assertThat(cpu, CoreMatchers.is(CPU.i386)); | ||
|
||
cpu = ToolsUtils.getCPU(currentNode); | ||
Assert.assertThat(cpu, CoreMatchers.is(CPU.amd64)); | ||
} | ||
|
||
@Test(expected = DetectionFailedException.class) | ||
public void nodejs_doesn_t_supports_32bit_on_armv64() throws Exception { | ||
Node currentNode = mock(Node.class); | ||
|
||
when(CPU.of(currentNode)).thenReturn(CPU.arm64); | ||
ToolsUtils.getCPU(currentNode, true); | ||
} | ||
|
||
@Test | ||
public void nodejs_supports_32bit_on_armv6_armv7() throws Exception { | ||
Node currentNode = mock(Node.class); | ||
|
||
when(CPU.of(currentNode)).thenReturn(CPU.armv7l); | ||
CPU cpu = ToolsUtils.getCPU(currentNode, true); | ||
Assert.assertThat(cpu, CoreMatchers.is(CPU.armv7l)); | ||
|
||
when(CPU.of(currentNode)).thenReturn(CPU.armv6l); | ||
cpu = ToolsUtils.getCPU(currentNode, true); | ||
Assert.assertThat(cpu, CoreMatchers.is(CPU.armv6l)); | ||
} | ||
|
||
} |