Search in sources :

Example 1 with BlazeLibrary

use of com.google.idea.blaze.base.model.BlazeLibrary in project intellij by bazelbuild.

the class JarCache method onSync.

void onSync(BlazeContext context, ProjectViewSet projectViewSet, BlazeProjectData projectData, BlazeSyncParams.SyncMode syncMode) {
    Collection<BlazeLibrary> libraries = BlazeLibraryCollector.getLibraries(projectViewSet, projectData);
    boolean fullRefresh = syncMode == SyncMode.FULL;
    boolean removeMissingFiles = syncMode == SyncMode.INCREMENTAL;
    boolean enabled = updateEnabled();
    if (!enabled || fullRefresh) {
        clearCache();
    }
    if (!enabled) {
        return;
    }
    List<BlazeJarLibrary> jarLibraries = libraries.stream().filter(library -> library instanceof BlazeJarLibrary).map(library -> (BlazeJarLibrary) library).collect(Collectors.toList());
    ArtifactLocationDecoder artifactLocationDecoder = projectData.artifactLocationDecoder;
    BiMap<File, String> sourceFileToCacheKey = HashBiMap.create(jarLibraries.size());
    for (BlazeJarLibrary library : jarLibraries) {
        File jarFile = artifactLocationDecoder.decode(library.libraryArtifact.jarForIntellijLibrary());
        sourceFileToCacheKey.put(jarFile, cacheKeyForJar(jarFile));
        for (ArtifactLocation sourceJar : library.libraryArtifact.sourceJars) {
            File srcJarFile = artifactLocationDecoder.decode(sourceJar);
            sourceFileToCacheKey.put(srcJarFile, cacheKeyForSourceJar(srcJarFile));
        }
    }
    this.traits = new JarCacheSynchronizerTraits(cacheDir, sourceFileToCacheKey);
    refresh(context, removeMissingFiles);
}
Also used : SyncMode(com.google.idea.blaze.base.sync.BlazeSyncParams.SyncMode) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) FileCache(com.google.idea.blaze.base.filecache.FileCache) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Future(java.util.concurrent.Future) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) BlazeDataStorage(com.google.idea.blaze.base.sync.data.BlazeDataStorage) Map(java.util.Map) Project(com.intellij.openapi.project.Project) BlazeJavaUserSettings(com.google.idea.blaze.java.settings.BlazeJavaUserSettings) FileUtil(com.intellij.openapi.util.io.FileUtil) FileSizeScanner(com.google.idea.blaze.base.io.FileSizeScanner) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(javax.annotation.Nullable) BiMap(com.google.common.collect.BiMap) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ImmutableMap(com.google.common.collect.ImmutableMap) Files(java.nio.file.Files) BlazeLibraryCollector(com.google.idea.blaze.base.sync.libraries.BlazeLibraryCollector) Collection(java.util.Collection) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) IOException(java.io.IOException) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) File(java.io.File) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) HashBiMap(com.google.common.collect.HashBiMap) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) FileCacheSynchronizerTraits(com.google.idea.blaze.base.filecache.FileCacheSynchronizerTraits) Paths(java.nio.file.Paths) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Preconditions(com.google.common.base.Preconditions) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) FileCacheSynchronizer(com.google.idea.blaze.base.filecache.FileCacheSynchronizer) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) File(java.io.File)

Example 2 with BlazeLibrary

use of com.google.idea.blaze.base.model.BlazeLibrary in project intellij by bazelbuild.

the class BlazeAndroidLiteSyncPlugin method getSdkLibrary.

@Nullable
private static BlazeLibrary getSdkLibrary(BlazeProjectData blazeProjectData) {
    List<AndroidSdkIdeInfo> sdkTargets = androidSdkTargets(blazeProjectData.targetMap);
    if (sdkTargets.isEmpty()) {
        return null;
    }
    // for now, just add the first one found
    // TODO: warn if there's more than one
    ArtifactLocation sdk = sdkTargets.stream().map(info -> info.androidJar).filter(Objects::nonNull).findFirst().orElse(null);
    return sdk != null ? new BlazeJarLibrary(new LibraryArtifact(null, sdk, ImmutableList.of())) : null;
}
Also used : BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ImmutableSet(com.google.common.collect.ImmutableSet) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) LibrarySource(com.google.idea.blaze.base.sync.libraries.LibrarySource) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) AndroidSdkIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidSdkIdeInfo) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Nullable(javax.annotation.Nullable) Objects(java.util.Objects) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) AndroidSdkIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidSdkIdeInfo) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) Nullable(javax.annotation.Nullable)

Example 3 with BlazeLibrary

use of com.google.idea.blaze.base.model.BlazeLibrary in project intellij by bazelbuild.

the class BlazeSyncTask method updateProjectStructure.

