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);
}
}
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);
}
}
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();
}
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();
}
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;
}
Aggregations