Search in sources :

Example 11 with JpsModuleSourceRoot

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

the class IdeaJdk method setupSdkPathsFromIDEAProject.

private static void setupSdkPathsFromIDEAProject(Sdk sdk, SdkModificator sdkModificator, SdkModel sdkModel) throws IOException {
    ProgressIndicator indicator = ObjectUtils.assertNotNull(ProgressManager.getInstance().getProgressIndicator());
    String sdkHome = ObjectUtils.notNull(sdk.getHomePath());
    JpsModel model = JpsSerializationManager.getInstance().loadModel(sdkHome, PathManager.getOptionsPath());
    JpsSdkReference<JpsDummyElement> sdkRef = model.getProject().getSdkReferencesTable().getSdkReference(JpsJavaSdkType.INSTANCE);
    String sdkName = sdkRef == null ? null : sdkRef.getSdkName();
    Sdk internalJava = sdkModel.findSdk(sdkName);
    if (internalJava != null && isValidInternalJdk(sdk, internalJava)) {
        setInternalJdk(sdk, sdkModificator, internalJava);
    }
    Set<VirtualFile> addedRoots = ContainerUtil.newTroveSet();
    VirtualFileManager vfsManager = VirtualFileManager.getInstance();
    JpsJavaExtensionService javaService = JpsJavaExtensionService.getInstance();
    boolean isUltimate = vfsManager.findFileByUrl(VfsUtilCore.pathToUrl(sdkHome + "/ultimate/ultimate-resources")) != null;
    Set<String> suppressedModules = ContainerUtil.newTroveSet("jps-plugin-system");
    Set<String> ultimateModules = ContainerUtil.newTroveSet("platform-ultimate", "ultimate-resources", "ultimate-verifier", "diagram-api", "diagram-impl", "uml-plugin");
    List<JpsModule> modules = JBIterable.from(model.getProject().getModules()).filter(o -> {
        if (suppressedModules.contains(o.getName()))
            return false;
        if (o.getName().endsWith("-ide"))
            return false;
        String contentUrl = ContainerUtil.getFirstItem(o.getContentRootsList().getUrls());
        if (contentUrl == null)
            return true;
        return !isUltimate || contentUrl.contains("/community/") || ultimateModules.contains(o.getName());
    }).toList();
    indicator.setIndeterminate(false);
    double delta = 1 / (2 * Math.max(0.5, modules.size()));
    for (JpsModule o : modules) {
        indicator.setFraction(indicator.getFraction() + delta);
        for (JpsDependencyElement dep : o.getDependenciesList().getDependencies()) {
            ProgressManager.checkCanceled();
            JpsLibrary library = dep instanceof JpsLibraryDependency ? ((JpsLibraryDependency) dep).getLibrary() : null;
            JpsLibraryType<?> libraryType = library == null ? null : library.getType();
            if (!(libraryType instanceof JpsJavaLibraryType))
                continue;
            JpsJavaDependencyExtension extension = javaService.getDependencyExtension(dep);
            if (extension == null)
                continue;
            // do not check extension.getScope(), plugin projects need tests too
            for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.COMPILED)) {
                VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
                if (root == null || !addedRoots.add(root))
                    continue;
                sdkModificator.addRoot(root, OrderRootType.CLASSES);
            }
            for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.SOURCES)) {
                VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
                if (root == null || !addedRoots.add(root))
                    continue;
                sdkModificator.addRoot(root, OrderRootType.SOURCES);
            }
        }
    }
    for (JpsModule o : modules) {
        indicator.setFraction(indicator.getFraction() + delta);
        String outputUrl = javaService.getOutputUrl(o, false);
        VirtualFile outputRoot = outputUrl == null ? null : vfsManager.findFileByUrl(outputUrl);
        if (outputRoot == null)
            continue;
        sdkModificator.addRoot(outputRoot, OrderRootType.CLASSES);
        for (JpsModuleSourceRoot jps : o.getSourceRoots()) {
            ProgressManager.checkCanceled();
            VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
            if (root == null || !addedRoots.add(root))
                continue;
            sdkModificator.addRoot(root, OrderRootType.SOURCES);
        }
    }
    indicator.setFraction(1.0);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Arrays(java.util.Arrays) JBIterable(com.intellij.util.containers.JBIterable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JpsJavaLibraryType(org.jetbrains.jps.model.java.JpsJavaLibraryType) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) Messages(com.intellij.openapi.ui.Messages) ZipFile(java.util.zip.ZipFile) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) ZipEntry(java.util.zip.ZipEntry) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) ProgressManager(com.intellij.openapi.progress.ProgressManager) LanguageLevel(com.intellij.pom.java.LanguageLevel) OrderRootType(com.intellij.openapi.roots.OrderRootType) Set(java.util.Set) JpsLibraryDependency(org.jetbrains.jps.model.module.JpsLibraryDependency) JpsJavaDependencyExtension(org.jetbrains.jps.model.java.JpsJavaDependencyExtension) JpsModule(org.jetbrains.jps.model.module.JpsModule) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) ApplicationStarter(com.intellij.openapi.application.ApplicationStarter) JavaDependentSdkType(com.intellij.openapi.projectRoots.impl.JavaDependentSdkType) JpsSerializationManager(org.jetbrains.jps.model.serialization.JpsSerializationManager) WriteExternalException(com.intellij.openapi.util.WriteExternalException) NotNull(org.jetbrains.annotations.NotNull) DataInputStream(java.io.DataInputStream) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) ArrayUtil(com.intellij.util.ArrayUtil) JpsOrderRootType(org.jetbrains.jps.model.library.JpsOrderRootType) PathManager(com.intellij.openapi.application.PathManager) DevkitIcons(icons.DevkitIcons) NonNls(org.jetbrains.annotations.NonNls) InvalidDataException(com.intellij.openapi.util.InvalidDataException) ContainerUtil(com.intellij.util.containers.ContainerUtil) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) JpsLibraryType(org.jetbrains.jps.model.library.JpsLibraryType) ClsParsingUtil(com.intellij.psi.impl.compiled.ClsParsingUtil) ArrayList(java.util.ArrayList) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) JpsSdkReference(org.jetbrains.jps.model.library.sdk.JpsSdkReference) com.intellij.openapi.projectRoots(com.intellij.openapi.projectRoots) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) JpsModel(org.jetbrains.jps.model.JpsModel) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) JpsJavaSdkType(org.jetbrains.jps.model.java.JpsJavaSdkType) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot) IOException(java.io.IOException) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) DevKitBundle(org.jetbrains.idea.devkit.DevKitBundle) AnnotationOrderRootType(com.intellij.openapi.roots.AnnotationOrderRootType) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) ObjectUtils(com.intellij.util.ObjectUtils) Element(org.jdom.Element) javax.swing(javax.swing) JpsLibraryDependency(org.jetbrains.jps.model.module.JpsLibraryDependency) JpsModel(org.jetbrains.jps.model.JpsModel) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) JpsJavaLibraryType(org.jetbrains.jps.model.java.JpsJavaLibraryType) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) JpsJavaDependencyExtension(org.jetbrains.jps.model.java.JpsJavaDependencyExtension) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot)

