Search in sources :

Example 16 with CompilerManager

use of com.intellij.openapi.compiler.CompilerManager in project intellij-community by JetBrains.

the class PackageFileAction method getFilesToPackage.

@NotNull
private static List<VirtualFile> getFilesToPackage(@NotNull AnActionEvent e, @NotNull Project project) {
    final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (files == null)
        return Collections.emptyList();
    List<VirtualFile> result = new ArrayList<>();
    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final CompilerManager compilerManager = CompilerManager.getInstance(project);
    for (VirtualFile file : files) {
        if (file == null || file.isDirectory() || fileIndex.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) && compilerManager.isCompilableFileType(file.getFileType())) {
            return Collections.emptyList();
        }
        final Collection<? extends Artifact> artifacts = ArtifactBySourceFileFinder.getInstance(project).findArtifacts(file);
        for (Artifact artifact : artifacts) {
            if (!StringUtil.isEmpty(artifact.getOutputPath())) {
                result.add(file);
                break;
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) CompilerManager(com.intellij.openapi.compiler.CompilerManager) ArrayList(java.util.ArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with CompilerManager

use of com.intellij.openapi.compiler.CompilerManager in project intellij-community by JetBrains.

the class InternalProjectTaskRunner method runModulesBuildTasks.

private static void runModulesBuildTasks(@NotNull Project project, @NotNull ProjectTaskContext context, @Nullable CompileStatusNotification compileNotification, @NotNull Map<Class<? extends ProjectTask>, List<ProjectTask>> tasksMap) {
    Collection<? extends ProjectTask> buildTasks = tasksMap.get(ModuleBuildTask.class);
    if (ContainerUtil.isEmpty(buildTasks))
        return;
    ModulesBuildSettings modulesBuildSettings = assembleModulesBuildSettings(buildTasks);
    CompilerManager compilerManager = CompilerManager.getInstance(project);
    CompileScope scope = createScope(compilerManager, context, modulesBuildSettings.modules, modulesBuildSettings.includeDependentModules, modulesBuildSettings.includeRuntimeDependencies);
    if (modulesBuildSettings.isIncrementalBuild) {
        compilerManager.make(scope, compileNotification);
    } else {
        compilerManager.compile(scope, compileNotification);
    }
}
Also used : ArtifactCompileScope(com.intellij.packaging.impl.compiler.ArtifactCompileScope) CompileScope(com.intellij.openapi.compiler.CompileScope) CompilerManager(com.intellij.openapi.compiler.CompilerManager)

Example 18 with CompilerManager

use of com.intellij.openapi.compiler.CompilerManager in project android by JetBrains.

the class GradleModuleTasksProvider method getAffectedModules.

@NotNull
private static Module[] getAffectedModules(@NotNull Project project, @NotNull Module[] modules) {
    final CompilerManager compilerManager = CompilerManager.getInstance(project);
    CompileScope scope = compilerManager.createModulesCompileScope(modules, true, true);
    return scope.getAffectedModules();
}
Also used : CompileScope(com.intellij.openapi.compiler.CompileScope) CompilerManager(com.intellij.openapi.compiler.CompilerManager) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with CompilerManager

use of com.intellij.openapi.compiler.CompilerManager in project intellij-plugins by JetBrains.

the class FlexIconProvider method getIcon.

@Override
public Icon getIcon(@NotNull PsiElement element, int flags) {
    int transformedFlags = ElementBase.transformFlags(element, flags);
    Icon icon = null;
    if (element instanceof XmlFile) {
        if (JavaScriptSupportLoader.isFlexMxmFile((PsiFile) element)) {
            final JSClass jsClass = XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) element);
            if (jsClass != null) {
                icon = jsClass.getIcon(flags);
            }
        }
    } else if (element instanceof JSFileImpl) {
        final JSNamedElement mainDeclaredElement = ActionScriptResolveUtil.findMainDeclaredElement((JSFileImpl) element);
        if (mainDeclaredElement != null) {
            icon = mainDeclaredElement.getIcon(transformedFlags);
        }
    }
    if (icon != null) {
        final PsiFile psiFile = element.getContainingFile();
        final VirtualFile vFile = psiFile == null ? null : psiFile.getVirtualFile();
        CompilerManager compilerManager = CompilerManager.getInstance(element.getProject());
        if (vFile != null && compilerManager != null && compilerManager.isExcludedFromCompilation(vFile)) {
            icon = new LayeredIcon(icon, PlatformIcons.EXCLUDED_FROM_COMPILE_ICON);
        }
    }
    return icon;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LayeredIcon(com.intellij.ui.LayeredIcon) XmlFile(com.intellij.psi.xml.XmlFile) CompilerManager(com.intellij.openapi.compiler.CompilerManager) JSNamedElement(com.intellij.lang.javascript.psi.JSNamedElement) PsiFile(com.intellij.psi.PsiFile) LayeredIcon(com.intellij.ui.LayeredIcon) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) JSFileImpl(com.intellij.lang.javascript.psi.impl.JSFileImpl)

Example 20 with CompilerManager

use of com.intellij.openapi.compiler.CompilerManager in project android by JetBrains.

the class AndroidJunitPatcher method handleJavaResources.

/**
   * Puts folders with merged java resources for the selected variant of every module on the classpath.
   *
   * <p>The problem we're solving here is that CompilerModuleExtension supports only one directory for "compiler output". When IJ compiles
   * Java projects, it copies resources to the output classes dir. This is something our Gradle plugin doesn't do, so we need to add the
   * resource directories to the classpath here.
   *
   * <p>We need to do this for every project dependency as well, since we're using classes and resources directories of these directly.
   *
   * @see <a href="http://b.android.com/172409">Bug 172409</a>
   */
private static void handleJavaResources(@NotNull Module module, @NotNull AndroidModuleModel androidModel, @NotNull PathsList classPath) {
    CompilerManager compilerManager = CompilerManager.getInstance(module.getProject());
    CompileScope scope = compilerManager.createModulesCompileScope(new Module[] { module }, true, true);
    // The only test resources we want to use, are the ones from the module where the test is. They should go first, before main resources.
    JavaArtifact testArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
    if (testArtifact != null) {
        try {
            classPath.add(testArtifact.getJavaResourcesFolder());
        } catch (UnsupportedMethodException ignored) {
        // Java resources were not present in older versions of the gradle plugin.
        }
    }
    FileRootSearchScope excludeScope = null;
    TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(module);
    if (testScopes != null) {
        excludeScope = testScopes.getUnitTestExcludeScope();
    }
    for (Module affectedModule : scope.getAffectedModules()) {
        AndroidFacet facet = AndroidFacet.getInstance(affectedModule);
        if (facet != null) {
            AndroidModuleModel affectedAndroidModel = AndroidModuleModel.get(facet);
            if (affectedAndroidModel != null) {
                try {
                    File resourceFolder = affectedAndroidModel.getMainArtifact().getJavaResourcesFolder();
                    if (excludeScope != null && excludeScope.accept(resourceFolder)) {
                        continue;
                    }
                    classPath.add(resourceFolder);
                } catch (UnsupportedMethodException ignored) {
                // Java resources were not present in older versions of the gradle plugin.
                }
            }
        }
    }
}
Also used : CompileScope(com.intellij.openapi.compiler.CompileScope) JavaArtifact(com.android.builder.model.JavaArtifact) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) CompilerManager(com.intellij.openapi.compiler.CompilerManager) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

CompilerManager (com.intellij.openapi.compiler.CompilerManager)22 CompileContext (com.intellij.openapi.compiler.CompileContext)9 Module (com.intellij.openapi.module.Module)6 CompileScope (com.intellij.openapi.compiler.CompileScope)5 CompileStatusNotification (com.intellij.openapi.compiler.CompileStatusNotification)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 NotNull (org.jetbrains.annotations.NotNull)5 CompileTask (com.intellij.openapi.compiler.CompileTask)3 Project (com.intellij.openapi.project.Project)3 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 FileType (com.intellij.openapi.fileTypes.FileType)2 ArtifactCompileScope (com.intellij.packaging.impl.compiler.ArtifactCompileScope)2 PsiFile (com.intellij.psi.PsiFile)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 JavaArtifact (com.android.builder.model.JavaArtifact)1 AndroidGradleBuildConfiguration (com.android.tools.idea.gradle.project.build.compiler.AndroidGradleBuildConfiguration)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 CompilerConfiguration (com.intellij.compiler.CompilerConfiguration)1