Skip to content

Commit e97e03f

Browse files
authored
Log the executed "nuget" and "dotnet" commands (#420)
* Log the executed "nuget" and "dotnet" commands * CR comments
1 parent e3e0b7b commit e97e03f

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

build-info-extractor-nuget/src/main/java/org/jfrog/build/extractor/nuget/drivers/DotnetDriver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public String addSource(String configPath, ArtifactoryDependenciesClient client,
2525
String sourceUrl = buildNugetSourceUrl(client, repo);
2626
List<String> extraArgs = new ArrayList<>();
2727
extraArgs.addAll(Arrays.asList(FLAG_PREFIX + CONFIG_FILE_FLAG, configPath, FLAG_PREFIX + NAME_FLAG, sourceName, FLAG_PREFIX + USERNAME_FLAG, username, FLAG_PREFIX + PASSWORD_FLAG, password, CLEAR_TEXT_PASSWORD_FLAG));
28-
return runCommand(new String[]{"nuget", "add", "source", sourceUrl}, extraArgs);
28+
return runCommand(new String[]{"nuget", "add", "source", sourceUrl}, extraArgs, logger);
2929
} catch (Exception e) {
3030
throw new IOException("dotnet nuget add source failed: " + e.getMessage() + ". Please make sure .NET Core 3.1.200 SDK or above is installed.", e);
3131
}
@@ -36,7 +36,7 @@ public String globalPackagesCache() throws IOException, InterruptedException {
3636
List<String> args = new ArrayList<>();
3737
args.add(GLOBAL_PACKAGES_ARG);
3838
args.add(getFlagSyntax(LIST_FLAG));
39-
String output = runCommand(new String[]{"nuget", LOCALS_ARG,}, args);
39+
String output = runCommand(new String[]{"nuget", LOCALS_ARG,}, args, logger);
4040
return output.replaceFirst(GLOBAL_PACKAGES_REGEX, "").trim();
4141
}
4242

build-info-extractor-nuget/src/main/java/org/jfrog/build/extractor/nuget/drivers/NugetDriver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public String addSource(String configPath, ArtifactoryDependenciesClient client,
2121
String sourceUrl = buildNugetSourceUrl(client, repo);
2222
List<String> extraArgs = new ArrayList<>();
2323
extraArgs.addAll(Arrays.asList(FLAG_PREFIX + CONFIG_FILE_FLAG, configPath, FLAG_PREFIX + SOURCE_FLAG, sourceUrl, FLAG_PREFIX + NAME_FLAG, sourceName, FLAG_PREFIX + USERNAME_FLAG, username, FLAG_PREFIX + PASSWORD_FLAG, password));
24-
return runCommand(new String[]{"sources", "add"}, extraArgs);
24+
return runCommand(new String[]{"sources", "add"}, extraArgs, logger);
2525
} catch (Exception e) {
2626
throw new IOException("nuget sources add failed: " + e.getMessage(), e);
2727
}
@@ -32,7 +32,7 @@ public String globalPackagesCache() throws IOException, InterruptedException {
3232
List<String> args = new ArrayList<>();
3333
args.add(GLOBAL_PACKAGES_ARG);
3434
args.add(getFlagSyntax(LIST_FLAG));
35-
String output = runCommand(new String[]{LOCALS_ARG, }, args);
35+
String output = runCommand(new String[]{LOCALS_ARG, }, args, logger);
3636
return output.replaceFirst(GLOBAL_PACKAGES_REGEX, "").trim();
3737
}
3838

build-info-extractor-nuget/src/main/java/org/jfrog/build/extractor/nuget/drivers/ToolchainDriverBase.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public boolean isInstalled() {
6060
abstract public String getFlagSyntax(String flagName);
6161

6262
public String help() throws IOException, InterruptedException {
63-
return runCommand(new String[]{"help"}, Collections.emptyList());
63+
return runCommand(new String[]{"help"}, Collections.emptyList(), logger);
6464
}
6565

6666
protected String buildNugetSourceUrl(ArtifactoryBaseClient client, String repo) throws Exception {
@@ -81,11 +81,7 @@ public void runCmd(String args, List<String> extraArgs, boolean prompt) throws I
8181
}
8282
}
8383

84-
protected String runCommand(String[] args, List<String> extraArgs) throws IOException, InterruptedException {
85-
return runCommand(args, extraArgs, null);
86-
}
87-
88-
private String runCommand(String[] args, List<String> extraArgs, Log logger) throws IOException, InterruptedException {
84+
protected String runCommand(String[] args, List<String> extraArgs, Log logger) throws IOException, InterruptedException {
8985
List<String> finalArgs = Stream.concat(Arrays.stream(args), extraArgs.stream()).collect(Collectors.toList());
9086
CommandResults nugetCommandRes = commandExecutor.exeCommand(workingDirectory, finalArgs, logger);
9187
if (!nugetCommandRes.isOk()) {

build-info-extractor/src/main/java/org/jfrog/build/extractor/executor/CommandExecutor.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,16 @@ private static boolean isMac() {
133133
}
134134

135135
private static Process runProcess(File execDir, List<String> args, String[] env, Log logger) throws IOException {
136-
String strArgs = String.join(" ", args);
137-
if (logger != null) {
138-
logger.info("Executing command: " + UrlUtils.maskCredentialsInUrl(strArgs));
139-
}
140136
if (isWindows()) {
141-
return Runtime.getRuntime().exec(new String[]{"cmd", "/c", strArgs}, env, execDir);
137+
args.add(0, "cmd");
138+
args.add(1, "/c");
139+
} else if (isMac()) {
140+
args.add(0, "/bin/sh");
141+
args.add(1, "-c");
142142
}
143-
if (isMac()) {
144-
return Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", strArgs}, env, execDir);
143+
if (logger != null) {
144+
logger.info("Executing command: " + UrlUtils.maskCredentialsInUrl(String.join(" ", args)));
145145
}
146-
// Linux
147146
return Runtime.getRuntime().exec(args.toArray(new String[0]), env, execDir);
148147
}
149-
150148
}

0 commit comments

Comments
 (0)