Search in sources :

Example 16 with ExternalProjectSettings

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

the class ExternalModuleStructureExtension method disposeUIResources.

@Override
public void disposeUIResources() {
    try {
        if (isExternalSystemsInvolved) {
            assert myOrphanProjectsCandidates != null;
            assert myProject != null;
            if (myExternalProjectsToRestore != null) {
                for (Pair<ProjectSystemId, ExternalProjectSettings> settingsPair : myExternalProjectsToRestore.values()) {
                    AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(myProject, settingsPair.first);
                    String rootProjectPath = settingsPair.second.getExternalProjectPath();
                    if (settings.getLinkedProjectSettings(rootProjectPath) == null) {
                        //noinspection unchecked
                        settings.linkProject(settingsPair.second);
                    }
                    myOrphanProjectsCandidates.remove(rootProjectPath);
                }
            }
            ModulesConfigurator modulesConfigurator = getModulesConfigurator(myProject);
            if (modulesConfigurator != null) {
                for (Map.Entry<String, ProjectSystemId> entry : myOrphanProjectsCandidates.entrySet()) {
                    String rootProjectPath = entry.getKey();
                    if (StringUtil.isNotEmpty(rootProjectPath)) {
                        unlinkProject(myProject, entry.getValue(), rootProjectPath);
                    }
                }
            }
        }
    } catch (Throwable e) {
        LOG.warn(e);
    } finally {
        myProject = null;
        myExternalProjectsToRestore = null;
        myOrphanProjectsCandidates = null;
    }
}
Also used : AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) ModulesConfigurator(com.intellij.openapi.roots.ui.configuration.ModulesConfigurator) HashMap(java.util.HashMap) Map(java.util.Map) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)

Example 17 with ExternalProjectSettings

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

the class ExternalSystemProjectsWatcher method updateWatchedRoots.

private void updateWatchedRoots(boolean isProjectOpen) {
    List<String> pathsToWatch = new SmartList<>();
    myFilesPointers.clear();
    LocalFileSystem.getInstance().removeWatchedRoots(myWatchedRoots);
    Map<String, VirtualFilePointer> pointerMap = ContainerUtil.newHashMap();
    for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
        if (!(manager instanceof ExternalSystemAutoImportAware))
            continue;
        ExternalSystemAutoImportAware importAware = (ExternalSystemAutoImportAware) manager;
        for (ExternalProjectSettings settings : manager.getSettingsProvider().fun(myProject).getLinkedProjectsSettings()) {
            List<File> files = importAware.getAffectedExternalProjectFiles(settings.getExternalProjectPath(), myProject);
            long timeStamp = 0;
            for (File file : files) {
                timeStamp += file.lastModified();
            }
            Map<String, Long> modificationStamps = manager.getLocalSettingsProvider().fun(myProject).getExternalConfigModificationStamps();
            if (isProjectOpen && myProject.getUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT) != Boolean.TRUE) {
                Long affectedFilesTimestamp = modificationStamps.get(settings.getExternalProjectPath());
                affectedFilesTimestamp = affectedFilesTimestamp == null ? -1L : affectedFilesTimestamp;
                if (timeStamp != affectedFilesTimestamp.longValue()) {
                    scheduleUpdate(settings.getExternalProjectPath());
                }
            } else {
                modificationStamps.put(settings.getExternalProjectPath(), timeStamp);
            }
            for (File file : files) {
                if (file == null)
                    continue;
                String path = getNormalizedPath(file);
                if (path == null)
                    continue;
                pathsToWatch.add(path);
                String url = VfsUtilCore.pathToUrl(path);
                VirtualFilePointer pointer = pointerMap.get(url);
                if (pointer == null) {
                    pointer = VirtualFilePointerManager.getInstance().create(url, myChangedDocumentsQueue, null);
                    pointerMap.put(url, pointer);
                    // update timestamps based on file crc and local settings
                    final VirtualFile virtualFile = pointer.getFile();
                    if (virtualFile != null) {
                        Long crc = virtualFile.getUserData(CRC_WITHOUT_SPACES_BEFORE_LAST_IMPORT);
                        if (crc != null) {
                            modificationStamps.put(path, crc);
                        }
                    }
                }
                myFilesPointers.putValue(pointer, settings.getExternalProjectPath());
            }
        }
    }
    myWatchedRoots.addAll(LocalFileSystem.getInstance().addRootsToWatch(pathsToWatch, false));
}
Also used : VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ExternalSystemAutoImportAware(com.intellij.openapi.externalSystem.ExternalSystemAutoImportAware) SmartList(com.intellij.util.SmartList) File(java.io.File)

Example 18 with ExternalProjectSettings

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

the class TaskCompletionProvider method addArgumentVariants.

