Search in sources :

Example 1 with DetectorException

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());
    }
}
Also used : DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) File(java.io.File) DotNetCoreNugetInspector(com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.DotNetCoreNugetInspector)

Example 2 with DetectorException

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.");
        }
    }
}
Also used : DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) File(java.io.File)

Example 3 with DetectorException

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);
    }
}
Also used : DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) IntegrationException(com.synopsys.integration.exception.IntegrationException) IOException(java.io.IOException) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException)

Example 4 with DetectorException

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;
}
Also used : DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) File(java.io.File)

Example 5 with DetectorException

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;
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) File(java.io.File) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Aggregations

DetectorException (com.blackducksoftware.integration.hub.detect.detector.DetectorException)13 File (java.io.File)8 IOException (java.io.IOException)5 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)4 IntegrationException (com.synopsys.integration.exception.IntegrationException)3 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)2 Detector (com.blackducksoftware.integration.hub.detect.detector.Detector)1 DetectorEnvironment (com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment)1 DetectorType (com.blackducksoftware.integration.hub.detect.detector.DetectorType)1 DotNetCoreNugetInspector (com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.DotNetCoreNugetInspector)1 ExeNugetInspector (com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.ExeNugetInspector)1 ExitCodeType (com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType)1 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)1 DetectorEvaluation (com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation)1 DetectorSearchRuleSet (com.blackducksoftware.integration.hub.detect.workflow.search.rules.DetectorSearchRuleSet)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1