|
5 | 5 | import com.checkmarx.ast.results.Results; |
6 | 6 | import com.checkmarx.ast.scan.Scan; |
7 | 7 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 8 | +import com.fasterxml.jackson.databind.type.CollectionType; |
| 9 | +import com.fasterxml.jackson.databind.type.TypeFactory; |
8 | 10 | import lombok.NonNull; |
9 | 11 | import org.apache.commons.lang3.StringUtils; |
10 | 12 | import org.slf4j.Logger; |
|
22 | 24 |
|
23 | 25 | public class CxWrapper { |
24 | 26 |
|
| 27 | + private static final CollectionType BRANCHES_TYPE = TypeFactory.defaultInstance() |
| 28 | + .constructCollectionType(List.class, String.class); |
| 29 | + |
25 | 30 | @NonNull |
26 | 31 | private final CxConfig cxConfig; |
27 | 32 | @NonNull |
@@ -79,10 +84,7 @@ public List<Scan> scanList(String filter) throws IOException, InterruptedExcepti |
79 | 84 | arguments.add(CxConstants.CMD_SCAN); |
80 | 85 | arguments.add(CxConstants.SUB_CMD_LIST); |
81 | 86 | arguments.addAll(jsonArguments()); |
82 | | - if (StringUtils.isNotBlank(filter)) { |
83 | | - arguments.add(CxConstants.FILTER); |
84 | | - arguments.add(filter); |
85 | | - } |
| 87 | + arguments.addAll(filterArguments(filter)); |
86 | 88 |
|
87 | 89 | return Execution.executeCommand(withConfigArguments(arguments), logger, Scan::listFromLine); |
88 | 90 | } |
@@ -133,15 +135,28 @@ public List<Project> projectList(String filter) throws IOException, InterruptedE |
133 | 135 | List<String> arguments = new ArrayList<>(); |
134 | 136 | arguments.add(CxConstants.CMD_PROJECT); |
135 | 137 | arguments.add(CxConstants.SUB_CMD_LIST); |
136 | | - if (StringUtils.isNotBlank(filter)) { |
137 | | - arguments.add(CxConstants.FILTER); |
138 | | - arguments.add(filter); |
139 | | - } |
| 138 | + arguments.addAll(filterArguments(filter)); |
140 | 139 | arguments.addAll(jsonArguments()); |
141 | 140 |
|
142 | 141 | return Execution.executeCommand(withConfigArguments(arguments), logger, Project::listFromLine); |
143 | 142 | } |
144 | 143 |
|
| 144 | + public List<String> projectBranches(@NonNull UUID projectId, String filter) |
| 145 | + throws CxException, IOException, InterruptedException { |
| 146 | + this.logger.info("initialized retrieval for project branches {}", filter); |
| 147 | + |
| 148 | + List<String> arguments = new ArrayList<>(); |
| 149 | + arguments.add(CxConstants.CMD_PROJECT); |
| 150 | + arguments.add(CxConstants.SUB_CMD_BRANCHES); |
| 151 | + arguments.add(CxConstants.PROJECT_ID); |
| 152 | + arguments.add(projectId.toString()); |
| 153 | + arguments.addAll(filterArguments(filter)); |
| 154 | + |
| 155 | + return Execution.executeCommand(withConfigArguments(arguments), |
| 156 | + logger, |
| 157 | + (line) -> CxBaseObject.parse(line, BRANCHES_TYPE)); |
| 158 | + } |
| 159 | + |
145 | 160 | public Results results(@NonNull UUID scanId) throws IOException, InterruptedException, CxException { |
146 | 161 | return new ObjectMapper() |
147 | 162 | .readerFor(Results.class) |
@@ -189,4 +204,15 @@ private List<String> jsonArguments() { |
189 | 204 |
|
190 | 205 | return arguments; |
191 | 206 | } |
| 207 | + |
| 208 | + private List<String> filterArguments(String filter) { |
| 209 | + List<String> arguments = new ArrayList<>(); |
| 210 | + |
| 211 | + if (StringUtils.isNotBlank(filter)) { |
| 212 | + arguments.add(CxConstants.FILTER); |
| 213 | + arguments.add(filter); |
| 214 | + } |
| 215 | + |
| 216 | + return arguments; |
| 217 | + } |
192 | 218 | } |
0 commit comments