Search in sources :

Example 56 with IAndroidTarget

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

the class RefreshRenderAction method clearCache.

public static void clearCache(EditorDesignSurface surface) {
    ModuleClassLoader.clearCache();
    Configuration configuration = surface.getConfiguration();
    if (configuration != null) {
        // Clear layoutlib bitmap cache (in case files have been modified externally)
        IAndroidTarget target = configuration.getTarget();
        Module module = configuration.getModule();
        if (module != null) {
            ResourceClassRegistry.get(module.getProject()).clearCache();
            if (target != null) {
                AndroidTargetData targetData = AndroidTargetData.getTargetData(target, module);
                if (targetData != null) {
                    targetData.clearLayoutBitmapCache(module);
                }
            }
        }
        AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
        if (facet != null) {
            facet.refreshResources();
        }
        configuration.updated(ConfigurationListener.MASK_RENDERING);
    }
    surface.requestRender();
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) IAndroidTarget(com.android.sdklib.IAndroidTarget) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData)

Example 57 with IAndroidTarget

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

the class AndroidAutogenerator method runRenderscript.

private static void runRenderscript(@NotNull final AndroidFacet facet, @NotNull final CompileContext context) {
    final Module module = facet.getModule();
    final ModuleCompileScope moduleCompileScope = new ModuleCompileScope(module, false);
    final VirtualFile[] files = moduleCompileScope.getFiles(AndroidRenderscriptFileType.INSTANCE, true);
    facet.clearAutogeneratedFiles(AndroidAutogeneratorMode.RENDERSCRIPT);
    for (final VirtualFile file : files) {
        final RenderscriptAutogenerationItem item = ApplicationManager.getApplication().runReadAction(new Computable<RenderscriptAutogenerationItem>() {

            @Nullable
            @Override
            public RenderscriptAutogenerationItem compute() {
                final AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
                if (platform == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.specify.platform", module.getName()), null, -1, -1);
                    return null;
                }
                final IAndroidTarget target = platform.getTarget();
                final String sdkLocation = platform.getSdkData().getPath();
                final String packageName = AndroidUtils.computePackageName(module, file);
                if (packageName == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, "Cannot compute package for file", file.getUrl(), -1, -1);
                    return null;
                }
                final String resourceDirPath = AndroidRootUtil.getResourceDirPath(facet);
                assert resourceDirPath != null;
                final String sourceRootPath = AndroidRootUtil.getRenderscriptGenSourceRootPath(facet);
                if (sourceRootPath == null) {
                    return null;
                }
                final String rawDirPath = resourceDirPath + '/' + SdkConstants.FD_RES_RAW;
                return new RenderscriptAutogenerationItem(sdkLocation, target, sourceRootPath, rawDirPath);
            }
        });
        if (item == null) {
            continue;
        }
        File tempOutDir = null;
        try {
            tempOutDir = FileUtil.createTempDirectory("android_renderscript_autogeneration", "tmp");
            final VirtualFile vTempOutDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempOutDir);
            final String depFolderPath = vTempOutDir != null ? getDependencyFolder(context.getProject(), file, vTempOutDir) : null;
            final Map<CompilerMessageCategory, List<String>> messages = AndroidCompileUtil.toCompilerMessageCategoryKeys(AndroidRenderscript.execute(item.mySdkLocation, item.myTarget, file.getPath(), tempOutDir.getPath(), depFolderPath, item.myRawDirPath));
            if (messages.get(CompilerMessageCategory.ERROR).size() == 0) {
                final List<File> newFiles = new ArrayList<File>();
                AndroidCommonUtils.moveAllFiles(tempOutDir, new File(item.myGenDirPath), newFiles);
                for (File newFile : newFiles) {
                    final VirtualFile newVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(newFile);
                    if (newVFile != null) {
                        patchAndMarkGeneratedFile(facet, AndroidAutogeneratorMode.RENDERSCRIPT, newVFile);
                    }
                }
                final File bcFile = new File(item.myRawDirPath, FileUtil.getNameWithoutExtension(file.getName()) + ".bc");
                final VirtualFile vBcFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(bcFile);
                if (vBcFile != null) {
                    facet.markFileAutogenerated(AndroidAutogeneratorMode.RENDERSCRIPT, vBcFile);
                }
            }
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    if (module.getProject().isDisposed()) {
                        return;
                    }
                    for (final CompilerMessageCategory category : messages.keySet()) {
                        final List<String> messageList = messages.get(category);
                        for (final String message : messageList) {
                            context.addMessage(category, message, file.getUrl(), -1, -1);
                        }
                    }
                }
            });
            final VirtualFile genDir = LocalFileSystem.getInstance().findFileByPath(item.myGenDirPath);
            if (genDir != null) {
                genDir.refresh(false, true);
            }
        } catch (final IOException e) {
            LOG.info(e);
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    if (module.getProject().isDisposed())
                        return;
                    context.addMessage(CompilerMessageCategory.ERROR, e.getMessage(), file.getUrl(), -1, -1);
                }
            });
        } finally {
            if (tempOutDir != null) {
                FileUtil.delete(tempOutDir);
            }
        }
    }
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) IOException(java.io.IOException) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope) Module(com.intellij.openapi.module.Module) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 58 with IAndroidTarget

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

the class AndroidAutogenerator method runAidl.

