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;
}
}
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));
}
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);
}
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;
}
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);
}
});
}
}
Aggregations