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);
}
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;
}
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);
}
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()));
}
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();
}
}
Aggregations