Search in sources :

Example 1 with ModuleCompileScope

use of com.intellij.compiler.impl.ModuleCompileScope in project android by JetBrains.

the class AndroidGradleBuildTargetScopeProvider method getBuildTargetScopes.

@Override
@NotNull
public List<TargetTypeBuildScope> getBuildTargetScopes(@NotNull CompileScope baseScope, @NotNull CompilerFilter filter, @NotNull Project project, boolean forceBuild) {
    if (!AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
        return Collections.emptyList();
    }
    BuildSettings buildSettings = BuildSettings.getInstance(project);
    String runConfigurationTypeId = baseScope.getUserData(CompilerManager.RUN_CONFIGURATION_TYPE_ID_KEY);
    buildSettings.setRunConfigurationTypeId(runConfigurationTypeId);
    if (baseScope instanceof ProjectCompileScope) {
        // Make or Rebuild project
        BuildMode buildMode = forceBuild ? BuildMode.REBUILD : BuildMode.ASSEMBLE;
        if (buildSettings.getBuildMode() == null) {
            buildSettings.setBuildMode(buildMode);
        }
        Module[] modulesToBuild = ModuleManager.getInstance(project).getModules();
        buildSettings.setModulesToBuild(modulesToBuild);
    } else if (baseScope instanceof ModuleCompileScope) {
        String userDataString = ((ModuleCompileScope) baseScope).getUserDataString();
        Module[] modulesToBuild;
        if (userDataString.contains("RUN_CONFIGURATION")) {
            // Triggered by a "Run Configuration"
            modulesToBuild = baseScope.getAffectedModules();
        } else {
            // Triggered by menu item.
            // Make selected modules
            modulesToBuild = Projects.getModulesToBuildFromSelection(project, null);
        }
        buildSettings.setModulesToBuild(modulesToBuild);
        buildSettings.setBuildMode(BuildMode.ASSEMBLE);
    } else if (baseScope instanceof CompositeScope) {
        // Compile selected modules
        buildSettings.setModulesToBuild(Projects.getModulesToBuildFromSelection(project, null));
        buildSettings.setBuildMode(BuildMode.COMPILE_JAVA);
    }
    TargetTypeBuildScope scope = CmdlineProtoUtil.createTargetsScope(AndroidGradleBuildTargetConstants.TARGET_TYPE_ID, Collections.singletonList(AndroidGradleBuildTargetConstants.TARGET_ID), forceBuild);
    return Collections.singletonList(scope);
}
Also used : ProjectCompileScope(com.intellij.compiler.impl.ProjectCompileScope) CompositeScope(com.intellij.compiler.impl.CompositeScope) BuildSettings(com.android.tools.idea.gradle.project.BuildSettings) BuildMode(com.android.tools.idea.gradle.util.BuildMode) Module(com.intellij.openapi.module.Module) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope) TargetTypeBuildScope(org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ModuleCompileScope

use of com.intellij.compiler.impl.ModuleCompileScope 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 3 with ModuleCompileScope

use of com.intellij.compiler.impl.ModuleCompileScope 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 4 with ModuleCompileScope

use of com.intellij.compiler.impl.ModuleCompileScope in project android by JetBrains.

the class AndroidCompileUtil method doGenerate.

public static boolean doGenerate(AndroidFacet facet, final AndroidAutogeneratorMode mode) {
    assert !ApplicationManager.getApplication().isDispatchThread();
    final CompileContext[] contextWrapper = new CompileContext[1];
    final Module module = facet.getModule();
    final Project project = module.getProject();
    ApplicationManager.getApplication().runReadAction(new Runnable() {

        @Override
        public void run() {
            if (project.isDisposed())
                return;
            CompilerTask task = new CompilerTask(project, "Android auto-generation", true, false, true, true);
            CompileScope scope = new ModuleCompileScope(module, false);
            contextWrapper[0] = new CompileContextImpl(project, task, scope, false, false);
        }
    });
    CompileContext context = contextWrapper[0];
    if (context == null) {
        return false;
    }
    generate(facet, mode, context, false);
    return context.getMessages(CompilerMessageCategory.ERROR).length == 0;
}
Also used : Project(com.intellij.openapi.project.Project) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope) CompileScope(com.intellij.openapi.compiler.CompileScope) ArtifactCompileScope(com.intellij.packaging.impl.compiler.ArtifactCompileScope) CompilerTask(com.intellij.compiler.progress.CompilerTask) CompileContextImpl(com.intellij.compiler.impl.CompileContextImpl) Module(com.intellij.openapi.module.Module) CompileContext(com.intellij.openapi.compiler.CompileContext) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope)

Aggregations

ModuleCompileScope (com.intellij.compiler.impl.ModuleCompileScope)4 Module (com.intellij.openapi.module.Module)4 IAndroidTarget (com.android.sdklib.IAndroidTarget)2 CompilerMessageCategory (com.intellij.openapi.compiler.CompilerMessageCategory)2 File (java.io.File)2 IOException (java.io.IOException)2 Nullable (org.jetbrains.annotations.Nullable)2 BuildSettings (com.android.tools.idea.gradle.project.BuildSettings)1 BuildMode (com.android.tools.idea.gradle.util.BuildMode)1 CompileContextImpl (com.intellij.compiler.impl.CompileContextImpl)1 CompositeScope (com.intellij.compiler.impl.CompositeScope)1 ProjectCompileScope (com.intellij.compiler.impl.ProjectCompileScope)1 CompilerTask (com.intellij.compiler.progress.CompilerTask)1 CompileContext (com.intellij.openapi.compiler.CompileContext)1 CompileScope (com.intellij.openapi.compiler.CompileScope)1 Project (com.intellij.openapi.project.Project)1 ArtifactCompileScope (com.intellij.packaging.impl.compiler.ArtifactCompileScope)1 HashSet (com.intellij.util.containers.HashSet)1 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)1 NotNull (org.jetbrains.annotations.NotNull)1