Search in sources :

Example 11 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.

the class DepPackager method getGopkgLockContents.

private String getGopkgLockContents(final File file, final String goDepExecutable) throws IOException {
    String gopkgLockContents = null;
    final File gopkgLockFile = new File(file, "Gopkg.lock");
    if (gopkgLockFile.exists()) {
        try (FileInputStream fis = new FileInputStream(gopkgLockFile)) {
            gopkgLockContents = IOUtils.toString(fis, Charset.defaultCharset());
            logger.debug(gopkgLockContents);
        } catch (final Exception e) {
            gopkgLockContents = null;
        }
        return gopkgLockContents;
    }
    // by default, we won't run 'init' and 'ensure' anymore so just return an empty string
    if (!detectConfiguration.getBooleanProperty(DetectProperty.DETECT_GO_RUN_DEP_INIT, PropertyAuthority.None)) {
        logger.info("Skipping Dep commands 'init' and 'ensure'");
        return "";
    }
    final File gopkgTomlFile = new File(file, "Gopkg.toml");
    final File vendorDirectory = new File(file, "vendor");
    final boolean vendorDirectoryExistedBefore = vendorDirectory.exists();
    final File vendorDirectoryBackup = new File(file, "vendor_old");
    if (vendorDirectoryExistedBefore) {
        logger.info(String.format("Backing up %s to %s", vendorDirectory.getAbsolutePath(), vendorDirectoryBackup.getAbsolutePath()));
        FileUtils.moveDirectory(vendorDirectory, vendorDirectoryBackup);
    }
    final String goDepInitString = String.format("%s 'init' on path %s", goDepExecutable, file.getAbsolutePath());
    try {
        logger.info("Running " + goDepInitString);
        final Executable executable = new Executable(file, goDepExecutable, Arrays.asList("init"));
        executableRunner.execute(executable);
    } catch (final ExecutableRunnerException e) {
        logger.error(String.format("Failed to run %s: %s", goDepInitString, e.getMessage()));
    }
    final String goDepEnsureUpdateString = String.format("%s 'ensure -update' on path %s", goDepExecutable, file.getAbsolutePath());
    try {
        logger.info("Running " + goDepEnsureUpdateString);
        final Executable executable = new Executable(file, goDepExecutable, Arrays.asList("ensure", "-update"));
        executableRunner.execute(executable);
    } catch (final ExecutableRunnerException e) {
        logger.error(String.format("Failed to run %s: %s", goDepEnsureUpdateString, e.getMessage()));
    }
    if (gopkgLockFile.exists()) {
        try (FileInputStream fis = new FileInputStream(gopkgLockFile)) {
            gopkgLockContents = IOUtils.toString(fis, Charset.defaultCharset());
        } catch (final Exception e) {
            gopkgLockContents = null;
        }
        gopkgLockFile.delete();
        gopkgTomlFile.delete();
        FileUtils.deleteDirectory(vendorDirectory);
        if (vendorDirectoryExistedBefore) {
            logger.info(String.format("Restoring back up %s from %s", vendorDirectory.getAbsolutePath(), vendorDirectoryBackup.getAbsolutePath()));
            FileUtils.moveDirectory(vendorDirectoryBackup, vendorDirectory);
        }
    }
    return gopkgLockContents;
}
Also used : Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 12 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.

the class GoInspectorManager method installGoDep.

private String installGoDep(final String goExecutable) throws ExecutableRunnerException {
    final File goDep = getGoDepInstallLocation();
    final File installDirectory = goDep.getParentFile();
    installDirectory.mkdirs();
    logger.debug("Retrieving the Go Dep tool");
    final Executable getGoDep = new Executable(installDirectory, goExecutable, Arrays.asList("get", "-u", "-v", "-d", "github.com/golang/dep/cmd/dep"));
    executableRunner.execute(getGoDep);
    logger.debug("Building the Go Dep tool in " + installDirectory.getAbsolutePath());
    final Executable buildGoDep = new Executable(installDirectory, goExecutable, Arrays.asList("build", "github.com/golang/dep/cmd/dep"));
    executableRunner.execute(buildGoDep);
    return goDep.getAbsolutePath();
}
Also used : Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) File(java.io.File)