private void updateProjectStructure(BlazeContext context, BlazeImportSettings importSettings, ProjectViewSet projectViewSet, BlazeVersionData blazeVersionData, DirectoryStructure directoryStructure, BlazeProjectData newBlazeProjectData, @Nullable BlazeProjectData oldBlazeProjectData) {
    for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
        syncPlugin.updateProjectSdk(project, context, projectViewSet, blazeVersionData, newBlazeProjectData);
    }
    ModuleEditorImpl moduleEditor = ModuleEditorProvider.getInstance().getModuleEditor(project, importSettings);
    ModuleType workspaceModuleType = null;
    for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
        workspaceModuleType = syncPlugin.getWorkspaceModuleType(newBlazeProjectData.workspaceLanguageSettings.getWorkspaceType());
        if (workspaceModuleType != null) {
            break;
        }
    }
    if (workspaceModuleType == null) {
        workspaceModuleType = ModuleType.EMPTY;
        IssueOutput.warn("Could not set module type for workspace module.").submit(context);
    }
    Module workspaceModule = moduleEditor.createModule(BlazeDataStorage.WORKSPACE_MODULE_NAME, workspaceModuleType);
    ModifiableRootModel workspaceModifiableModel = moduleEditor.editModule(workspaceModule);
    ContentEntryEditor.createContentEntries(project, workspaceRoot, projectViewSet, newBlazeProjectData, directoryStructure, workspaceModifiableModel);
    List<BlazeLibrary> libraries = BlazeLibraryCollector.getLibraries(projectViewSet, newBlazeProjectData);
    LibraryEditor.updateProjectLibraries(project, context, projectViewSet, newBlazeProjectData, libraries);
    LibraryEditor.configureDependencies(workspaceModifiableModel, libraries);
    for (BlazeSyncPlugin blazeSyncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
        blazeSyncPlugin.updateProjectStructure(project, context, workspaceRoot, projectViewSet, newBlazeProjectData, oldBlazeProjectData, moduleEditor, workspaceModule, workspaceModifiableModel);
    }
    createProjectDataDirectoryModule(moduleEditor, new File(importSettings.getProjectDataDirectory()), workspaceModuleType);
    moduleEditor.commitWithGc(context);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModuleType(com.intellij.openapi.module.ModuleType) ModuleEditorImpl(com.google.idea.blaze.base.sync.projectstructure.ModuleEditorImpl) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) Module(com.intellij.openapi.module.Module) File(java.io.File)

Example 4 with BlazeLibrary

use of com.google.idea.blaze.base.model.BlazeLibrary in project intellij by bazelbuild.

the class BlazeLibraryCollector method getLibraries.

public static List<BlazeLibrary> getLibraries(ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData) {
    // Use set to filter out duplicates.
    Set<BlazeLibrary> result = Sets.newLinkedHashSet();
    List<LibrarySource> librarySources = Lists.newArrayList();
    for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
        LibrarySource librarySource = syncPlugin.getLibrarySource(projectViewSet, blazeProjectData);
        if (librarySource != null) {
            librarySources.add(librarySource);
        }
    }
    for (LibrarySource librarySource : librarySources) {
        result.addAll(librarySource.getLibraries());
    }
    Predicate<BlazeLibrary> libraryFilter = librarySources.stream().map(LibrarySource::getLibraryFilter).filter(Objects::nonNull).reduce(Predicate::and).orElse(o -> true);
    return BlazeLibrarySorter.sortLibraries(result.stream().filter(libraryFilter).collect(Collectors.toList()));
}
Also used : Objects(java.util.Objects) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin)

Example 5 with BlazeLibrary

use of com.google.idea.blaze.base.model.BlazeLibrary in project intellij by bazelbuild.

the class LibraryEditor method updateProjectLibraries.

public static void updateProjectLibraries(Project project, BlazeContext context, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, Collection<BlazeLibrary> libraries) {
    Set<LibraryKey> intelliJLibraryState = Sets.newHashSet();
    for (Library library : ProjectLibraryTable.getInstance(project).getLibraries()) {
        String name = library.getName();
        if (name != null) {
            intelliJLibraryState.add(LibraryKey.fromIntelliJLibraryName(name));
        }
    }
    context.output(PrintOutput.log(String.format("Workspace has %d libraries", libraries.size())));
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
    LibraryTable.ModifiableModel libraryTableModel = libraryTable.getModifiableModel();
    try {
        for (BlazeLibrary library : libraries) {
            updateLibrary(project, blazeProjectData.artifactLocationDecoder, libraryTable, libraryTableModel, library);
        }
        // Garbage collect unused libraries
        List<LibrarySource> librarySources = Lists.newArrayList();
        for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
            LibrarySource librarySource = syncPlugin.getLibrarySource(projectViewSet, blazeProjectData);
            if (librarySource != null) {
                librarySources.add(librarySource);
            }
        }
        Predicate<Library> gcRetentionFilter = librarySources.stream().map(LibrarySource::getGcRetentionFilter).filter(Objects::nonNull).reduce(Predicate::or).orElse(o -> false);
        Set<LibraryKey> newLibraryKeys = libraries.stream().map((blazeLibrary) -> blazeLibrary.key).collect(Collectors.toSet());
        for (LibraryKey libraryKey : intelliJLibraryState) {
            String libraryIntellijName = libraryKey.getIntelliJLibraryName();
            if (!newLibraryKeys.contains(libraryKey)) {
                Library library = libraryTable.getLibraryByName(libraryIntellijName);
                if (!gcRetentionFilter.test(library)) {
                    if (library != null) {
                        libraryTableModel.removeLibrary(library);
                    }
                }
            }
        }
    } finally {
        libraryTableModel.commit();
    }
}
Also used : LibraryKey(com.google.idea.blaze.base.model.LibraryKey) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) OrderRootType(com.intellij.openapi.roots.OrderRootType) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) Set(java.util.Set) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Library(com.intellij.openapi.roots.libraries.Library) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) List(java.util.List) Lists(com.google.common.collect.Lists) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Objects(java.util.Objects) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

BlazeLibrary (com.google.idea.blaze.base.model.BlazeLibrary)10 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)5 ImmutableList (com.google.common.collect.ImmutableList)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)4 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)4 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)4 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)3 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)3 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)3 PrintOutput (com.google.idea.blaze.base.scope.output.PrintOutput)3 BlazeSyncPlugin (com.google.idea.blaze.base.sync.BlazeSyncPlugin)3 Logger (com.intellij.openapi.diagnostic.Logger)3 Project (com.intellij.openapi.project.Project)3 File (java.io.File)3 Collection (java.util.Collection)3 List (java.util.List)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 Preconditions (com.google.common.base.Preconditions)2 BiMap (com.google.common.collect.BiMap)2