Search in sources :

Example 6 with WorkspaceType

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

the class LanguageSupportTest method testFailWithUnsupportedWorkspaceType.

@Test
public void testFailWithUnsupportedWorkspaceType() {
    syncPlugins.registerExtension(new BlazeSyncPlugin() {

        @Override
        public WorkspaceType getDefaultWorkspaceType() {
            return WorkspaceType.JAVA;
        }
    });
    ProjectViewSet projectViewSet = ProjectViewSet.builder().add(ProjectView.builder().add(ScalarSection.builder(WorkspaceTypeSection.KEY).set(WorkspaceType.C)).build()).build();
    WorkspaceLanguageSettings settings = LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
    LanguageSupport.validateLanguageSettings(context, settings);
    errorCollector.assertIssues("Workspace type 'c' is not supported by this plugin");
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) Test(org.junit.Test)

Example 7 with WorkspaceType

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

the class LanguageSupportTest method testWorkspaceTypeImpliesLanguages.

/**
 * Tests that we ask for java and android when the workspace type is android.
 */
@Test
public void testWorkspaceTypeImpliesLanguages() {
    syncPlugins.registerExtension(new BlazeSyncPlugin() {

        @Override
        public Set<LanguageClass> getSupportedLanguagesInWorkspace(WorkspaceType workspaceType) {
            return ImmutableSet.of(LanguageClass.ANDROID, LanguageClass.JAVA, LanguageClass.C);
        }

        @Override
        public ImmutableList<WorkspaceType> getSupportedWorkspaceTypes() {
            return ImmutableList.of(WorkspaceType.ANDROID);
        }

        @Override
        public WorkspaceType getDefaultWorkspaceType() {
            return WorkspaceType.ANDROID;
        }
    });
    ProjectViewSet projectViewSet = ProjectViewSet.builder().add(ProjectView.builder().add(ScalarSection.builder(WorkspaceTypeSection.KEY).set(WorkspaceType.ANDROID)).build()).build();
    WorkspaceLanguageSettings workspaceLanguageSettings = LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
    assertThat(workspaceLanguageSettings).isEqualTo(new WorkspaceLanguageSettings(WorkspaceType.ANDROID, ImmutableSet.of(LanguageClass.JAVA, LanguageClass.ANDROID, LanguageClass.GENERIC)));
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) 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) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) Test(org.junit.Test)

Example 8 with WorkspaceType

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

the class LanguageSupport method validateLanguageSettings.

public static boolean validateLanguageSettings(BlazeContext context, WorkspaceLanguageSettings languageSettings) {
    Set<WorkspaceType> supportedTypes = supportedWorkspaceTypes();
    WorkspaceType workspaceType = languageSettings.getWorkspaceType();
    if (!supportedTypes.contains(languageSettings.getWorkspaceType())) {
        IssueOutput.error(String.format("Workspace type '%s' is not supported by this plugin", languageSettings.getWorkspaceType().getName())).submit(context);
        return false;
    }
    Set<LanguageClass> supportedLanguages = supportedLanguagesForWorkspaceType(workspaceType);
    Set<LanguageClass> availableLanguages = EnumSet.noneOf(LanguageClass.class);
    for (WorkspaceType type : supportedTypes) {
        availableLanguages.addAll(supportedLanguagesForWorkspaceType(type));
    }
    for (LanguageClass languageClass : languageSettings.activeLanguages) {
        if (!availableLanguages.contains(languageClass)) {
            IssueOutput.error(String.format("Language '%s' is not supported by this plugin", languageClass.getName())).submit(context);
            return false;
        }
        if (!supportedLanguages.contains(languageClass)) {
            IssueOutput.error(String.format("Language '%s' is not supported for this plugin with workspace type: '%s'", languageClass.getName(), workspaceType.getName())).submit(context);
            return false;
        }
    }
    return true;
}
Also used : WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass)

Example 9 with WorkspaceType

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

the class LanguageSupport method getDefaultWorkspaceType.

public static WorkspaceType getDefaultWorkspaceType() {
    WorkspaceType workspaceType = null;
    // prioritize by enum ordinal.
    for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
        WorkspaceType recommendedType = syncPlugin.getDefaultWorkspaceType();
        if (recommendedType != null && (workspaceType == null || workspaceType.ordinal() > recommendedType.ordinal())) {
            workspaceType = recommendedType;
        }
    }
    // Should never happen, outside of tests without proper set up.
    checkState(workspaceType != null, "No SyncPlugin present which provides a default workspace type.");
    return workspaceType;
}
Also used : WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin)

Example 10 with WorkspaceType

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

the class BlazeGoSyncPluginTest method initTest.

@Override
protected void initTest(@NotNull Container applicationServices, @NotNull Container projectServices) {
    super.initTest(applicationServices, projectServices);
    syncPluginEp = registerExtensionPoint(BlazeSyncPlugin.EP_NAME, BlazeSyncPlugin.class);
    syncPluginEp.registerExtension(new BlazeGoSyncPlugin());
    syncPluginEp.registerExtension(new AlwaysPresentGoSyncPlugin());
    // At least one sync plugin providing a default workspace type must be present
    syncPluginEp.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);
        }

        @Nullable
        @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) Nullable(javax.annotation.Nullable)

Aggregations

WorkspaceType (com.google.idea.blaze.base.model.primitives.WorkspaceType)13 ImmutableSet (com.google.common.collect.ImmutableSet)9 ImmutableList (com.google.common.collect.ImmutableList)8 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)8 Set (java.util.Set)8 BlazeSyncPlugin (com.google.idea.blaze.base.sync.BlazeSyncPlugin)7 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)6 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)4 Test (org.junit.Test)4 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)2 Nullable (javax.annotation.Nullable)1