Search in sources :

Example 1 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class BlackDuckJsonTransformer method getResponses.

public <T extends BlackDuckResponse> BlackDuckPageResponse<T> getResponses(String json, Class<T> clazz) throws IntegrationException {
    try {
        JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
        int totalCount = jsonObject.get("totalCount").getAsInt();
        JsonArray items = jsonObject.get("items").getAsJsonArray();
        List<T> itemList = new ArrayList<>();
        for (JsonElement jsonElement : items) {
            itemList.add(getResponseAs(jsonElement, clazz));
        }
        return new BlackDuckPageResponse<>(totalCount, itemList);
    } catch (JsonSyntaxException e) {
        logger.error(String.format("Could not parse the provided json responses with Gson:%s%s", System.lineSeparator(), json));
        throw new BlackDuckIntegrationException(e.getMessage(), e);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse)

Example 2 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class BlackDuckJsonTransformer method getResponseAs.

public <T extends BlackDuckResponse> T getResponseAs(JsonElement jsonElement, Class<T> clazz) throws BlackDuckIntegrationException {
    String json = gson.toJson(jsonElement);
    try {
        T blackDuckResponse = responseResolver.resolve(jsonElement, clazz);
        blackDuckResponse.setGson(gson);
        blackDuckResponse.setJsonElement(jsonElement);
        blackDuckResponse.setJson(json);
        setPatch(blackDuckResponse);
        return blackDuckResponse;
    } catch (JsonSyntaxException e) {
        logger.error(String.format("Could not parse the provided jsonElement with Gson:%s%s", System.lineSeparator(), json));
        throw new BlackDuckIntegrationException(e.getMessage(), e);
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

Example 3 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class ScanPathsUtility method findPathToJavaExe.

private String findPathToJavaExe(final File jreContentsDirectory) throws BlackDuckIntegrationException {
    File jdkBase = getJdkBase(jreContentsDirectory);
    File javaExe = new File(jdkBase, OTHER_JAVA_PATH);
    if (OperatingSystemType.WINDOWS == operatingSystemType) {
        javaExe = new File(jdkBase, WINDOWS_JAVA_PATH);
    }
    if (!javaExe.exists() || !javaExe.isFile()) {
        throw new BlackDuckIntegrationException(String.format("The java executable does not exist at: %s", javaExe.getAbsolutePath()));
    }
    return javaExe.getAbsolutePath();
}
Also used : BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) File(java.io.File)

Example 4 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class ScanPathsUtility method determinePathToJavaExecutable.

private String determinePathToJavaExecutable(File jreContentsDirectory) throws BlackDuckIntegrationException {
    ThrowingSupplier<String, BlackDuckIntegrationException> javaHomeSupplier = () -> findPathToJavaExe(jreContentsDirectory);
    final String bdsJavaHome = intEnvironmentVariables.getValue(BDS_JAVA_HOME);
    if (StringUtils.isNotBlank(bdsJavaHome)) {
        File bdsJavaHomeDirectory = new File(bdsJavaHome);
        if (bdsJavaHomeDirectory.exists() && bdsJavaHomeDirectory.isDirectory()) {
            javaHomeSupplier = () -> findPathToJavaExe(bdsJavaHomeDirectory);
        } else {
            String warningFormat = "The environment variable %s is set, but it cannot be used as a valid directory. It will be ignored and should either be corrected, or unset in the environment to avoid this warning.";
            logger.warn(String.format(warningFormat, BDS_JAVA_HOME));
        }
    }
    return javaHomeSupplier.get();
}
Also used : BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) File(java.io.File)

Example 5 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class ScanPathsUtility method createRunOutputDirectory.

public File createRunOutputDirectory(final File generalOutputDirectory, final String userProvidedPrefix, final String userProvidedUniqueSuffix) throws BlackDuckIntegrationException {
    final String signatureScanOutputDirectoryName = "BlackDuckScanOutput";
    final File signatureScanOutputDirectory = new File(generalOutputDirectory, signatureScanOutputDirectoryName);
    final String uniqueOutputDirectoryName = userProvidedPrefix + "_" + userProvidedUniqueSuffix;
    final File specificRunOutputDirectory = new File(signatureScanOutputDirectory, uniqueOutputDirectoryName);
    if (!specificRunOutputDirectory.exists() && !specificRunOutputDirectory.mkdirs()) {
        throw new BlackDuckIntegrationException(String.format("Could not create the %s directory!", specificRunOutputDirectory.getAbsolutePath()));
    }
    final File bdIgnoreLogsFile = new File(generalOutputDirectory, ".bdignore");
    if (!bdIgnoreLogsFile.exists()) {
        try {
            if (!bdIgnoreLogsFile.createNewFile()) {
                throw new BlackDuckIntegrationException(String.format("Could not create the %s file!", bdIgnoreLogsFile.getAbsolutePath()));
            }
            final String exclusionPattern = "/" + signatureScanOutputDirectoryName + "/";
            Files.write(bdIgnoreLogsFile.toPath(), exclusionPattern.getBytes());
        } catch (final IOException e) {
            throw new BlackDuckIntegrationException(String.format("Unexpected error creating the .bdignore file in the %s directory: %s", bdIgnoreLogsFile.getAbsolutePath(), e.getMessage()));
        }
    }
    return specificRunOutputDirectory;
}
Also used : BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) IOException(java.io.IOException) File(java.io.File)

Aggregations

BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)29 File (java.io.File)8 HttpUrl (com.synopsys.integration.rest.HttpUrl)7 ArrayList (java.util.ArrayList)7 IntegrationException (com.synopsys.integration.exception.IntegrationException)6 IOException (java.io.IOException)6 Future (java.util.concurrent.Future)5 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)3 UploadOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadOutput)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)2 ProjectVersionReportView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionReportView)2 BdioFileContent (com.synopsys.integration.blackduck.bdio2.model.BdioFileContent)2 Bdio2ContentExtractor (com.synopsys.integration.blackduck.bdio2.util.Bdio2ContentExtractor)2 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)2 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 DataService (com.synopsys.integration.blackduck.service.DataService)2 BlackDuckRequestBuilderEditor (com.synopsys.integration.blackduck.service.request.BlackDuckRequestBuilderEditor)2 IntLogger (com.synopsys.integration.log.IntLogger)2