use of org.eclipse.n4js.semver.Semver.NPMVersionRequirement in project n4js by eclipse.
the class N4JSCommandService method installNpm.
/**
* Install the given NPM into the workspace.
*
* @param cancelIndicator
* not required.
*/
@SuppressWarnings("unused")
@ExecutableCommandHandler(JSONCodeActionService.INSTALL_NPM)
public Void installNpm(String packageName, String version, String fileUri, ILanguageServerAccess access, CancelIndicator cancelIndicator) {
builderFrontend.asyncRunBuildTask("InstallNpm", () -> {
return (ci) -> {
// FIXME: Use CliTools in favor of npmCli
NPMVersionRequirement versionRequirement = semverHelper.parse(version);
if (versionRequirement == null) {
versionRequirement = SemverUtils.createEmptyVersionRequirement();
}
// @formatter:off
access.getLanguageClient().showMessage(new MessageParams(MessageType.Warning, "Installation of npm packages is disabled. Use command line."));
// @formatter:on
return new CoarseGrainedChangeEvent();
};
}).whenComplete((a, b) -> builderFrontend.reinitWorkspace());
return null;
}
use of org.eclipse.n4js.semver.Semver.NPMVersionRequirement in project n4js by eclipse.
the class PackageJsonValidatorExtension method checkVersion.
/**
* Check the version property.
*/
@CheckProperty(property = VERSION)
public void checkVersion(JSONValue versionValue) {
if (!checkIsType(versionValue, JSONPackage.Literals.JSON_STRING_LITERAL, "as package version")) {
return;
}
JSONStringLiteral versionJsonString = (JSONStringLiteral) versionValue;
String versionString = versionJsonString.getValue();
IParseResult parseResult = validateSemver(versionValue, versionString);
NPMVersionRequirement npmVersion = semverHelper.parse(parseResult);
VersionRangeSetRequirement vrs = semverHelper.parseVersionRangeSet(parseResult);
if (vrs == null) {
String reason = "Cannot parse given string";
if (npmVersion != null) {
reason = "Given string is parsed as " + getVersionRequirementType(npmVersion);
}
String msg = IssueCodes.getMessageForPKGJ_INVALID_VERSION_NUMBER(versionString, reason);
addIssue(msg, versionValue, IssueCodes.PKGJ_INVALID_VERSION_NUMBER);
return;
}
if (!vrs.getRanges().isEmpty() && vrs.getRanges().get(0) instanceof VersionRangeConstraint) {
VersionRangeConstraint vrc = (VersionRangeConstraint) vrs.getRanges().get(0);
SimpleVersion simpleVersion = vrc.getVersionConstraints().get(0);
if (!simpleVersion.getComparators().isEmpty()) {
String comparator = SemverSerializer.serialize(simpleVersion.getComparators().get(0));
String reason = "Version numbers must not have comparators: '" + comparator + "'";
String msg = IssueCodes.getMessageForPKGJ_INVALID_VERSION_NUMBER(versionString, reason);
addIssue(msg, versionValue, IssueCodes.PKGJ_INVALID_VERSION_NUMBER);
return;
}
}
}
use of org.eclipse.n4js.semver.Semver.NPMVersionRequirement in project n4js by eclipse.
the class PackageJsonHelper method convertDependencies.
private void convertDependencies(ProjectDescriptionBuilder target, List<NameValuePair> depPairs, boolean avoidDuplicates, DependencyType type) {
Objects.requireNonNull(type);
Set<String> existingProjectNames = new HashSet<>();
if (avoidDuplicates) {
for (ProjectDependency pd : target.getDependencies()) {
existingProjectNames.add(pd.getPackageName());
}
}
for (NameValuePair pair : depPairs) {
String projectName = pair.getName();
boolean addProjectDependency = true;
addProjectDependency &= projectName != null && !projectName.isEmpty();
addProjectDependency &= !(avoidDuplicates && existingProjectNames.contains(projectName));
existingProjectNames.add(projectName);
if (addProjectDependency) {
JSONValue value = pair.getValue();
String valueStr = asStringOrNull(value);
NPMVersionRequirement versionRequirement = valueStr != null ? semverHelper.parse(valueStr) : null;
ProjectDependency dep = new ProjectDependency(projectName, type, valueStr, versionRequirement);
target.addDependency(dep);
}
}
}
Aggregations