Search in sources :

Example 6 with AbstractExternalSystemLocalSettings

use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings in project intellij-community by JetBrains.

the class ToolWindowModuleService method processData.

@Override
protected void processData(@NotNull final Collection<DataNode<ModuleData>> nodes, @NotNull Project project) {
    if (nodes.isEmpty()) {
        return;
    }
    ProjectSystemId externalSystemId = nodes.iterator().next().getData().getOwner();
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
    assert manager != null;
    final MultiMap<DataNode<ProjectData>, DataNode<ModuleData>> grouped = ExternalSystemApiUtil.groupBy(nodes, ProjectKeys.PROJECT);
    Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> data = ContainerUtilRt.newHashMap();
    for (Map.Entry<DataNode<ProjectData>, Collection<DataNode<ModuleData>>> entry : grouped.entrySet()) {
        data.put(ExternalProjectPojo.from(entry.getKey().getData()), ContainerUtilRt.map2List(entry.getValue(), MAPPER));
    }
    AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
    Set<String> pathsToForget = detectRenamedProjects(data, settings.getAvailableProjects());
    if (!pathsToForget.isEmpty()) {
        settings.forgetExternalProjects(pathsToForget);
    }
    Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> projects = ContainerUtilRt.newHashMap(settings.getAvailableProjects());
    projects.putAll(data);
    settings.setAvailableProjects(projects);
}
Also used : AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) MultiMap(com.intellij.util.containers.MultiMap)

Example 7 with AbstractExternalSystemLocalSettings

use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings in project intellij-community by JetBrains.

the class BuildClasspathModuleGradleDataService method importData.