@Override
protected void addArgumentVariants(@NotNull CompletionResultSet result) {
    List<LookupElement> cachedElements = myCachedElements;
    final String projectPath = myProjectPathAccessor.getText();
    if (cachedElements == null || !StringUtil.equals(myCachedWorkingDir, projectPath)) {
        final ExternalProjectSettings linkedProjectSettings = ExternalSystemApiUtil.getSettings(myProject, mySystemId).getLinkedProjectSettings(projectPath);
        if (linkedProjectSettings == null)
            return;
        final ExternalProjectInfo projectData = ProjectDataManager.getInstance().getExternalProjectData(myProject, mySystemId, linkedProjectSettings.getExternalProjectPath());
        if (projectData == null || projectData.getExternalProjectStructure() == null)
            return;
        cachedElements = ContainerUtil.newArrayList(getVariants(projectData.getExternalProjectStructure(), projectPath));
        myCachedElements = cachedElements;
        myCachedWorkingDir = projectPath;
    }
    result.addAllElements(cachedElements);
}
Also used : ExternalProjectInfo(com.intellij.openapi.externalSystem.model.ExternalProjectInfo) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)

Example 19 with ExternalProjectSettings

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

the class GradleAutoImportAware method getAffectedExternalProjectPath.

@Nullable
@Override
public String getAffectedExternalProjectPath(@NotNull String changedFileOrDirPath, @NotNull Project project) {
    if (!changedFileOrDirPath.endsWith(GradleConstants.EXTENSION)) {
        return null;
    }
    File file = new File(changedFileOrDirPath);
    if (file.isDirectory()) {
        return null;
    }
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(GradleConstants.SYSTEM_ID);
    assert manager != null;
    AbstractExternalSystemSettings<?, ?, ?> systemSettings = manager.getSettingsProvider().fun(project);
    Collection<? extends ExternalProjectSettings> projectsSettings = systemSettings.getLinkedProjectsSettings();
    if (projectsSettings.isEmpty()) {
        return null;
    }
    Map<String, String> rootPaths = ContainerUtil.newHashMap();
    for (ExternalProjectSettings setting : projectsSettings) {
        if (setting != null) {
            for (String path : setting.getModules()) {
                rootPaths.put(new File(path).getAbsolutePath(), setting.getExternalProjectPath());
            }
        }
    }
    for (File f = file.getParentFile(); f != null; f = f.getParentFile()) {
        String dirPath = f.getAbsolutePath();
        if (rootPaths.containsKey(dirPath)) {
            return rootPaths.get(dirPath);
        }
    }
    return null;
}
Also used : File(java.io.File) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with ExternalProjectSettings

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

the class ExternalSystemVcsRegistrar method handle.

@SuppressWarnings("unchecked")
public static void handle(@NotNull final Project project) {
    for (final ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
        final AbstractExternalSystemSettings settings = manager.getSettingsProvider().fun(project);
        settings.subscribe(new ExternalSystemSettingsListenerAdapter() {

            @Override
            public void onProjectsLinked(@NotNull final Collection linked) {
                List<VcsDirectoryMapping> newMappings = ContainerUtilRt.newArrayList();
                final LocalFileSystem fileSystem = LocalFileSystem.getInstance();
                ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
                for (Object o : linked) {
                    final ExternalProjectSettings settings = (ExternalProjectSettings) o;
                    VirtualFile dir = fileSystem.refreshAndFindFileByPath(settings.getExternalProjectPath());
                    if (dir == null) {
                        continue;
                    }
                    if (!dir.isDirectory()) {
                        dir = dir.getParent();
                    }
                    newMappings.addAll(VcsUtil.findRoots(dir, project));
                }
                // There is a possible case that no VCS mappings are configured for the current project. There is a single
                // mapping like <Project> - <No VCS> then. We want to replace it if only one mapping to the project root dir
                // has been detected then.
                List<VcsDirectoryMapping> oldMappings = vcsManager.getDirectoryMappings();
                if (oldMappings.size() == 1 && newMappings.size() == 1 && StringUtil.isEmpty(oldMappings.get(0).getVcs())) {
                    VcsDirectoryMapping newMapping = newMappings.iterator().next();
                    String detectedDirPath = newMapping.getDirectory();
                    VirtualFile detectedDir = fileSystem.findFileByPath(detectedDirPath);
                    if (detectedDir != null && detectedDir.equals(project.getBaseDir())) {
                        newMappings.clear();
                        newMappings.add(new VcsDirectoryMapping("", newMapping.getVcs()));
                        vcsManager.setDirectoryMappings(newMappings);
                        return;
                    }
                }
                newMappings.addAll(oldMappings);
                vcsManager.setDirectoryMappings(newMappings);
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Collection(java.util.Collection) List(java.util.List)

Aggregations

ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)26 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)13 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)7 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)5 ImportSpecBuilder (com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)4 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)4 File (java.io.File)4 Collection (java.util.Collection)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)3 DataNode (com.intellij.openapi.externalSystem.model.DataNode)2 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)2 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)2 ExternalConfigPathAware (com.intellij.openapi.externalSystem.model.project.ExternalConfigPathAware)2 ExternalSystemProcessingManager (com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager)2 ProjectDataManager (com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager)2 ExternalSystemNode (com.intellij.openapi.externalSystem.view.ExternalSystemNode)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 ModulesConfigurator (com.intellij.openapi.roots.ui.configuration.ModulesConfigurator)2