use of com.vdurmont.semver4j.SemverException in project aws-greengrass-cli by aws-greengrass.
the class CLIService method install.
@Override
protected void install() {
try {
Path clientArtifact = kernel.getNucleusPaths().unarchiveArtifactPath(new ComponentIdentifier(CLI_SERVICE, new Semver(Coerce.toString(getConfig().find(VERSION_CONFIG_KEY)))), CLI_CLIENT_ARTIFACT);
if (!Files.exists(clientArtifact)) {
logger.atWarn().kv("path", clientArtifact).log("Unable to locate CLI binary. Make sure CLI component is properly deployed");
return;
}
Path unpackDir = clientArtifact.resolve(CLI_CLIENT_DIRECTORY);
setCliClientPermission(unpackDir);
for (String bin : CLI_CLIENT_BINARIES) {
Path binary = unpackDir.resolve(CLI_CLIENT_BIN).resolve(bin);
Path link = kernel.getNucleusPaths().binPath().resolve(bin);
Files.deleteIfExists(link);
Files.createSymbolicLink(link, binary);
logger.atInfo().kv("binary", binary).kv("link", link).log("Set up symlink to CLI binary");
}
} catch (IOException | SemverException e) {
logger.atError().log("Failed to set up symlink to CLI binary", e);
}
}
use of com.vdurmont.semver4j.SemverException in project DependencyCheck by jeremylong.
the class DependencyBundlingAnalyzer method npmVersionsMatch.
/**
* Determine if the dependency version is equal in the given dependencies.
* This method attempts to evaluate version range checks.
*
* @param current a dependency version to compare
* @param next a dependency version to compare
* @return true if the version is equal in both dependencies; otherwise
* false
*/
public static boolean npmVersionsMatch(String current, String next) {
String left = current;
String right = next;
if (left == null || right == null) {
return false;
}
if (left.equals(right) || "*".equals(left) || "*".equals(right)) {
return true;
}
if (left.contains(" ")) {
// we have a version string from package.json
if (right.contains(" ")) {
// we can't evaluate this ">=1.5.4 <2.0.0" vs "2 || 3"
return false;
}
if (!right.matches("^\\d.*$")) {
right = stripLeadingNonNumeric(right);
if (right == null) {
return false;
}
}
try {
final Semver v = new Semver(right, SemverType.NPM);
return v.satisfies(left);
} catch (SemverException ex) {
LOGGER.trace("ignore", ex);
}
} else {
if (!left.matches("^\\d.*$")) {
left = stripLeadingNonNumeric(left);
if (left == null || left.isEmpty()) {
return false;
}
}
try {
Semver v = new Semver(left, SemverType.NPM);
if (!right.isEmpty() && v.satisfies(right)) {
return true;
}
if (!right.contains(" ")) {
left = current;
right = stripLeadingNonNumeric(right);
if (right != null) {
v = new Semver(right, SemverType.NPM);
return v.satisfies(left);
}
}
} catch (SemverException ex) {
LOGGER.trace("ignore", ex);
} catch (NullPointerException ex) {
LOGGER.error("SemVer comparison error: left:\"{}\", right:\"{}\"", left, right);
LOGGER.debug("SemVer comparison resulted in NPE", ex);
}
}
return false;
}
use of com.vdurmont.semver4j.SemverException in project aws-greengrass-nucleus by aws-greengrass.
the class UnloadableService method isBootstrapRequired.
@Override
public boolean isBootstrapRequired(Map<String, Object> newServiceConfig) {
if (!PLUGIN.name().equals(newServiceConfig.get(SERVICE_TYPE_TOPIC_KEY))) {
logger.atInfo().log("Bootstrap is not required: component type is not Plugin");
return false;
}
if (!newServiceConfig.containsKey(VERSION_CONFIG_KEY)) {
logger.atInfo().log("Bootstrap is not required: config incomplete with no version");
return false;
}
String newVersion = newServiceConfig.get(VERSION_CONFIG_KEY).toString();
if (Utils.stringHasChanged(Coerce.toString(getConfig().find(VERSION_CONFIG_KEY)), newVersion)) {
logger.atInfo().log("Bootstrap is required: plugin version changed");
return true;
}
try {
Path pluginJar = config.getContext().get(NucleusPaths.class).artifactPath(new ComponentIdentifier(getName(), new Semver(newVersion))).resolve(getName() + JAR_FILE_EXTENSION);
if (!pluginJar.toFile().exists() || !pluginJar.toFile().isFile()) {
logger.atInfo().kv("pluginJar", pluginJar).log("Bootstrap is not required: plugin JAR not found");
return false;
}
if (Files.getLastModifiedTime(pluginJar).toMillis() > exceptionTimestamp) {
logger.atInfo().kv("pluginJar", pluginJar).log("Bootstrap is required: plugin JAR was modified");
return true;
}
logger.atInfo().kv("pluginJar", pluginJar).log("Bootstrap is not required: no change in plugin JAR");
} catch (IOException | SemverException e) {
logger.atError().log("Bootstrap is not required: unable to locate plugin JAR", e);
}
return false;
}
use of com.vdurmont.semver4j.SemverException in project aws-greengrass-nucleus by aws-greengrass.
the class ComponentManager method cleanupStaleVersions.
/**
* Delete stale versions from local store. It's best effort and all the errors are logged.
*/
public void cleanupStaleVersions() {
logger.atDebug("cleanup-stale-versions-start").log();
Map<String, Set<String>> versionsToKeep = getVersionsToKeep();
Map<String, Set<String>> versionsToRemove = componentStore.listAvailableComponentVersions();
// remove all local versions that does not exist in versionsToKeep
for (Map.Entry<String, Set<String>> localVersions : versionsToRemove.entrySet()) {
String compName = localVersions.getKey();
Set<String> removeVersions = new HashSet<>(localVersions.getValue());
if (versionsToKeep.containsKey(compName)) {
removeVersions.removeAll(versionsToKeep.get(compName));
}
for (String compVersion : removeVersions) {
try {
ComponentIdentifier identifier = new ComponentIdentifier(compName, new Semver(compVersion));
removeRecipeDigestIfExists(identifier);
componentStore.deleteComponent(identifier);
} catch (SemverException | PackageLoadingException e) {
// Log a warn here. This shouldn't cause a deployment to fail.
logger.atWarn().kv(COMPONENT_NAME, compName).kv("version", compVersion).setCause(e).log("Failed to clean up component");
}
}
}
logger.atDebug("cleanup-stale-versions-finish").log();
}
Aggregations