Search in sources :

Example 6 with CompilerConfiguration

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

the class CompilerConfigGenerator method addLibClasses.

private void addLibClasses(final Element rootElement) throws IOException {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myModule.getProject()).getFileIndex();
    final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(myModule.getProject());
    final Ref<Boolean> noClasses = new Ref<>(true);
    for (final VirtualFile sourceRoot : ModuleRootManager.getInstance(myModule).getSourceRoots(false)) {
        fileIndex.iterateContentUnderDirectory(sourceRoot, file -> {
            if (file.isDirectory())
                return true;
            if (!FlexCommonUtils.isSourceFile(file.getName()))
                return true;
            if (compilerConfiguration.isExcludedFromCompilation(file))
                return true;
            final String packageText = VfsUtilCore.getRelativePath(file.getParent(), sourceRoot, '.');
            assert packageText != null : sourceRoot.getPath() + ": " + file.getPath();
            final String qName = (packageText.length() > 0 ? packageText + "." : "") + file.getNameWithoutExtension();
            if (isSourceFileWithPublicDeclaration(myModule, file, qName)) {
                addOption(rootElement, CompilerOptionInfo.INCLUDE_CLASSES_INFO, qName);
                noClasses.set(false);
            }
            return true;
        });
    }
    if (noClasses.get() && myBC.getCompilerOptions().getFilesToIncludeInSWC().isEmpty() && !ApplicationManager.getApplication().isUnitTestMode()) {
        throw new IOException(FlexCommonBundle.message("nothing.to.compile.in.library", myModule.getName(), myBC.getName()));
    }
}
Also used : Ref(com.intellij.openapi.util.Ref) CompilerConfiguration(com.intellij.compiler.CompilerConfiguration) IOException(java.io.IOException)

Example 7 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)

Example 8 with CompilerConfiguration

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

the class AbstractModuleDataService method setBytecodeTargetLevel.

private void setBytecodeTargetLevel(@NotNull Project project, @NotNull Module module, @NotNull E data) {
    String targetLevel = data.getTargetCompatibility();
    if (targetLevel != null) {
        CompilerConfiguration configuration = CompilerConfiguration.getInstance(project);
        configuration.setBytecodeTargetLevel(module, targetLevel);
    }
}
Also used : CompilerConfiguration(com.intellij.compiler.CompilerConfiguration)

Example 9 with CompilerConfiguration

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

the class MavenCompilerConfigurer method configure.

@Override
public void configure(@NotNull MavenProject mavenProject, @NotNull Project project, @Nullable Module module) {
    if (module == null)
        return;
    CompilerConfiguration configuration = CompilerConfiguration.getInstance(project);
    if (!Boolean.TRUE.equals(module.getUserData(IGNORE_MAVEN_COMPILER_TARGET_KEY))) {
        String targetLevel = mavenProject.getTargetLevel();
        // default source and target settings of maven-compiler-plugin is 1.5, see details at http://maven.apache.org/plugins/maven-compiler-plugin
        configuration.setBytecodeTargetLevel(module, ObjectUtils.notNull(targetLevel, "1.5"));
    }
    module.putUserData(IGNORE_MAVEN_COMPILER_TARGET_KEY, Boolean.FALSE);
    // Exclude src/main/archetype-resources
    VirtualFile dir = VfsUtil.findRelativeFile(mavenProject.getDirectoryFile(), "src", "main", "resources", "archetype-resources");
    if (dir != null && !configuration.isExcludedFromCompilation(dir)) {
        ExcludesConfiguration cfg = configuration.getExcludedEntriesConfiguration();
        cfg.addExcludeEntryDescription(new ExcludeEntryDescription(dir, true, false, project));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExcludesConfiguration(com.intellij.openapi.compiler.options.ExcludesConfiguration) ExcludeEntryDescription(com.intellij.openapi.compiler.options.ExcludeEntryDescription) CompilerConfiguration(com.intellij.compiler.CompilerConfiguration)

Example 10 with CompilerConfiguration

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

the class TypeCustomizerInspection method buildVisitor.

@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
    return new BaseInspectionVisitor() {

        @Override
        public void visitFile(@NotNull GroovyFileBase file) {
            CompilerConfiguration configuration = CompilerConfiguration.getInstance(file.getProject());
            if (configuration != null && !configuration.isResourceFile(file.getVirtualFile()) && fileSeemsToBeTypeCustomizer(file)) {
                final LocalQuickFix[] fixes = { new AddToResourceFix(file) };
                final String message = GroovyInspectionBundle.message("type.customizer.is.not.marked.as.a.resource.file");
                registerError(file, message, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
            }
        }
    };
}
Also used : GroovyFileBase(org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase) BaseInspectionVisitor(org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor) CompilerConfiguration(com.intellij.compiler.CompilerConfiguration) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

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