Search in sources :

Example 1 with BlazeSyncPlugin

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);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ImmutableList(com.google.common.collect.ImmutableList) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin)

Example 2 with BlazeSyncPlugin

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);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ImmutableList(com.google.common.collect.ImmutableList) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin)

Example 3 with BlazeSyncPlugin

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;
}
Also used : BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 4 with BlazeSyncPlugin

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

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

BlazeSyncPlugin (com.google.idea.blaze.base.sync.BlazeSyncPlugin)13 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)9 WorkspaceType (com.google.idea.blaze.base.model.primitives.WorkspaceType)7 Set (java.util.Set)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)5 BlazeLibrary (com.google.idea.blaze.base.model.BlazeLibrary)2 BlazeJavaSyncPlugin (com.google.idea.blaze.java.sync.BlazeJavaSyncPlugin)2 Objects (java.util.Objects)2 Nullable (javax.annotation.Nullable)2 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 BazelBuildSystemProvider (com.google.idea.blaze.base.bazel.BazelBuildSystemProvider)1 BuildSystemProvider (com.google.idea.blaze.base.bazel.BuildSystemProvider)1 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)1 LibraryKey (com.google.idea.blaze.base.model.LibraryKey)1 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)1 PrintOutput (com.google.idea.blaze.base.scope.output.PrintOutput)1 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)1