@Override public boolean isPreview() { return getRevision().isPreview(); }
@Override public String getInstallId() { String id = getBaseInstallId(); if (getRevision().isPreview()) { return id + PREVIEW_SUFFIX; } return id; }
/** * Returns the version in a fixed format major.minor.micro with an optional "rc preview#". For * example it would return "18.0.0", "18.1.0" or "18.1.2 rc5", with the separator between the * main version number and the preview component being specified by {@code previewSeparator}. */ public String toString(@NonNull String previewSeparator) { StringBuilder sb = new StringBuilder(); sb.append(getMajor()); if (mPrecision.compareTo(Precision.MINOR) >= 0) { sb.append('.').append(getMinor()); if (mPrecision.compareTo(Precision.MICRO) >= 0) { sb.append('.').append(getMicro()); if (mPrecision.compareTo(Precision.PREVIEW) >= 0 && isPreview()) { sb.append(previewSeparator).append("rc").append(getPreview()); } } } return sb.toString(); }
/** * @param packages a {@link Collection} of packages which share a common {@code prefix}, * from which we wish to extract the "Latest" package, * as sorted with {@code mapper} and {@code comparator} on the suffixes. * @param allowPreview whether we allow returning a preview package. * @param mapper maps from path suffix to a {@link Comparable}, * so that we can sort the packages by suffix. * @param comparator how to sort suffixes after mapping them. * @param <P> {@link LocalPackage} or {@link RemotePackage} * @param <T> {@link Comparable} that we map the suffix to. * @return the "Latest" package from the {@link Collection}, * as sorted with {@code mapper} and {@code comparator} on the last path component. */ @Nullable @VisibleForTesting static <P extends RepoPackage, T> P getLatestPackageFromPrefixCollection( @NonNull Collection<P> packages, boolean allowPreview, @NonNull Function<String, T> mapper, @NonNull Comparator<T> comparator) { Function<P, T> keyGen = p -> mapper.apply(p.getPath().substring( p.getPath().lastIndexOf(RepoPackage.PATH_SEPARATOR) + 1)); return packages.stream() .filter(p -> allowPreview || !p.getVersion().isPreview()) .max((p1, p2) -> comparator.compare(keyGen.apply(p1), keyGen.apply(p2))) .orElse(null); }
@NonNull @Override public Channel getChannel() { if (getVersion().isPreview()) { // We map the old concept of previews to the second-stablest channel. return Channel.create(1); } return Channel.create(0); }
Revision revision = parseRevisionSilently(response.substring(start, end)); if (revision != null) { foundPreview = revision.isPreview(); if (allowPreview || !foundPreview) { return revision;
/** * Creates a new revision with at least three components (major, minor, micro) * based on the given revision. This is important since in the past we would * sometimes write out revisions with only one component when internally we * required that they have more, and would convert using the specific Revision * subclass. * @param rev * @return */ private static Revision fullySpecifyRevision(Revision rev) { // Since we used to require a complete revision if (!rev.isPreview()) { rev = new Revision(rev.getMajor(), rev.getMinor(), rev.getMicro()); } return rev; }
for (String s : metadata.versioning.versions.version) { Revision rev = Revision.parseRevision(s); if (max == null || (!rev.isPreview() && rev.compareTo(max) > 0)) { max = rev;
/** * Gets a {@link BuildToolInfo} corresponding to the newest installed build tool * {@link RepoPackage}, or {@code null} if none are installed (or if the {@code allowPreview} * parameter is false and there was non-preview version available) * * @param progress a progress indicator * @param allowPreview ignore preview build tools version unless this parameter is true */ @Nullable public BuildToolInfo getLatestBuildTool(@NonNull ProgressIndicator progress, boolean allowPreview) { if (!allowPreview && mLatestBuildTool != null) { return mLatestBuildTool; } LocalPackage latestBuildToolPackage = getLatestLocalPackageForPrefix( SdkConstants.FD_BUILD_TOOLS, allowPreview, progress); if (latestBuildToolPackage == null) { return null; } BuildToolInfo latestBuildTool = BuildToolInfo.fromLocalPackage(latestBuildToolPackage); // Don't cache if preview. if (!latestBuildToolPackage.getVersion().isPreview()) { mLatestBuildTool = latestBuildTool; } return latestBuildTool; }
private static Revision getNewerRevision(@NonNull GradleCoordinate dependency, @NonNull Revision revision) { assert dependency.getGroupId() != null; assert dependency.getArtifactId() != null; GradleCoordinate coordinate; if (revision.isPreview()) { String coordinateString = dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + revision.toString(); coordinate = GradleCoordinate.parseCoordinateString(coordinateString); } else { coordinate = new GradleCoordinate(dependency.getGroupId(), dependency.getArtifactId(), revision.getMajor(), revision.getMinor(), revision.getMicro()); } if (COMPARE_PLUS_HIGHER.compare(dependency, coordinate) < 0) { return revision; } else { return null; } }
Revision v = Revision.parseRevision(GRADLE_PLUGIN_RECOMMENDED_VERSION); if (!v.isPreview()) { version = getNewerRevision(dependency, v);