use of com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson in project synopsys-detect by blackducksoftware.
the class PackageJsonExtractorTest method createPackageJson.
private PackageJson createPackageJson() {
PackageJson packageJson = new PackageJson();
packageJson.name = "test";
packageJson.version = "test-version";
packageJson.dependencies = new HashMap<>();
packageJson.devDependencies = new HashMap<>();
packageJson.dependencies.put(testDep1.getName(), testDep1.getVersion());
packageJson.dependencies.put(testDep2.getName(), testDep2.getVersion());
packageJson.devDependencies.put(testDevDep1.getName(), testDevDep1.getVersion());
packageJson.devDependencies.put(testDevDep2.getName(), testDevDep2.getVersion());
return packageJson;
}
use of com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson in project synopsys-detect by blackducksoftware.
the class PackageJsonExtractorTest method extractWithDevNoPeerDependencies.
@Test
void extractWithDevNoPeerDependencies() {
PackageJson packageJson = createPackageJson();
Extraction extraction = createExtractor(NpmDependencyType.PEER).extract(packageJson);
assertEquals(1, extraction.getCodeLocations().size());
CodeLocation codeLocation = extraction.getCodeLocations().get(0);
DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
GraphAssert graphAssert = new GraphAssert(Forge.RUBYGEMS, dependencyGraph);
graphAssert.hasRootDependency(testDep1);
graphAssert.hasRootDependency(testDep2);
graphAssert.hasRootDependency(testDevDep1);
graphAssert.hasRootDependency(testDevDep2);
graphAssert.hasRootSize(4);
}
use of com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson in project synopsys-detect by blackducksoftware.
the class LernaDetectableTest method addPackageJson.
private void addPackageJson(Path directory, String packageName, String packageVersion, List<NameVersion> dependencies, List<NameVersion> devDependencies, List<NameVersion> peerDependencies) throws IOException {
PackageJson packageJson = new PackageJson();
packageJson.name = packageName;
packageJson.version = packageVersion;
packageJson.dependencies = dependencies.stream().collect(Collectors.toMap(NameVersion::getName, NameVersion::getVersion));
packageJson.devDependencies = devDependencies.stream().collect(Collectors.toMap(NameVersion::getName, NameVersion::getVersion));
packageJson.peerDependencies = peerDependencies.stream().collect(Collectors.toMap(NameVersion::getName, NameVersion::getVersion));
addFile(directory.resolve(LernaDetectable.PACKAGE_JSON), gson.toJson(packageJson));
}
use of com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson in project synopsys-detect by blackducksoftware.
the class LernaExternalDetectableTest method addPackageJson.
private void addPackageJson(Path directory, String packageName, String packageVersion, NameVersion... dependencies) throws IOException {
PackageJson packageJson = new PackageJson();
packageJson.name = packageName;
packageJson.version = packageVersion;
packageJson.dependencies = Arrays.stream(dependencies).collect(Collectors.toMap(NameVersion::getName, NameVersion::getVersion));
addFile(directory.resolve(LernaDetectable.PACKAGE_JSON), gson.toJson(packageJson));
}
use of com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson 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();
}
}
Aggregations