@Override
public void importData(@NotNull final Collection<DataNode<BuildScriptClasspathData>> toImport, @Nullable final ProjectData projectData, @NotNull final Project project, @NotNull final IdeModifiableModelsProvider modelsProvider) {
    if (projectData == null || toImport.isEmpty()) {
        return;
    }
    final GradleInstallationManager gradleInstallationManager = ServiceManager.getService(GradleInstallationManager.class);
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(GradleConstants.SYSTEM_ID);
    assert manager != null;
    AbstractExternalSystemLocalSettings localSettings = manager.getLocalSettingsProvider().fun(project);
    final String linkedExternalProjectPath = projectData.getLinkedExternalProjectPath();
    final File gradleHomeDir = toImport.iterator().next().getData().getGradleHomeDir();
    final GradleLocalSettings gradleLocalSettings = GradleLocalSettings.getInstance(project);
    if (gradleHomeDir != null) {
        gradleLocalSettings.setGradleHome(linkedExternalProjectPath, gradleHomeDir.getPath());
    }
    final GradleProjectSettings settings = GradleSettings.getInstance(project).getLinkedProjectSettings(linkedExternalProjectPath);
    final NotNullLazyValue<Set<String>> externalProjectGradleSdkLibs = new NotNullLazyValue<Set<String>>() {

        @NotNull
        @Override
        protected Set<String> compute() {
            final Set<String> gradleSdkLibraries = ContainerUtil.newLinkedHashSet();
            File gradleHome = gradleInstallationManager.getGradleHome(project, linkedExternalProjectPath);
            if (gradleHome != null && gradleHome.isDirectory()) {
                final Collection<File> libraries = gradleInstallationManager.getClassRoots(project, linkedExternalProjectPath);
                if (libraries != null) {
                    for (File library : libraries) {
                        gradleSdkLibraries.add(FileUtil.toCanonicalPath(library.getPath()));
                    }
                }
            }
            return gradleSdkLibraries;
        }
    };
    final NotNullLazyValue<Set<String>> buildSrcProjectsRoots = new NotNullLazyValue<Set<String>>() {

        @NotNull
        @Override
        protected Set<String> compute() {
            Set<String> result = new LinkedHashSet<>();
            //// add main java root of buildSrc project
            result.add(linkedExternalProjectPath + "/buildSrc/src/main/java");
            //// add main groovy root of buildSrc project
            result.add(linkedExternalProjectPath + "/buildSrc/src/main/groovy");
            for (Module module : modelsProvider.getModules(projectData)) {
                final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
                if (projectPath != null && StringUtil.startsWith(projectPath, linkedExternalProjectPath + "/buildSrc")) {
                    final List<String> sourceRoots = ContainerUtil.map(modelsProvider.getSourceRoots(module, false), VirtualFile::getPath);
                    result.addAll(sourceRoots);
                }
            }
            return result;
        }
    };
    final Map<String, ExternalProjectBuildClasspathPojo> localProjectBuildClasspath = ContainerUtil.newHashMap(localSettings.getProjectBuildClasspath());
    for (final DataNode<BuildScriptClasspathData> node : toImport) {
        if (GradleConstants.SYSTEM_ID.equals(node.getData().getOwner())) {
            DataNode<ModuleData> moduleDataNode = ExternalSystemApiUtil.findParent(node, ProjectKeys.MODULE);
            if (moduleDataNode == null)
                continue;
            String externalModulePath = moduleDataNode.getData().getLinkedExternalProjectPath();
            if (settings == null || settings.getDistributionType() == null) {
                LOG.warn("Gradle SDK distribution type was not configured for the project at " + linkedExternalProjectPath);
            }
            final Set<String> buildClasspath = ContainerUtil.newLinkedHashSet();
            BuildScriptClasspathData buildScriptClasspathData = node.getData();
            for (BuildScriptClasspathData.ClasspathEntry classpathEntry : buildScriptClasspathData.getClasspathEntries()) {
                for (String path : classpathEntry.getSourcesFile()) {
                    buildClasspath.add(FileUtil.toCanonicalPath(path));
                }
                for (String path : classpathEntry.getClassesFile()) {
                    buildClasspath.add(FileUtil.toCanonicalPath(path));
                }
            }
            ExternalProjectBuildClasspathPojo projectBuildClasspathPojo = localProjectBuildClasspath.get(linkedExternalProjectPath);
            if (projectBuildClasspathPojo == null) {
                projectBuildClasspathPojo = new ExternalProjectBuildClasspathPojo(moduleDataNode.getData().getExternalName(), ContainerUtil.newArrayList(), ContainerUtil.newHashMap());
                localProjectBuildClasspath.put(linkedExternalProjectPath, projectBuildClasspathPojo);
            }
            List<String> projectBuildClasspath = ContainerUtil.newArrayList(externalProjectGradleSdkLibs.getValue());
            projectBuildClasspath.addAll(buildSrcProjectsRoots.getValue());
            projectBuildClasspathPojo.setProjectBuildClasspath(projectBuildClasspath);
            projectBuildClasspathPojo.getModulesBuildClasspath().put(externalModulePath, new ExternalModuleBuildClasspathPojo(externalModulePath, ContainerUtil.newArrayList(buildClasspath)));
        }
    }
    localSettings.setProjectBuildClasspath(localProjectBuildClasspath);
    if (!project.isDisposed()) {
        GradleBuildClasspathManager.getInstance(project).reload();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) NotNullLazyValue(com.intellij.openapi.util.NotNullLazyValue) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) GradleLocalSettings(org.jetbrains.plugins.gradle.settings.GradleLocalSettings) GradleInstallationManager(org.jetbrains.plugins.gradle.service.GradleInstallationManager) ExternalProjectBuildClasspathPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectBuildClasspathPojo) ExternalModuleBuildClasspathPojo(com.intellij.openapi.externalSystem.model.project.ExternalModuleBuildClasspathPojo) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) BuildScriptClasspathData(org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 8 with AbstractExternalSystemLocalSettings

use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings in project intellij-community by JetBrains.

the class GradleBuildClasspathManager method reload.

public void reload() {
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(GradleConstants.SYSTEM_ID);
    assert manager != null;
    AbstractExternalSystemLocalSettings localSettings = manager.getLocalSettingsProvider().fun(myProject);
    Map<String, List<VirtualFile>> /*module build classpath*/
    map = ContainerUtil.newHashMap();
    final JarFileSystem jarFileSystem = JarFileSystem.getInstance();
    for (final ExternalProjectBuildClasspathPojo projectBuildClasspathPojo : localSettings.getProjectBuildClasspath().values()) {
        final List<VirtualFile> projectBuildClasspath = ContainerUtil.newArrayList();
        for (String path : projectBuildClasspathPojo.getProjectBuildClasspath()) {
            final VirtualFile virtualFile = ExternalSystemUtil.findLocalFileByPath(path);
            ContainerUtil.addIfNotNull(projectBuildClasspath, virtualFile == null || virtualFile.isDirectory() ? virtualFile : jarFileSystem.getJarRootForLocalFile(virtualFile));
        }
        for (final ExternalModuleBuildClasspathPojo moduleBuildClasspathPojo : projectBuildClasspathPojo.getModulesBuildClasspath().values()) {
            final List<VirtualFile> moduleBuildClasspath = ContainerUtil.newArrayList(projectBuildClasspath);
            for (String path : moduleBuildClasspathPojo.getEntries()) {
                final VirtualFile virtualFile = ExternalSystemUtil.findLocalFileByPath(path);
                ContainerUtil.addIfNotNull(moduleBuildClasspath, virtualFile == null || virtualFile.isDirectory() ? virtualFile : jarFileSystem.getJarRootForLocalFile(virtualFile));
            }
            map.put(moduleBuildClasspathPojo.getPath(), moduleBuildClasspath);
        }
    }
    myClasspathMap.set(map);
    Set<VirtualFile> set = new LinkedHashSet<>();
    for (List<VirtualFile> virtualFiles : myClasspathMap.get().values()) {
        set.addAll(virtualFiles);
    }
    allFilesCache = ContainerUtil.newArrayList(set);
    Extensions.findExtension(PsiElementFinder.EP_NAME, myProject, GradleClassFinder.class).clearCache();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) GradleClassFinder(org.jetbrains.plugins.gradle.config.GradleClassFinder) ExternalProjectBuildClasspathPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectBuildClasspathPojo) ExternalModuleBuildClasspathPojo(com.intellij.openapi.externalSystem.model.project.ExternalModuleBuildClasspathPojo)

Aggregations

AbstractExternalSystemLocalSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings)8 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)5 Collection (java.util.Collection)5 Map (java.util.Map)4 MultiMap (com.intellij.util.containers.MultiMap)3 ExternalSystemUiAware (com.intellij.openapi.externalSystem.ExternalSystemUiAware)2 DataNode (com.intellij.openapi.externalSystem.model.DataNode)2 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)2 ExternalModuleBuildClasspathPojo (com.intellij.openapi.externalSystem.model.project.ExternalModuleBuildClasspathPojo)2 ExternalProjectBuildClasspathPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectBuildClasspathPojo)2 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 NotNull (org.jetbrains.annotations.NotNull)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)1 ExternalConfigPathAware (com.intellij.openapi.externalSystem.model.project.ExternalConfigPathAware)1 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)1 TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)1 ExternalSystemTasksTree (com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemTasksTree)1 ExternalSystemTasksTreeModel (com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemTasksTreeModel)1