Skip to content

Commit

Permalink
Extend executable names (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikRehmTT authored Mar 18, 2024
1 parent 83df701 commit 0e4eee6
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> 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<String> COM_EXECUTABLES = Arrays.asList("ecu.test_com.exe", "ECU-TEST_COM.exe");
/**
* Executable file name of Tool-Server.
*/
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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()) {

Check warning on line 514 in src/main/java/de/tracetronic/jenkins/plugins/ecutest/tool/installation/ETInstallation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 374-514 are not covered by tests
returnValue = FormValidation.error(Messages.ETInstallation_NotHomeDirectory(value));
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);
}
}

0 comments on commit 0e4eee6

Please sign in to comment.