Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project to ScanBuild service #519

Merged
merged 1 commit into from
Jun 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ public List<BuildPatternArtifacts> retrievePatternArtifacts(List<BuildPatternArt
return retrievePatternArtifactsService.execute(jfrogHttpClient);
}

public ArtifactoryXrayResponse scanBuild(String buildName, String buildNumber, String context) throws IOException {
public ArtifactoryXrayResponse scanBuild(String buildName, String buildNumber, String project, String context) throws IOException {
setConnectionTimeout(XRAY_SCAN_CONNECTION_TIMEOUT_SECS);
ScanBuild scanBuildService = new ScanBuild(buildName, buildNumber, context, log);
ScanBuild scanBuildService = new ScanBuild(buildName, buildNumber, project, context, log);
return scanBuildService.execute(jfrogHttpClient);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.NullArgumentException;
import org.apache.commons.lang.StringUtils;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.StringEntity;
Expand Down Expand Up @@ -37,22 +38,22 @@ public class ScanBuild extends JFrogService<ArtifactoryXrayResponse> {
private static final String SCAN_BUILD_URL = "api/xray/scanBuild";
private final String buildName;
private final String buildNumber;
private final String project;
private final String context;
private HttpPost request;

public ScanBuild(String buildName, String buildNumber, String context, Log log) {
public ScanBuild(String buildName, String buildNumber, String project, String context, Log log) {
super(log);
this.buildName = buildName;
this.buildNumber = buildNumber;
this.project = project;
this.context = context;
}

@Override
public HttpRequestBase createRequest() throws IOException {
StringEntity entity = new StringEntity("{\"buildName\":\"" + buildName + "\",\"buildNumber\":\"" + buildNumber +
"\",\"context\":\"" + context + "\"}");
StringEntity entity = new StringEntity(getXrayScanBody());
entity.setContentType("application/json");

HttpPost request = new HttpPost(SCAN_BUILD_URL);

// The scan build operation can take a long time to finish.
Expand Down Expand Up @@ -153,4 +154,16 @@ private XrayErrorException(String message) {
super(message);
}
}

/**
* Creates JSON body request for ScanBuild API.
*/
private String getXrayScanBody() {
String body = "{\"buildName\":\"" + buildName + "\",\"buildNumber\":\"" + buildNumber +
"\",\"context\":\"" + context;
if (StringUtils.isNotEmpty(project)) {
body += "\",\"project\":\"" + project;
}
return body + "\"}";
}
}