use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class VaryingConfigurationTest method test.
public void test() throws Exception {
VirtualFile file = myFixture.copyFileToProject(TEST_FILE, "res/layout/layout1.xml");
final AndroidFacet facet = AndroidFacet.getInstance(myModule);
assertNotNull(facet);
ConfigurationManager manager = facet.getConfigurationManager();
assertNotNull(manager);
assertSame(manager, facet.getConfigurationManager());
Configuration parent = Configuration.create(manager, file, new FolderConfiguration());
assertNotNull(parent);
parent.startBulkEditing();
parent.setDisplayName("myconfig");
parent.setTheme("@style/Theme1");
parent.setNightMode(NightMode.NIGHT);
parent.setActivity("tes.tpkg.MyActivity1");
parent.setUiMode(UiMode.TELEVISION);
IAndroidTarget target = parent.getConfigurationManager().getTarget();
Device device = parent.getConfigurationManager().getDefaultDevice();
State deviceState = device != null ? device.getState("Portrait") : null;
if (target != null) {
parent.setTarget(target);
}
if (device != null) {
parent.setDevice(device, false);
assertNotNull(deviceState);
parent.setDeviceState(deviceState);
}
parent.setLocale(Locale.create("en-rUS"));
parent.finishBulkEditing();
VaryingConfiguration configuration = VaryingConfiguration.create(parent);
configuration.setAlternateUiMode(true);
assertEquals(UiMode.TELEVISION, parent.getUiMode());
assertEquals(UiMode.APPLIANCE, configuration.getUiMode());
parent.setUiMode(UiMode.APPLIANCE);
assertEquals(UiMode.WATCH, configuration.getUiMode());
assertNotNull(device);
State portrait = device.getState("Portrait");
State landscape = device.getState("Landscape");
assertNotNull(portrait);
assertNotNull(landscape);
configuration.setAlternateDeviceState(true);
assertTrue(configuration.isAlternatingDeviceState());
assertEquals(ScreenOrientation.LANDSCAPE, configuration.getFullConfig().getScreenOrientationQualifier().getValue());
parent.setDeviceState(landscape);
assertEquals(ScreenOrientation.PORTRAIT, configuration.getFullConfig().getScreenOrientationQualifier().getValue());
assertEquals(portrait, configuration.getDeviceState());
parent.setDeviceState(portrait);
assertEquals(ScreenOrientation.LANDSCAPE, configuration.getFullConfig().getScreenOrientationQualifier().getValue());
assertEquals(landscape, configuration.getDeviceState());
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidSdksTest method testNeedsAnnotationsJarInClasspathWithApiLevelGreaterThan15.
public void testNeedsAnnotationsJarInClasspathWithApiLevelGreaterThan15() {
IAndroidTarget target = createTargetWithApiLevel(16);
assertFalse(myAndroidSdks.needsAnnotationsJarInClasspath(target));
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidSdksTest method testTryToCreate.
public void testTryToCreate() {
IAndroidTarget target = findAndroidTarget();
String hash = getTargetHashString(target);
Sdk sdk = myAndroidSdks.tryToCreate(mySdkPath, hash);
assertNotNull(sdk);
verifyCorrectPath(sdk);
AndroidSdkAdditionalData data = getAndroidSdkAdditionalData(sdk);
assertEquals(hash, data.getBuildTargetHashString());
}
use of com.android.sdklib.IAndroidTarget 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();
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidResourceCachingBuilder method runPngCaching.
private static boolean runPngCaching(AndroidResourceCachingBuildTarget target, CompileContext context, BuildOutputConsumer outputConsumer) throws IOException {
final JpsModule module = target.getModule();
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
assert extension != null;
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.INFO, AndroidJpsBundle.message("android.jps.progress.res.caching", module.getName())));
final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
if (platform == null) {
return false;
}
final File resCacheDir = target.getOutputDir(context);
// todo: probably it may be done automatically
if (context.getScope().isBuildForced(target) && resCacheDir.exists()) {
if (!FileUtil.delete(resCacheDir)) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", resCacheDir.getPath())));
return false;
}
}
if (!resCacheDir.exists()) {
if (!resCacheDir.mkdirs()) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", resCacheDir.getPath())));
return false;
}
}
final IAndroidTarget androidTarget = platform.getTarget();
final List<BuildRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
if (roots.size() == 0) {
return true;
}
final List<String> inputDirs = new ArrayList<String>();
for (BuildRootDescriptor root : roots) {
final File f = root.getRootFile();
if (f.exists()) {
inputDirs.add(f.getPath());
}
}
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidApt.crunch(androidTarget, inputDirs, resCacheDir.getPath());
AndroidJpsUtil.addMessages(context, messages, BUILDER_NAME, module.getName());
final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).isEmpty();
if (success) {
final Map<String, File> outputFiles = new HashMap<String, File>();
FileUtil.processFilesRecursively(resCacheDir, new Processor<File>() {
@Override
public boolean process(File file) {
if (file.isFile()) {
final String relativePath = FileUtil.getRelativePath(resCacheDir, file);
if (relativePath != null) {
outputFiles.put(relativePath, file);
}
}
return true;
}
});
for (Map.Entry<String, File> entry : outputFiles.entrySet()) {
final String relativePath = entry.getKey();
final File outputFile = entry.getValue();
for (String inputDir : inputDirs) {
final File srcFile = new File(inputDir, relativePath);
outputConsumer.registerOutputFile(outputFile, Collections.singletonList(srcFile.getPath()));
}
}
}
return success;
}
Aggregations