use of com.google.idea.blaze.base.sync.BlazeSyncPlugin in project intellij by bazelbuild.
the class ProjectViewVerifierTest method initTest.
@Override
protected void initTest(@NotNull Container applicationServices, @NotNull Container projectServices) {
super.initTest(applicationServices, projectServices);
ExtensionPointImpl<BlazeSyncPlugin> ep = registerExtensionPoint(BlazeSyncPlugin.EP_NAME, BlazeSyncPlugin.class);
ep.registerExtension(new BlazeSyncPlugin() {
@Override
public ImmutableList<WorkspaceType> getSupportedWorkspaceTypes() {
return ImmutableList.of(WorkspaceType.JAVA);
}
@Override
public Set<LanguageClass> getSupportedLanguagesInWorkspace(WorkspaceType workspaceType) {
return ImmutableSet.of(LanguageClass.JAVA);
}
});
fileOperationProvider = new MockFileOperationProvider(workspaceRoot);
applicationServices.register(FileOperationProvider.class, fileOperationProvider);
context = new BlazeContext();
context.addOutputSink(IssueOutput.class, errorCollector);
}
use of com.google.idea.blaze.base.sync.BlazeSyncPlugin in project intellij by bazelbuild.
the class BlazeAndroidLiteSyncPluginTest method initTest.
@Override
protected void initTest(@NotNull Container applicationServices, @NotNull Container projectServices) {
super.initTest(applicationServices, projectServices);
ExtensionPointImpl<BlazeSyncPlugin> ep = registerExtensionPoint(BlazeSyncPlugin.EP_NAME, BlazeSyncPlugin.class);
ep.registerExtension(new BlazeAndroidLiteSyncPlugin());
// add java, because we need at least one WorkspaceType available.
ep.registerExtension(new BlazeSyncPlugin() {
@Override
public ImmutableList<WorkspaceType> getSupportedWorkspaceTypes() {
return ImmutableList.of(WorkspaceType.JAVA);
}
@Override
public Set<LanguageClass> getSupportedLanguagesInWorkspace(WorkspaceType workspaceType) {
return ImmutableSet.of(LanguageClass.JAVA);
}
@Override
public WorkspaceType getDefaultWorkspaceType() {
return WorkspaceType.JAVA;
}
});
context = new BlazeContext();
context.addOutputSink(IssueOutput.class, errorCollector);
}
use of com.google.idea.blaze.base.sync.BlazeSyncPlugin in project intellij by bazelbuild.
the class BlazeProjectDataManagerImpl method loadProject.
@Nullable
private synchronized BlazeProjectData loadProject(BlazeImportSettings importSettings) throws IOException {
File file = getCacheFile(project, importSettings);
List<ClassLoader> classLoaders = Lists.newArrayList();
for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
classLoaders.add(syncPlugin.getClass().getClassLoader());
}
classLoaders.add(getClass().getClassLoader());
classLoaders.add(Thread.currentThread().getContextClassLoader());
blazeProjectData = (BlazeProjectData) SerializationUtil.loadFromDisk(file, classLoaders);
return blazeProjectData;
}
use of com.google.idea.blaze.base.sync.BlazeSyncPlugin 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.sync.BlazeSyncPlugin 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