use of com.blackducksoftware.integration.hub.detect.detector.DetectorException in project hub-detect by blackducksoftware.
the class NugetInspectorManager method findDotnetCoreInspector.
private DotNetCoreNugetInspector findDotnetCoreInspector(File nupkgFolder, String dotnetExecutable) throws DetectorException {
// new inspector
final String dotnetInspectorName = "BlackduckNugetInspector.dll";
logger.info("Searching for: " + dotnetInspectorName);
File toolsFolder = new File(nupkgFolder, "tools");
Optional<File> foundExe = detectFileFinder.findFilesToDepth(toolsFolder, dotnetInspectorName, 3).stream().findFirst();
if (foundExe.isPresent() && foundExe.get().exists()) {
String inspectorExe = foundExe.get().toString();
logger.info("Found nuget inspector: " + inspectorExe);
return new DotNetCoreNugetInspector(dotnetExecutable, inspectorExe, executableRunner);
} else {
throw new DetectorException("Unable to find nuget inspector, looking for " + dotnetInspectorName + " in " + toolsFolder.toString());
}
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorException in project hub-detect by blackducksoftware.
the class NugetInspectorManager method install.
public NugetInspector install() throws DetectUserFriendlyException, IntegrationException, IOException {
// dotnet
final String dotnetExecutable = executableFinder.getExecutablePathOrOverride(ExecutableType.DOTNET, true, directoryManager.getSourceDirectory(), detectConfiguration.getProperty(DetectProperty.DETECT_DOTNET_PATH, PropertyAuthority.None));
boolean useDotnet = true;
if (shouldForceExeInspector(detectInfo)) {
logger.info("Will use the classic inspector.");
useDotnet = false;
} else if (dotnetExecutable == null) {
if (isNotWindows(detectInfo)) {
throw new DetectorException("When not on Windows, the nuget inspector requires the dotnet executable to run.");
} else {
useDotnet = false;
}
}
if (shouldUseAirGap()) {
logger.debug("Running in airgap mode. Resolving from local path");
File nugetFolder = new File(airGapManager.getNugetInspectorAirGapPath());
if (useDotnet) {
File dotnetFolder = new File(nugetFolder, "nuget_dotnet");
return findDotnetCoreInspector(dotnetFolder, dotnetExecutable);
} else {
File classicFolder = new File(nugetFolder, "nuget_classic");
return findExeInspector(classicFolder);
}
} else {
logger.info("Determining the nuget inspector version.");
File nugetDirectory = directoryManager.getPermanentDirectory("nuget");
// create the artifact
String nugetInspectorVersion = detectConfiguration.getProperty(DetectProperty.DETECT_NUGET_INSPECTOR_VERSION, PropertyAuthority.None);
Optional<String> source;
if (useDotnet) {
logger.info("Will attempt to resolve the dotnet inspector version.");
source = artifactResolver.resolveArtifactLocation(ArtifactoryConstants.ARTIFACTORY_URL, ArtifactoryConstants.NUGET_INSPECTOR_REPO, ArtifactoryConstants.NUGET_INSPECTOR_PROPERTY, nugetInspectorVersion, ArtifactoryConstants.NUGET_INSPECTOR_VERSION_OVERRIDE);
} else {
logger.info("Will attempt to resolve the classic inspector version.");
source = artifactResolver.resolveArtifactLocation(ArtifactoryConstants.ARTIFACTORY_URL, ArtifactoryConstants.CLASSIC_NUGET_INSPECTOR_REPO, ArtifactoryConstants.CLASSIC_NUGET_INSPECTOR_PROPERTY, nugetInspectorVersion, ArtifactoryConstants.CLASSIC_NUGET_INSPECTOR_VERSION_OVERRIDE);
}
if (source.isPresent()) {
logger.debug("Resolved the nuget inspector url: " + source.get());
String nupkgName = artifactResolver.parseFileName(source.get());
logger.debug("Parsed artifact name: " + nupkgName);
File nupkgFile = new File(nugetDirectory, nupkgName);
String inspectorFolderName = nupkgName.replace(".nupkg", "");
File inspectorFolder = new File(nugetDirectory, inspectorFolderName);
if (!inspectorFolder.exists()) {
logger.info("Downloading nuget inspector.");
artifactResolver.downloadArtifact(nupkgFile, source.get());
logger.info("Extracting nuget inspector.");
DetectZipUtil.unzip(nupkgFile, inspectorFolder, Charset.defaultCharset());
}
if (inspectorFolder.exists()) {
logger.info("Found nuget inspector folder. Looking for inspector.");
if (useDotnet) {
return findDotnetCoreInspector(inspectorFolder, dotnetExecutable);
} else {
return findExeInspector(inspectorFolder);
}
} else {
throw new DetectorException("Unable to find inspector folder even after zip extraction attempt.");
}
} else {
throw new DetectorException("Unable to find nuget inspector location in Artifactory.");
}
}
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorException in project hub-detect by blackducksoftware.
the class DockerInspectorManager method getDockerInspector.
public DockerInspectorInfo getDockerInspector() throws DetectorException {
try {
if (!hasResolvedInspector) {
hasResolvedInspector = true;
resolvedInfo = install();
}
return resolvedInfo;
} catch (final Exception e) {
throw new DetectorException(e);
}
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorException in project hub-detect by blackducksoftware.
the class CacheableExecutableFinder method getExecutable.
public File getExecutable(final CacheableExecutableType executableType) throws DetectorException {
if (alreadyFound.containsKey(executableType)) {
logger.debug("Already found executable, resolving with cached value.");
return alreadyFound.get(executableType);
}
final StandardExecutableInfo info = createInfo(executableType);
if (info == null) {
throw new DetectorException("Unknown executable type: " + executableType.toString());
}
final String exe = executableFinder.getExecutablePathOrOverride(info.detectExecutableType, true, directoryManager.getSourceDirectory(), info.override);
File exeFile = null;
if (exe != null) {
exeFile = new File(exe);
}
logger.debug("Cached executable " + executableType.toString() + " to: " + exeFile.getAbsolutePath());
alreadyFound.put(executableType, exeFile);
return exeFile;
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorException in project hub-detect by blackducksoftware.
the class BazelExecutableFinder method findBazel.
public String findBazel(final DetectorEnvironment environment) {
final boolean resolvedPreviously = isAlreadyFound(CacheableExecutableType.BAZEL);
String resolvedBazel = null;
try {
final File bazelExeFile = getExecutable(CacheableExecutableType.BAZEL);
if (bazelExeFile == null) {
logger.debug("Unable to locate Bazel executable");
return null;
}
resolvedBazel = bazelExeFile.getAbsolutePath();
} catch (DetectorException e) {
logger.debug(String.format("Unable to locate Bazel executable: %s", e.getMessage()));
return null;
}
if (!resolvedPreviously) {
final ExecutableOutput bazelQueryDepsRecursiveOutput;
try {
bazelQueryDepsRecursiveOutput = executableRunner.executeQuietly(environment.getDirectory(), resolvedBazel, BAZEL_VERSION_SUBCOMMAND);
int returnCode = bazelQueryDepsRecursiveOutput.getReturnCode();
logger.trace(String.format("Bazel version returned %d; output: %s", returnCode, bazelQueryDepsRecursiveOutput.getStandardOutput()));
} catch (ExecutableRunnerException e) {
logger.debug(String.format("Bazel version threw exception: %s", e.getMessage()));
resolvedBazel = null;
}
}
return resolvedBazel;
}
Aggregations