/** * Checks if a given path is malformed or if it contains a valid Cloud SDK. * * <p>Windows' implementation of Paths doesn't handle well converting strings with certain special * characters to paths. This method should be called before {@code Paths.get(path)}. */ public Set<CloudSdkValidationResult> validateCloudSdk(String path) { if (path == null) { return ImmutableSet.of(CloudSdkValidationResult.CLOUD_SDK_NOT_FOUND); } if (isMalformedCloudSdkPath(path)) { return ImmutableSet.of(CloudSdkValidationResult.MALFORMED_PATH); } return validateCloudSdk(Paths.get(path)); }
@Override public SdkStatus getStatus() { String sdkPath = CloudSdkServiceUserSettings.getInstance().getCustomSdkPath(); if (Strings.isNullOrEmpty(sdkPath)) { return SdkStatus.NOT_AVAILABLE; } boolean malformedSdkPath = CloudSdkValidator.isMalformedCloudSdkPath(sdkPath); return malformedSdkPath ? SdkStatus.INVALID : SdkStatus.READY; }
@Nullable @Override public Path getSdkHomePath() { String sdkPath = CloudSdkServiceUserSettings.getInstance().getCustomSdkPath(); if (sdkPath != null) { // To let Windows users that persisted the old malformed path save a new one. // TODO(joaomartins): Delete this after a while so gets are faster. if (CloudSdkValidator.isMalformedCloudSdkPath(sdkPath)) { UsageTrackerService.getInstance().trackEvent(GctTracking.CLOUD_SDK_MALFORMED_PATH).ping(); return null; } return Paths.get(sdkPath); } // Let common library auto-discover Cloud SDK's location. try { return new CloudSdk.Builder().build().getPath(); } catch (AppEngineException aee) { return null; } }