Skip to content

Commit 516e2f9

Browse files
committed
Updates logic that reads cli path to take into account new tool structure
1 parent 34005c6 commit 516e2f9

File tree

4 files changed

+35
-46
lines changed

4 files changed

+35
-46
lines changed

src/main/java/com/uipath/uipathpackage/configuration/UiPathCliConfiguration.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.core.type.TypeReference;
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import com.uipath.uipathpackage.actions.AddEnvironmentVariablesAction;
7+
import com.uipath.uipathpackage.util.Utility;
78
import edu.umd.cs.findbugs.annotations.NonNull;
89
import hudson.AbortException;
910
import hudson.EnvVars;
@@ -138,13 +139,8 @@ public Optional<FilePath> getCliPath(@Nonnull Launcher launcher, @Nonnull EnvVar
138139
PrintStream logger = launcher.getListener().getLogger();
139140
try {
140141
FilePath cliCachedPath = getCliRootCachedDirectoryPath(launcher, env, cliVersionKey);
141-
Configuration configuration = cliConfigurationMap.get(cliVersionKey);
142-
if (configuration.getVersion().getMajor() >= 22) {
143-
cliCachedPath = cliCachedPath.child("tools").child("uipcli.dll");
144-
} else {
145-
/** To Support Backward compatibility cli-21.10.xxx.xxx conventions needs to be followed.*/
146-
cliCachedPath = cliCachedPath.child("lib").child("net461").child("uipcli.exe");
147-
}
142+
cliCachedPath = Utility.getDotnetToolCliPath(cliCachedPath);
143+
148144
if (cliCachedPath.exists()) {
149145
return Optional.of(cliCachedPath);
150146
}

src/main/java/com/uipath/uipathpackage/util/ActualVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public int getMinor() {
1818
}
1919

2020
public boolean supportsNewTelemetry() {
21-
return major >= 23 && minor >= 10;
21+
return major == 23 ? minor >= 10 : major > 23;
2222
}
2323
}

src/main/java/com/uipath/uipathpackage/util/Utility.java

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public int execute(@Nonnull String command, @Nonnull SerializableCliOptions opti
8888

8989
FilePath commandOptionsFile = remoteTempDir.createTextTempFile("uipcliargs", "", new JSONObject(new RunOptions(command, options)).toString());
9090

91-
int result = launcher.launch().cmds(this.buildCommandLine(cliPath, commandOptionsFile, envVars)).envs(envVars).stdout(listener).pwd(cliPath.getParent()).start().join();
91+
String[] commandParams = new String[]{"dotnet", cliPath.getRemote(), "run", commandOptionsFile.getRemote()};
92+
int result = launcher.launch().cmds(commandParams).envs(envVars).stdout(listener).pwd(cliPath.getParent()).start().join();
9293
if (throwExceptionOnFailure && result != 0) {
9394
throw new AbortException("Failed to run the command, the CLI failed with error code " + result);
9495
}
@@ -123,7 +124,8 @@ public CliDetails getCliDetails(
123124

124125
StreamTaskListener execListener = new StreamTaskListener(commandOutput, run.getCharset());
125126

126-
launcher.launch().cmds(this.buildVersionArgs(cliPath, envVars)).envs(envVars).stdout(execListener).pwd(cliPath.getParent()).start().join();
127+
String [] commandParameters = new String[] {"dotnet", cliPath.getRemote(), "--version" };
128+
launcher.launch().cmds(commandParameters).envs(envVars).stdout(execListener).pwd(cliPath.getParent()).start().join();
127129

128130
String stdoutText = commandOutput.toString(run.getCharset().name());
129131

@@ -160,8 +162,8 @@ public void validateRuntime(@Nonnull Launcher launcher, @Nonnull EnvVars envVars
160162

161163
public FilePath extractCliApp(@Nonnull FilePath targetRootCacheDir, @Nonnull TaskListener listener, @Nonnull EnvVars env) throws IOException, InterruptedException, URISyntaxException {
162164
PrintStream logger = listener.getLogger();
163-
ResourceBundle rb = ResourceBundle.getBundle("config");
164-
FilePath targetCliPath = targetRootCacheDir.child("tools").child("uipcli.dll");
165+
FilePath targetCliPath = getDotnetToolCliPath(targetRootCacheDir);
166+
165167
if (targetCliPath.exists())
166168
{
167169
logger.println("Using previously extracted UiPath CLI from " + targetCliPath);
@@ -183,6 +185,29 @@ public FilePath extractCliApp(@Nonnull FilePath targetRootCacheDir, @Nonnull Tas
183185
return targetCliPath;
184186
}
185187

188+
// With support for .NET tool structure, look for uipcli.dll in tools/netX.X/any/uipcli.dll. Maintain also backward compatibility.
189+
public static FilePath getDotnetToolCliPath(FilePath targetPath) throws IOException, InterruptedException {
190+
FilePath uipcliToolPath;
191+
192+
FilePath toolsDir = targetPath.child("tools");
193+
uipcliToolPath = toolsDir.child("uipcli.dll");
194+
195+
if(uipcliToolPath.exists()) {
196+
return uipcliToolPath;
197+
}
198+
199+
if (toolsDir.exists()) {
200+
for (FilePath child : toolsDir.listDirectories()) {
201+
String dirName = child.getName();
202+
if (dirName.startsWith("net")) {
203+
uipcliToolPath = child.child("any").child("uipcli.dll");
204+
break;
205+
}
206+
}
207+
}
208+
return uipcliToolPath;
209+
}
210+
186211
public void downloadCli(String feedUrl,@Nonnull FilePath downloadPath, @Nonnull TaskListener listener) throws AbortException {
187212
PrintStream logger = listener.getLogger();
188213
logger.println("Downloading CLI from "+ feedUrl);
@@ -298,40 +323,6 @@ else if (strategy instanceof UnattendedJobTypeEntry)
298323
}
299324
}
300325

301-
private String[] buildCommandLine(FilePath cliPath, FilePath commandOptionsFile, @Nonnull EnvVars envVars) throws JsonProcessingException {
302-
UiPathCliConfiguration configuration = UiPathCliConfiguration.getInstance();
303-
String selectedCliVersionKey = envVars.get(UiPathCliConfiguration.SELECTED_CLI_VERSION_KEY);
304-
305-
if(StringUtils.isBlank(selectedCliVersionKey)) {
306-
selectedCliVersionKey = configuration.getDefaultCliVersionKey();
307-
}
308-
309-
UiPathCliConfiguration.Configuration cliConfig = configuration.getConfiguration().get(selectedCliVersionKey);
310-
311-
if(cliConfig.getVersion().getMajor() >= 22) {
312-
return new String[] {"dotnet", cliPath.getRemote(), "run", commandOptionsFile.getRemote() };
313-
}
314-
315-
return new String[] { cliPath.getRemote(), "run", commandOptionsFile.getRemote() };
316-
}
317-
318-
private String[] buildVersionArgs(FilePath cliPath, @Nonnull EnvVars envVars) throws JsonProcessingException {
319-
UiPathCliConfiguration configuration = UiPathCliConfiguration.getInstance();
320-
String selectedCliVersionKey = envVars.get(UiPathCliConfiguration.SELECTED_CLI_VERSION_KEY);
321-
322-
if(StringUtils.isBlank(selectedCliVersionKey)) {
323-
selectedCliVersionKey = configuration.getDefaultCliVersionKey();
324-
}
325-
326-
UiPathCliConfiguration.Configuration cliConfig = configuration.getConfiguration().get(selectedCliVersionKey);
327-
328-
if(cliConfig.getVersion().getMajor() >= 22) {
329-
return new String[] {"dotnet", cliPath.getRemote(), "--version" };
330-
}
331-
332-
return new String[] { cliPath.getRemote(), "--version" };
333-
}
334-
335326
private void extractResourcesToTempFolder(FilePath tempDir, File jarfile, TaskListener listener) throws IOException, InterruptedException {
336327
try (JarFile archive = new JarFile(jarfile)) {
337328
// sort entries by name to always create folders first

stage.test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ stages:
5353
configurationName: 'JenkinsE2ETests/UiPathInstallPlatform/InstallLocalNuPkgCLI'
5454
- jobName: 'SuccessiveInstallPlatforms'
5555
configurationName: 'JenkinsE2ETests/UiPathInstallPlatform/SuccessiveInstallPlatforms'
56+
- jobName: 'InstallLocalNuPkgCLINetToolFolderStructure'
57+
configurationName: 'JenkinsE2ETests/UiPathInstallPlatform/InstallLocalNuPkgCLINetToolFolderStructure'
5658
#### UiPathPack E2E tests ###
5759
- jobName: 'PackGenerateVersionTypes'
5860
configurationName: 'JenkinsE2ETests/UiPathPack/PackGenerateVersionTypes'

0 commit comments

Comments
 (0)