diff --git a/src/main/java/de/tracetronic/jenkins/plugins/ecutest/tool/installation/ETInstallation.java b/src/main/java/de/tracetronic/jenkins/plugins/ecutest/tool/installation/ETInstallation.java index e3c7aab9..a7abbfa3 100644 --- a/src/main/java/de/tracetronic/jenkins/plugins/ecutest/tool/installation/ETInstallation.java +++ b/src/main/java/de/tracetronic/jenkins/plugins/ecutest/tool/installation/ETInstallation.java @@ -37,6 +37,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -50,15 +51,14 @@ public class ETInstallation extends AbstractToolInstallation { private static final long serialVersionUID = 1L; /** - * Executable file name of ecu.test. + * Executable file names of ecu.test. */ - private static final String EXECUTABLE = "ECU-TEST.exe"; + private static final List EXECUTABLES = Arrays.asList("ecu.test.exe", "ECU-TEST.exe"); /** - * Executable file name of ecu.test COM server. + * Executable file names of ecu.test COM server. */ - private static final String COM_EXECUTABLE = "ECU-TEST_COM.exe"; - + private static final List COM_EXECUTABLES = Arrays.asList("ecu.test_com.exe", "ECU-TEST_COM.exe"); /** * Executable file name of Tool-Server. */ @@ -371,7 +371,12 @@ public DescriptorImpl() { @CheckForNull private static File getExeFile(final File home) { if (Functions.isWindows() && home != null) { - return new File(home, EXECUTABLE); + for (String filename: EXECUTABLES) { + final File exe = new File(home, filename); + if (exe.exists()) { + return exe; + } + } } return null; } @@ -386,7 +391,12 @@ private static File getExeFile(final File home) { @CheckForNull private static File getComExeFile(final File home) { if (Functions.isWindows() && home != null) { - return new File(home, COM_EXECUTABLE); + for (String filename: COM_EXECUTABLES) { + final File exe = new File(home, filename); + if (exe.exists()) { + return exe; + } + } } return null; } @@ -501,7 +511,7 @@ public FormValidation doCheckHome(@QueryParameter final File value) { } else if (StringUtils.isNotEmpty(value.toString())) { if (value.isDirectory()) { final File etExe = getExeFile(value); - if (!etExe.exists()) { + if (etExe != null && !etExe.exists()) { returnValue = FormValidation.error(Messages.ETInstallation_NotHomeDirectory(value)); } } else { diff --git a/src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/installation/ETInstallationIT.java b/src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/installation/ETInstallationIT.java index 0b8b5e96..f7a9810f 100644 --- a/src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/installation/ETInstallationIT.java +++ b/src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/installation/ETInstallationIT.java @@ -12,7 +12,11 @@ import hudson.Launcher; import hudson.slaves.DumbSlave; import hudson.tools.ToolLocationNodeProperty; +import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.io.CleanupMode; +import org.junit.jupiter.api.io.TempDir; +import org.junit.rules.TemporaryFolder; import org.jvnet.hudson.test.recipes.LocalData; import java.io.File; @@ -21,12 +25,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; /** * Integration tests for {@link ETInstallation}. */ public class ETInstallationIT extends IntegrationTestBase { + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + @Test @LocalData public void testInstallation() { @@ -111,14 +119,15 @@ public void testFormRoundTrip() throws Exception { } @Test - public void testExecutable() throws Exception { + public void testExecutableOldName() throws Exception { + String exeFilePath = tempFolder.newFile("ECU-TEST.exe").getAbsolutePath(); + DumbSlave agent = assumeWindowsSlave(); - String exeFilePath = new File("C:\\ECU-TEST", "ECU-TEST.exe").getAbsolutePath(); - Objects.requireNonNull(agent.createPath(exeFilePath)).write(); + Objects.requireNonNull(agent.createPath(exeFilePath)); final ETInstallation.DescriptorImpl etDescriptor = jenkins.jenkins .getDescriptorByType(ETInstallation.DescriptorImpl.class); - etDescriptor.setInstallations(new ETInstallation("ecu.test", "C:\\ECU-TEST", null)); + etDescriptor.setInstallations(new ETInstallation("ecu.test", tempFolder.getRoot().getAbsolutePath(), null)); final ETInstallation[] installations = etDescriptor.getInstallations(); assertEquals(1, installations.length); @@ -130,14 +139,77 @@ public void testExecutable() throws Exception { } @Test - public void testComExecutable() throws Exception { + public void testExecutableNewName() throws Exception { + String exeFilePath = tempFolder.newFile( "ecu.test.exe").getAbsolutePath(); + + DumbSlave agent = assumeWindowsSlave(); + Objects.requireNonNull(agent.createPath(exeFilePath)); + + final ETInstallation.DescriptorImpl etDescriptor = jenkins.jenkins + .getDescriptorByType(ETInstallation.DescriptorImpl.class); + etDescriptor.setInstallations(new ETInstallation("ecu.test", tempFolder.getRoot().getAbsolutePath(), null)); + final ETInstallation[] installations = etDescriptor.getInstallations(); + assertEquals(1, installations.length); + + final ETInstallation inst = installations[0]; + final Launcher launcher = agent.createLauncher(jenkins.createTaskListener()); + + String executable = inst.getExecutable(launcher); + assertEquals(exeFilePath, executable); + } + + @Test + public void testExecutableNull() throws Exception { + //wrong name + String exeFilePath = tempFolder.newFile("ecu-test123.exe").getAbsolutePath(); + + DumbSlave agent = assumeWindowsSlave(); + Objects.requireNonNull(agent.createPath(exeFilePath)); + + final ETInstallation.DescriptorImpl etDescriptor = jenkins.jenkins + .getDescriptorByType(ETInstallation.DescriptorImpl.class); + etDescriptor.setInstallations(new ETInstallation("ecu.test", tempFolder.getRoot().getAbsolutePath(), null)); + final ETInstallation[] installations = etDescriptor.getInstallations(); + assertEquals(1, installations.length); + + final ETInstallation inst = installations[0]; + final Launcher launcher = agent.createLauncher(jenkins.createTaskListener()); + + String executable = inst.getExecutable(launcher); + assertNull(executable); + } + + + @Test + public void testComExecutableOldName() throws Exception { + String exeFilePath = tempFolder.newFile("ECU-TEST_COM.exe").getAbsolutePath(); + + DumbSlave agent = assumeWindowsSlave(); + Objects.requireNonNull(agent.createPath(exeFilePath)); + + final ETInstallation.DescriptorImpl etDescriptor = jenkins.jenkins + .getDescriptorByType(ETInstallation.DescriptorImpl.class); + etDescriptor.setInstallations(new ETInstallation("ecu.test", tempFolder.getRoot().getAbsolutePath(), null)); + final ETInstallation[] installations = etDescriptor.getInstallations(); + assertEquals(1, installations.length); + + final ETInstallation inst = installations[0]; + final Launcher launcher = agent.createLauncher(jenkins.createTaskListener()); + + String executable = inst.getComExecutable(launcher); + assertEquals(exeFilePath, executable); + } + + @Test + public void testComExecutableNewName() throws Exception { + String exeFilePath = tempFolder.newFile("ecu.test_com.exe").getAbsolutePath(); + DumbSlave agent = assumeWindowsSlave(); - String exeFilePath = new File("C:\\ECU-TEST", "ECU-TEST_COM.exe").getAbsolutePath(); - Objects.requireNonNull(agent.createPath(exeFilePath)).write(); + Objects.requireNonNull(agent.createPath(exeFilePath)); final ETInstallation.DescriptorImpl etDescriptor = jenkins.jenkins .getDescriptorByType(ETInstallation.DescriptorImpl.class); - etDescriptor.setInstallations(new ETInstallation("ecu.test", "C:\\ECU-TEST", null)); + etDescriptor.setInstallations(new ETInstallation("ecu.test", tempFolder.getRoot().getAbsolutePath(), null)); final ETInstallation[] installations = etDescriptor.getInstallations(); assertEquals(1, installations.length); @@ -148,15 +220,36 @@ public void testComExecutable() throws Exception { assertEquals(exeFilePath, executable); } + @Test + public void testComExecutableNull() throws Exception { + String exeFilePath = tempFolder.newFile("ecu-test_com123.exe").getAbsolutePath(); + + DumbSlave agent = assumeWindowsSlave(); + Objects.requireNonNull(agent.createPath(exeFilePath)); + + final ETInstallation.DescriptorImpl etDescriptor = jenkins.jenkins + .getDescriptorByType(ETInstallation.DescriptorImpl.class); + etDescriptor.setInstallations(new ETInstallation("ecu.test", tempFolder.getRoot().getAbsolutePath(), null)); + final ETInstallation[] installations = etDescriptor.getInstallations(); + assertEquals(1, installations.length); + + final ETInstallation inst = installations[0]; + final Launcher launcher = agent.createLauncher(jenkins.createTaskListener()); + + String executable = inst.getComExecutable(launcher); + assertNull(executable); + } + @Test public void testTSExecutable() throws Exception { + String exeFilePath = tempFolder.newFile("Tool-Server.exe").getAbsolutePath(); + DumbSlave agent = assumeWindowsSlave(); - String exeFilePath = new File("C:\\ECU-TEST", "Tool-Server.exe").getAbsolutePath(); - Objects.requireNonNull(agent.createPath(exeFilePath)).write(); + Objects.requireNonNull(agent.createPath(exeFilePath)); final ETInstallation.DescriptorImpl etDescriptor = jenkins.jenkins .getDescriptorByType(ETInstallation.DescriptorImpl.class); - etDescriptor.setInstallations(new ETInstallation("ecu.test", "C:\\ECU-TEST", null)); + etDescriptor.setInstallations(new ETInstallation("ecu.test", tempFolder.getRoot().getAbsolutePath(), null)); final ETInstallation[] installations = etDescriptor.getInstallations(); assertEquals(1, installations.length); @@ -166,4 +259,25 @@ public void testTSExecutable() throws Exception { String executable = inst.getTSExecutable(launcher); assertEquals(exeFilePath, executable); } + + @Test + public void testTSExecutableNull() throws Exception { + //wrong Name + String exeFilePath = tempFolder.newFile( "tool-Server123.exe").getAbsolutePath(); + + DumbSlave agent = assumeWindowsSlave(); + Objects.requireNonNull(agent.createPath(exeFilePath)); + + final ETInstallation.DescriptorImpl etDescriptor = jenkins.jenkins + .getDescriptorByType(ETInstallation.DescriptorImpl.class); + etDescriptor.setInstallations(new ETInstallation("ecu.test", tempFolder.getRoot().getAbsolutePath(), null)); + final ETInstallation[] installations = etDescriptor.getInstallations(); + assertEquals(1, installations.length); + + final ETInstallation inst = installations[0]; + final Launcher launcher = agent.createLauncher(jenkins.createTaskListener()); + + String executable = inst.getTSExecutable(launcher); + assertNull(executable); + } }