use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.
the class DartSdkConfigurationTest method testSdkRootsFromLibrariesFile.
public void testSdkRootsFromLibrariesFile() throws Exception {
final DartSdk sdk = DartSdk.getDartSdk(getProject());
assertNotNull(sdk);
final String[] actualRoots = ArrayUtil.toStringArray(DartSdkLibUtil.getRootUrlsFromLibrariesFile(getProject(), sdk.getHomePath()));
checkSdkRoots(sdk.getHomePath(), actualRoots);
}
use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.
the class DartSdkConfigurationTest method testSdkRoots.
public void testSdkRoots() throws Exception {
final DartSdk sdk = DartSdk.getDartSdk(getProject());
assertNotNull(sdk);
final String[] actualRoots = ProjectLibraryTable.getInstance(getProject()).getLibraries()[0].getRootProvider().getUrls(OrderRootType.CLASSES);
checkSdkRoots(sdk.getHomePath(), actualRoots);
}
use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method doConfigureImportedLibraries.
private static void doConfigureImportedLibraries(@NotNull final Project project, @NotNull final Collection<String> filePaths) {
final DartSdk sdk = DartSdk.getDartSdk(project);
if (sdk == null)
return;
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final SortedSet<String> folderPaths = new TreeSet<>();
final Collection<String> rootsToAddToLib = new THashSet<>();
for (final String path : filePaths) {
if (path != null) {
folderPaths.add(PathUtil.getParentPath(FileUtil.toSystemIndependentName(path)));
}
}
outer: for (final String path : folderPaths) {
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(path);
if (!path.startsWith(sdk.getHomePath() + "/") && (vFile == null || !fileIndex.isInContent(vFile))) {
for (String configuredPath : rootsToAddToLib) {
if (path.startsWith(configuredPath + "/")) {
// folderPaths is sorted so subfolders go after parent folder
continue outer;
}
}
rootsToAddToLib.add(path);
}
}
final Processor<? super PsiFileSystemItem> falseProcessor = (Processor<PsiFileSystemItem>) item -> false;
final Condition<Module> moduleFilter = module -> DartSdkLibUtil.isDartSdkEnabled(module) && !FilenameIndex.processFilesByName(PubspecYamlUtil.PUBSPEC_YAML, false, falseProcessor, module.getModuleContentScope(), project, null);
final DartFileListener.DartLibInfo libInfo = new DartFileListener.DartLibInfo(true);
libInfo.addRoots(rootsToAddToLib);
final Library library = DartFileListener.updatePackagesLibraryRoots(project, libInfo);
DartFileListener.updateDependenciesOnDartPackagesLibrary(project, moduleFilter, library);
}
use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.
the class DartProjectComponent method convertOrderEntriesTargetingGlobalDartSdkLib.
private void convertOrderEntriesTargetingGlobalDartSdkLib() {
final DartSdk correctSdk = DartSdk.getDartSdk(myProject);
// already converted
if (correctSdk != null)
return;
// for performance reasons avoid taking write action and modifiable models if not needed
if (!hasIncorrectModuleDependencies())
return;
final String sdkPath = DartSdkUtil.getFirstKnownDartSdkPath();
if (sdkPath == null)
return;
ApplicationManager.getApplication().runWriteAction(() -> {
DartSdkLibUtil.ensureDartSdkConfigured(myProject, sdkPath);
final Collection<ModifiableRootModel> modelsToCommit = new SmartList<>();
for (final Module module : ModuleManager.getInstance(myProject).getModules()) {
boolean hasCorrectDependency = false;
boolean needsCorrectDependency = false;
final List<OrderEntry> orderEntriesToRemove = new SmartList<>();
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
for (final OrderEntry orderEntry : model.getOrderEntries()) {
if (isOldGlobalDartSdkLibEntry(orderEntry)) {
needsCorrectDependency = true;
orderEntriesToRemove.add(orderEntry);
} else if (DartSdkLibUtil.isDartSdkOrderEntry(orderEntry)) {
hasCorrectDependency = true;
}
}
if (needsCorrectDependency && !hasCorrectDependency || !orderEntriesToRemove.isEmpty()) {
if (needsCorrectDependency && !hasCorrectDependency) {
model.addInvalidLibrary(DartSdk.DART_SDK_LIB_NAME, LibraryTablesRegistrar.PROJECT_LEVEL);
}
for (OrderEntry entry : orderEntriesToRemove) {
model.removeOrderEntry(entry);
}
modelsToCommit.add(model);
} else {
model.dispose();
}
}
commitModifiableModels(myProject, modelsToCommit);
});
}
use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.
the class DartServerRootsHandler method updateRoots.
private void updateRoots() {
final DartSdk sdk = DartSdk.getDartSdk(myProject);
if (sdk == null || !DartAnalysisServerService.isDartSdkVersionSufficient(sdk)) {
DartAnalysisServerService.getInstance(myProject).stopServer();
}
final List<String> newIncludedRoots = new SmartList<>();
final List<String> newExcludedRoots = new SmartList<>();
if (sdk != null) {
@SuppressWarnings("ConstantConditions") final String dotIdeaPath = PathUtil.getParentPath(myProject.getProjectFilePath());
if (dotIdeaPath.endsWith("/.idea")) {
newExcludedRoots.add(FileUtil.toSystemDependentName(dotIdeaPath));
}
for (Module module : DartSdkLibUtil.getModulesWithDartSdkEnabled(myProject)) {
final Set<String> excludedPackageSymlinkUrls = getExcludedPackageSymlinkUrls(module);
for (ContentEntry contentEntry : ModuleRootManager.getInstance(module).getContentEntries()) {
final String contentEntryUrl = contentEntry.getUrl();
if (contentEntryUrl.startsWith(URLUtil.FILE_PROTOCOL + URLUtil.SCHEME_SEPARATOR)) {
newIncludedRoots.add(FileUtil.toSystemDependentName(VfsUtilCore.urlToPath(contentEntryUrl)));
for (String excludedUrl : contentEntry.getExcludeFolderUrls()) {
if (excludedUrl.startsWith(contentEntryUrl) && !excludedPackageSymlinkUrls.contains(excludedUrl)) {
newExcludedRoots.add(FileUtil.toSystemDependentName(VfsUtilCore.urlToPath(excludedUrl)));
}
}
}
}
}
}
if (!myIncludedRoots.equals(newIncludedRoots) || !myExcludedRoots.equals(newExcludedRoots)) {
myIncludedRoots.clear();
myExcludedRoots.clear();
if (DartAnalysisServerService.getInstance(myProject).updateRoots(newIncludedRoots, newExcludedRoots)) {
myIncludedRoots.addAll(newIncludedRoots);
myExcludedRoots.addAll(newExcludedRoots);
}
}
}
Aggregations