Search in sources :

Example 91 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class TemplateTest method checkTemplate.

private void checkTemplate(File templateFile, boolean createWithProject, @Nullable Map<String, Object> overrides, @Nullable Map<String, Object> projectOverrides) throws Exception {
    if (KNOWN_BROKEN.contains(templateFile.getName())) {
        return;
    }
    AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    assertNotNull(sdkData);
    NewProjectWizardState values = createNewProjectState(createWithProject, sdkData);
    String projectNameBase = "TestProject" + templateFile.getName();
    TemplateWizardState state = values.getActivityTemplateState();
    state.setTemplateLocation(templateFile);
    // Iterate over all (valid) combinations of build target, minSdk and targetSdk
    // TODO: Assert that the SDK manager has a minimum set of SDKs installed needed to be certain
    // the test is comprehensive
    // For now make sure there's at least one
    boolean ranTest = false;
    IAndroidTarget[] targets = sdkData.getTargets();
    for (int i = targets.length - 1; i >= 0; i--) {
        IAndroidTarget target = targets[i];
        if (!target.isPlatform()) {
            continue;
        }
        if (!isInterestingApiLevel(target.getVersion().getApiLevel(), MANUAL_BUILD_API)) {
            continue;
        }
        TemplateMetadata activityMetadata = state.getTemplateMetadata();
        TemplateMetadata projectMetadata = values.getTemplateMetadata();
        assertNotNull(activityMetadata);
        assertNotNull(projectMetadata);
        int lowestSupportedApi = Math.max(projectMetadata.getMinSdk(), activityMetadata.getMinSdk());
        for (int minSdk = lowestSupportedApi; minSdk <= SdkVersionInfo.HIGHEST_KNOWN_API; minSdk++) {
            // Don't bother checking *every* single minSdk, just pick some interesting ones
            if (!isInterestingApiLevel(minSdk, MANUAL_MIN_API)) {
                continue;
            }
            for (int targetSdk = minSdk; targetSdk <= SdkVersionInfo.HIGHEST_KNOWN_API; targetSdk++) {
                if (!isInterestingApiLevel(targetSdk, MANUAL_TARGET_API)) {
                    continue;
                }
                String status = validateTemplate(projectMetadata, minSdk, target.getVersion().getApiLevel());
                if (status != null) {
                    continue;
                }
                // Also make sure activity is enabled for these versions
                status = validateTemplate(activityMetadata, minSdk, target.getVersion().getApiLevel());
                if (status != null) {
                    continue;
                }
                // Iterate over all new new project templates
                // should I try all options of theme with all platforms?
                // or just try all platforms, with one setting for each?
                // doesn't seem like I need to multiply
                // just pick the best setting that applies instead for each platform
                Collection<Parameter> parameters = projectMetadata.getParameters();
                projectParameters: for (Parameter parameter : parameters) {
                    if (overrides != null) {
                        String base = projectNameBase + "_min_" + minSdk + "_target_" + targetSdk + "_build_" + target.getVersion().getApiLevel() + "_overrides";
                        checkApiTarget(minSdk, targetSdk, target, values, base, state, overrides, projectOverrides);
                        ranTest = true;
                        break projectParameters;
                    }
                    List<Element> options = parameter.getOptions();
                    if (parameter.type == Parameter.Type.ENUM) {
                        assertNotNull(parameter.id);
                        for (Element element : options) {
                            Option option = Option.get(element);
                            String optionId = option.id;
                            int optionMinSdk = option.minSdk;
                            int optionMinBuildApi = option.minBuild;
                            if (optionMinSdk <= minSdk && optionMinBuildApi <= target.getVersion().getApiLevel()) {
                                values.put(parameter.id, optionId);
                                if (parameter.id.equals("baseTheme")) {
                                    String base = projectNameBase + "_min_" + minSdk + "_target_" + targetSdk + "_build_" + target.getVersion().getApiLevel() + "_theme_" + optionId;
                                    checkApiTarget(minSdk, targetSdk, target, values, base, state, null, null);
                                    ranTest = true;
                                    if (!TEST_VARIABLE_COMBINATIONS) {
                                        break projectParameters;
                                    }
                                }
                            }
                        }
                    }
                }
                if (TEST_JUST_ONE_TARGET_SDK_VERSION) {
                    break;
                }
            }
            if (TEST_JUST_ONE_MIN_SDK) {
                break;
            }
        }
        if (TEST_JUST_ONE_BUILD_TARGET) {
            break;
        }
    }
    assertTrue("Didn't run any tests! Make sure you have the right platforms installed.", ranTest);
}
Also used : Element(org.w3c.dom.Element) TemplateWizardState(com.android.tools.idea.wizard.template.TemplateWizardState) IAndroidTarget(com.android.sdklib.IAndroidTarget) NewProjectWizardState(com.android.tools.idea.npw.NewProjectWizardState) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Example 92 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget 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 93 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class NlUsageTrackerManagerTest method getConfigurationMock.

