use of org.graalvm.component.installer.Version in project graal by oracle.
the class CatalogCompatTest method testOldFormatIgnoresPrevVersionsAvailable.
/**
* Checks that previous versions (RCs) are ignored with the old format.
*
* @throws Exception
*/
@Test
public void testOldFormatIgnoresPrevVersionsAvailable() throws Exception {
storage.graalInfo.put(CommonConstants.CAP_GRAALVM_VERSION, "1.0.0");
setupCatalogFormat1("catalogFormat1.properties");
// interprets user input for 'available'
Version gv = getLocalRegistry().getGraalVersion();
Version.Match selector = gv.match(Version.Match.Type.INSTALLABLE);
List<ComponentInfo> infos;
// check that versions 1.0.0-rcX are ignored for version 1.0.0
infos = new ArrayList<>(registry.loadComponents("ruby", selector, verbose));
assertEquals(1, infos.size());
infos = new ArrayList<>(registry.loadComponents("python", selector, verbose));
assertEquals(1, infos.size());
infos = new ArrayList<>(registry.loadComponents("r", selector, verbose));
assertEquals(1, infos.size());
}
use of org.graalvm.component.installer.Version in project graal by oracle.
the class CatalogCompatTest method testOldFormatIgnoresPrevVersionsMostRecent.
/**
* Checks that previous versions (RCs) are ignored with the old format.
*
* @throws Exception
*/
@Test
public void testOldFormatIgnoresPrevVersionsMostRecent() throws Exception {
storage.graalInfo.put(CommonConstants.CAP_GRAALVM_VERSION, "1.0.0");
setupCatalogFormat1("catalogFormat1.properties");
// copied from CatalogIterable, this is what interprets user input for install
Version gv = getLocalRegistry().getGraalVersion();
Version.Match selector = gv.match(Version.Match.Type.MOSTRECENT);
List<ComponentInfo> infos;
// check that versions 1.0.0-rcX are ignored for version 1.0.0
infos = new ArrayList<>(registry.loadComponents("ruby", selector, verbose));
assertEquals(1, infos.size());
infos = new ArrayList<>(registry.loadComponents("python", selector, verbose));
assertEquals(1, infos.size());
infos = new ArrayList<>(registry.loadComponents("r", selector, verbose));
assertEquals(1, infos.size());
}
use of org.graalvm.component.installer.Version in project graal by oracle.
the class WebCatalog method getStorage.
@Override
public ComponentStorage getStorage() {
if (this.storage != null) {
return this.storage;
}
Map<String, String> graalCaps = local.getGraalCapabilities();
StringBuilder sb = new StringBuilder();
sb.append(SystemUtils.patternOsName(graalCaps.get(CommonConstants.CAP_OS_NAME)).toLowerCase());
sb.append("_");
sb.append(SystemUtils.patternOsArch(graalCaps.get(CommonConstants.CAP_OS_ARCH).toLowerCase()));
try {
catalogURL = new URL(urlString);
} catch (MalformedURLException ex) {
throw feedback.failure("REMOTE_InvalidURL", ex, catalogURL, ex.getLocalizedMessage());
}
Properties props = new Properties();
// create the storage. If the init fails, but process will not terminate, the storage will
// serve no components on the next call.
RemotePropertiesStorage newStorage = createPropertiesStorage(feedback, local, props, sb.toString(), catalogURL);
if (remoteProcessor != null) {
newStorage.setRemoteProcessor(remoteProcessor);
}
Properties loadProps = new Properties();
FileDownloader dn;
try {
// avoid duplicate (failed) downloads
if (savedException != null) {
throw savedException;
}
catalogURL = new URL(urlString);
String l = source.getLabel();
dn = new FileDownloader(feedback.l10n(l == null || l.isEmpty() ? "REMOTE_CatalogLabel2" : "REMOTE_CatalogLabel", l), catalogURL, feedback);
dn.download();
} catch (NoRouteToHostException | ConnectException ex) {
throw savedException = feedback.failure("REMOTE_ErrorDownloadCatalogProxy", ex, catalogURL, ex.getLocalizedMessage());
} catch (FileNotFoundException ex) {
// treat missing resources as non-fatal errors, print warning
feedback.error("REMOTE_WarningErrorDownloadCatalogNotFoundSkip", ex, catalogURL);
this.storage = newStorage;
return storage;
} catch (IOException ex) {
throw savedException = feedback.failure("REMOTE_ErrorDownloadCatalog", ex, catalogURL, ex.getLocalizedMessage());
}
// download is successful; if the processing fails after download, next call will report an
// empty catalog.
this.storage = newStorage;
StringBuilder oldGraalPref = new StringBuilder("^" + BundleConstants.GRAAL_COMPONENT_ID);
oldGraalPref.append('.');
String graalVersionString;
Version normalizedVersion;
if (matchVersion != null) {
graalVersionString = matchVersion.getVersion().displayString();
normalizedVersion = matchVersion.getVersion().installVersion();
} else {
// read from the release file
graalVersionString = graalCaps.get(CommonConstants.CAP_GRAALVM_VERSION).toLowerCase();
normalizedVersion = local.getGraalVersion().installVersion();
}
StringBuilder graalPref = new StringBuilder(oldGraalPref);
oldGraalPref.append(Pattern.quote(graalVersionString));
oldGraalPref.append('_').append(sb);
graalPref.append(sb).append('/');
// NOI18N
graalPref.append("(?<ver>[^/]+)$");
try (FileInputStream fis = new FileInputStream(dn.getLocalFile())) {
loadProps.load(fis);
} catch (IllegalArgumentException | IOException ex) {
throw feedback.failure("REMOTE_CorruptedCatalogFile", ex, catalogURL);
}
Pattern oldPrefixPattern = Pattern.compile(oldGraalPref.toString(), Pattern.CASE_INSENSITIVE);
Pattern newPrefixPattern = Pattern.compile(graalPref.toString(), Pattern.CASE_INSENSITIVE);
Stream<String> propNames = loadProps.stringPropertyNames().stream();
boolean foundPrefix = propNames.anyMatch(p -> {
if (oldPrefixPattern.matcher(p).matches()) {
return true;
}
Matcher m = newPrefixPattern.matcher(p);
if (!m.find() || m.start() > 0) {
return false;
}
try {
// NOI18N
Version v = Version.fromString(m.group("ver"));
return normalizedVersion.match(Version.Match.Type.INSTALLABLE).test(v);
} catch (IllegalArgumentException ex) {
return false;
}
});
if (!foundPrefix) {
boolean graalPrefixFound = false;
boolean componentFound = false;
for (String s : loadProps.stringPropertyNames()) {
if (s.startsWith(BundleConstants.GRAAL_COMPONENT_ID)) {
graalPrefixFound = true;
}
if (s.startsWith("Component.")) {
componentFound = true;
}
}
if (!componentFound) {
// no graal prefix, no components
feedback.verboseOutput("REMOTE_CatalogDoesNotContainComponents", catalogURL);
return newStorage;
} else if (!graalPrefixFound) {
// strange thing, no graal declaration, but components are there ?
throw feedback.failure("REMOTE_CorruptedCatalogFile", null, catalogURL);
} else {
throw new IncompatibleException(feedback.l10n("REMOTE_UnsupportedGraalVersion", graalCaps.get(CommonConstants.CAP_GRAALVM_VERSION), graalCaps.get(CommonConstants.CAP_OS_NAME), graalCaps.get(CommonConstants.CAP_OS_ARCH)), null);
}
}
props.putAll(loadProps);
return newStorage;
}
use of org.graalvm.component.installer.Version in project graal by oracle.
the class Verifier method validateRequirements.
@SuppressWarnings("StringEquality")
@SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "intentional comparison of strings using ==")
public Verifier validateRequirements(ComponentInfo componentInfo) {
errors.clear();
// check the component is not in the registry
ComponentInfo existing = localRegistry.findComponent(componentInfo.getId());
if (existing != null) {
if (existing.getVersion().compareTo(componentInfo.getVersion()) >= 0) {
if (!ignoreExisting && !replaceComponents) {
addOrThrow(new DependencyException.Conflict(existing.getId(), componentInfo.getVersionString(), existing.getVersionString(), feedback.l10n("VERIFY_ComponentExists", existing.getName(), existing, existing.getVersionString())));
}
}
}
if (ignoreRequirements) {
return this;
}
Map<String, String> requiredCaps = componentInfo.getRequiredGraalValues();
Map<String, String> graalCaps = localRegistry.getGraalCapabilities();
boolean verbose = feedback.verboseOutput(null);
if (!isSilent() && verbose) {
feedback.verboseOutput("VERIFY_VerboseCheckRequirements", catalog.shortenComponentId(componentInfo), componentInfo.getName(), componentInfo.getVersionString());
List<String> keys = new ArrayList<>(requiredCaps.keySet());
Collections.sort(keys);
String none = feedback.l10n("VERIFY_VerboseCapabilityNone");
for (String s : keys) {
String v = graalCaps.get(s);
feedback.verboseOutput("VERIFY_VerboseCapability", localRegistry.localizeCapabilityName(s), requiredCaps.get(s), v == null ? none : v);
}
}
for (String s : requiredCaps.keySet()) {
String reqVal = requiredCaps.get(s);
String graalVal = graalCaps.get(s);
boolean matches;
if (BundleConstants.GRAAL_VERSION.equals(s)) {
if (versionMatch != null) {
Version cv = Version.fromString(reqVal.toLowerCase());
matches = versionMatch.test(cv);
} else {
Version rv = Version.fromString(reqVal);
Version gv = Version.fromString(graalVal);
matches = rv.installVersion().equals(gv.installVersion());
}
if (!matches) {
Version rq = Version.fromString(reqVal);
Version gv = localRegistry.getGraalVersion();
int n = gv.compareTo(rq);
if (n > 0) {
if (!gv.installVersion().equals(rq.installVersion())) {
addOrThrow(new DependencyException.Mismatch(GRAALVM_CAPABILITY, s, reqVal, graalVal, feedback.l10n("VERIFY_ObsoleteGraalVM", componentInfo.getName(), reqVal, gv.displayString())));
}
} else if (collectVersion) {
minVersion = rq;
} else {
addOrThrow(new DependencyException.Mismatch(GRAALVM_CAPABILITY, s, reqVal, graalVal, feedback.l10n("VERIFY_UpdateGraalVM", componentInfo.getName(), reqVal, gv.displayString())));
}
}
continue;
} else {
matches = matches(reqVal, graalVal);
}
if (!matches) {
String val = graalVal != null ? graalVal : feedback.l10n("VERIFY_CapabilityMissing");
addOrThrow(new DependencyException.Mismatch(componentInfo.getId(), s, reqVal, graalVal, feedback.l10n("VERIFY_Dependency_Failed", componentInfo.getName(), localRegistry.localizeCapabilityName(s), reqVal, val)));
}
}
return this;
}
use of org.graalvm.component.installer.Version in project graal by oracle.
the class UpgradeProcess method findInstallables.
Set<ComponentInfo> findInstallables(ComponentInfo graal) {
Version gv = graal.getVersion();
Version.Match satisfies = gv.match(Version.Match.Type.COMPATIBLE);
Set<ComponentInfo> ret = new HashSet<>();
for (String id : existingComponents) {
if (explicitIds.contains(id)) {
continue;
}
Collection<ComponentInfo> cis = catalog.loadComponents(id, satisfies, false);
if (cis == null || cis.isEmpty()) {
continue;
}
List<ComponentInfo> versions = new ArrayList<>(cis);
ret.add(versions.get(versions.size() - 1));
}
return ret;
}
Aggregations