Java Code Examples for com.intellij.openapi.compiler.CompilerManager#getInstance()

The following examples show how to use com.intellij.openapi.compiler.CompilerManager#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageFileAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static List<VirtualFile> getFilesToPackage(@Nonnull AnActionEvent e, @Nonnull Project project) {
  final VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
  if (files == null) return Collections.emptyList();

  List<VirtualFile> result = new ArrayList<VirtualFile>();
  ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final CompilerManager compilerManager = CompilerManager.getInstance(project);
  for (VirtualFile file : files) {
    if (file == null || file.isDirectory() ||
        fileIndex.isInSourceContent(file) && 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;
}
 
Example 2
Source File: CompilerExcludedConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public CompilerExcludedConfigurable(final Project project) {
  CompilerManager compilerManager = CompilerManager.getInstance(project);

  myConfigurable = new ExcludedEntriesConfigurable(project, new FileChooserDescriptor(true, true, false, false, false, true),
                                                   compilerManager.getExcludedEntriesConfiguration());
}
 
Example 3
Source File: CompileAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final CompilerManager compilerManager = CompilerManager.getInstance(project);
  final List<VirtualFile> filesToCompile = new ArrayList<VirtualFile>();
  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 || PsiPackageManager.getInstance(project).findAnyPackage(directory) == null) {
        continue;
      }
    }
    else {
      FileType fileType = file.getFileType();
      if (!(compilerManager.isCompilableFileType(fileType) || isCompilableResourceFile(project, file))) {
        continue;
      }
    }
    filesToCompile.add(file);
  }
  return VfsUtil.toVirtualFileArray(filesToCompile);
}
 
Example 4
Source File: ContentResourceChangeListener.java    From aem-ide-tooling-4-intellij with Apache License 2.0 4 votes vote down vote up
private void executeMakeInUIThread(final VirtualFileEvent event) {
    if(project.isInitialized() && !project.isDisposed() && project.isOpen()) {
        final CompilerManager compilerManager = CompilerManager.getInstance(project);
        if(!compilerManager.isCompilationActive() &&
            !compilerManager.isExcludedFromCompilation(event.getFile()) // &&
        ) {
            // Check first if there are no errors in the code
            CodeSmellDetector codeSmellDetector = CodeSmellDetector.getInstance(project);
            boolean isOk = true;
            if(codeSmellDetector != null) {
                List<CodeSmellInfo> codeSmellInfoList = codeSmellDetector.findCodeSmells(Arrays.asList(event.getFile()));
                for(CodeSmellInfo codeSmellInfo: codeSmellInfoList) {
                    if(codeSmellInfo.getSeverity() == HighlightSeverity.ERROR) {
                        isOk = false;
                        break;
                    }
                }
            }
            if(isOk) {
                // Changed file found in module. Make it.
                final ToolWindow tw = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW);
                final boolean isShown = tw != null && tw.isVisible();
                compilerManager.compile(
                    new VirtualFile[]{event.getFile()},
                    new CompileStatusNotification() {
                        @Override
                        public void finished(boolean b, int i, int i1, CompileContext compileContext) {
                            if (tw != null && tw.isVisible()) {
                                // Close / Hide the Build Message Window after we did the build if it wasn't shown
                                if(!isShown) {
                                    tw.hide(null);
                                }
                            }
                        }
                    }
                );
            } else {
                MessageManager messageManager = ComponentProvider.getComponent(project, MessageManager.class);
                if(messageManager != null) {
                    messageManager.sendErrorNotification(
                        "server.update.file.change.with.error",
                        event.getFile()
                    );
                }
            }
        }
    }
}