Example 12 with JpsModuleSourceRoot

use of org.jetbrains.jps.model.module.JpsModuleSourceRoot in project kotlin by JetBrains.

the class KotlinSourceFileCollector method getAllKotlinSourceFiles.

@NotNull
public static List<File> getAllKotlinSourceFiles(@NotNull ModuleBuildTarget target) {
    final List<File> moduleExcludes = ContainerUtil.map(target.getModule().getExcludeRootsList().getUrls(), new Function<String, File>() {

        @Override
        public File fun(String url) {
            return JpsPathUtil.urlToFile(url);
        }
    });
    final JpsCompilerExcludes compilerExcludes = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(target.getModule().getProject()).getCompilerExcludes();
    final List<File> result = ContainerUtil.newArrayList();
    for (JpsModuleSourceRoot sourceRoot : getRelevantSourceRoots(target)) {
        FileUtil.processFilesRecursively(sourceRoot.getFile(), new Processor<File>() {

            @Override
            public boolean process(File file) {
                if (compilerExcludes.isExcluded(file))
                    return true;
                if (file.isFile() && isKotlinSourceFile(file)) {
                    result.add(file);
                }
                return true;
            }
        }, new Processor<File>() {

            @Override
            public boolean process(final File dir) {
                return ContainerUtil.find(moduleExcludes, new Condition<File>() {

                    @Override
                    public boolean value(File exclude) {
                        return FileUtil.filesEqual(exclude, dir);
                    }
                }) == null;
            }
        });
    }
    return result;
}
Also used : JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with JpsModuleSourceRoot

use of org.jetbrains.jps.model.module.JpsModuleSourceRoot in project android by JetBrains.

the class ContentEntriesSetup method addSourceFolder.

private static void addSourceFolder(@NotNull ContentEntry contentEntry, @NotNull File folderPath, @NotNull JpsModuleSourceRootType type, boolean generated) {
    String url = pathToIdeaUrl(folderPath);
    SourceFolder sourceFolder = contentEntry.addSourceFolder(url, type);
    if (generated) {
        JpsModuleSourceRoot sourceRoot = sourceFolder.getJpsElement();
        JpsElement properties = sourceRoot.getProperties();
        if (properties instanceof JavaSourceRootProperties) {
            ((JavaSourceRootProperties) properties).setForGeneratedSources(true);
        }
    }
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) JpsElement(org.jetbrains.jps.model.JpsElement) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties)

