Search in sources :

Example 1 with NewProjectWizardState

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

the class TemplateTest method testJdk5.

public void testJdk5() throws Exception {
    if (DISABLED) {
        return;
    }
    AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    assertNotNull(sdkData);
    IAndroidTarget[] targets = sdkData.getTargets();
    IAndroidTarget target = targets[targets.length - 1];
    Map<String, Object> overrides = new HashMap<>();
    overrides.put(ATTR_JAVA_VERSION, "1.5");
    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(9, 18, target, state, "Test15", null, overrides, null);
}
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 2 with NewProjectWizardState

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

the class TemplateTest method createProject.

private static void createProject(@NotNull final NewModuleWizardState wizardState, @NotNull Project project, @Nullable AssetStudioAssetGenerator assetGenerator) {
    List<String> errors = Lists.newArrayList();
    try {
        wizardState.populateDirectoryParameters();
        String moduleName = wizardState.getString(ATTR_MODULE_NAME);
        String projectName = wizardState.getString(ATTR_APP_TITLE);
        File projectRoot = new File(wizardState.getString(ATTR_PROJECT_LOCATION));
        File moduleRoot = new File(projectRoot, moduleName);
        if (FileUtilRt.createDirectory(projectRoot)) {
            if (wizardState.getBoolean(ATTR_CREATE_ICONS) && assetGenerator != null) {
                assetGenerator.outputImagesIntoDefaultVariant(moduleRoot);
            }
            wizardState.updateParameters();
            wizardState.updateDependencies();
            // If this is a new project, instantiate the project-level files
            if (wizardState instanceof NewProjectWizardState) {
                Template projectTemplate = ((NewProjectWizardState) wizardState).getProjectTemplate();
                final RenderingContext projectContext = RenderingContext.Builder.newContext(projectTemplate, project).withOutputRoot(projectRoot).withModuleRoot(moduleRoot).withParams(wizardState.myParameters).build();
                projectTemplate.render(projectContext);
                AndroidGradleModuleUtils.setGradleWrapperExecutable(projectRoot);
            }
            final RenderingContext context = RenderingContext.Builder.newContext(wizardState.myTemplate, project).withOutputRoot(projectRoot).withModuleRoot(moduleRoot).withParams(wizardState.myParameters).build();
            wizardState.myTemplate.render(context);
            if (wizardState.getBoolean(ATTR_CREATE_ACTIVITY)) {
                TemplateWizardState activityTemplateState = wizardState.getActivityTemplateState();
                activityTemplateState.populateRelativePackage(null);
                Template template = activityTemplateState.getTemplate();
                assert template != null;
                final RenderingContext activityContext = RenderingContext.Builder.newContext(template, project).withOutputRoot(moduleRoot).withModuleRoot(moduleRoot).withParams(activityTemplateState.myParameters).build();
                template.render(activityContext);
                context.getFilesToOpen().addAll(activityContext.getFilesToOpen());
            }
        } else {
            errors.add(String.format("Unable to create directory '%1$s'.", projectRoot.getPath()));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    assertEmpty(errors);
}
Also used : RenderingContext(com.android.tools.idea.templates.recipe.RenderingContext) TemplateWizardState(com.android.tools.idea.wizard.template.TemplateWizardState) 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) IOException(java.io.IOException)

Example 3 with NewProjectWizardState

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

the class TemplateTest method createNewProjectState.

private static NewProjectWizardState createNewProjectState(boolean createWithProject, AndroidSdkData sdkData) {
    NewProjectWizardState values = new NewProjectWizardState();
    assertNotNull(values);
    Template.convertApisToInt(values.getParameters());
    values.put(ATTR_CREATE_ACTIVITY, createWithProject);
    values.put(ATTR_GRADLE_VERSION, GRADLE_LATEST_VERSION);
    values.put(ATTR_GRADLE_PLUGIN_VERSION, GRADLE_PLUGIN_RECOMMENDED_VERSION);
    values.put(ATTR_MODULE_NAME, "TestModule");
    values.put(ATTR_PACKAGE_NAME, "test.pkg");
    // TODO: Test the icon generator too
    values.put(ATTR_CREATE_ICONS, false);
    BuildToolInfo buildTool = sdkData.getLatestBuildTool();
    if (buildTool != null) {
        values.put(ATTR_BUILD_TOOLS_VERSION, buildTool.getRevision().toString());
    }
    return values;
}
Also used : BuildToolInfo(com.android.sdklib.BuildToolInfo) NewProjectWizardState(com.android.tools.idea.npw.NewProjectWizardState)

Example 4 with NewProjectWizardState

use of com.android.tools.idea.npw.NewProjectWizardState 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 5 with NewProjectWizardState

use of com.android.tools.idea.npw.NewProjectWizardState 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)

Aggregations

NewProjectWizardState (com.android.tools.idea.npw.NewProjectWizardState)5 TemplateWizardState (com.android.tools.idea.wizard.template.TemplateWizardState)4 IAndroidTarget (com.android.sdklib.IAndroidTarget)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 File (java.io.File)3 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)3 BuildToolInfo (com.android.sdklib.BuildToolInfo)1 TemplateMetadata (com.android.tools.idea.templates.TemplateMetadata)1 RenderingContext (com.android.tools.idea.templates.recipe.RenderingContext)1 IOException (java.io.IOException)1 Element (org.w3c.dom.Element)1