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