Search in sources :

Example 6 with JpsCompilerExcludes

use of org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes in project intellij-plugins by JetBrains.

the class CompilerConfigGeneratorRt method addLibClasses.

private void addLibClasses(final Element rootElement) throws IOException {
    final JpsCompilerExcludes excludes = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(myModule.getProject()).getCompilerExcludes();
    final Ref<Boolean> noClasses = new Ref<>(true);
    for (JpsTypedModuleSourceRoot srcRoot : myModule.getSourceRoots(JavaSourceRootType.SOURCE)) {
        final File srcFolder = JpsPathUtil.urlToFile(srcRoot.getUrl());
        if (srcFolder.isDirectory()) {
            processFilesRecursively(srcFolder, file -> {
                if (myProjectDescriptor.getIgnoredFileIndex().isIgnored(file.getName()))
                    return false;
                if (file.isDirectory())
                    return true;
                if (!FlexCommonUtils.isSourceFile(file.getName()))
                    return true;
                if (excludes.isExcluded(file))
                    return true;
                String packageRelativePath = FileUtil.getRelativePath(srcFolder, file.getParentFile());
                assert packageRelativePath != null : srcFolder.getPath() + ": " + file.getPath();
                if (packageRelativePath.equals("."))
                    packageRelativePath = "";
                final String packageName = packageRelativePath.replace(File.separatorChar, '.');
                final String qName = StringUtil.getQualifiedName(packageName, FileUtil.getNameWithoutExtension(file));
                if (isSourceFileWithPublicDeclaration(file)) {
                    addOption(rootElement, CompilerOptionInfo.INCLUDE_CLASSES_INFO, qName);
                    noClasses.set(false);
                }
                return true;
            });
        }
    }
    if (noClasses.get() && myBC.getCompilerOptions().getFilesToIncludeInSWC().isEmpty() && !Utils.IS_TEST_MODE) {
        throw new IOException(FlexCommonBundle.message("nothing.to.compile.in.library", myModule.getName(), myBC.getName()));
    }
}
Also used : JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) Ref(com.intellij.openapi.util.Ref) JpsTypedModuleSourceRoot(org.jetbrains.jps.model.module.JpsTypedModuleSourceRoot) IOException(java.io.IOException) File(java.io.File)

Example 7 with JpsCompilerExcludes

use of org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes in project intellij-community by JetBrains.

the class ResourceRootDescriptor method createFileFilter.

@NotNull
@Override
public FileFilter createFileFilter() {
    final JpsProject project = getTarget().getModule().getProject();
    final JpsCompilerExcludes excludes = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project).getCompilerExcludes();
    return file -> !excludes.isExcluded(file);
}
Also used : JpsProject(org.jetbrains.jps.model.JpsProject) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) FileFilter(java.io.FileFilter) ResourcesTarget(org.jetbrains.jps.incremental.ResourcesTarget) Set(java.util.Set) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) FileUtil(com.intellij.openapi.util.io.FileUtil) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) NotNull(org.jetbrains.annotations.NotNull) File(java.io.File) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) JpsProject(org.jetbrains.jps.model.JpsProject) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with JpsCompilerExcludes

use of org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes in project intellij-community by JetBrains.

the class JpsJavaExtensionServiceImpl method getJavaModuleIndex.

@NotNull
@Override
public JavaModuleIndex getJavaModuleIndex(@NotNull JpsProject project, @NotNull File storageRoot) {
    if (myModuleIndex == null) {
        JpsCompilerExcludes excludes = getOrCreateCompilerConfiguration(project).getCompilerExcludes();
        myModuleIndex = JavaModuleIndexImpl.load(storageRoot, excludes);
    }
    return myModuleIndex;
}
Also used : JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with JpsCompilerExcludes

use of org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes in project intellij-community by JetBrains.

the class FormsBindingManager method build.

