Search in sources :

Example 1 with ValidationResult

use of com.android.tools.idea.npw.WizardUtils.ValidationResult in project android by JetBrains.

the class GradleSpecificInitializer method setupSdks.

private static void setupSdks() {
    IdeSdks ideSdks = IdeSdks.getInstance();
    File androidHome = ideSdks.getAndroidSdkPath();
    if (androidHome != null) {
        String androidHomePath = androidHome.getAbsolutePath();
        ValidationResult result = validateLocation(androidHomePath, "Android SDK location", false, WritableCheckMode.DO_NOT_CHECK);
        if (result.isError()) {
            notifyInvalidSdk();
        }
        // Do not prompt user to select SDK path (we have one already.) Instead, check SDK compatibility when a project is opened.
        return;
    }
    // If running in a GUI test we don't want the "Select SDK" dialog to show up when running GUI tests.
    if (AndroidPlugin.isGuiTestingMode()) {
        // This is good enough. Later on in the GUI test we'll validate the given SDK path.
        return;
    }
    Sdk sdk = findFirstCompatibleAndroidSdk();
    if (sdk != null) {
        String sdkHomePath = sdk.getHomePath();
        assert sdkHomePath != null;
        ideSdks.createAndroidSdkPerAndroidTarget(new File(toSystemDependentName(sdkHomePath)));
        return;
    }
    // Called in a 'invokeLater' block, otherwise file chooser will hang forever.
    ApplicationManager.getApplication().invokeLater(() -> {
        File androidSdkPath = getAndroidSdkPath();
        if (androidSdkPath == null) {
            return;
        }
        FirstRunWizardMode wizardMode = AndroidStudioWelcomeScreenProvider.getWizardMode();
        // Only show "Select SDK" dialog if the "First Run" wizard is not displayed.
        boolean promptSdkSelection = wizardMode == null;
        Sdk sdk1 = createNewAndroidPlatform(androidSdkPath.getPath(), promptSdkSelection);
        if (sdk1 != null) {
            // Rename the SDK to fit our default naming convention.
            String sdkNamePrefix = AndroidSdks.SDK_NAME_PREFIX;
            if (sdk1.getName().startsWith(sdkNamePrefix)) {
                SdkModificator sdkModificator = sdk1.getSdkModificator();
                sdkModificator.setName(sdkNamePrefix + sdk1.getName().substring(sdkNamePrefix.length()));
                sdkModificator.commitChanges();
                // Rename the JDK that goes along with this SDK.
                AndroidSdkAdditionalData additionalData = AndroidSdks.getInstance().getAndroidSdkAdditionalData(sdk1);
                if (additionalData != null) {
                    Sdk jdk = additionalData.getJavaSdk();
                    if (jdk != null) {
                        sdkModificator = jdk.getSdkModificator();
                        sdkModificator.setName(DEFAULT_JDK_NAME);
                        sdkModificator.commitChanges();
                    }
                }
                // Fill out any missing build APIs for this new SDK.
                ideSdks.createAndroidSdkPerAndroidTarget(androidSdkPath);
            }
        }
    });
}
Also used : IdeSdks(com.android.tools.idea.sdk.IdeSdks) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) FirstRunWizardMode(com.android.tools.idea.welcome.config.FirstRunWizardMode) Sdk(com.intellij.openapi.projectRoots.Sdk) ValidationResult(com.android.tools.idea.npw.WizardUtils.ValidationResult) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with ValidationResult

use of com.android.tools.idea.npw.WizardUtils.ValidationResult in project android by JetBrains.

the class SdkUpdaterConfigPanel method validate.

/**
   * Validates {@link #mySdkLocationTextField} and shows appropriate errors in the UI if needed.
   */
private void validate() {
    File sdkLocation = myConfigurable.getRepoManager().getLocalPath();
    String sdkLocationPath = sdkLocation == null ? null : sdkLocation.getAbsolutePath();
    ValidationResult result = WizardUtils.validateLocation(sdkLocationPath, "Android SDK location", false, WritableCheckMode.NOT_WRITABLE_IS_WARNING);
    switch(result.getStatus()) {
        case OK:
            mySdkLocationLabel.setForeground(JBColor.foreground());
            mySdkErrorLabel.setVisible(false);
            myPlatformComponentsPanel.setEnabled(true);
            myTabPane.setEnabled(true);
            break;
        case WARN:
            mySdkErrorLabel.setIcon(AllIcons.General.BalloonWarning);
            mySdkErrorLabel.setText(result.getFormattedMessage());
            mySdkErrorLabel.setVisible(true);
            myPlatformComponentsPanel.setEnabled(false);
            myTabPane.setEnabled(false);
            break;
        case ERROR:
            mySdkErrorLabel.setIcon(AllIcons.General.BalloonError);
            mySdkErrorLabel.setText(result.getFormattedMessage());
            mySdkErrorLabel.setVisible(true);
            myPlatformComponentsPanel.setEnabled(false);
            myTabPane.setEnabled(false);
            break;
    }
}
Also used : ValidationResult(com.android.tools.idea.npw.WizardUtils.ValidationResult) File(java.io.File)

Aggregations

ValidationResult (com.android.tools.idea.npw.WizardUtils.ValidationResult)2 File (java.io.File)2 IdeSdks (com.android.tools.idea.sdk.IdeSdks)1 FirstRunWizardMode (com.android.tools.idea.welcome.config.FirstRunWizardMode)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)1