Example 13 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.

the class DockerInspectorManager method getInspectorVersion.

String getInspectorVersion(final String bashExecutablePath) throws IOException, ExecutableRunnerException, DetectUserFriendlyException {
    if (StringUtils.isBlank(this.inspectorVersion)) {
        if ("latest".equalsIgnoreCase(this.detectConfiguration.getDockerInspectorVersion())) {
            final File dockerPropertiesFile = this.detectFileManager.createFile(BomToolType.DOCKER, "application.properties");
            final File dockerBomToolDirectory = dockerPropertiesFile.getParentFile();
            if (null == this.dockerInspectorShellScript) {
                this.dockerInspectorShellScript = getShellScript();
            }
            final List<String> bashArguments = new ArrayList<>();
            bashArguments.add("-c");
            bashArguments.add("\"" + this.dockerInspectorShellScript.getCanonicalPath() + "\" --version");
            final Executable getDockerInspectorVersion = new Executable(dockerBomToolDirectory, bashExecutablePath, bashArguments);
            this.inspectorVersion = this.executableRunner.execute(getDockerInspectorVersion).getStandardOutput().split(" ")[1];
            this.logger.info(String.format("Resolved docker inspector version from latest to: %s", this.inspectorVersion));
        } else {
            this.inspectorVersion = this.detectConfiguration.getDockerInspectorVersion();
        }
    }
    return this.inspectorVersion;
}
Also used : ArrayList(java.util.ArrayList) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) File(java.io.File)

Example 14 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.

the class PipInspectorManager method runInspector.

public String runInspector(File sourceDirectory, String pythonPath, File inspectorScript, String projectName, String requirementsFilePath) throws ExecutableRunnerException {
    List<String> inspectorArguments = new ArrayList<>();
    inspectorArguments.add(inspectorScript.getAbsolutePath());
    if (StringUtils.isNotBlank(requirementsFilePath)) {
        File requirementsFile = new File(requirementsFilePath);
        inspectorArguments.add(String.format("--requirements=%s", requirementsFile.getAbsolutePath()));
    }
    if (StringUtils.isNotBlank(projectName)) {
        inspectorArguments.add(String.format("--projectname=%s", projectName));
    }
    Executable pipInspector = new Executable(sourceDirectory, pythonPath, inspectorArguments);
    return executableRunner.execute(pipInspector).getStandardOutput();
}
Also used : ArrayList(java.util.ArrayList) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) File(java.io.File)

Example 15 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.

the class NpmExecutableFinder method validateNpm.

boolean validateNpm(final File directoryToSearch, final String npmExePath) {
    if (StringUtils.isNotBlank(npmExePath)) {
        Executable npmVersionExe = null;
        final List<String> arguments = new ArrayList<>();
        arguments.add("-version");
        String npmNodePath = detectConfiguration.getProperty(DetectProperty.DETECT_NPM_NODE_PATH, PropertyAuthority.None);
        if (StringUtils.isNotBlank(npmNodePath)) {
            final int lastSlashIndex = npmNodePath.lastIndexOf("/");
            if (lastSlashIndex >= 0) {
                npmNodePath = npmNodePath.substring(0, lastSlashIndex);
            }
            final Map<String, String> environmentVariables = new HashMap<>();
            environmentVariables.put("PATH", npmNodePath);
            npmVersionExe = new Executable(directoryToSearch, environmentVariables, npmExePath, arguments);
        } else {
            npmVersionExe = new Executable(directoryToSearch, npmExePath, arguments);
        }
        try {
            final String npmVersion = executableRunner.execute(npmVersionExe).getStandardOutput();
            logger.debug("Npm version " + npmVersion);
            return true;
        } catch (final ExecutableRunnerException e) {
            logger.error("Could not run npm to get the version: " + e.getMessage());
        }
    }
    return false;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Aggregations

Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)22 ArrayList (java.util.ArrayList)13 File (java.io.File)11 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)10 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)8 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)6 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)5 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)2 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)2 PropertyAuthority (com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority)2 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)2 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 StringUtils (org.apache.commons.lang3.StringUtils)2 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)1