Search in sources :

Example 1 with CxProfile

use of com.checkmarx.flow.dto.CxProfile in project cx-flow by checkmarx-ltd.

the class HelperService method loadCxProfiles.

@PostConstruct
public void loadCxProfiles() {
    if (properties.isAutoProfile() && !ScanUtils.empty(properties.getProfileConfig())) {
        log.debug("Loading CxProfile: {}", properties.getProfileConfig());
        File profileConfig = new File(properties.getProfileConfig());
        ObjectMapper mapper = new ObjectMapper();
        // if override is provided, check if chars are more than 20 in length, implying base64 encoded json
        try {
            CxProfile[] cxProfiles = mapper.readValue(profileConfig, CxProfile[].class);
            this.profiles = Arrays.asList(cxProfiles);
        } catch (IOException e) {
            log.warn("No CxProfile found - {}", e.getMessage());
        }
    }
}
Also used : CxProfile(com.checkmarx.flow.dto.CxProfile) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PostConstruct(javax.annotation.PostConstruct)

Example 2 with CxProfile

use of com.checkmarx.flow.dto.CxProfile in project cx-flow by checkmarx-ltd.

the class HelperServiceTest method testGetPresetFromSources.

@Test
public void testGetPresetFromSources() {
    FlowProperties properties = new FlowProperties();
    CxProperties cxProperties = new CxProperties();
    JiraProperties jiraProperties = new JiraProperties();
    cxProperties.setScanPreset(Constants.CX_DEFAULT_PRESET);
    CxScannerService cxScannerService = new CxScannerService(cxProperties, null, null, null, null);
    HelperService helperService = new HelperService(properties, cxScannerService, jiraProperties, null);
    Sources sources = new Sources();
    Sources.Source src1 = new Sources.Source();
    src1.setFile("abc.java");
    src1.setPath("abc.java");
    Sources.Source src2 = new Sources.Source();
    src2.setFile("abc.html");
    src2.setPath("abc.html");
    Sources.Source src3 = new Sources.Source();
    src3.setFile("abc.css");
    src3.setPath("abc.css");
    Sources.Source src4 = new Sources.Source();
    src4.setFile("buildspec.yml");
    src4.setPath("buildspec.yml");
    Map<String, Integer> sourceWeight = new HashMap<>();
    sourceWeight.put("Java", 65);
    sourceWeight.put("CSS", 15);
    sourceWeight.put("HTML", 20);
    sources.setLanguageStats(sourceWeight);
    sources.setSources(Arrays.asList(src1, src2, src3, src4));
    ObjectMapper mapper = new ObjectMapper();
    System.out.println(HelperService.class.getResource(".").getPath());
    File file = new File(getClass().getClassLoader().getResource("CxProfile.json").getFile());
    try {
        CxProfile[] cxProfiles = mapper.readValue(file, CxProfile[].class);
        helperService.setProfiles(Arrays.asList(cxProfiles));
        String preset = helperService.getPresetFromSources(sources);
        assertEquals(preset, "Checkmarx Express");
    } catch (IOException e) {
        fail("Unexpected IO Exception");
    }
}
Also used : FlowProperties(com.checkmarx.flow.config.FlowProperties) HashMap(java.util.HashMap) CxProfile(com.checkmarx.flow.dto.CxProfile) IOException(java.io.IOException) Sources(com.checkmarx.flow.dto.Sources) CxProperties(com.checkmarx.sdk.config.CxProperties) JiraProperties(com.checkmarx.flow.config.JiraProperties) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

CxProfile (com.checkmarx.flow.dto.CxProfile)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 File (java.io.File)2 IOException (java.io.IOException)2 FlowProperties (com.checkmarx.flow.config.FlowProperties)1 JiraProperties (com.checkmarx.flow.config.JiraProperties)1 Sources (com.checkmarx.flow.dto.Sources)1 CxProperties (com.checkmarx.sdk.config.CxProperties)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1