Skip to content

Commit d7aa465

Browse files
authored
Merge pull request #12 from young-s-park/scancentral-renaming
Scancentral renaming
2 parents cb5591f + 881349b commit d7aa465

File tree

19 files changed

+171
-240
lines changed

19 files changed

+171
-240
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ call mvn -Djetty.port=8181 -DskipTests=true hpi:run
2727

2828
You must obtain a Fortify SSC authentication token to use the plugin's server related functionality, which includes build failure conditions and getting all vulnerability results in Jenkins.
2929

30-
* SSC authentication token (either JenkinsToken or CIToken). Token creation command:
30+
* SSC authentication token (CIToken). Token creation command:
3131
```
32-
$ fortifyclient token -gettoken JenkinsToken -url http://localhost:8180/ssc -user admin
32+
$ fortifyclient token -gettoken CIToken -url http://localhost:8180/ssc -user admin
3333
```
3434
* Tests. Some of the junit tests can utilize a connection to Fortify Software Security Center to verify the plugin functionality.
3535
To override the default SSC location (localhost:8080), you can specify the optional SSC URL parameter: 'ssc.url'.

src/main/java/com/fortify/plugin/jenkins/FortifyPlugin.java

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* (c) Copyright 2019 Micro Focus or one of its affiliates.
2+
* (c) Copyright 2020 Micro Focus or one of its affiliates.
33
*
44
* Licensed under the MIT License (the "License");
55
* you may not use this file except in compliance with the License.
@@ -282,6 +282,10 @@ public String getUpdateServerUrl() {
282282
return getUpdateContent() ? analysisRunType.getUpdateContent().getUpdateServerUrl() : "";
283283
}
284284

