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