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);
}
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");
}
}
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;
}
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);
}
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");
}
}
Aggregations