Skip to content

Commit 1c60e58

Browse files
authored
Merge pull request #40 from CheckmarxDev/AST-6032/thin-wrapper
AST-6032 add a thin wrapper for usage in light plugins e.g. maven
2 parents b3b9cf3 + 50a1e45 commit 1c60e58

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.checkmarx.ast.wrapper;
2+
3+
import lombok.NonNull;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
7+
import java.io.IOException;
8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
import java.util.List;
11+
12+
public class CxThinWrapper {
13+
14+
@NonNull
15+
private final Logger logger;
16+
@NonNull
17+
private final String executable;
18+
19+
public CxThinWrapper() throws IOException {
20+
this(LoggerFactory.getLogger(CxWrapper.class));
21+
}
22+
23+
public CxThinWrapper(@NonNull Logger logger) throws IOException {
24+
this.logger = logger;
25+
this.executable = Execution.getTempBinary();
26+
this.logger.info("using executable: " + executable);
27+
}
28+
29+
public String run(@NonNull String arguments) throws CxException, IOException, InterruptedException {
30+
this.logger.info("executing thin wrapper command");
31+
List<String> argv = new ArrayList<>();
32+
argv.add(executable);
33+
argv.addAll(Arrays.asList(arguments.split(" ")));
34+
return Execution.executeCommand(argv, logger, (line) -> line);
35+
}
36+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.checkmarx.ast;
2+
3+
import com.checkmarx.ast.scan.Scan;
4+
import com.checkmarx.ast.wrapper.CxException;
5+
import com.checkmarx.ast.wrapper.CxThinWrapper;
6+
import lombok.SneakyThrows;
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
10+
import java.util.List;
11+
12+
public class ThinWrapperTest extends BaseTest {
13+
14+
@SneakyThrows
15+
@Test
16+
public void testThinWrapper() {
17+
CxThinWrapper wrapper = new CxThinWrapper(getLogger());
18+
String result = wrapper.run("scan list --format json --filter limit=10");
19+
List<Scan> scanList = Scan.listFromLine(result);
20+
Assert.assertTrue(scanList.size() <= 10);
21+
}
22+
23+
@SneakyThrows
24+
@Test
25+
public void testThinWrapperFail() {
26+
CxThinWrapper wrapper = new CxThinWrapper(getLogger());
27+
String arguments = "scan create -s . --project-name thin-wrapper-test --sast-preset invalid-preset";
28+
CxException e = Assert.assertThrows(CxException.class, () -> wrapper.run(arguments));
29+
Assert.assertTrue(e.getMessage().contains("--sast-preset"));
30+
}
31+
}

0 commit comments

Comments
 (0)