|
13 | 13 |
|
14 | 14 | package io.openliberty.tools.eclipse.test.ut; |
15 | 15 |
|
| 16 | +import static io.openliberty.tools.eclipse.test.it.utils.SWTBotPluginOperations.unsetBuildCmdPathInPreferences; |
16 | 17 | import static org.junit.jupiter.api.Assertions.assertEquals; |
17 | 18 |
|
| 19 | +import java.io.File; |
18 | 20 | import java.nio.file.Path; |
19 | 21 | import java.nio.file.Paths; |
20 | 22 |
|
| 23 | +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
21 | 24 | import org.junit.jupiter.api.Test; |
22 | 25 |
|
23 | 26 | import io.openliberty.tools.eclipse.CommandBuilder; |
24 | 27 |
|
25 | 28 | public class CommandBuilderTest { |
26 | 29 |
|
| 30 | + |
27 | 31 |
|
| 32 | + /** |
| 33 | + * Tests the CommandBuilder builds a mvn invocation using the mvnw wrapper found in the project, even when the preference |
| 34 | + * is unset |
| 35 | + * |
| 36 | + * @throws Exception |
| 37 | + */ |
28 | 38 | @Test |
29 | 39 | public void testCmdBuilderMvnWrapper() throws Exception { |
| 40 | + // This allows the test to prove the wrapper is in use even when the preference is unset, since an empty string preference would |
| 41 | + // resolve to "" + "/bin/mvn" = "/bin/mvn" and would typically be an actual path on Unix/Mac |
| 42 | + unsetBuildCmdPathInPreferences(new SWTWorkbenchBot(), "Maven"); |
30 | 43 | Path projectPath = Paths.get("resources", "applications", "maven", "liberty-maven-test-wrapper-app"); |
31 | | - String pathEnv="C:\\abc;;C:\\xyz"; |
32 | | - String retVal = CommandBuilder.getMavenCommandLine(projectPath.toString(), "-a 123", pathEnv, false); |
| 44 | + String retVal = CommandBuilder.getMavenCommandLine(projectPath.toString(), "-a 123", obfuscatedPath(), false); |
33 | 45 | assertEquals(projectPath.resolve(mvnwName()) + " -a 123", retVal, "Wrong cmd line"); |
34 | 46 | } |
35 | 47 |
|
| 48 | + /** |
| 49 | + * Tests the CommandBuilder builds a mvn invocation using the mvn found in the path, even when there is an empty path element |
| 50 | + * |
| 51 | + * @throws Exception |
| 52 | + */ |
36 | 53 | @Test |
37 | 54 | public void testCmdBuilderMvn() throws Exception { |
38 | 55 | Path projectPath = Paths.get("resources", "applications", "maven", "liberty-maven-test-app"); |
39 | 56 | Path mvnPath = Paths.get("resources", "execs"); |
40 | | - String mvnPathStr = mvnPath.toAbsolutePath().toString(); |
41 | | - |
42 | | - String pathEnv= null; |
| 57 | + String pathEnv= obfuscatedPath() + File.pathSeparator + mvnPath.toAbsolutePath().toString(); |
| 58 | + String retVal = CommandBuilder.getMavenCommandLine(projectPath.toString(), "-a 123", pathEnv, false); |
| 59 | + assertEquals(mvnPath.toAbsolutePath().resolve(mvnName()) + " -a 123", retVal, "Wrong cmd line"); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @return A platform-dependent path very unlikely to be used, with an empty element |
| 64 | + */ |
| 65 | + private String obfuscatedPath() { |
43 | 66 | if (System.getProperty("os.name").contains("Windows")) { |
44 | | - pathEnv="C:\\abc;;C:\\xyz;" +mvnPathStr; |
| 67 | + return "C:\\abc\\xyz\\123\456;;C:\\xyz\\abc\\456\\123"; |
45 | 68 | } else { |
46 | | - pathEnv="/a/b/c1::/x/y/z1:" +mvnPathStr; |
| 69 | + return "/a/b/c/d1/e/f/g::/x/ya/b2/saa/"; |
47 | 70 | } |
48 | | - String retVal = CommandBuilder.getMavenCommandLine(projectPath.toString(), "-a 123", pathEnv, false); |
49 | | - assertEquals(mvnPath.toAbsolutePath().resolve(mvnName()) + " -a 123", retVal, "Wrong cmd line"); |
50 | 71 | } |
51 | 72 |
|
| 73 | + |
52 | 74 | private String mvnName() { |
53 | 75 | if (System.getProperty("os.name").contains("Windows")) { |
54 | 76 | return "mvn.cmd"; |
|
0 commit comments