@Override
public ExitCode build(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
    ExitCode exitCode = ExitCode.NOTHING_DONE;
    final JpsProject project = context.getProjectDescriptor().getProject();
    final JpsUiDesignerConfiguration config = JpsUiDesignerExtensionService.getInstance().getOrCreateUiDesignerConfiguration(project);
    if (!config.isInstrumentClasses() && !config.isCopyFormsRuntimeToOutput()) {
        return exitCode;
    }
    final Map<File, ModuleBuildTarget> filesToCompile = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    final Map<File, ModuleBuildTarget> formsToCompile = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    final Map<File, Collection<File>> srcToForms = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    if (!JavaBuilderUtil.isForcedRecompilationAllJavaModules(context) && config.isInstrumentClasses() && FORCE_FORMS_REBUILD_FLAG.get(context, Boolean.FALSE)) {
        // force compilation of all forms, but only once per chunk
        if (!FORMS_REBUILD_FORCED.get(context, Boolean.FALSE)) {
            FORMS_REBUILD_FORCED.set(context, Boolean.TRUE);
            FSOperations.markDirty(context, CompilationRound.CURRENT, chunk, FORM_SOURCES_FILTER);
        }
    }
    dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

        public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor descriptor) throws IOException {
            if (JAVA_SOURCES_FILTER.accept(file)) {
                filesToCompile.put(file, target);
            } else if (FORM_SOURCES_FILTER.accept(file)) {
                formsToCompile.put(file, target);
            }
            return true;
        }
    });
    if (config.isInstrumentClasses()) {
        final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
        final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
        // force compilation of bound source file if the form is dirty
        for (final Map.Entry<File, ModuleBuildTarget> entry : formsToCompile.entrySet()) {
            final File form = entry.getKey();
            final ModuleBuildTarget target = entry.getValue();
            final Collection<File> sources = findBoundSourceCandidates(context, target, form);
            for (File boundSource : sources) {
                if (!excludes.isExcluded(boundSource)) {
                    addBinding(boundSource, form, srcToForms);
                    FSOperations.markDirty(context, CompilationRound.CURRENT, boundSource);
                    filesToCompile.put(boundSource, target);
                    exitCode = ExitCode.OK;
                }
            }
        }
        // form should be considered dirty if the class it is bound to is dirty
        final OneToManyPathsMapping sourceToFormMap = context.getProjectDescriptor().dataManager.getSourceToFormMap();
        for (Map.Entry<File, ModuleBuildTarget> entry : filesToCompile.entrySet()) {
            final File srcFile = entry.getKey();
            final ModuleBuildTarget target = entry.getValue();
            final Collection<String> boundForms = sourceToFormMap.getState(srcFile.getPath());
            if (boundForms != null) {
                for (String formPath : boundForms) {
                    final File formFile = new File(formPath);
                    if (!excludes.isExcluded(formFile) && formFile.exists()) {
                        addBinding(srcFile, formFile, srcToForms);
                        FSOperations.markDirty(context, CompilationRound.CURRENT, formFile);
                        formsToCompile.put(formFile, target);
                        exitCode = ExitCode.OK;
                    }
                }
            }
        }
    }
    FORMS_TO_COMPILE.set(context, srcToForms.isEmpty() ? null : srcToForms);
    if (config.isCopyFormsRuntimeToOutput() && containsValidForm(formsToCompile.keySet())) {
        for (ModuleBuildTarget target : chunk.getTargets()) {
            if (!target.isTests()) {
                final File outputDir = target.getOutputDir();
                if (outputDir != null) {
                    final String outputRoot = FileUtil.toSystemIndependentName(outputDir.getPath());
                    final List<File> generatedFiles = CopyResourcesUtil.copyFormsRuntime(outputRoot, false);
                    if (!generatedFiles.isEmpty()) {
                        exitCode = ExitCode.OK;
                        // now inform others about files just copied
                        for (File file : generatedFiles) {
                            outputConsumer.registerOutputFile(target, file, Collections.<String>emptyList());
                        }
                    }
                }
            }
        }
    }
    return exitCode;
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) OneToManyPathsMapping(org.jetbrains.jps.incremental.storage.OneToManyPathsMapping) IOException(java.io.IOException) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) THashMap(gnu.trove.THashMap) JpsUiDesignerConfiguration(org.jetbrains.jps.uiDesigner.model.JpsUiDesignerConfiguration) JpsProject(org.jetbrains.jps.model.JpsProject) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) THashMap(gnu.trove.THashMap)

Example 10 with JpsCompilerExcludes

use of org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes in project intellij-plugins by JetBrains.