private static Configuration getConfigurationMock() {
    IAndroidTarget target = mock(IAndroidTarget.class);
    when(target.getVersion()).thenReturn(new AndroidVersion(0, "mock"));
    State state = mock(State.class);
    when(state.getOrientation()).thenReturn(PORTRAIT);
    Configuration configuration = mock(Configuration.class);
    when(configuration.getTarget()).thenReturn(target);
    when(configuration.getDeviceState()).thenReturn(state);
    return configuration;
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) State(com.android.sdklib.devices.State) LayoutEditorState(com.google.wireless.android.sdk.stats.LayoutEditorState) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion)

Example 94 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class AndroidSdkUtilsTest method createAndroidSdk.

private static void createAndroidSdk(@NotNull File androidHomePath, @NotNull String targetHashString, @NotNull Sdk javaSdk) {
    Sdk sdk = SdkConfigurationUtil.createAndAddSDK(androidHomePath.getPath(), AndroidSdkType.getInstance());
    assertNotNull(sdk);
    AndroidSdkData sdkData = AndroidSdkData.getSdkData(androidHomePath);
    assertNotNull(sdkData);
    IAndroidTarget target = sdkData.findTargetByHashString(targetHashString);
    assertNotNull(target);
    AndroidSdks.getInstance().setUpSdk(sdk, target, target.getName(), Collections.singletonList(javaSdk), javaSdk, true);
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) IAndroidTarget(com.android.sdklib.IAndroidTarget)

Example 95 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class ThemeEditorUtilsTest method testGenerateToolTipText.

public void testGenerateToolTipText() throws IOException {
    if (SystemInfo.isWindows) {
        // Do not run tests on Windows (see http://b.android.com/222904)
        return;
    }
    VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_1.xml", "res/values/styles.xml");
    myFixture.copyFileToProject("themeEditor/attrs.xml", "res/values/attrs.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
    IAndroidTarget androidTarget = configuration.getTarget();
    assertNotNull(androidTarget);
    sdkPlatformPath = androidTarget.getLocation();
    if (LayoutLibraryLoader.USE_SDK_LAYOUTLIB) {
        if (!sdkPlatformPath.endsWith("/"))
            sdkPlatformPath += "/";
        sdkPlatformPath += "platforms/android-" + androidTarget.getVersion().getApiString();
    }
    sdkPlatformPath = Files.simplifyPath(sdkPlatformPath);
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle theme = themeResolver.getTheme("AppTheme");
    assertNotNull(theme);
    Collection<EditedStyleItem> values = ThemeEditorTestUtils.getStyleLocalValues(theme);
    assertEquals(7, values.size());
    configuration.setTheme("AppTheme");
    for (EditedStyleItem item : values) {
        String doc = ThemeEditorUtils.generateToolTipText(item.getSelectedValue(), myModule, configuration);
        compareWithGoldenFile(doc, myFixture.getTestDataPath() + "/themeEditor/tooltipDocAns/" + item.getName() + ".ans");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) IAndroidTarget(com.android.sdklib.IAndroidTarget) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)

Aggregations

IAndroidTarget (com.android.sdklib.IAndroidTarget)105 Nullable (org.jetbrains.annotations.Nullable)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Module (com.intellij.openapi.module.Module)17 NotNull (org.jetbrains.annotations.NotNull)16 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)15 Sdk (com.intellij.openapi.projectRoots.Sdk)14 File (java.io.File)13 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)13 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)13 AndroidVersion (com.android.sdklib.AndroidVersion)11 Device (com.android.sdklib.devices.Device)11 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)9 State (com.android.sdklib.devices.State)8 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)8 AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)8 Configuration (com.android.tools.idea.configurations.Configuration)7 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)7 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)7 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)6