use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class GradleInstallationManager method getClassRoots.
/**
* Allows to ask for the classpath roots of the classes that are additionally provided by the gradle integration (e.g. gradle class
* files, bundled groovy-all jar etc).
*
* @param project target project to use for gradle home retrieval
* @return classpath roots of the classes that are additionally provided by the gradle integration (if any);
* <code>null</code> otherwise
*/
@Nullable
public List<VirtualFile> getClassRoots(@Nullable Project project) {
List<File> files = getClassRoots(project, null);
if (files == null)
return null;
final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
final JarFileSystem jarFileSystem = JarFileSystem.getInstance();
return ContainerUtil.mapNotNull(files, file -> {
final VirtualFile virtualFile = localFileSystem.refreshAndFindFileByIoFile(file);
return virtualFile != null ? jarFileSystem.getJarRootForLocalFile(virtualFile) : null;
});
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class GradleModuleBuilder method setupRootModel.
@Override
public void setupRootModel(final ModifiableRootModel modifiableRootModel) throws ConfigurationException {
String contentEntryPath = getContentEntryPath();
if (StringUtil.isEmpty(contentEntryPath)) {
return;
}
File contentRootDir = new File(contentEntryPath);
FileUtilRt.createDirectory(contentRootDir);
LocalFileSystem fileSystem = LocalFileSystem.getInstance();
VirtualFile modelContentRootDir = fileSystem.refreshAndFindFileByIoFile(contentRootDir);
if (modelContentRootDir == null) {
return;
}
modifiableRootModel.addContentEntry(modelContentRootDir);
// todo this should be moved to generic ModuleBuilder
if (myJdk != null) {
modifiableRootModel.setSdk(myJdk);
} else {
modifiableRootModel.inheritSdk();
}
final Project project = modifiableRootModel.getProject();
if (myParentProject != null) {
rootProjectPath = myParentProject.getLinkedExternalProjectPath();
} else {
rootProjectPath = FileUtil.toCanonicalPath(myWizardContext.isCreatingNewProject() ? project.getBasePath() : modelContentRootDir.getPath());
}
assert rootProjectPath != null;
final VirtualFile gradleBuildFile = setupGradleBuildFile(modelContentRootDir);
setupGradleSettingsFile(rootProjectPath, modelContentRootDir, modifiableRootModel.getProject().getName(), myProjectId == null ? modifiableRootModel.getModule().getName() : myProjectId.getArtifactId(), myWizardContext.isCreatingNewProject() || myParentProject == null);
if (gradleBuildFile != null) {
modifiableRootModel.getModule().putUserData(BUILD_SCRIPT_DATA, new BuildScriptDataBuilder(gradleBuildFile));
}
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class ExternalSystemNodeAction method getExternalConfig.
@Nullable
protected VirtualFile getExternalConfig(@NotNull ExternalConfigPathAware data, ProjectSystemId externalSystemId) {
String path = data.getLinkedExternalProjectPath();
LocalFileSystem fileSystem = LocalFileSystem.getInstance();
VirtualFile externalSystemConfigPath = fileSystem.refreshAndFindFileByPath(path);
if (externalSystemConfigPath == null) {
return null;
}
VirtualFile toOpen = externalSystemConfigPath;
for (ExternalSystemConfigLocator locator : ExternalSystemConfigLocator.EP_NAME.getExtensions()) {
if (externalSystemId.equals(locator.getTargetExternalSystemId())) {
toOpen = locator.adjust(toOpen);
if (toOpen == null) {
return null;
}
break;
}
}
return toOpen.isDirectory() ? null : toOpen;
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class ShowImageDuplicatesAction method collectAndShowDuplicates.
private static void collectAndShowDuplicates(final Project project) {
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
if (indicator != null && !indicator.isCanceled()) {
indicator.setText("Collecting project images...");
indicator.setIndeterminate(false);
final List<VirtualFile> images = new ArrayList<>();
for (String ext : IMAGE_EXTENSIONS) {
images.addAll(FilenameIndex.getAllFilesByExt(project, ext));
}
final Map<Long, Set<VirtualFile>> duplicates = new HashMap<>();
final Map<Long, VirtualFile> all = new HashMap<>();
for (int i = 0; i < images.size(); i++) {
indicator.setFraction((double) (i + 1) / (double) images.size());
final VirtualFile file = images.get(i);
if (!(file.getFileSystem() instanceof LocalFileSystem))
continue;
final long length = file.getLength();
if (all.containsKey(length)) {
if (!duplicates.containsKey(length)) {
final HashSet<VirtualFile> files = new HashSet<>();
files.add(all.get(length));
duplicates.put(length, files);
}
duplicates.get(length).add(file);
} else {
all.put(length, file);
}
indicator.checkCanceled();
}
showResults(project, images, duplicates, all);
}
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class DirectoryIndexRestoreTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
LocalFileSystem fs = LocalFileSystem.getInstance();
File temp = createTempDirectory();
myTempVFile = fs.findFileByIoFile(temp);
assertNotNull(myTempVFile);
File root = new File(temp, "top/d1/d2/root");
assertTrue(root.mkdirs());
VirtualFile rootVFile = fs.findFileByIoFile(root);
assertNotNull(rootVFile);
VirtualFile moduleDir = createChildDirectory(rootVFile, "module");
VirtualFile srcDir = createChildDirectory(moduleDir, "src");
VirtualFile testDir = createChildDirectory(srcDir, "pkg");
ModuleRootModificationUtil.setModuleSdk(myModule, null);
PsiTestUtil.addContentRoot(myModule, moduleDir);
PsiTestUtil.addSourceRoot(myModule, srcDir);
myTestDirPath = testDir.getPath();
myFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
// to not interfere with previous test firing vfs events
VirtualFileManager.getInstance().syncRefresh();
}
Aggregations