diff options
3 files changed, 17 insertions, 13 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java index eef30e7c0e..be529acddb 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java @@ -49,9 +49,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -public class BazelAnalysisMock extends AnalysisMock { +public final class BazelAnalysisMock extends AnalysisMock { public static final AnalysisMock INSTANCE = new BazelAnalysisMock(); + private BazelAnalysisMock() { + } + @Override public void setupMockClient(MockToolsConfig config) throws IOException { String workspace = config.getPath("").getPathString(); diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java index 33ed3cdda4..037862a0da 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java @@ -25,11 +25,13 @@ import com.google.devtools.build.lib.rules.repository.LocalRepositoryRule; import com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction; import com.google.devtools.build.lib.rules.repository.RepositoryFunction; import com.google.devtools.build.lib.skyframe.SkyFunctions; +import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionName; import java.io.IOException; +import java.lang.reflect.Field; import java.util.Collection; import java.util.concurrent.atomic.AtomicBoolean; @@ -38,6 +40,16 @@ import java.util.concurrent.atomic.AtomicBoolean; */ public abstract class AnalysisMock { + public static AnalysisMock get() { + try { + Class<?> providerClass = Class.forName(TestConstants.TEST_ANALYSIS_MOCK); + Field instanceField = providerClass.getField("INSTANCE"); + return (AnalysisMock) instanceField.get(null); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + /** * This is called from test setup to create the mock directory layout needed to create the * configuration. diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java index 4efc342969..247b121b97 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java @@ -68,7 +68,6 @@ import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.common.options.Options; import com.google.devtools.common.options.OptionsParser; -import java.lang.reflect.Field; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -132,7 +131,7 @@ public abstract class AnalysisTestCase extends FoundationTestCase { @Override protected void setUp() throws Exception { super.setUp(); - analysisMock = getAnalysisMock(); + analysisMock = AnalysisMock.get(); pkgLocator = new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)); directories = new BlazeDirectories(outputBase, outputBase, rootDirectory); workspaceStatusActionFactory = @@ -146,16 +145,6 @@ public abstract class AnalysisTestCase extends FoundationTestCase { useRuleClassProvider(TestRuleClassProvider.getRuleClassProvider()); } - protected AnalysisMock getAnalysisMock() { - try { - Class<?> providerClass = Class.forName(TestConstants.TEST_ANALYSIS_MOCK); - Field instanceField = providerClass.getField("INSTANCE"); - return (AnalysisMock) instanceField.get(null); - } catch (Exception e) { - throw new IllegalStateException(e); - } - } - /** * Changes the rule class provider to be used for the loading and the analysis phase. */ |