private static void runAidl(@NotNull final AndroidFacet facet, @NotNull final CompileContext context) {
    final Module module = facet.getModule();
    final ModuleCompileScope moduleCompileScope = new ModuleCompileScope(module, false);
    final VirtualFile[] files = moduleCompileScope.getFiles(AidlFileType.INSTANCE, true);
    final List<IdlAutogenerationItem> items = new ArrayList<IdlAutogenerationItem>();
    for (final VirtualFile file : files) {
        final IdlAutogenerationItem item = ApplicationManager.getApplication().runReadAction(new Computable<IdlAutogenerationItem>() {

            @Nullable
            @Override
            public IdlAutogenerationItem compute() {
                if (module.isDisposed() || module.getProject().isDisposed()) {
                    return null;
                }
                final IAndroidTarget target = facet.getConfiguration().getAndroidTarget();
                if (target == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.specify.platform", module.getName()), null, -1, -1);
                    return null;
                }
                final String packageName = AndroidUtils.computePackageName(module, file);
                if (packageName == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, "Cannot compute package for file", file.getUrl(), -1, -1);
                    return null;
                }
                final String sourceRootPath = AndroidRootUtil.getAidlGenSourceRootPath(facet);
                if (sourceRootPath == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.apt.gen.not.specified", module.getName()), null, -1, -1);
                    return null;
                }
                final VirtualFile[] sourceRoots = getSourceRootsForModuleAndDependencies(module, false);
                final String[] sourceRootOsPaths = AndroidCompileUtil.toOsPaths(sourceRoots);
                final String outFileOsPath = FileUtil.toSystemDependentName(sourceRootPath + '/' + packageName.replace('.', '/') + '/' + file.getNameWithoutExtension() + ".java");
                return new IdlAutogenerationItem(file, target, outFileOsPath, sourceRootOsPaths, sourceRootPath, packageName);
            }
        });
        if (item != null) {
            items.add(item);
        }
    }
    final Set<VirtualFile> filesToCheck = new HashSet<VirtualFile>();
    for (IdlAutogenerationItem item : items) {
        if (new File(FileUtil.toSystemDependentName(item.myFile.getPath())).exists()) {
            filesToCheck.add(item.myFile);
        }
    }
    if (!ensureFilesWritable(module.getProject(), filesToCheck)) {
        return;
    }
    facet.clearAutogeneratedFiles(AndroidAutogeneratorMode.AIDL);
    for (IdlAutogenerationItem item : items) {
        final VirtualFile file = item.myFile;
        final String fileOsPath = FileUtil.toSystemDependentName(file.getPath());
        try {
            final Map<CompilerMessageCategory, List<String>> messages = AndroidCompileUtil.toCompilerMessageCategoryKeys(AndroidIdl.execute(item.myTarget, fileOsPath, item.myOutFileOsPath, item.mySourceRootOsPaths));
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    if (module.getProject().isDisposed())
                        return;
                    for (CompilerMessageCategory category : messages.keySet()) {
                        List<String> messageList = messages.get(category);
                        for (String message : messageList) {
                            context.addMessage(category, message, file.getUrl(), -1, -1);
                        }
                    }
                }
            });
            removeDuplicateClasses(module, item.myPackage, new File(item.myOutFileOsPath), item.myOutDirOsPath);
            final VirtualFile genDir = LocalFileSystem.getInstance().findFileByPath(item.myOutDirOsPath);
            if (genDir != null) {
                genDir.refresh(false, true);
            }
            final VirtualFile outFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(item.myOutFileOsPath);
            if (outFile != null && outFile.exists()) {
                patchAndMarkGeneratedFile(facet, AndroidAutogeneratorMode.AIDL, outFile);
            }
        } catch (final IOException e) {
            LOG.info(e);
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    if (module.getProject().isDisposed())
                        return;
                    context.addMessage(CompilerMessageCategory.ERROR, e.getMessage(), file.getUrl(), -1, -1);
                }
            });
        }
    }
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) IAndroidTarget(com.android.sdklib.IAndroidTarget) IOException(java.io.IOException) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope) Module(com.intellij.openapi.module.Module) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) HashSet(com.intellij.util.containers.HashSet)

Example 59 with IAndroidTarget

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

the class AndroidSdkUtils method updateSdkSourceRoot.

/**
   * Reload SDK information and update the source root of the SDK.
   */
public static void updateSdkSourceRoot(@NotNull Sdk sdk) {
    AndroidPlatform platform = AndroidPlatform.getInstance(sdk);
    if (platform != null) {
        IAndroidTarget target = platform.getTarget();
        SdkModificator sdkModificator = sdk.getSdkModificator();
        sdkModificator.removeRoots(SOURCES);
        AndroidSdks.getInstance().findAndSetPlatformSources(target, sdkModificator);
        sdkModificator.commitChanges();
    }
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Example 60 with IAndroidTarget

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

the class AndroidTargetData method getLayoutLibrary.

@Nullable
public synchronized LayoutLibrary getLayoutLibrary(@NotNull Project project) throws RenderingException, IOException {
    if (myLayoutLibrary == null) {
        if (myTarget instanceof CompatibilityRenderTarget) {
            IAndroidTarget target = ((CompatibilityRenderTarget) myTarget).getRenderTarget();
            AndroidTargetData targetData = mySdkData.getTargetData(target);
            if (targetData != this) {
                myLayoutLibrary = targetData.getLayoutLibrary(project);
                return myLayoutLibrary;
            }
        }
        final AttributeDefinitionsImpl attrDefs = getAllAttrDefs(project);
        if (attrDefs == null) {
            return null;
        }
        myLayoutLibrary = LayoutLibraryLoader.load(myTarget, attrDefs.getEnumMap());
    }
    return myLayoutLibrary;
}
Also used : CompatibilityRenderTarget(com.android.tools.idea.rendering.multi.CompatibilityRenderTarget) AttributeDefinitionsImpl(org.jetbrains.android.dom.attrs.AttributeDefinitionsImpl) IAndroidTarget(com.android.sdklib.IAndroidTarget) Nullable(org.jetbrains.annotations.Nullable)

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