285+
public String getLocale() {
286+
return getUpdateContent() ? analysisRunType.getUpdateContent().getLocale() : "";
287+
}
288+
285289
@Deprecated
286290
public boolean getUpdateUseProxy() {
287291
return getUpdateContent() && updateContent.getUpdateUseProxy();
@@ -715,7 +719,7 @@ private void runLocal(AbstractBuild<?, ?> build, Launcher launcher, BuildListene
715719
private void performLocalTranslation(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
716720
// Update security content
717721
if (getUpdateContent()) {
718-
FortifyUpdate fu = new FortifyUpdate.Builder().updateServerURL(getUpdateServerUrl()).build();
722+
FortifyUpdate fu = new FortifyUpdate.Builder().updateServerURL(getUpdateServerUrl()).locale(getLocale()).build();
719723
fu.perform(build, launcher, listener);
720724
}
721725
// run Fortify SCA clean
@@ -821,16 +825,6 @@ private static <T> T runWithFortifyClient(String token, FortifyClient.Command<T>
821825
client.init(url, token, proxyHost, proxyPort, DESCRIPTOR.getProxyUsername(),
822826
DESCRIPTOR.getProxyPassword());
823827
}
824-
/*boolean useProxy = Jenkins.get().proxy != null;
825-
if (!useProxy) {
826-
client.init(url, token);
827-
} else {
828-
String proxyHost = Jenkins.get().proxy.name;
829-
int proxyPort = Jenkins.get().proxy.port;
830-
String proxyUsername = Jenkins.get().proxy.getUserName();
831-
String proxyPassword = Jenkins.get().proxy.getPassword();
832-
client.init(url, token, proxyHost, proxyPort, proxyUsername, proxyPassword);
833-
}*/
834828
}
835829
return cmd.runWith(client);
836830
} finally {
@@ -1142,7 +1136,8 @@ public FormValidation doTestCtrlConnection(@QueryParameter String ctrlUrl) throw
11421136
try {
11431137
response = client.newCall(request).execute();
11441138

1145-
if (response.isSuccessful() && response.body().string().contains("Fortify CloudScan Controller")) {
1139+
if (response.isSuccessful() && (response.body().string().contains("Fortify ScanCentral Controller") ||
1140+
response.body().string().contains("Fortify CloudScan Controller"))) {
11461141
return FormValidation.okWithMarkup("<font color=\"blue\">Connection successful!</font>");
11471142
} else {
11481143
return FormValidation.error("Connection failed. Check the Controller URL.");
@@ -1231,7 +1226,7 @@ private void checkCtrlUrlValue(String url) throws FortifyException {
12311226
if (url.trim().equalsIgnoreCase("http://") || url.trim().equalsIgnoreCase("https://")) {
12321227
throw new FortifyException(new Message(Message.ERROR, "URL host is required"));
12331228
}
1234-
if (!StringUtils.endsWith(url,"/cloud-ctrl")) {
1229+
if (!StringUtils.endsWith(url,"/scancentral-ctrl") && !StringUtils.endsWith(url,"/cloud-ctrl")) {
12351230
throw new FortifyException(new Message(Message.ERROR, "Invalid context"));
12361231
}
12371232
} else {
@@ -1713,27 +1708,21 @@ public Map<String, String> runWith(FortifyClient client) throws Exception {
17131708
return Collections.emptyList();
17141709
}
17151710

1716-
public ListBoxModel doFillTranslationApplicationTypeItems() {
1717-
ListBoxModel options = new ListBoxModel(5);
1718-
options.add("Java", "java");
1719-
options.add(".NET", "dotnet");
1720-
options.add("Maven 3", "maven3");
1721-
options.add("Gradle", "gradle");
1722-
options.add("Other", "other");
1723-
return options;
1724-
}
1711+
public ListBoxModel doFillLocaleItems(String value) {
1712+
ListBoxModel items = new ListBoxModel();
1713+
items.add("English", "en");
1714+
items.add("Chinese Simplified", "zh_CN");
1715+
items.add("Chinese Traditional", "zh_TW");
1716+
items.add("Japanese", "ja");
1717+
items.add("Korean", "ko");
1718+
items.add("Portuguese (Brazil)", "pt_BR");
1719+
items.add("Spanish", "es");
17251720

1726-
public ListBoxModel doFillTranslationJavaVersionItems() {
1727-
ListBoxModel options = new ListBoxModel();
1728-
options.add("1.5", "1.5");
1729-
options.add("1.6", "1.6");
1730-
options.add("1.7", "1.7");
1731-
options.add("1.8", "1.8");
1732-
options.add("1.9", "1.9");
1733-
options.add("10", "10");
1734-
options.add("11", "11");
1735-
options.add("12", "12");
1736-
return options;
1721+
if ((null == value) || (0 == value.length())) {
1722+
items.get(0).selected = true; // default to en_US
1723+
}
1724+
1725+
return items;
17371726
}
17381727
}
17391728

@@ -2396,6 +2385,7 @@ public String getScanLogFile() {
23962385

23972386
public static class UpdateContentBlock {
23982387
private String updateServerUrl;
2388+
private String locale;
23992389
private UseProxyBlock useProxy;
24002390

24012391
@DataBoundConstructor
@@ -2413,6 +2403,10 @@ public String getUpdateServerUrl() {
24132403
@DataBoundSetter
24142404
public void setUpdateServerUrl(String updateServerUrl) { this.updateServerUrl = updateServerUrl; }
24152405

2406+
public String getLocale() { return locale; }
2407+
@DataBoundSetter
2408+
public void setLocale(String locale) { this.locale = locale; }
2409+
24162410
@Deprecated
24172411
public boolean getUpdateUseProxy() {
24182412
return useProxy != null;

src/main/java/com/fortify/plugin/jenkins/steps/CloudScanArguments.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,8 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull
4848
setLastBuild(run);
4949
PrintStream log = taskListener.getLogger();
5050
log.println("Fortify Jenkins plugin v " + VERSION);
51-
log.println("Launching Fortify cloudscan arguments command");
52-
//String projectRoot = filePath.getRemote() + File.separator + ".fortify";
53-
String cloudscanExec = null;
54-
55-
if (cloudscanExec == null) {
56-
cloudscanExec = getCloudScanExecutable(run, filePath, launcher, taskListener);
57-
}
51+
log.println("Launching Fortify scancentral arguments command");
52+
String cloudscanExec = getScancentralExecutable(run, filePath, launcher, taskListener);
5853

5954
EnvVars vars = run.getEnvironment(taskListener);
6055
ArrayList<String> args = new ArrayList<String>(2);

src/main/java/com/fortify/plugin/jenkins/steps/CloudScanMbs.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull
116116
log.println("Fortify Jenkins plugin v " + VERSION);
117117
log.println("Performing Fortify remote scan");
118118
String projectRoot = filePath.getRemote() + File.separator + ".fortify";
119-
String cloudscanExec = null;
120-
121-
if (cloudscanExec == null) {
122-
cloudscanExec = getCloudScanExecutable(run, filePath, launcher, taskListener);
123-
}
119+
String cloudscanExec = getScancentralExecutable(run, filePath, launcher, taskListener);
124120

125121
EnvVars vars = run.getEnvironment(taskListener);
126122
ArrayList<String> args = new ArrayList<String>(2);

src/main/java/com/fortify/plugin/jenkins/steps/CloudScanStart.java

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public class CloudScanStart extends FortifyCloudScanStep implements SimpleBuildS
2929
private FortifyPlugin.RemoteOptionalConfigBlock remoteOptionalConfig;
3030
private FortifyPlugin.UploadSSCBlock uploadSSC;
3131

32-
//private String mbsFile;
33-
//private boolean createMbs;
3432
private String buildID;
3533

3634
@DataBoundConstructor
@@ -87,22 +85,6 @@ public boolean isIncludeTests() {
8785
}
8886
}
8987

90-
/*public String getMbsFile() {
91-
return mbsFile;
92-
}
93-
94-
public void setMbsFile(String mbsFile) {
95-
this.mbsFile = mbsFile;
96-
}
97-
98-
public boolean isCreateMbs() {
99-
return createMbs;
100-
}
101-
102-
public void setCreateMbs(boolean createMbs) {
103-
this.createMbs = createMbs;
104-
}*/
105-
10688
public String getSensorPoolName() {
10789
return getRemoteOptionalConfig() == null ? "" : getRemoteOptionalConfig().getSensorPoolUUID();
10890
}
@@ -119,10 +101,6 @@ public String getFilterFile() {
119101
return getRemoteOptionalConfig() == null ? "" : getRemoteOptionalConfig().getFilterFile();
120102
}
121103

122-
/*public String getResultsFile() {
123-
return getRemoteOptionalConfig() == null ? "" : getRemoteOptionalConfig().getResultsFile();
124-
}*/
125-
126104
public String getApplicationName() {
127105
return getUploadSSC() == null ? "" : getUploadSSC().getAppName();
128106
}
@@ -160,10 +138,6 @@ public String getResolvedBuildFile(TaskListener listener) {
160138
return resolve(getBuildFile(), listener);
161139
}
162140

163-
/*public String getResolvedMbsFile(TaskListener listener) {
164-
return resolve(getMbsFile(), listener);
165-
}*/
166-
167141
public String getResolvedSensorPoolName(TaskListener listener) {
168142
return resolve(getSensorPoolName(), listener);
169143
}
@@ -182,8 +156,6 @@ public String getResolvedFilterFile(TaskListener listener) {
182156

183157
public String getResolvedBuildID(TaskListener listener) { return resolve(getBuildID(), listener); }
184158

185-
/*public String getResolvedScanArgs(TaskListener listener) { return resolve(getScanOptions(), listener); }*/
186-
187159
public String getResolvedApplicationName(TaskListener listener) { return resolve(getApplicationName(), listener); }
188160

189161
public String getResolvedApplicationVersion(TaskListener listener) { return resolve(getApplicationVersion(), listener); }
@@ -196,8 +168,6 @@ public String getResolvedFilterFile(TaskListener listener) {
196168

197169
public String getResolvedPhpVersion(TaskListener listener) { return resolve(getPhpVersion(), listener); }
198170

199-
/*public String getResolvedResultsFile(TaskListener listener) { return resolve(getResultsFile(), listener); }*/
200-
201171
@Override
202172
public StepExecution start(StepContext context) throws Exception {
203173
return new Execution(this, context);
@@ -210,11 +180,7 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull
210180
log.println("Fortify Jenkins plugin v " + VERSION);
211181
log.println("Performing Fortify remote analysis");
212182
String projectRoot = filePath.getRemote() + File.separator + ".fortify";
213-
String cloudscanExec = null;
214-
215-
if (cloudscanExec == null) {
216-
cloudscanExec = getCloudScanExecutable(run, filePath, launcher, taskListener);
217-
}
183+
String cloudscanExec = getScancentralExecutable(run, filePath, launcher, taskListener);
218184

219185
EnvVars vars = run.getEnvironment(taskListener);
220186
ArrayList<String> args = new ArrayList<String>(2);
@@ -270,11 +236,6 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull
270236
args.add("-project-root");
271237
args.add(projectRoot);
272238
}
273-
/*if (StringUtils.isNotEmpty(getResolvedResultsFile(taskListener))) {
274-
args.add("-o"); // overwrite existing FPR
275-
args.add("-f");
276-
args.add(getResolvedResultsFile(taskListener));
277-
}*/
278239
if (StringUtils.isNotEmpty(getResolvedEmailAddr(taskListener))) {
279240
args.add("-email");
280241
args.add(getResolvedEmailAddr(taskListener));

src/main/java/com/fortify/plugin/jenkins/steps/FortifyCloudScanStep.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,21 @@ public String getResolvedScanArgs(TaskListener listener) {
2727
protected String getCloudScanExecutable(Run<?, ?> build, FilePath workspace, Launcher launcher,
2828
TaskListener listener) throws InterruptedException, IOException {
2929
return getExecutable("cloudscan" + (launcher.isUnix() ? "" : ".bat"), true, build, workspace, launcher,
30-
listener);
30+
listener, null);
3131
}
3232

33+
/* Look for scancentral executable in Jenkins environment, if not found, get the old cloudscan executable. It's considered not found
34+
* if the getExecutable() returns just the filename rather than the full path.*/
35+
protected String getScancentralExecutable(Run<?, ?> build, FilePath workspace, Launcher launcher,
36+
TaskListener listener) throws InterruptedException, IOException {
37+
String filename = "scancentral" + (launcher.isUnix() ? "" : ".bat");
38+
String msg = "Checking for cloudscan executable";
39+
String exec = getExecutable(filename, true, build, workspace, launcher,
40+
listener, msg);
41+
if (exec.equals(filename)) {
42+
return getCloudScanExecutable(build, workspace, launcher, listener);
43+
} else {
44+
return exec;
45+
}
46+
}
3347
}

src/main/java/com/fortify/plugin/jenkins/steps/FortifySCAStep.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,30 +86,32 @@ public void setLogFile(String logFile) {
8686

8787
protected String getSourceAnalyzerExecutable(Run<?, ?> build, FilePath workspace, Launcher launcher,
8888
TaskListener listener) throws InterruptedException, IOException {
89-
return getExecutable("sourceanalyzer" + (launcher.isUnix() ? "" : ".exe"), true, build, workspace, launcher,
90-
listener);
89+
return getExecutable("sourceanalyzer" + (launcher.isUnix() ? "" : ".exe"), true, build, workspace,
90+
launcher, listener, null);
9191
}
9292

9393
protected String getMavenExecutable(Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener)
9494
throws InterruptedException, IOException {
95-
return getExecutable("mvn" + (launcher.isUnix() ? "" : ".cmd"), false, build, workspace, launcher, listener);
95+
return getExecutable("mvn" + (launcher.isUnix() ? "" : ".cmd"), false, build, workspace, launcher,
96+
listener, null);
9697
}
9798

9899
protected String getGradleExecutable(boolean useWrapper, Run<?, ?> build, FilePath workspace, Launcher launcher,
99100
TaskListener listener) throws InterruptedException, IOException {
100101
return getExecutable("gradle" + (useWrapper ? "w" : "") + (launcher.isUnix() ? "" : ".bat"), false, build,
101-
workspace, launcher, listener);
102+
workspace, launcher, listener, null);
102103
}
103104

104105
protected String getDevenvExecutable(Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener)
105106
throws InterruptedException, IOException {
106-
return getExecutable("devenv" + (launcher.isUnix() ? "" : ".exe"), false, build, workspace, launcher, listener);
107+
return getExecutable("devenv" + (launcher.isUnix() ? "" : ".exe"), false, build, workspace, launcher,
108+
listener, null);
107109
}
108110

109111
protected String getMSBuildExecutable(Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener)
110112
throws InterruptedException, IOException {
111113
return getExecutable("msbuild" + (launcher.isUnix() ? "" : ".exe"), false, build, workspace, launcher,
112-
listener);
114+
listener, null);
113115
}
114116

115117
public Integer getResolvedMaxHeap(TaskListener listener) {

src/main/java/com/fortify/plugin/jenkins/steps/FortifyStep.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ protected void setLastBuild(Run<?, ?> lastBuild) {
6161
* @param workspace
6262
* @param launcher
6363
* @param listener
64+
* @param msg
6465
* @return found executable or filename if not found
6566
* @throws InterruptedException
6667
* @throws IOException
6768
*/
6869
protected String getExecutable(String filename, boolean checkFortifyHome, Run<?, ?> build, FilePath workspace,
69-
Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
70+
Launcher launcher, TaskListener listener, String msg) throws InterruptedException, IOException {
7071
EnvVars env = build.getEnvironment(listener);
7172
String fortifyHome = null;
7273
String path = null;
@@ -82,13 +83,15 @@ protected String getExecutable(String filename, boolean checkFortifyHome, Run<?,
8283
}
8384
String s = workspace.act(new FindExecutableRemoteService(filename, fortifyHome, path, workspace));
8485
if (s == null) {
85-
listener.getLogger().printf("executable not found: %s%n", filename);
86-
listener.getLogger().printf("\tfortify_home: %s%n", fortifyHome);
87-
listener.getLogger().printf("\tpath: %s%n", path);
88-
listener.getLogger().printf("\tworkspace: %s%n", workspace.getRemote());
86+
listener.getLogger().printf("WARNING: %s executable not found in the Jenkins environment.%n", filename);
87+
if (msg != null) {
88+
listener.getLogger().println(msg);
89+
} else {
90+
listener.getLogger().printf("Checking system PATH for %s.%n", filename);
91+
}
8992
return filename;
9093
} else {
91-
listener.getLogger().printf("found executable: %s%n", s);
94+
listener.getLogger().printf("Found executable: %s%n", s);
9295
return s;
9396
}
9497
}

0 commit comments

Comments
 (0)