Search in sources :

Example 16 with AndroidSdkAdditionalData

use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.

the class IdeSdks method getJdk.

@Nullable
private Sdk getJdk(@Nullable JavaSdkVersion preferredVersion) {
    List<Sdk> androidSdks = getEligibleAndroidSdks();
    if (!androidSdks.isEmpty()) {
        Sdk androidSdk = androidSdks.get(0);
        AndroidSdkAdditionalData data = myAndroidSdks.getAndroidSdkAdditionalData(androidSdk);
        assert data != null;
        Sdk jdk = data.getJavaSdk();
        if (isJdkCompatible(jdk, preferredVersion)) {
            return jdk;
        }
    }
    JavaSdk javaSdk = JavaSdk.getInstance();
    List<Sdk> jdks = ProjectJdkTable.getInstance().getSdksOfType(javaSdk);
    if (!jdks.isEmpty()) {
        for (Sdk jdk : jdks) {
            if (isJdkCompatible(jdk, preferredVersion)) {
                return jdk;
            }
        }
    }
    // This happens when user has a fresh installation of Android Studio, and goes through the 'First Run' Wizard.
    if (myIdeInfo.isAndroidStudio()) {
        Sdk jdk = myJdks.createEmbeddedJdk();
        if (jdk != null) {
            assert isJdkCompatible(jdk, preferredVersion);
            return jdk;
        }
    }
    List<File> jdkPaths = getPotentialJdkPaths();
    for (File jdkPath : jdkPaths) {
        if (checkForJdk(jdkPath)) {
            Sdk jdk = createJdk(jdkPath);
            return isJdkCompatible(jdk, preferredVersion) ? jdk : null;
        }
        // On Linux, the returned path is the folder that contains all JDKs, instead of a specific JDK.
        if (SystemInfo.isLinux) {
            for (File child : notNullize(jdkPath.listFiles())) {
                if (child.isDirectory() && checkForJdk(child)) {
                    Sdk jdk = myJdks.createJdk(child.getPath());
                    if (isJdkCompatible(jdk, preferredVersion)) {
                        return jdk;
                    }
                }
            }
        }
    }
    return null;
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) SdkPaths.validateAndroidSdk(com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with AndroidSdkAdditionalData

use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.

the class IdeSdks method doGetJdkPath.

@Nullable
private File doGetJdkPath(boolean createJdkIfNeeded) {
    List<Sdk> androidSdks = getEligibleAndroidSdks();
    if (androidSdks.isEmpty() && createJdkIfNeeded) {
        // This happens when user has a fresh installation of Android Studio without an Android SDK, but with a JDK. Android Studio should
        // populate the text field with the existing JDK.
        Sdk jdk = myJdks.chooseOrCreateJavaSdk();
        if (jdk != null) {
            String jdkPath = jdk.getHomePath();
            if (jdkPath != null) {
                return new File(toSystemDependentName(jdkPath));
            }
        }
    } else {
        for (Sdk sdk : androidSdks) {
            AndroidSdkAdditionalData data = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
            assert data != null;
            Sdk jdk = data.getJavaSdk();
            if (jdk != null) {
                String jdkHomePath = jdk.getHomePath();
                if (jdkHomePath != null) {
                    return new File(toSystemDependentName(jdkHomePath));
                }
            }
        }
    }
    return null;
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) SdkPaths.validateAndroidSdk(com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with AndroidSdkAdditionalData

use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.

the class IdeSdks method updateAndroidSdks.

/**
   * Iterates through all Android SDKs and makes them point to the given JDK.
   */
private void updateAndroidSdks(@NotNull Sdk jdk) {
    for (Sdk sdk : myAndroidSdks.getAllAndroidSdks()) {
        AndroidSdkAdditionalData oldData = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
        if (oldData == null) {
            continue;
        }
        oldData.setJavaSdk(jdk);
        SdkModificator modificator = sdk.getSdkModificator();
        modificator.setSdkAdditionalData(oldData);
        modificator.commitChanges();
    }
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) SdkPaths.validateAndroidSdk(com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk)

Example 19 with AndroidSdkAdditionalData

use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.

the class AndroidSdksTest method testTryToCreate.

public void testTryToCreate() {
    IAndroidTarget target = findAndroidTarget();
    String hash = getTargetHashString(target);
    Sdk sdk = myAndroidSdks.tryToCreate(mySdkPath, hash);
    assertNotNull(sdk);
    verifyCorrectPath(sdk);
    AndroidSdkAdditionalData data = getAndroidSdkAdditionalData(sdk);
    assertEquals(hash, data.getBuildTargetHashString());
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidTargetHash.getTargetHashString(com.android.sdklib.AndroidTargetHash.getTargetHashString) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 20 with AndroidSdkAdditionalData

use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.

the class AndroidSdksTest method testCreateSdkWithoutSpecifyingJdk.

public void testCreateSdkWithoutSpecifyingJdk() {
    Sdk sdk = myAndroidSdks.create(findAndroidTarget(), mySdkPath, true);
    assertNotNull(sdk);
    verifyCorrectPath(sdk);
    AndroidSdkAdditionalData androidData = getAndroidSdkAdditionalData(sdk);
    Sdk jdk = androidData.getJavaSdk();
    assertNotNull(jdk);
    assertEquals(myJdk.getHomePath(), jdk.getHomePath());
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) Sdk(com.intellij.openapi.projectRoots.Sdk)

Aggregations

AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)22 Sdk (com.intellij.openapi.projectRoots.Sdk)16 IAndroidTarget (com.android.sdklib.IAndroidTarget)8 File (java.io.File)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)5 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)5 AndroidTargetHash.getTargetHashString (com.android.sdklib.AndroidTargetHash.getTargetHashString)4 Nullable (org.jetbrains.annotations.Nullable)4 SdkPaths.validateAndroidSdk (com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk)3 SdkAdditionalData (com.intellij.openapi.projectRoots.SdkAdditionalData)3 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)3 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)3 AndroidSdks (com.android.tools.idea.sdk.AndroidSdks)2 FirstRunWizardMode (com.android.tools.idea.welcome.config.FirstRunWizardMode)2 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)2 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)2 AndroidVersion (com.android.sdklib.AndroidVersion)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1