use of com.intellij.openapi.externalSystem.model.project.ExternalProjectBuildClasspathPojo 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();
}
use of com.intellij.openapi.externalSystem.model.project.ExternalProjectBuildClasspathPojo 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();
}
}
use of com.intellij.openapi.externalSystem.model.project.ExternalProjectBuildClasspathPojo in project intellij-community by JetBrains.
the class AbstractExternalSystemLocalSettings method forgetExternalProjects.
/**
* Asks current settings to drop all information related to external projects which root configs are located at the given paths.
*
* @param linkedProjectPathsToForget target root external project paths
*/
public void forgetExternalProjects(@NotNull Set<String> linkedProjectPathsToForget) {
Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> projects = myAvailableProjects.get();
for (Iterator<Map.Entry<ExternalProjectPojo, Collection<ExternalProjectPojo>>> it = projects.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<ExternalProjectPojo, Collection<ExternalProjectPojo>> entry = it.next();
if (linkedProjectPathsToForget.contains(entry.getKey().getPath())) {
it.remove();
}
}
for (Iterator<Map.Entry<String, Collection<ExternalTaskPojo>>> it = myAvailableTasks.get().entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Collection<ExternalTaskPojo>> entry = it.next();
if (linkedProjectPathsToForget.contains(entry.getKey()) || linkedProjectPathsToForget.contains(ExternalSystemApiUtil.getRootProjectPath(entry.getKey(), myExternalSystemId, myProject))) {
it.remove();
}
}
for (Iterator<ExternalTaskExecutionInfo> it = myRecentTasks.get().iterator(); it.hasNext(); ) {
ExternalTaskExecutionInfo taskInfo = it.next();
String path = taskInfo.getSettings().getExternalProjectPath();
if (linkedProjectPathsToForget.contains(path) || linkedProjectPathsToForget.contains(ExternalSystemApiUtil.getRootProjectPath(path, myExternalSystemId, myProject))) {
it.remove();
}
}
for (Iterator<Map.Entry<String, ExternalProjectBuildClasspathPojo>> it = myProjectBuildClasspath.get().entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, ExternalProjectBuildClasspathPojo> entry = it.next();
if (linkedProjectPathsToForget.contains(entry.getKey()) || linkedProjectPathsToForget.contains(ExternalSystemApiUtil.getRootProjectPath(entry.getKey(), myExternalSystemId, myProject))) {
it.remove();
}
}
Map<String, Long> modificationStamps = myExternalConfigModificationStamps.get();
for (String path : linkedProjectPathsToForget) {
modificationStamps.remove(path);
}
}
Aggregations