Search in sources :

Example 1 with Version

use of org.graalvm.component.installer.Version 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;
}
Also used : Path(java.nio.file.Path) Version(org.graalvm.component.installer.Version) ComponentParam(org.graalvm.component.installer.ComponentParam) MetadataLoader(org.graalvm.component.installer.persist.MetadataLoader) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo)

Example 2 with Version

use of org.graalvm.component.installer.Version 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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Version(org.graalvm.component.installer.Version) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) UnknownVersionException(org.graalvm.component.installer.UnknownVersionException) HashSet(java.util.HashSet)

Example 3 with Version

use of org.graalvm.component.installer.Version in project graal by oracle.

the class GraalChannel method loadStorage.

@Override
protected ComponentStorage loadStorage() throws IOException {
    FileDownloader dn = new FileDownloader(fb.l10n("OLDS_ReleaseFile"), getIndexURL(), fb);
    dn.download();
    Path storagePath = dn.getLocalFile().toPath();
    List<ReleaseEntry> releases = loadReleasesIndex(storagePath);
    if (releases.isEmpty()) {
        return throwEmptyStorage();
    }
    MergeStorage store = new MergeStorage(localRegistry, fb);
    store.setAcceptAllSources(true);
    for (ReleaseEntry en : releases) {
        URL catURL = en.getCatalogURL();
        Version v = Version.fromString(en.getVersion().displayString());
        SoftwareChannelSource src = new SoftwareChannelSource(catURL.toString(), en.getLabel());
        WebCatalog cata = new WebCatalog(src.getLocationURL(), src) {

            @Override
            protected RemotePropertiesStorage createPropertiesStorage(Feedback aFeedback, ComponentRegistry aLocal, Properties props, String selector, URL baseURL) {
                return new RemotePropertiesStorage(aFeedback, aLocal, props, selector, v, baseURL);
            }
        };
        cata.init(localRegistry, fb);
        cata.setMatchVersion(en.getVersion().match(Version.Match.Type.EXACT));
        cata.setRemoteProcessor((i) -> configureLicense(i, en));
        store.addChannel(src, cata);
    }
    return store;
}
Also used : Path(java.nio.file.Path) SoftwareChannelSource(org.graalvm.component.installer.SoftwareChannelSource) WebCatalog(org.graalvm.component.installer.ce.WebCatalog) RemotePropertiesStorage(org.graalvm.component.installer.remote.RemotePropertiesStorage) MergeStorage(org.graalvm.component.installer.remote.MergeStorage) Properties(java.util.Properties) URL(java.net.URL) Version(org.graalvm.component.installer.Version) Feedback(org.graalvm.component.installer.Feedback) ComponentRegistry(org.graalvm.component.installer.model.ComponentRegistry) FileDownloader(org.graalvm.component.installer.remote.FileDownloader)

Example 4 with Version

use of org.graalvm.component.installer.Version in project graal by oracle.

the class GraalChannel method loadReleasesIndex.

