Search in sources :

Example 1 with JpsTypedModuleSourceRoot

use of org.jetbrains.jps.model.module.JpsTypedModuleSourceRoot in project intellij-community by JetBrains.

the class ModuleBuildTarget method computeRootDescriptors.

@NotNull
@Override
public List<JavaSourceRootDescriptor> computeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
    List<JavaSourceRootDescriptor> roots = new ArrayList<>();
    JavaSourceRootType type = isTests() ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE;
    Iterable<ExcludedJavaSourceRootProvider> excludedRootProviders = JpsServiceManager.getInstance().getExtensions(ExcludedJavaSourceRootProvider.class);
    final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(myModule.getProject());
    roots_loop: for (JpsTypedModuleSourceRoot<JavaSourceRootProperties> sourceRoot : myModule.getSourceRoots(type)) {
        if (index.isExcludedFromModule(sourceRoot.getFile(), myModule)) {
            continue;
        }
        for (ExcludedJavaSourceRootProvider provider : excludedRootProviders) {
            if (provider.isExcludedFromCompilation(myModule, sourceRoot)) {
                continue roots_loop;
            }
        }
        final String packagePrefix = sourceRoot.getProperties().getPackagePrefix();
        // consider annotation processors output for generated sources, if contained under some source root
        Set<File> excludes = computeRootExcludes(sourceRoot.getFile(), index);
        final ProcessorConfigProfile profile = compilerConfig.getAnnotationProcessingProfile(myModule);
        if (profile.isEnabled()) {
            final File outputDir = ProjectPaths.getAnnotationProcessorGeneratedSourcesOutputDir(myModule, JavaSourceRootType.TEST_SOURCE == sourceRoot.getRootType(), profile);
            if (outputDir != null && FileUtil.isAncestor(sourceRoot.getFile(), outputDir, true)) {
                excludes = ContainerUtil.newTroveSet(FileUtil.FILE_HASHING_STRATEGY, excludes);
                excludes.add(outputDir);
            }
        }
        roots.add(new JavaSourceRootDescriptor(sourceRoot.getFile(), this, false, false, packagePrefix, excludes));
    }
    return roots;
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) THashSet(gnu.trove.THashSet) Set(java.util.Set) ExcludedJavaSourceRootProvider(org.jetbrains.jps.builders.java.ExcludedJavaSourceRootProvider) JpsTypedModuleSourceRoot(org.jetbrains.jps.model.module.JpsTypedModuleSourceRoot) ArrayList(java.util.ArrayList) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JpsTypedModuleSourceRoot

use of org.jetbrains.jps.model.module.JpsTypedModuleSourceRoot 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)

Aggregations

File (java.io.File)2 JpsTypedModuleSourceRoot (org.jetbrains.jps.model.module.JpsTypedModuleSourceRoot)2 Ref (com.intellij.openapi.util.Ref)1 THashSet (gnu.trove.THashSet)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 NotNull (org.jetbrains.annotations.NotNull)1 ExcludedJavaSourceRootProvider (org.jetbrains.jps.builders.java.ExcludedJavaSourceRootProvider)1 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)1 JpsCompilerExcludes (org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes)1 JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)1 ProcessorConfigProfile (org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile)1