use of com.intellij.openapi.vfs.VirtualFileManager in project intellij-community by JetBrains.
the class MvcModuleStructureUtil method cleanupDefaultLibrary.
public static void cleanupDefaultLibrary(Module module, Collection<Consumer<ModifiableRootModel>> actions, Collection<VirtualFile> appRoots, final String libName) {
final Library library = findUserLibrary(module, libName);
if (library == null) {
return;
}
final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
final List<String> toRemoveUrls = new ArrayList<>();
for (String url : library.getUrls(OrderRootType.CLASSES)) {
VirtualFile virtualFile = virtualFileManager.findFileByUrl(url);
if (virtualFile == null) {
toRemoveUrls.add(url);
} else {
if (library.isJarDirectory(url)) {
if (!virtualFile.getName().equals("lib") || !appRoots.contains(virtualFile.getParent())) {
toRemoveUrls.add(url);
}
}
}
}
if (!toRemoveUrls.isEmpty()) {
actions.add(model -> {
final Library.ModifiableModel modifiableModel = modifyDefaultLibrary(model, libName);
for (String url : toRemoveUrls) {
modifiableModel.removeRoot(url, OrderRootType.CLASSES);
}
modifiableModel.commit();
});
}
}
use of com.intellij.openapi.vfs.VirtualFileManager in project intellij-community by JetBrains.
the class RepositoryAttachHandler method createRoots.
public static List<OrderRoot> createRoots(@NotNull Collection<MavenArtifact> artifacts, @Nullable String copyTo) {
final List<OrderRoot> result = new ArrayList<>();
final VirtualFileManager manager = VirtualFileManager.getInstance();
for (MavenArtifact each : artifacts) {
try {
File repoFile = each.getFile();
File toFile = repoFile;
if (copyTo != null) {
toFile = new File(copyTo, repoFile.getName());
if (repoFile.exists()) {
FileUtil.copy(repoFile, toFile);
}
}
// search for jar file first otherwise lib root won't be found!
manager.refreshAndFindFileByUrl(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(toFile.getPath())));
final String url = VfsUtil.getUrlForLibraryRoot(toFile);
final VirtualFile file = manager.refreshAndFindFileByUrl(url);
if (file != null) {
OrderRootType rootType;
if (MavenExtraArtifactType.DOCS.getDefaultClassifier().equals(each.getClassifier())) {
rootType = JavadocOrderRootType.getInstance();
} else if (MavenExtraArtifactType.SOURCES.getDefaultClassifier().equals(each.getClassifier())) {
rootType = OrderRootType.SOURCES;
} else {
rootType = OrderRootType.CLASSES;
}
result.add(new OrderRoot(file, rootType));
}
} catch (IOException e) {
MavenLog.LOG.warn(e);
}
}
return result;
}
use of com.intellij.openapi.vfs.VirtualFileManager in project intellij-community by JetBrains.
the class DslActivationStatus method loadState.
@Override
public void loadState(State state) {
synchronized (myStatus) {
myStatus.clear();
if (ContainerUtil.isEmpty(state.entries)) {
return;
}
final VirtualFileManager fileManager = VirtualFileManager.getInstance();
for (Entry entry : state.entries) {
if (entry.url == null || entry.status == null)
continue;
final VirtualFile file = fileManager.findFileByUrl(entry.url);
if (file != null) {
myStatus.put(file, entry);
}
}
}
}
use of com.intellij.openapi.vfs.VirtualFileManager in project intellij-community by JetBrains.
the class ResourceBundleEditor method installPropertiesChangeListeners.
private void installPropertiesChangeListeners() {
final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
if (myVfsListener != null) {
throw new AssertionError("Listeners can't be initialized twice");
}
myVfsListener = new ResourceBundleEditorFileListener(this);
virtualFileManager.addVirtualFileListener(myVfsListener, this);
PsiTreeChangeAdapter psiTreeChangeAdapter = new PsiTreeChangeAdapter() {
@Override
public void childAdded(@NotNull PsiTreeChangeEvent event) {
final PsiFile file = event.getFile();
if (file instanceof XmlFile) {
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
if (propertiesFile != null) {
final ResourceBundle bundle = propertiesFile.getResourceBundle();
if (bundle.equals(myResourceBundle) && !myEditors.containsKey(propertiesFile.getVirtualFile())) {
recreateEditorsPanel();
}
}
}
}
@Override
public void childRemoved(@NotNull PsiTreeChangeEvent event) {
final PsiFile file = event.getFile();
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
if (propertiesFile != null) {
final ResourceBundle bundle = propertiesFile.getResourceBundle();
if (bundle.equals(myResourceBundle) && myEditors.containsKey(propertiesFile.getVirtualFile())) {
final IProperty property = PropertiesImplUtil.getProperty(event.getParent());
if (property != null && Comparing.equal(property.getName(), getSelectedPropertyName())) {
updateEditorsFromProperties(false);
}
}
}
}
};
PsiManager.getInstance(myProject).addPsiTreeChangeListener(psiTreeChangeAdapter, this);
}
Aggregations