use of com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult in project synopsys-detect by blackducksoftware.
the class NpmPeerExclusionTest method testPeerDependencyExists.
@Test
public void testPeerDependencyExists() {
NpmPackagerResult result = createPackager(NpmDependencyType.DEV).parseAndTransform(packageJsonText, packageLockText);
GraphAssert graphAssert = new GraphAssert(Forge.NPMJS, result.getCodeLocation().getDependencyGraph());
graphAssert.hasDependency(childPeer);
graphAssert.hasDependency(parentPeer);
graphAssert.hasRootSize(1);
}
use of com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult in project synopsys-detect by blackducksoftware.
the class NpmCliExtractor method extract.
public Extraction extract(File directory, ExecutableTarget npmExe, @Nullable String npmArguments, File packageJsonFile) {
toolVersionLogger.log(directory, npmExe);
PackageJson packageJson;
try {
packageJson = parsePackageJson(packageJsonFile);
} catch (IOException e) {
return new Extraction.Builder().exception(e).build();
}
List<String> exeArgs = new ArrayList<>();
exeArgs.add("ls");
exeArgs.add("-json");
Optional.ofNullable(npmArguments).map(arg -> arg.split(" ")).ifPresent(additionalArguments -> exeArgs.addAll(Arrays.asList(additionalArguments)));
ExecutableOutput npmLsOutput;
try {
npmLsOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, npmExe, exeArgs));
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
String standardOutput = npmLsOutput.getStandardOutput();
String errorOutput = npmLsOutput.getErrorOutput();
if (StringUtils.isNotBlank(errorOutput)) {
logger.error("Error when running npm ls -json command");
logger.error(errorOutput);
return new Extraction.Builder().failure("Npm wrote to stderr while running npm ls.").build();
} else if (StringUtils.isNotBlank(standardOutput)) {
logger.debug("Parsing npm ls file.");
logger.debug(standardOutput);
NpmPackagerResult result = npmCliParser.generateCodeLocation(standardOutput, packageJson);
String projectName = result.getProjectName() != null ? result.getProjectName() : packageJson.name;
String projectVersion = result.getProjectVersion() != null ? result.getProjectVersion() : packageJson.version;
return new Extraction.Builder().success(result.getCodeLocation()).projectName(projectName).projectVersion(projectVersion).build();
} else {
logger.error("Nothing returned from npm ls -json command");
return new Extraction.Builder().failure("Npm returned error after running npm ls.").build();
}
}
use of com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult in project synopsys-detect by blackducksoftware.
the class NpmDevExclusionTest method testDevDependencyNotExists.
@Test
public void testDevDependencyNotExists() {
NpmPackagerResult result = createPackager(NpmDependencyType.DEV, NpmDependencyType.PEER).parseAndTransform(packageJsonText, packageLockText);
GraphAssert graphAssert = new GraphAssert(Forge.NPMJS, result.getCodeLocation().getDependencyGraph());
graphAssert.hasNoDependency(childDev);
graphAssert.hasNoDependency(parentDev);
graphAssert.hasRootSize(0);
}
use of com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult in project synopsys-detect by blackducksoftware.
the class NpmDevExclusionTest method testDevDependencyExists.
@Test
public void testDevDependencyExists() {
NpmPackagerResult result = createPackager(NpmDependencyType.PEER).parseAndTransform(packageJsonText, packageLockText);
GraphAssert graphAssert = new GraphAssert(Forge.NPMJS, result.getCodeLocation().getDependencyGraph());
graphAssert.hasDependency(childDev);
graphAssert.hasDependency(parentDev);
graphAssert.hasRootSize(1);
}
Aggregations