the class FlexResourceBuilder method build.

public void build(@NotNull final FlexResourceBuildTarget target, @NotNull final DirtyFilesHolder<BuildRootDescriptor, FlexResourceBuildTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
    final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(target.getModule().getProject());
    final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
    try {
        holder.processDirtyFiles(new FileProcessor<BuildRootDescriptor, FlexResourceBuildTarget>() {

            public boolean apply(final FlexResourceBuildTarget target, final File file, final BuildRootDescriptor root) throws IOException {
                if (excludes.isExcluded(file))
                    return true;
                final String relativePath = FileUtil.toSystemIndependentName(FileUtil.getRelativePath(root.getRootFile(), file));
                if (target.isTests()) {
                    if (!FlexCommonUtils.isSourceFile(file.getName())) {
                        final String outputRootUrl = JpsJavaExtensionService.getInstance().getOutputUrl(target.getModule(), target.isTests());
                        if (outputRootUrl == null)
                            return true;
                        final String targetPath = JpsPathUtil.urlToPath(outputRootUrl) + '/' + relativePath;
                        context.processMessage(new ProgressMessage("Copying " + file.getPath()));
                        copyResource(context, file, Collections.singleton(targetPath), outputConsumer);
                    }
                } else {
                    final Collection<String> targetPaths = new ArrayList<>();
                    for (JpsFlexBuildConfiguration bc : target.getModule().getProperties().getBuildConfigurations()) {
                        if (bc.isSkipCompile() || !FlexCommonUtils.canHaveResourceFiles(bc.getNature()) || bc.getCompilerOptions().getResourceFilesMode() == JpsFlexCompilerOptions.ResourceFilesMode.None) {
                            continue;
                        }
                        final JpsFlexCompilerOptions.ResourceFilesMode mode = bc.getCompilerOptions().getResourceFilesMode();
                        if (mode == JpsFlexCompilerOptions.ResourceFilesMode.All && !FlexCommonUtils.isSourceFile(file.getName()) || mode == JpsFlexCompilerOptions.ResourceFilesMode.ResourcePatterns && configuration.isResourceFile(file, root.getRootFile())) {
                            final String outputFolder = PathUtilRt.getParentPath(bc.getActualOutputFilePath());
                            targetPaths.add(outputFolder + "/" + relativePath);
                        }
                    }
                    if (!targetPaths.isEmpty()) {
                        context.processMessage(new ProgressMessage("Copying " + file.getPath()));
                        copyResource(context, file, targetPaths, outputConsumer);
                    }
                }
                return true;
            }
        });
    } catch (Exception e) {
        throw new ProjectBuildException(e.getMessage(), e);
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) IOException(java.io.IOException) FlexResourceBuildTarget(com.intellij.flex.build.FlexResourceBuildTarget) IOException(java.io.IOException) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) Collection(java.util.Collection) JpsFlexBuildConfiguration(com.intellij.flex.model.bc.JpsFlexBuildConfiguration) File(java.io.File)

Aggregations

JpsCompilerExcludes (org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes)10 File (java.io.File)8 NotNull (org.jetbrains.annotations.NotNull)5 JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)4 FileFilter (java.io.FileFilter)3 IOException (java.io.IOException)3 Set (java.util.Set)3 BuildRootDescriptor (org.jetbrains.jps.builders.BuildRootDescriptor)3 JpsProject (org.jetbrains.jps.model.JpsProject)3 JpsJavaExtensionService (org.jetbrains.jps.model.java.JpsJavaExtensionService)3 FileUtil (com.intellij.openapi.util.io.FileUtil)2 THashMap (gnu.trove.THashMap)2 ResourcesTarget (org.jetbrains.jps.incremental.ResourcesTarget)2 FlexResourceBuildTarget (com.intellij.flex.build.FlexResourceBuildTarget)1 JpsFlexBuildConfiguration (com.intellij.flex.model.bc.JpsFlexBuildConfiguration)1 Ref (com.intellij.openapi.util.Ref)1 Collection (java.util.Collection)1 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)1 BuilderRegistry (org.jetbrains.jps.incremental.BuilderRegistry)1 ModuleBuildTarget (org.jetbrains.jps.incremental.ModuleBuildTarget)1