Search in sources :

Example 21 with AndroidSdkAdditionalData

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

the class AndroidSdksTest method testCreateSdkWithoutAddingRoots.

public void testCreateSdkWithoutAddingRoots() {
    IAndroidTarget target = findAndroidTarget();
    String name = "testSdk";
    Sdk sdk = myAndroidSdks.create(target, mySdkPath, name, myJdk, false);
    assertNotNull(sdk);
    assertEquals(name, sdk.getName());
    verifyCorrectPath(sdk);
    AndroidSdkAdditionalData androidData = getAndroidSdkAdditionalData(sdk);
    assertSame(myJdk, androidData.getJavaSdk());
    AndroidPlatform androidPlatform = androidData.getAndroidPlatform();
    assertNotNull(androidPlatform);
    assertSame(target, androidPlatform.getTarget());
    VirtualFile[] sdkRoots = sdk.getSdkModificator().getRoots(CLASSES);
    assertThat(sdkRoots).isEmpty();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidTargetHash.getTargetHashString(com.android.sdklib.AndroidTargetHash.getTargetHashString) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 22 with AndroidSdkAdditionalData

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

the class KotlinAndroidTestCaseBase method createAndroidSdk.

public Sdk createAndroidSdk(String sdkPath, String platformDir) {
    Sdk sdk = ProjectJdkTable.getInstance().createSdk("android_test_sdk", AndroidSdkType.getInstance());
    SdkModificator sdkModificator = sdk.getSdkModificator();
    sdkModificator.setHomePath(sdkPath);
    if (platformDir.equals(getDefaultPlatformDir())) {
        // Compatibility: the unit tests were using android.jar outside the sdk1.5 install;
        // we need to use that one, rather than the real one in sdk1.5, in order for the
        // tests to pass. Longer term, we should switch the unit tests over to all using
        // a valid SDK.
        String androidJarPath = sdkPath + "/../android.jar!/";
        androidJar = VirtualFileManager.getInstance().findFileByUrl("jar://" + androidJarPath);
    } else {
        androidJar = VirtualFileManager.getInstance().findFileByUrl("jar://" + sdkPath + "/platforms/" + platformDir + "/android.jar!/");
    }
    sdkModificator.addRoot(androidJar, OrderRootType.CLASSES);
    VirtualFile resFolder = LocalFileSystem.getInstance().findFileByPath(sdkPath + "/platforms/" + platformDir + "/data/res");
    sdkModificator.addRoot(resFolder, OrderRootType.CLASSES);
    VirtualFile docsFolder = LocalFileSystem.getInstance().findFileByPath(sdkPath + "/docs/reference");
    if (docsFolder != null) {
        sdkModificator.addRoot(docsFolder, JavadocOrderRootType.getInstance());
    }
    AndroidSdkAdditionalData data = new AndroidSdkAdditionalData(sdk);
    AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdkPath);
    assertNotNull(sdkData);
    // TODO: Get rid of this hardcoded version number
    IAndroidTarget target = sdkData.findTargetByName("Android 5.0");
    if (target == null) {
        IAndroidTarget[] targets = sdkData.getTargets();
        for (IAndroidTarget t : targets) {
            if (t.getLocation().contains(platformDir)) {
                target = t;
                break;
            }
        }
        if (target == null && targets.length > 0) {
            target = targets[targets.length - 1];
        }
    }
    assertNotNull(target);
    data.setBuildTarget(target);
    sdkModificator.setSdkAdditionalData(data);
    sdkModificator.commitChanges();
    return sdk;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) Sdk(com.intellij.openapi.projectRoots.Sdk) IAndroidTarget(com.android.sdklib.IAndroidTarget) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

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