/**
 * 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<ReleaseEntry> loadReleasesIndex(Path releasesIndexPath) throws IOException {
    if (edition == null) {
        edition = localRegistry.getGraalCapabilities().get(CommonConstants.CAP_EDITION);
    }
    List<ReleaseEntry> result = new ArrayList<>();
    try (Reader urlReader = new InputStreamReader(Files.newInputStream(releasesIndexPath))) {
        JSONTokener tokener = new JSONTokener(urlReader);
        JSONObject obj = new JSONObject(tokener);
        JSONObject releases = obj.getJSONObject(KEY_RELEASES);
        if (releases == null) {
            // malformed releases file;
            throw new IncompatibleException(fb.l10n("OLDS_InvalidReleasesFile"));
        }
        Version v = localRegistry.getGraalVersion();
        for (String k : releases.keySet()) {
            JSONObject jo = releases.getJSONObject(k);
            ReleaseEntry e = null;
            try {
                e = jsonToRelease(k, jo);
            } catch (JSONException | IllegalArgumentException ex) {
                fb.error("OLDS_ErrorReadingRelease", ex, k, ex.getLocalizedMessage());
            }
            if (e == null) {
                invalidReleases.add(k);
            } else if (!localRegistry.getJavaVersion().equals(e.getJavaVersion())) {
                LOG.log(Level.FINER, "Invalid Java: {0}", k);
            } else if (e.getBasePackages().isEmpty()) {
                LOG.log(Level.FINER, "No distribution packages: {0}", k);
            } else if (edition != null && !edition.equals(e.getEdition())) {
                LOG.log(Level.FINER, "Incorrect edition: {0}", k);
            } else if (!acceptsVersion(v, e.getVersion())) {
                LOG.log(Level.FINER, "Old version: {0}", k);
            } else {
                result.add(e);
            }
        }
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) JSONException(com.oracle.truffle.tools.utils.json.JSONException) JSONTokener(com.oracle.truffle.tools.utils.json.JSONTokener) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) Version(org.graalvm.component.installer.Version) IncompatibleException(org.graalvm.component.installer.IncompatibleException)

Example 5 with Version

use of org.graalvm.component.installer.Version in project graal by oracle.

the class DirectoryStorage method metaToProperties.

public static Properties metaToProperties(ComponentInfo info) {
    SortedProperties p = new SortedProperties();
    p.setProperty(BundleConstants.BUNDLE_ID, info.getId());
    p.setProperty(BundleConstants.BUNDLE_NAME, info.getName());
    p.setProperty(BundleConstants.BUNDLE_VERSION, info.getVersionString());
    String s = info.getTag();
    if (s != null && !s.isEmpty()) {
        p.setProperty(BundleConstants.BUNDLE_SERIAL, s);
    }
    if (info.getLicensePath() != null) {
        p.setProperty(BundleConstants.BUNDLE_LICENSE_PATH, info.getLicensePath());
    }
    if (info.getLicenseType() != null) {
        p.setProperty(BundleConstants.BUNDLE_LICENSE_TYPE, info.getLicenseType());
    }
    if (info.getStability() != StabilityLevel.Undefined) {
        p.setProperty(BundleConstants.BUNDLE_STABILITY2, info.getStability().toString());
    }
    for (String k : info.getRequiredGraalValues().keySet()) {
        String v = info.getRequiredGraalValues().get(k);
        if (v == null) {
            // NOI18N
            v = "";
        }
        p.setProperty(BUNDLE_REQUIRED_PREFIX + k, v);
    }
    for (String k : info.getProvidedValues().keySet()) {
        Object o = info.getProvidedValue(k, Object.class);
        char t;
        if (o instanceof String) {
            // NOI18N
            t = '"';
        } else if (o instanceof Version) {
            t = 'V';
            o = ((Version) o).originalString();
        } else {
            continue;
        }
        p.setProperty(BUNDLE_PROVIDED_PREFIX + k, t + o.toString());
    }
    if (!info.getDependencies().isEmpty()) {
        p.setProperty(BundleConstants.BUNDLE_DEPENDENCY, info.getDependencies().stream().sequential().collect(Collectors.joining(":")));
    }
    if (info.getPostinstMessage() != null) {
        p.setProperty(BundleConstants.BUNDLE_MESSAGE_POSTINST, info.getPostinstMessage());
    }
    if (info.isPolyglotRebuild()) {
        p.setProperty(BundleConstants.BUNDLE_POLYGLOT_PART, Boolean.TRUE.toString());
    }
    if (!info.getWorkingDirectories().isEmpty()) {
        p.setProperty(BundleConstants.BUNDLE_WORKDIRS, info.getWorkingDirectories().stream().sequential().collect(Collectors.joining(":")));
    }
    if (info.getDistributionType() != DistributionType.OPTIONAL) {
        p.setProperty(BundleConstants.BUNDLE_COMPONENT_DISTRIBUTION, info.getDistributionType().name().toLowerCase(Locale.ENGLISH));
    }
    URL u = info.getRemoteURL();
    if (u != null) {
        p.setProperty(CommonConstants.BUNDLE_ORIGIN_URL, u.toString());
    }
    return p;
}
Also used : Version(org.graalvm.component.installer.Version) URL(java.net.URL)

Aggregations

Version (org.graalvm.component.installer.Version)44 ComponentInfo (org.graalvm.component.installer.model.ComponentInfo)21 Test (org.junit.Test)19 Path (java.nio.file.Path)10 ArrayList (java.util.ArrayList)7 URL (java.net.URL)5 HashSet (java.util.HashSet)5 Properties (java.util.Properties)5 RemotePropertiesStorage (org.graalvm.component.installer.remote.RemotePropertiesStorage)4 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 ComponentParam (org.graalvm.component.installer.ComponentParam)3 IncompatibleException (org.graalvm.component.installer.IncompatibleException)3 CatalogContents (org.graalvm.component.installer.model.CatalogContents)3 ComponentRegistry (org.graalvm.component.installer.model.ComponentRegistry)3 CatalogIterable (org.graalvm.component.installer.remote.CatalogIterable)3 RemoteCatalogDownloader (org.graalvm.component.installer.remote.RemoteCatalogDownloader)3 JSONException (com.oracle.truffle.tools.utils.json.JSONException)2 JSONTokener (com.oracle.truffle.tools.utils.json.JSONTokener)2