use of com.intellij.openapi.vfs.VirtualFileManager in project android by JetBrains.
the class ExternalAnnotationsSupport method attachJdkAnnotations.
// Based on similar code in JavaSdkImpl
public static void attachJdkAnnotations(@NotNull SdkModificator modificator) {
String homePath = FileUtil.toSystemIndependentName(PathManager.getHomePath());
VirtualFileManager fileManager = VirtualFileManager.getInstance();
// release build?
String releaseLocation = homePath + "/plugins/android/lib/androidAnnotations.jar";
VirtualFile root = fileManager.findFileByUrl("jar://" + releaseLocation + "!/");
for (String relativePath : DEVELOPMENT_ANNOTATIONS_PATHS) {
if (root != null)
break;
String developmentLocation = homePath + relativePath;
root = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(developmentLocation));
}
if (root == null) {
// error message tailored for release build file layout
LOG.error("jdk annotations not found in: " + releaseLocation);
return;
}
OrderRootType annoType = AnnotationOrderRootType.getInstance();
modificator.removeRoot(root, annoType);
modificator.addRoot(root, annoType);
}
use of com.intellij.openapi.vfs.VirtualFileManager in project intellij-plugins by JetBrains.
the class ImageRefreshFix method setStamps.
@NotNull
static String setStamps(@NotNull String html) {
final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
final String pattern = "<img src=\"file:";
StringBuilder sb = StringBuilderSpinAllocator.alloc();
try {
int processedOffset = 0;
while (true) {
final int nextI = html.indexOf(pattern, processedOffset);
if (nextI == -1) {
break;
}
final int nextJ = html.indexOf('"', nextI + pattern.length());
if (nextJ == -1) {
return html;
}
sb.append(html, processedOffset, nextI + pattern.length());
final String url = html.substring(nextI + pattern.length(), nextJ);
sb.append(processUrl(virtualFileManager, url));
sb.append('"');
processedOffset = nextJ + 1;
}
if (processedOffset < html.length()) {
sb.append(html, processedOffset, html.length());
}
return sb.toString();
} finally {
StringBuilderSpinAllocator.dispose(sb);
}
}
use of com.intellij.openapi.vfs.VirtualFileManager in project intellij-community by JetBrains.
the class SimpleClasspathElementFactory method convertToFiles.
public static List<VirtualFile> convertToFiles(Collection<SimpleClasspathElement> cpeList) {
VirtualFileManager fileManager = VirtualFileManager.getInstance();
List<VirtualFile> files = new ArrayList<>();
for (SimpleClasspathElement cpe : cpeList) {
for (String fileUrl : cpe.getClassesRootUrls()) {
VirtualFile file = fileManager.findFileByUrl(fileUrl);
if (file != null) {
files.add(file);
}
}
}
return files;
}
use of com.intellij.openapi.vfs.VirtualFileManager in project intellij-community by JetBrains.
the class LocalHistoryImpl method disposeComponent.
@Override
public void disposeComponent() {
if (!isInitialized.getAndSet(false))
return;
long period = Registry.intValue("localHistory.daysToKeep") * 1000L * 60L * 60L * 24L;
myConnection.disconnect();
myConnection = null;
VirtualFileManager fm = VirtualFileManager.getInstance();
fm.removeVirtualFileManagerListener(myEventDispatcher);
CommandProcessor.getInstance().removeCommandListener(myEventDispatcher);
LocalHistoryLog.LOG.debug("Purging local history...");
myChangeList.purgeObsolete(period);
myChangeList.close();
LocalHistoryLog.LOG.debug("Local history storage successfully closed.");
ShutDownTracker.getInstance().unregisterShutdownTask(myShutdownTask);
}
use of com.intellij.openapi.vfs.VirtualFileManager in project intellij-community by JetBrains.
the class JarDirectoryWatcherImpl method updateWatchedRoots.
@Override
public void updateWatchedRoots() {
final LocalFileSystem fs = LocalFileSystem.getInstance();
if (!myJarDirectories.isEmpty()) {
final Set<String> recursiveRoots = new HashSet<>();
final Set<String> flatRoots = new HashSet<>();
final VirtualFileManager fm = VirtualFileManager.getInstance();
for (OrderRootType rootType : myJarDirectories.getRootTypes()) {
for (String url : myJarDirectories.getDirectories(rootType)) {
if (fm.getFileSystem(VirtualFileManager.extractProtocol(url)) instanceof LocalFileSystem) {
final boolean watchRecursively = myJarDirectories.isRecursive(rootType, url);
final String path = VirtualFileManager.extractPath(url);
(watchRecursively ? recursiveRoots : flatRoots).add(path);
}
}
}
myWatchRequests = fs.replaceWatchedRoots(myWatchRequests, recursiveRoots, flatRoots);
if (myBusConnection == null) {
myBusConnection = ApplicationManager.getApplication().getMessageBus().connect();
myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void after(@NotNull final List<? extends VFileEvent> events) {
boolean changesDetected = false;
for (VFileEvent event : events) {
if (event instanceof VFileCopyEvent) {
final VFileCopyEvent copyEvent = (VFileCopyEvent) event;
final VirtualFile file = copyEvent.getFile();
if (isUnderJarDirectory(copyEvent.getNewParent() + "/" + copyEvent.getNewChildName()) || file != null && isUnderJarDirectory(file.getUrl())) {
changesDetected = true;
break;
}
} else if (event instanceof VFileMoveEvent) {
final VFileMoveEvent moveEvent = (VFileMoveEvent) event;
final VirtualFile file = moveEvent.getFile();
if (file != null && (isUnderJarDirectory(file.getUrl()) || isUnderJarDirectory(moveEvent.getOldParent().getUrl() + "/" + file.getName()))) {
changesDetected = true;
break;
}
} else if (event instanceof VFileDeleteEvent) {
final VFileDeleteEvent deleteEvent = (VFileDeleteEvent) event;
if (isUnderJarDirectory(deleteEvent.getFile().getUrl())) {
changesDetected = true;
break;
}
} else if (event instanceof VFileCreateEvent) {
final VFileCreateEvent createEvent = (VFileCreateEvent) event;
if (isUnderJarDirectory(createEvent.getParent().getUrl() + "/" + createEvent.getChildName())) {
changesDetected = true;
break;
}
}
}
if (changesDetected) {
fireRootSetChanged();
}
}
private boolean isUnderJarDirectory(String url) {
for (String rootUrl : myJarDirectories.getAllDirectories()) {
if (FileUtil.startsWith(url, rootUrl)) {
return true;
}
}
return false;
}
});
}
} else {
cleanup();
}
}
Aggregations