Search in sources :

Example 96 with IAndroidTarget

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Device(com.android.sdklib.devices.Device) State(com.android.sdklib.devices.State) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 97 with IAndroidTarget

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));
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget)

Example 98 with IAndroidTarget

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());
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidTargetHash.getTargetHashString(com.android.sdklib.AndroidTargetHash.getTargetHashString) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 99 with IAndroidTarget

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidTargetHash.getTargetHashString(com.android.sdklib.AndroidTargetHash.getTargetHashString) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 100 with IAndroidTarget

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;
}
Also used : BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) HashMap(com.intellij.util.containers.HashMap) ArrayList(java.util.ArrayList) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map)

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