Search in sources :

Example 11 with CompilerManager

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

the class IdeFrameFixture method invokeProjectMakeUsingJps.

@NotNull
public CompileContext invokeProjectMakeUsingJps() {
    Project project = getProject();
    AndroidGradleBuildConfiguration buildConfiguration = AndroidGradleBuildConfiguration.getInstance(project);
    buildConfiguration.USE_EXPERIMENTAL_FASTER_BUILD = false;
    AtomicReference<CompileContext> contextRef = new AtomicReference<>();
    CompilerManager compilerManager = CompilerManager.getInstance(project);
    Disposable disposable = new NoOpDisposable();
    compilerManager.addCompilationStatusListener(new CompilationStatusListener() {

        @Override
        public void compilationFinished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
            contextRef.set(compileContext);
        }
    }, disposable);
    try {
        selectProjectMakeAction();
        Wait.seconds(10).expecting("Build (" + COMPILE_JAVA + ") for project " + quote(project.getName()) + " to finish'").until(() -> contextRef.get() != null);
        return contextRef.get();
    } finally {
        Disposer.dispose(disposable);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) CompilerManager(com.intellij.openapi.compiler.CompilerManager) CompilationStatusListener(com.intellij.openapi.compiler.CompilationStatusListener) AndroidGradleBuildConfiguration(com.android.tools.idea.gradle.project.build.compiler.AndroidGradleBuildConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) CompileContext(com.intellij.openapi.compiler.CompileContext) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with CompilerManager

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

the class FlexCompilerHandler method projectOpened.

public void projectOpened() {
    CompilerManager compilerManager = CompilerManager.getInstance(myProject);
    if (compilerManager != null) {
        compilerManager.addBeforeTask(new ValidateFlashConfigurationsPrecompileTask());
        compilerManager.addBeforeTask(new FlexUnitPrecompileTask(myProject));
        compilerManager.addAfterTask(new FlexUnitAfterCompileTask());
        compilerManager.setValidationEnabled(FlexModuleType.getInstance(), false);
    }
    myWidget = new ActiveBuildConfigurationWidget(myProject);
}
Also used : ActiveBuildConfigurationWidget(com.intellij.lang.javascript.flex.projectStructure.ui.ActiveBuildConfigurationWidget) FlexUnitAfterCompileTask(com.intellij.lang.javascript.flex.flexunit.FlexUnitAfterCompileTask) CompilerManager(com.intellij.openapi.compiler.CompilerManager) FlexUnitPrecompileTask(com.intellij.lang.javascript.flex.flexunit.FlexUnitPrecompileTask)

Example 13 with CompilerManager

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

the class ClassFilesIndexFeaturesHolder method projectOpened.

@Override
public final void projectOpened() {
    for (final ClassFilesIndexFeature feature : ClassFilesIndexFeature.values()) {
        final RegistryValue registryValue = feature.getRegistryValue();
        registryValue.addListener(new RegistryValueListener.Adapter() {

            @Override
            public void afterValueChanged(final RegistryValue rawValue) {
                if (!rawValue.asBoolean() && myEnabledFeatures.containsKey(feature)) {
                    disposeFeature(feature);
                }
            }
        }, myProject);
    }
    final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
    compilerManager.addBeforeTask(new CompileTask() {

        @Override
        public boolean execute(final CompileContext context) {
            close();
            return true;
        }
    });
}
Also used : CompileTask(com.intellij.openapi.compiler.CompileTask) RegistryValue(com.intellij.openapi.util.registry.RegistryValue) CompilerManager(com.intellij.openapi.compiler.CompilerManager) RegistryValueListener(com.intellij.openapi.util.registry.RegistryValueListener) CompileContext(com.intellij.openapi.compiler.CompileContext)

Example 14 with CompilerManager

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

the class CompileAction method getCompilableFiles.

private static VirtualFile[] getCompilableFiles(Project project, VirtualFile[] files) {
    if (files == null || files.length == 0) {
        return VirtualFile.EMPTY_ARRAY;
    }
    final PsiManager psiManager = PsiManager.getInstance(project);
    final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(project);
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final CompilerManager compilerManager = CompilerManager.getInstance(project);
    final List<VirtualFile> filesToCompile = new ArrayList<>();
    for (final VirtualFile file : files) {
        if (!fileIndex.isInSourceContent(file)) {
            continue;
        }
        if (!file.isInLocalFileSystem()) {
            continue;
        }
        if (file.isDirectory()) {
            final PsiDirectory directory = psiManager.findDirectory(file);
            if (directory == null || JavaDirectoryService.getInstance().getPackage(directory) == null) {
                continue;
            }
        } else {
            FileType fileType = file.getFileType();
            if (!(compilerManager.isCompilableFileType(fileType) || compilerConfiguration.isCompilableResourceFile(project, file))) {
                continue;
            }
        }
        filesToCompile.add(file);
    }
    return VfsUtilCore.toVirtualFileArray(filesToCompile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FileType(com.intellij.openapi.fileTypes.FileType) CompilerManager(com.intellij.openapi.compiler.CompilerManager) CompilerConfiguration(com.intellij.compiler.CompilerConfiguration) ArrayList(java.util.ArrayList)

Example 15 with CompilerManager

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

the class CompilerEncodingServiceImpl method computeModuleCharsetMap.

@NotNull
private Map<Module, Set<Charset>> computeModuleCharsetMap() {
    final Map<Module, Set<Charset>> map = new THashMap<>();
    final Map<VirtualFile, Charset> mappings = ((EncodingProjectManagerImpl) EncodingProjectManager.getInstance(myProject)).getAllMappings();
    ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
    final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
    for (Map.Entry<VirtualFile, Charset> entry : mappings.entrySet()) {
        final VirtualFile file = entry.getKey();
        final Charset charset = entry.getValue();
        if (file == null || charset == null || (!file.isDirectory() && !compilerManager.isCompilableFileType(file.getFileType())) || !index.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES))
            continue;
        final Module module = index.getModuleForFile(file);
        if (module == null)
            continue;
        Set<Charset> set = map.get(module);
        if (set == null) {
            set = new LinkedHashSet<>();
            map.put(module, set);
            final VirtualFile sourceRoot = index.getSourceRootForFile(file);
            VirtualFile current = file.getParent();
            Charset parentCharset = null;
            while (current != null) {
                final Charset currentCharset = mappings.get(current);
                if (currentCharset != null) {
                    parentCharset = currentCharset;
                }
                if (current.equals(sourceRoot)) {
                    break;
                }
                current = current.getParent();
            }
            if (parentCharset != null) {
                set.add(parentCharset);
            }
        }
        set.add(charset);
    }
    //todo[nik,jeka] perhaps we should take into account encodings of source roots only not individual files
    for (Module module : ModuleManager.getInstance(myProject).getModules()) {
        for (VirtualFile file : ModuleRootManager.getInstance(module).getSourceRoots(true)) {
            Charset encoding = EncodingProjectManager.getInstance(myProject).getEncoding(file, true);
            if (encoding != null) {
                Set<Charset> charsets = map.get(module);
                if (charsets == null) {
                    charsets = new LinkedHashSet<>();
                    map.put(module, charsets);
                }
                charsets.add(encoding);
            }
        }
    }
    return map;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) CompilerManager(com.intellij.openapi.compiler.CompilerManager) Charset(java.nio.charset.Charset) THashMap(gnu.trove.THashMap) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) EncodingProjectManagerImpl(com.intellij.openapi.vfs.encoding.EncodingProjectManagerImpl) Module(com.intellij.openapi.module.Module) THashMap(gnu.trove.THashMap) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

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