Search in sources :

Example 36 with AndroidSdkData

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

the class TemplateTest method testJdk7.

public void testJdk7() throws Exception {
    if (DISABLED) {
        return;
    }
    AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    assertNotNull(sdkData);
    if (IdeSdks.getInstance().isJdk7Supported(sdkData)) {
        IAndroidTarget[] targets = sdkData.getTargets();
        IAndroidTarget target = targets[targets.length - 1];
        Map<String, Object> overrides = new HashMap<>();
        overrides.put(ATTR_JAVA_VERSION, "1.7");
        NewProjectWizardState state = createNewProjectState(true, sdkData);
        // TODO: Allow null activity state!
        File activity = findTemplate("activities", "BasicActivity");
        TemplateWizardState activityState = state.getActivityTemplateState();
        assertNotNull(activity);
        activityState.setTemplateLocation(activity);
        checkApiTarget(19, 19, target, state, "Test17", null, overrides, null);
    } else {
        System.out.println("JDK 7 not supported by current SDK manager: not testing");
    }
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) TemplateWizardState(com.android.tools.idea.wizard.template.TemplateWizardState) IAndroidTarget(com.android.sdklib.IAndroidTarget) NewProjectWizardState(com.android.tools.idea.npw.NewProjectWizardState) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 37 with AndroidSdkData

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

the class LintIdeApiDetectorTest method testTryWithResources.

// This test does not yet work reliably; need to ensure correct JDK 7 loading.
public void testTryWithResources() throws Exception {
    // TODO: Allow setting a custom minSdkVersion in the manifest so I can test both with and without
    AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    if (sdkData == null || !IdeSdks.getInstance().isJdk7Supported(sdkData)) {
        System.out.println("Skipping LintIdeApiDetectorTest#testTryWithResources: Test JDK must be JDK 7 or higher");
        return;
    }
    AndroidLintNewApiInspection inspection = new AndroidLintNewApiInspection();
    doTest(inspection, null);
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData)

Example 38 with AndroidSdkData

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

the class AndroidSdksTest method testTryToChooseSdkHandler.

public void testTryToChooseSdkHandler() {
    myAndroidSdks.create(findAndroidTarget(), mySdkPath, myJdk, false);
    AndroidSdkHandler sdkHandler = myAndroidSdks.tryToChooseSdkHandler();
    AndroidSdkData sdkData = getSdkData(mySdkPath);
    assertNotNull(sdkData);
    assertSame(sdkData.getSdkHandler(), sdkHandler);
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler)

Example 39 with AndroidSdkData

use of org.jetbrains.android.sdk.AndroidSdkData 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

AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)39 IAndroidTarget (com.android.sdklib.IAndroidTarget)15 File (java.io.File)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Sdk (com.intellij.openapi.projectRoots.Sdk)9 NotNull (org.jetbrains.annotations.NotNull)7 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)6 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)6 Nullable (org.jetbrains.annotations.Nullable)6 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)5 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)5 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 AndroidVersion (com.android.sdklib.AndroidVersion)3 NewProjectWizardState (com.android.tools.idea.npw.NewProjectWizardState)3 SdkPaths.validateAndroidSdk (com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk)3 TemplateWizardState (com.android.tools.idea.wizard.template.TemplateWizardState)3 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)3 ProgressIndicator (com.android.repository.api.ProgressIndicator)2