Skip to content

Commit

Permalink
Extract cidr.lang dependent code in //clwb to optional runtime dep
Browse files Browse the repository at this point in the history
Provide access via EP
  • Loading branch information
ujohnny committed Oct 13, 2023
1 parent a354342 commit 0784fbf
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 12 deletions.
1 change: 1 addition & 0 deletions clwb/src/META-INF/clwb-oclang.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</extensions>

<extensions defaultExtensionNs="com.google.idea.blaze">
<clwb.googleTestUtilAdapter implementation="com.google.idea.blaze.clwb.oclang.run.CidrGoogleTestUtilAdapter"/>
<TestContextProvider implementation="com.google.idea.blaze.clwb.oclang.run.producers.CppTestContextProvider"/>
</extensions>
</idea-plugin>
4 changes: 4 additions & 0 deletions clwb/src/META-INF/clwb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<depends>com.intellij.modules.clion</depends>
<depends>org.jetbrains.plugins.clion.test.google</depends>

<extensionPoints>
<extensionPoint qualifiedName="com.google.idea.blaze.clwb.googleTestUtilAdapter" interface="com.google.idea.blaze.clwb.run.GoogleTestUtilAdapter"/>
</extensionPoints>

<extensions defaultExtensionNs="com.intellij">
<consoleFilterProvider implementation="com.google.idea.blaze.clwb.run.BlazeCppPathConsoleFilter$Provider"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.idea.blaze.clwb;
package com.google.idea.blaze.clwb.oclang.run;

import com.google.common.collect.Iterables;
import com.google.idea.blaze.clwb.run.GoogleTestUtilAdapter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Couple;
import com.intellij.psi.PsiElement;
Expand All @@ -33,12 +34,7 @@
import javax.annotation.Nullable;

/** Adapter to bridge different SDK versions. */
public class CidrGoogleTestUtilAdapter {
@Nullable
public static PsiElement findGoogleTestSymbol(Project project) {
return findGoogleTestSymbol(project, testScopeElement -> true);
}

public class CidrGoogleTestUtilAdapter implements GoogleTestUtilAdapter {
@Nullable
public static PsiElement findGoogleTestSymbol(
Project project, String suiteName, String testName) {
Expand Down Expand Up @@ -132,7 +128,7 @@ public static Couple<String> extractFullSuiteNameFromMacro(PsiElement element) {
}

@Nullable
private static PsiElement findGoogleTestSymbol(
public PsiElement findGoogleTestSymbol(
Project project, Predicate<CidrTestScopeElement> predicate) {
CidrGoogleTestFramework instance = CidrGoogleTestFramework.getInstance();
FindFirstWithPredicateProcessor<CidrTestScopeElement> processor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.google.idea.blaze.clwb.oclang.run.test;

import com.google.common.collect.ImmutableList;
import com.google.idea.blaze.clwb.CidrGoogleTestUtilAdapter;
import com.google.idea.blaze.clwb.oclang.run.CidrGoogleTestUtilAdapter;
import com.intellij.execution.Location;
import com.intellij.execution.testframework.sm.runner.SMTestLocator;
import com.intellij.openapi.project.Project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import com.google.idea.blaze.base.sync.autosync.ProjectTargetManager.SyncStatus;
import com.google.idea.blaze.base.syncstatus.SyncStatusContributor;
import com.google.idea.blaze.clwb.CidrGoogleTestUtilAdapter;
import com.google.idea.blaze.clwb.oclang.run.CidrGoogleTestUtilAdapter;
import com.intellij.execution.Location;
import com.intellij.execution.PsiLocation;
import com.intellij.openapi.project.Project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import com.google.idea.blaze.base.settings.Blaze;
import com.google.idea.blaze.base.settings.BlazeUserSettings;
import com.google.idea.blaze.base.settings.BuildSystemName;
import com.google.idea.blaze.clwb.CidrGoogleTestUtilAdapter;
import com.google.idea.blaze.clwb.ToolchainUtils;
import com.google.idea.blaze.cpp.CppBlazeRules;
import com.intellij.execution.ExecutionException;
Expand Down Expand Up @@ -296,7 +295,7 @@ private boolean shouldDisplayBazelTestFilterWarning() {
&& handlerState.getTestFilterFlag() != null
&& !PropertiesComponent.getInstance()
.getBoolean(DISABLE_BAZEL_GOOGLETEST_FILTER_WARNING, false)
&& CidrGoogleTestUtilAdapter.findGoogleTestSymbol(getProject()) != null;
&& GoogleTestUtilAdapter.findGoogleTestSymbol(getProject()) != null;
}

/**
Expand Down
41 changes: 41 additions & 0 deletions clwb/src/com/google/idea/blaze/clwb/run/GoogleTestUtilAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2023 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.idea.blaze.clwb.run;

import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.jetbrains.cidr.execution.testing.CidrTestScopeElement;
import java.util.function.Predicate;
import javax.annotation.Nullable;

public interface GoogleTestUtilAdapter {
ExtensionPointName<GoogleTestUtilAdapter> EP_NAME =
ExtensionPointName.create("com.google.idea.blaze.clwb.googleTestUtilAdapter");

@Nullable
static PsiElement findGoogleTestSymbol(Project project) {
GoogleTestUtilAdapter adapter = EP_NAME.getPoint().extensions().findFirst().orElse(null);
if (adapter != null) {
return adapter.findGoogleTestSymbol(project, testScopeElement -> true);
}

return null;
}

PsiElement findGoogleTestSymbol(
Project project, Predicate<CidrTestScopeElement> predicate);
}

0 comments on commit 0784fbf

Please sign in to comment.