Skip to content

Commit

Permalink
D535070 | Jenkins Plugin: Pipeline: GlobalTooling: Gradle: jenkins is…
Browse files Browse the repository at this point in the history
… unable to find executable when gradle is installed with global tooling
  • Loading branch information
akaryakina committed Dec 7, 2021
1 parent 48639dd commit b741445
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/fortify/plugin/jenkins/FortifyPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ private void performLocalTranslation(AbstractBuild<?, ?> build, Launcher launche
ft.setAdvOptions(((AdvancedScanType) projectScanType).getAdvOptions());
}

ft.setCurrentNode(build.getBuiltOn());
ft.perform(build, launcher, listener);
}
}
Expand Down Expand Up @@ -1442,8 +1443,9 @@ private String sanitizeUnicodeControls(String unsafeInput) {
}
String trimmed = unsafeInput.trim();
// we are limited with validation by the chars SSC supports for their application and version names
String withoutUnicodeControls = trimmed.replaceAll("[\\0\\p{C}&&\\p{Cntrl}]", "?");
return withoutUnicodeControls;
//String withoutUnicodeControls = trimmed.replaceAll("[\\p{C}&&\\p{Cntrl}]", "?");
//return withoutUnicodeControls;
return trimmed;
}

private StringBuilder appVersionToJson(String appName, Map<String, Long> appVersions) {
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/com/fortify/plugin/jenkins/steps/FortifySCAStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.Node;
import hudson.model.Run;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -97,7 +96,7 @@ protected String getSourceAnalyzerExecutable(Run<?, ?> build, FilePath workspace
listener, "FORTIFY_HOME");
}

protected String getMavenExecutable(Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, String mavenInstallationName)
protected String getMavenExecutable(Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, String mavenInstallationName, Node currentNode)
throws InterruptedException, IOException {
String result = "";
final EnvVars envVars = build.getEnvironment(listener);
Expand All @@ -106,11 +105,10 @@ protected String getMavenExecutable(Run<?, ?> build, FilePath workspace, Launche
if (ti != null) {
for (ToolInstallation inst : ti.getInstallations()) {
String instName = inst.getName();
if (((instName == null && mavenInstallationName == null) || (instName != null && instName.equalsIgnoreCase(mavenInstallationName))) && build instanceof AbstractBuild) {
if (((instName == null && mavenInstallationName == null) || (instName != null && instName.equalsIgnoreCase(mavenInstallationName)))) {
MavenInstallation mvn = (MavenInstallation)inst;
Node node = ((AbstractBuild)build).getBuiltOn();
if (node != null) {
mvn = mvn.forNode(node, listener);
if (currentNode != null) {
mvn = mvn.forNode(currentNode, listener);
}
mvn = mvn.forEnvironment(envVars);
mvn.buildEnvVars(envVars);
Expand Down Expand Up @@ -147,19 +145,18 @@ private String getExecutableForEnvVar(Run<?, ?> build, FilePath workspace, Launc
}
}

protected String getGradleExecutable(boolean useWrapper, Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, String gradleInstallationName) throws InterruptedException, IOException {
protected String getGradleExecutable(boolean useWrapper, Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, String gradleInstallationName, Node currentNode) throws InterruptedException, IOException {
String result = "";
final EnvVars envVars = build.getEnvironment(listener);
DescriptorExtensionList<ToolInstallation, ToolDescriptor<?>> tools = ToolInstallation.all();
ToolDescriptor<?> ti = tools.find(GradleInstallation.class);
if (ti != null) {
for (ToolInstallation inst : ti.getInstallations()) {
String instName = inst.getName();
if (((instName == null && gradleInstallationName == null) || (instName != null && instName.equalsIgnoreCase(gradleInstallationName))) && build instanceof AbstractBuild) {
if (((instName == null && gradleInstallationName == null) || (instName != null && instName.equalsIgnoreCase(gradleInstallationName)))) {
GradleInstallation gradle = (GradleInstallation)inst;
Node node = ((AbstractBuild)build).getBuiltOn();
if (node != null) {
gradle = gradle.forNode(node, listener);
if (currentNode != null) {
gradle = gradle.forNode(currentNode, listener);
}
gradle = gradle.forEnvironment(envVars);
gradle.buildEnvVars(envVars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import hudson.Launcher;
import hudson.Launcher.ProcStarter;
import hudson.Util;
import hudson.model.Node;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
Expand All @@ -59,13 +60,19 @@
public class FortifyTranslate extends FortifySCAStep {
private ProjectScanType projectScanType;
private String excludeList;
private Node currentNode;

@DataBoundConstructor
public FortifyTranslate(String buildID, ProjectScanType projectScanType) {
this.buildID = buildID;
this.projectScanType = projectScanType;
}

// this is required for GlobalTooling accessing the node during the build
public void setCurrentNode(Node node) {
this.currentNode = node;
}

public ProjectScanType getProjectScanType() {
return projectScanType;
}
Expand Down Expand Up @@ -358,7 +365,7 @@ public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher, Task
} else if (projectScanType instanceof MavenScanType) {
log.println("Running Maven 3 translation");
String mavenInstallationName = ((MavenScanType) projectScanType).getMavenInstallationName();
args.add(getMavenExecutable(build, workspace, launcher, listener, mavenInstallationName));
args.add(getMavenExecutable(build, workspace, launcher, listener, mavenInstallationName, currentNode));
option = getResolvedTranslationExcludeList(listener);
if (StringUtils.isNotEmpty(option)) {
addMavenExcludes(args, option, launcher.isUnix());
Expand All @@ -377,7 +384,7 @@ public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher, Task
if (StringUtils.isNotEmpty(option)) {
addAllArguments(args, option, "-exclude");
}
args.add(getGradleExecutable(((GradleScanType) projectScanType).getUseWrapper(), build, workspace, launcher, listener, gradleInstallationName));
args.add(getGradleExecutable(((GradleScanType) projectScanType).getUseWrapper(), build, workspace, launcher, listener, gradleInstallationName, currentNode));
option = getResolvedGradleOptions((GradleScanType) projectScanType, listener);
if (StringUtils.isNotEmpty(option)) {
addAllArguments(args, option);
Expand Down Expand Up @@ -466,12 +473,16 @@ protected Execution(FortifyTranslate ft, StepContext context) {

@Override
protected Void run() throws Exception {
getContext().get(TaskListener.class).getLogger().println("Running FortifyTranslate step");
if (!getContext().get(FilePath.class).exists()) {
getContext().get(FilePath.class).mkdirs();
StepContext context = getContext();
TaskListener taskListener = context.get(TaskListener.class);
taskListener.getLogger().println("Running FortifyTranslate step");
FilePath workspace = context.get(FilePath.class);
if (!workspace.exists()) {
workspace.mkdirs();
}
ft.perform(getContext().get(Run.class), getContext().get(FilePath.class), getContext().get(Launcher.class),
getContext().get(TaskListener.class));

ft.setCurrentNode(context.get(Node.class));
ft.perform(context.get(Run.class), workspace, context.get(Launcher.class), taskListener);

return null;
}
Expand Down

0 comments on commit b741445

Please sign in to comment.