Example 14 with JpsModuleSourceRoot

use of org.jetbrains.jps.model.module.JpsModuleSourceRoot in project intellij-plugins by JetBrains.

the class CompilerConfigGeneratorRt method getCustomLinkReportPath.

@Nullable
private static String getCustomLinkReportPath(final JpsFlexBuildConfiguration rlmBC) {
    final JpsFlexBuildConfiguration appBC = rlmBC.getModule().getProperties().findConfigurationByName(rlmBC.getName());
    if (appBC != null) {
        final List<String> linkReports = FlexCommonUtils.getOptionValues(appBC.getCompilerOptions().getAdditionalOptions(), "link-report");
        if (!linkReports.isEmpty()) {
            final String path = linkReports.get(0);
            if (new File(path).isFile())
                return path;
            final String absPath = FlexCommonUtils.getFlexCompilerWorkDirPath(appBC.getModule().getProject()) + "/" + path;
            if (new File(absPath).isFile())
                return absPath;
        } else {
            final String configFilePath = appBC.getCompilerOptions().getAdditionalConfigFilePath();
            if (!configFilePath.isEmpty()) {
                final File configFile = new File(configFilePath);
                if (configFile.isFile()) {
                    final String path = FlexCommonUtils.findXMLElement(configFile, "<flex-config><link-report>");
                    if (path != null) {
                        if (new File(path).isFile())
                            return path;
                        // I have no idea why Flex compiler treats path relative to source root for "link-report" option
                        for (JpsModuleSourceRoot srcRoot : appBC.getModule().getSourceRoots(JavaSourceRootType.SOURCE)) {
                            final String absPath = srcRoot.getFile().getPath() + "/" + path;
                            if (new File(absPath).isFile())
                                return absPath;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with JpsModuleSourceRoot

use of org.jetbrains.jps.model.module.JpsModuleSourceRoot in project intellij-plugins by JetBrains.

the class InfoFromConfigFile method getMainClassByPath.

private static String getMainClassByPath(final JpsModule module, final String mainClassPath, final String baseDir) {
    if (mainClassPath.isEmpty())
        return "unknown";
    File mainClassFile = new File(mainClassPath);
    if (!mainClassFile.isFile()) {
        mainClassFile = new File(baseDir + File.pathSeparator + mainClassPath);
    }
    if (!mainClassFile.isFile()) {
        return FileUtil.getNameWithoutExtension(FileUtil.getNameWithoutExtension(PathUtilRt.getFileName(mainClassPath)));
    }
    String mainClassCanonicalPath;
    try {
        mainClassCanonicalPath = FileUtil.toSystemIndependentName(mainClassFile.getCanonicalPath());
    } catch (IOException e) {
        mainClassCanonicalPath = FileUtil.toSystemIndependentName(mainClassFile.getPath());
    }
    for (JpsModuleSourceRoot sourceRoot : module.getSourceRoots()) {
        final String sourcePath = JpsPathUtil.urlToPath(sourceRoot.getUrl());
        if (FileUtil.isAncestor(sourcePath, mainClassCanonicalPath, true)) {
            final String relativePath = FileUtil.getRelativePath(sourcePath, mainClassCanonicalPath, '/');
            if (relativePath != null) {
                return FileUtil.getNameWithoutExtension(relativePath).replace("/", ".");
            }
        }
    }
    return FileUtil.getNameWithoutExtension(mainClassCanonicalPath);
}
Also used : JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) IOException(java.io.IOException) File(java.io.File)

Aggregations

JpsModuleSourceRoot (org.jetbrains.jps.model.module.JpsModuleSourceRoot)22 File (java.io.File)9 NotNull (org.jetbrains.annotations.NotNull)8 JpsModule (org.jetbrains.jps.model.module.JpsModule)4 ArrayList (java.util.ArrayList)3 JpsElement (org.jetbrains.jps.model.JpsElement)3 SourceFolder (com.intellij.openapi.roots.SourceFolder)2 JpsSourceFolder (com.intellij.project.model.impl.module.content.JpsSourceFolder)2 THashSet (gnu.trove.THashSet)2 Element (org.jdom.Element)2 JavaSourceRootProperties (org.jetbrains.jps.model.java.JavaSourceRootProperties)2 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)2 ApplicationStarter (com.intellij.openapi.application.ApplicationStarter)1 PathManager (com.intellij.openapi.application.PathManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 com.intellij.openapi.projectRoots (com.intellij.openapi.projectRoots)1 JavaDependentSdkType (com.intellij.openapi.projectRoots.impl.JavaDependentSdkType)1