Search in sources :

Example 1 with FileOperationProvider

use of com.google.idea.blaze.base.io.FileOperationProvider in project intellij by bazelbuild.

the class PrefetchServiceImpl method prefetchFiles.

private ListenableFuture<?> prefetchFiles(Project project, Set<File> excludeDirectories, Collection<File> files, boolean refetchCachedFiles, boolean fetchFileTypes) {
    if (files.isEmpty() || !enabled(project)) {
        return Futures.immediateFuture(null);
    }
    if (!refetchCachedFiles) {
        long startTime = System.currentTimeMillis();
        // ignore recently fetched files
        files = files.stream().filter(file -> shouldPrefetch(file, startTime)).collect(Collectors.toList());
    }
    FileOperationProvider provider = FileOperationProvider.getInstance();
    List<ListenableFuture<File>> canonicalFiles = files.stream().map(file -> FetchExecutor.EXECUTOR.submit(() -> toCanonicalFile(provider, file))).collect(Collectors.toList());
    List<ListenableFuture<?>> futures = Lists.newArrayList();
    for (Prefetcher prefetcher : Prefetcher.EP_NAME.getExtensions()) {
        futures.add(prefetcher.prefetchFiles(project, excludeDirectories, canonicalFiles, FetchExecutor.EXECUTOR, fetchFileTypes));
    }
    return Futures.allAsList(futures);
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LowMemoryWatcher(com.intellij.openapi.util.LowMemoryWatcher) HashSet(java.util.HashSet) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Lists(com.google.common.collect.Lists) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(javax.annotation.Nullable) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) Set(java.util.Set) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) File(java.io.File) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ApplicationManager(com.intellij.openapi.application.ApplicationManager) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 2 with FileOperationProvider

use of com.google.idea.blaze.base.io.FileOperationProvider in project intellij by bazelbuild.

the class BlazeIdeInterfaceAspectsImplTest method initTest.

@Override
protected void initTest(Container applicationServices, Container projectServices) {
    super.initTest(applicationServices, projectServices);
    applicationServices.register(ExperimentService.class, new MockExperimentService());
    applicationServices.register(FileOperationProvider.class, new FileOperationProvider());
}
Also used : MockExperimentService(com.google.idea.common.experiments.MockExperimentService) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider)

Example 3 with FileOperationProvider

use of com.google.idea.blaze.base.io.FileOperationProvider in project intellij by bazelbuild.

the class UnpackedAars method clearCache.

private void clearCache() {
    FileOperationProvider fileOperationProvider = FileOperationProvider.getInstance();
    if (fileOperationProvider.exists(cacheDir)) {
        try {
            fileOperationProvider.deleteRecursively(cacheDir);
        } catch (IOException e) {
            logger.warn("Failed to clear unpacked AAR directory: " + cacheDir, e);
        }
    }
    aarTraits = null;
    jarTraits = null;
}
Also used : FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) IOException(java.io.IOException)

Example 4 with FileOperationProvider

use of com.google.idea.blaze.base.io.FileOperationProvider in project intellij by bazelbuild.

the class UnpackedAars method refresh.

private void refresh(@Nullable BlazeContext context, boolean removeMissingFiles) {
    if (!enabled || jarTraits == null || aarTraits == null) {
        return;
    }
    FileOperationProvider fileOpProvider = FileOperationProvider.getInstance();
    // Ensure the cache dir exists
    if (!fileOpProvider.exists(cacheDir)) {
        if (!fileOpProvider.mkdirs(cacheDir)) {
            logger.warn("Could not create unpacked AAR directory: " + cacheDir);
            return;
        }
    }
    FileCacheSynchronizer aarSynchronizer = new FileCacheSynchronizer(aarTraits);
    if (!aarSynchronizer.synchronize(context, removeMissingFiles)) {
        logger.warn("Unpacked AAR synchronization didn't complete");
    }
    FileCacheSynchronizer aarJarSynchronizer = new FileCacheSynchronizer(jarTraits);
    if (!aarJarSynchronizer.synchronize(context, removeMissingFiles)) {
        logger.warn("Unpacked AAR jar synchronization didn't complete");
    }
}
Also used : FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) FileCacheSynchronizer(com.google.idea.blaze.base.filecache.FileCacheSynchronizer)

Example 5 with FileOperationProvider

use of com.google.idea.blaze.base.io.FileOperationProvider in project intellij by bazelbuild.

the class BuildReferenceManager method findBuildFile.

@Nullable
public BuildFile findBuildFile(@Nullable File packageDirectory) {
    FileOperationProvider provider = FileOperationProvider.getInstance();
    if (packageDirectory == null || !provider.isDirectory(packageDirectory)) {
        return null;
    }
    VirtualFile vf = VirtualFileSystemProvider.getInstance().getSystem().findFileByPath(packageDirectory.getPath());
    if (vf == null) {
        return null;
    }
    VirtualFile buildFile = Blaze.getBuildSystemProvider(project).findBuildFileInDirectory(vf);
    if (buildFile == null) {
        return null;
    }
    PsiFile psiFile = PsiManager.getInstance(project).findFile(buildFile);
    return psiFile instanceof BuildFile ? (BuildFile) psiFile : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) PsiFile(com.intellij.psi.PsiFile) Nullable(javax.annotation.Nullable)

Aggregations

FileOperationProvider (com.google.idea.blaze.base.io.FileOperationProvider)15 File (java.io.File)10 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 IOException (java.io.IOException)5 Nullable (javax.annotation.Nullable)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)3 PsiFile (com.intellij.psi.PsiFile)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 Futures (com.google.common.util.concurrent.Futures)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)2 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)2 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)2 Project (com.intellij.openapi.project.Project)2 Collection (java.util.Collection)2 List (java.util.List)2 Set (java.util.Set)2