Search in sources :

Example 11 with CompilerConfiguration

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

the class CompilerConfigGenerator method addFilesIncludedInSwc.

private void addFilesIncludedInSwc(final Element rootElement) {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myModule.getProject()).getFileIndex();
    final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(myModule.getProject());
    final Map<String, String> filePathToPathInSwc = new THashMap<>();
    for (String path : myBC.getCompilerOptions().getFilesToIncludeInSWC()) {
        final VirtualFile fileOrDir = LocalFileSystem.getInstance().findFileByPath(path);
        if (fileOrDir == null || compilerConfiguration.isExcludedFromCompilation(fileOrDir) || FileTypeManager.getInstance().isFileIgnored(fileOrDir)) {
            continue;
        }
        if (fileOrDir.isDirectory()) {
            final VirtualFile srcRoot = fileIndex.getModuleForFile(fileOrDir) == myModule ? fileIndex.getSourceRootForFile(fileOrDir) : null;
            final String baseRelativePath = srcRoot == null ? fileOrDir.getName() : VfsUtilCore.getRelativePath(fileOrDir, srcRoot, '/');
            assert baseRelativePath != null;
            VfsUtilCore.visitChildrenRecursively(fileOrDir, new VirtualFileVisitor() {

                @Override
                public boolean visitFile(@NotNull final VirtualFile file) {
                    if (FileTypeManager.getInstance().isFileIgnored(file))
                        return false;
                    if (!file.isDirectory() && !FlexCommonUtils.isSourceFile(file.getName()) && !compilerConfiguration.isExcludedFromCompilation(file)) {
                        final String relativePath = VfsUtilCore.getRelativePath(file, fileOrDir, '/');
                        final String pathInSwc = baseRelativePath.isEmpty() ? relativePath : baseRelativePath + "/" + relativePath;
                        filePathToPathInSwc.put(file.getPath(), pathInSwc);
                    }
                    return true;
                }
            });
        } else {
            final VirtualFile srcRoot = fileIndex.getSourceRootForFile(fileOrDir);
            final String relativePath = srcRoot == null ? null : VfsUtilCore.getRelativePath(fileOrDir, srcRoot, '/');
            final String pathInSwc = StringUtil.notNullize(relativePath, fileOrDir.getName());
            filePathToPathInSwc.put(fileOrDir.getPath(), pathInSwc);
        }
    }
    for (Map.Entry<String, String> entry : filePathToPathInSwc.entrySet()) {
        final String value = entry.getValue() + CompilerOptionInfo.LIST_ENTRY_PARTS_SEPARATOR + entry.getKey();
        addOption(rootElement, CompilerOptionInfo.INCLUDE_FILE_INFO, value);
    }
}
Also used : THashMap(gnu.trove.THashMap) CompilerConfiguration(com.intellij.compiler.CompilerConfiguration) THashMap(gnu.trove.THashMap)

Aggregations

CompilerConfiguration (com.intellij.compiler.CompilerConfiguration)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 FileType (com.intellij.openapi.fileTypes.FileType)2 Module (com.intellij.openapi.module.Module)2 IOException (java.io.IOException)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 CompilerWorkspaceConfiguration (com.intellij.compiler.CompilerWorkspaceConfiguration)1 ExecutionException (com.intellij.execution.ExecutionException)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 CompilerManager (com.intellij.openapi.compiler.CompilerManager)1 ExcludeEntryDescription (com.intellij.openapi.compiler.options.ExcludeEntryDescription)1 ExcludesConfiguration (com.intellij.openapi.compiler.options.ExcludesConfiguration)1 Project (com.intellij.openapi.project.Project)1 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)1 JavaSdkVersion (com.intellij.openapi.projectRoots.JavaSdkVersion)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 Ref (com.intellij.openapi.util.Ref)1 SmartList (com.intellij.util.SmartList)1