use of org.graalvm.component.installer.model.ComponentInfo in project graal by oracle.
the class UpgradeProcess method prepareInstall.
/**
* Prepares the installation of the core Component. Returns {@code false} if the upgrade is not
* necessary or not found.
*
* @param info
* @return true, if the graalvm should be updated.
* @throws IOException
*/
boolean prepareInstall(ComponentInfo info) throws IOException {
Version min = input.getLocalRegistry().getGraalVersion();
if (info == null) {
feedback.message("UPGRADE_NoUpdateFound", min.displayString());
return false;
}
int cmp = min.compareTo(info.getVersion());
if ((cmp > 0) || ((editionUpgrade == null) && (cmp == 0))) {
feedback.message("UPGRADE_NoUpdateLatestVersion", min.displayString());
migrated.clear();
return false;
}
Path reported = createInstallName(info);
// there's a slight chance this will be different from the final name ...
feedback.output("UPGRADE_PreparingInstall", info.getVersion().displayString(), reported);
failIfDirectotyExistsNotEmpty(reported);
ComponentParam coreParam = createGraalComponentParam(info);
// reuse License logic from the installer command:
InstallCommand cmd = new InstallCommand();
cmd.init(input, feedback);
// ask the InstallCommand to process/accept the licenses, if there are any.
MetadataLoader ldr = coreParam.createMetaLoader();
cmd.addLicenseToAccept(ldr);
cmd.acceptLicenses();
acceptedLicenseIDs = cmd.getProcessedLicenses();
// force download
ComponentParam param = input.existingFiles().createParam("core", info);
metaLoader = param.createFileLoader();
ComponentInfo completeInfo = metaLoader.completeMetadata();
newInstallPath = createInstallName(completeInfo);
newGraalHomePath = newInstallPath;
failIfDirectotyExistsNotEmpty(newInstallPath);
if (!reported.equals(newInstallPath)) {
feedback.error("UPGRADE_WarningEditionDifferent", null, info.getVersion().displayString(), newInstallPath);
}
existingComponents.addAll(input.getLocalRegistry().getComponentIDs());
existingComponents.remove(BundleConstants.GRAAL_COMPONENT_ID);
return true;
}
use of org.graalvm.component.installer.model.ComponentInfo in project graal by oracle.
the class UpgradeProcess method allComponents.
public List<ComponentParam> allComponents() throws IOException {
Set<String> ids = new HashSet<>();
ArrayList<ComponentParam> allComps = new ArrayList<>(addedComponents());
for (ComponentParam p : allComps) {
ids.add(p.createMetaLoader().getComponentInfo().getId());
}
for (ComponentInfo mig : migrated) {
if (ids.contains(mig.getId())) {
continue;
}
allComps.add(input.existingFiles().createParam(mig.getId(), mig));
}
return allComps;
}
use of org.graalvm.component.installer.model.ComponentInfo in project graal by oracle.
the class UpgradeProcess method findGraalVersion.
public ComponentInfo findGraalVersion(Version.Match minimum) throws IOException {
Version.Match filter;
if (minimum.getType() == Version.Match.Type.MOSTRECENT) {
filter = minimum.getVersion().match(Version.Match.Type.INSTALLABLE);
} else {
filter = minimum;
}
Collection<ComponentInfo> graals;
try {
graals = catalog.loadComponents(BundleConstants.GRAAL_COMPONENT_ID, filter, false);
if (graals == null || graals.isEmpty()) {
return null;
}
} catch (UnknownVersionException ex) {
// could not find anything to match the user version against
if (ex.getCandidate() == null) {
throw feedback.failure("UPGRADE_NoSpecificVersion", ex, filter.getVersion().displayString());
} else {
throw feedback.failure("UPGRADE_NoSpecificVersion2", ex, filter.getVersion().displayString(), ex.getCandidate().displayString());
}
}
List<ComponentInfo> versions = new ArrayList<>(graals);
Collections.sort(versions, ComponentInfo.versionComparator().reversed());
for (Iterator<ComponentInfo> it = versions.iterator(); it.hasNext(); ) {
ComponentInfo candidate = it.next();
Collection<ComponentInfo> broken = satisfiedAddedComponents(candidate);
if (!broken.isEmpty()) {
it.remove();
}
}
if (versions.isEmpty()) {
throw feedback.failure("UPGRADE_NoVersionSatisfiesComponents", null, minVersion.toString());
}
Set<ComponentInfo> installables = null;
Set<ComponentInfo> first = null;
ComponentInfo result = null;
Set<String> toMigrate = existingComponents.stream().filter((id) -> {
ComponentInfo ci = input.getLocalRegistry().loadSingleComponent(id, false);
return ci.getDistributionType() != DistributionType.BUNDLED;
}).map(this::lowerCaseId).collect(Collectors.toSet());
toMigrate.removeAll(explicitIds);
Map<ComponentInfo, Set<ComponentInfo>> missingParts = new HashMap<>();
for (Iterator<ComponentInfo> it = versions.iterator(); it.hasNext(); ) {
ComponentInfo candidate = it.next();
Set<ComponentInfo> instCandidates = findInstallables(candidate);
if (first == null) {
first = instCandidates;
}
Set<String> canMigrate = instCandidates.stream().map(ComponentInfo::getId).map(this::lowerCaseId).collect(Collectors.toSet());
if (allowMissing || canMigrate.containsAll(toMigrate)) {
installables = instCandidates;
result = candidate;
break;
} else {
Set<String> miss = new HashSet<>(toMigrate);
miss.removeAll(canMigrate);
missingParts.put(candidate, miss.stream().map((id) -> input.getLocalRegistry().findComponent(id)).collect(Collectors.toSet()));
}
}
if (installables == null) {
if (!allowMissing) {
List<ComponentInfo> reportVersions = new ArrayList<>(missingParts.keySet());
for (ComponentInfo core : reportVersions) {
List<ComponentInfo> list = new ArrayList<>(missingParts.get(core));
Collections.sort(list, (a, b) -> a.getId().compareToIgnoreCase(b.getId()));
String msg = null;
for (ComponentInfo ci : list) {
String shortId = input.getLocalRegistry().shortenComponentId(ci);
String s = feedback.l10n("UPGRADE_MissingComponentItem", shortId, ci.getName());
if (msg == null) {
msg = s;
} else {
msg = feedback.l10n("UPGRADE_MissingComponentListPart", msg, s);
}
}
feedback.error("UPGRADE_MissingComponents", null, core.getName(), core.getVersion().displayString(), msg);
}
if (editionUpgrade != null) {
throw feedback.failure("UPGRADE_ComponentsMissingFromEdition", null, editionUpgrade);
} else {
throw feedback.failure("UPGRADE_ComponentsCannotMigrate", null);
}
}
if (versions.isEmpty()) {
throw feedback.failure("UPGRADE_NoVersionSatisfiesComponents", null);
}
result = versions.get(0);
installables = first;
}
migrated.clear();
// if the result GraalVM is identical to current, do not migrate anything.
if (result != null && (!input.getLocalRegistry().getGraalVersion().equals(result.getVersion()) || input.hasOption(Commands.OPTION_USE_EDITION))) {
migrated.addAll(installables);
targetInfo = result;
}
return result;
}
use of org.graalvm.component.installer.model.ComponentInfo in project graal by oracle.
the class GDSChannel method loadArtifacts.
/**
* Loads the release index. Must be loaded from a local file.
*
* @param releasesIndexPath path to the downloaded releases index.
* @return list of entries in the index
* @throws IOException in case of I/O error.
*/
List<ComponentInfo> loadArtifacts(Path releasesIndexPath) throws IOException {
if (edition == null) {
edition = localRegistry.getGraalCapabilities().get(CommonConstants.CAP_EDITION);
}
List<ComponentInfo> result = new ArrayList<>();
try (InputStreamReader urlReader = new InputStreamReader(new GZIPInputStream(Files.newInputStream(releasesIndexPath)))) {
JSONTokener tokener = new JSONTokener(urlReader);
JSONObject obj = new JSONObject(tokener);
JSONArray releases = obj.getJSONArray(JSON_ITEMS);
if (releases == null) {
// malformed releases file;
throw new IncompatibleException(fb.l10n("OLDS_InvalidReleasesFile"));
}
Version v = localRegistry.getGraalVersion();
for (Object k : releases) {
JSONObject jo = (JSONObject) k;
ArtifactParser e;
try {
e = new ArtifactParser(jo);
} catch (JSONException | IllegalArgumentException ex) {
fb.error("OLDS_ErrorReadingRelease", ex, k, ex.getLocalizedMessage());
continue;
}
if (!OS.get().equals(OS.fromName(e.getOs()))) {
LOG.log(Level.FINER, "Incorrect OS: {0}", k);
} else if (!ARCH.get().equals(ARCH.fromName(e.getArch()))) {
LOG.log(Level.FINER, "Incorrect Arch: {0}", k);
} else if (!localRegistry.getJavaVersion().equals(e.getJava())) {
LOG.log(Level.FINER, "Incorrect Java: {0}", k);
} else if (edition != null && !edition.equals(e.getEdition())) {
LOG.log(Level.FINER, "Incorrect edition: {0}", k);
} else if (!acceptsVersion(v, Version.fromString(e.getVersion()))) {
LOG.log(Level.FINER, "Old version: {0} != {1}", new Object[] { v, Version.fromString(e.getVersion()), e.getVersion() });
} else {
result.add(e.asComponentInfo(gdsConnector, fb));
}
}
}
return result;
}
use of org.graalvm.component.installer.model.ComponentInfo in project graal by oracle.
the class GDSChannel method loadStorage.
/**
* Initializes the component storage. Loads the releases index, selects matching releases and
* creates {@link WebCatalog} for each of the catalogs. Merges using {@link MergeStorage}.
*
* @return merged storage.
* @throws IOException in case of an I/O error.
*/
@Override
protected ComponentStorage loadStorage() throws IOException {
Path storagePath = getConnector().obtainArtifacts(localRegistry.getJavaVersion());
List<ComponentInfo> artifacts = loadArtifacts(storagePath);
if (artifacts.isEmpty()) {
return throwEmptyStorage();
}
return new GDSCatalogStorage(localRegistry, fb, storagePath.toUri().toURL(), artifacts);
}
Aggregations