Search in sources :

Example 11 with MockArtifactLocationDecoder

use of com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method importJava.

private BlazeJavaImportResult importJava(ProjectView projectView, TargetMap targetMap) {
    ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
    WorkspaceLanguageSettings languageSettings = new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of(LanguageClass.GENERIC, LanguageClass.SCALA, LanguageClass.JAVA));
    JavaSourceFilter sourceFilter = new JavaSourceFilter(Blaze.getBuildSystemName(project), workspaceRoot, projectViewSet, targetMap);
    JdepsMap jdepsMap = key -> ImmutableList.of();
    ArtifactLocationDecoder decoder = new MockArtifactLocationDecoder();
    return new BlazeJavaWorkspaceImporter(project, workspaceRoot, projectViewSet, languageSettings, targetMap, sourceFilter, jdepsMap, null, decoder, null).importWorkspace(context);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) Map(java.util.Map) MockRemoteArtifactPrefetcher(com.google.idea.blaze.base.sync.MockRemoteArtifactPrefetcher) JavaLikeLanguage(com.google.idea.blaze.java.sync.source.JavaLikeLanguage) Blaze(com.google.idea.blaze.base.settings.Blaze) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ImmutableSet(com.google.common.collect.ImmutableSet) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) BuildSystemName(com.google.idea.blaze.base.settings.BuildSystemName) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) RemoteArtifactPrefetcher(com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) ScalaJavaLikeLanguage(com.google.idea.blaze.scala.ScalaJavaLikeLanguage) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact) ErrorCollector(com.google.idea.blaze.base.scope.ErrorCollector) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) NotNull(org.jetbrains.annotations.NotNull) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) JavaSourcePackageReader(com.google.idea.blaze.java.sync.source.JavaSourcePackageReader) EmptyLibraryFilterSettings(com.google.idea.blaze.java.sync.importer.emptylibrary.EmptyLibraryFilterSettings) PackageManifestReader(com.google.idea.blaze.java.sync.source.PackageManifestReader) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) RunWith(org.junit.runner.RunWith) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ExperimentService(com.google.idea.common.experiments.ExperimentService) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) GenericBlazeRules(com.google.idea.blaze.base.model.primitives.GenericBlazeRules) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) ImmutableList(com.google.common.collect.ImmutableList) Provider(com.google.idea.blaze.base.model.primitives.Kind.Provider) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) MockPrefetchService(com.google.idea.blaze.base.prefetch.MockPrefetchService) JavaBlazeRules(com.google.idea.blaze.java.JavaBlazeRules) BlazeJavaSyncAugmenter(com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) File(java.io.File) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) ExtensionPointImpl(com.intellij.openapi.extensions.impl.ExtensionPointImpl) MockExperimentService(com.google.idea.common.experiments.MockExperimentService) ScalaBlazeRules(com.google.idea.blaze.scala.ScalaBlazeRules) JdepsMap(com.google.idea.blaze.java.sync.jdeps.JdepsMap) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) JdepsMap(com.google.idea.blaze.java.sync.jdeps.JdepsMap) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter)

Example 12 with MockArtifactLocationDecoder

use of com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder in project intellij by bazelbuild.

the class RenderJarCacheTest method initTest.

@Before
public void initTest() throws IOException {
    errorCollector = new ErrorCollector();
    outputSink = new WritingOutputSink();
    context = BlazeContext.create();
    context.addOutputSink(PrintOutput.class, outputSink);
    workspaceRoot = new WorkspaceRoot(temporaryFolder.getRoot());
    artifactLocationDecoder = new MockArtifactLocationDecoder() {

        @Override
        public File decode(ArtifactLocation artifactLocation) {
            return new File(workspaceRoot.directory(), artifactLocation.getRelativePath());
        }
    };
    registerMockBlazeImportSettings();
    mockedArtifactCache = Mockito.mock(ArtifactCache.class);
    intellijRule.registerProjectService(RenderJarCache.class, new RenderJarCache(intellijRule.getProject(), RenderJarCache.getCacheDirForProject(intellijRule.getProject()), mockedArtifactCache));
    intellijRule.registerApplicationService(FileOperationProvider.class, new FileOperationProvider());
    intellijRule.registerApplicationService(RemoteArtifactPrefetcher.class, new DefaultPrefetcher());
    intellijRule.registerExtensionPoint(FileCache.EP_NAME, FileCache.class);
    intellijRule.registerExtension(FileCache.EP_NAME, new FileCacheAdapter());
    // Required to enable RenderJarClassFileFinder
    MockExperimentService experimentService = new MockExperimentService();
    experimentService.setExperiment(RenderResolveOutputGroupProvider.buildOnSync, true);
    intellijRule.registerApplicationService(ExperimentService.class, experimentService);
    // Setup needed for setting a projectview
    intellijRule.registerExtensionPoint(BlazeSyncPlugin.EP_NAME, BlazeSyncPlugin.class);
    intellijRule.registerExtension(BlazeSyncPlugin.EP_NAME, new BlazeJavaSyncPlugin());
    // RenderJarCache looks at targets of `Kind`s with LanguageClass.ANDROID
    // so we need to setup the framework for fetching a target's `Kind`
    intellijRule.registerExtensionPoint(Kind.Provider.EP_NAME, Kind.Provider.class);
    intellijRule.registerExtension(Kind.Provider.EP_NAME, new AndroidBlazeRules());
    intellijRule.registerApplicationService(ApplicationState.class, new ApplicationState());
    // registered because `RenderJarCache` uses it to filter source targets
    projectViewManager = new MockProjectViewManager();
    intellijRule.registerProjectService(ProjectViewManager.class, projectViewManager);
    intellijRule.registerApplicationService(BlazeExecutor.class, new MockBlazeExecutor());
    setupProjectData();
    setProjectView("directories:", "  com/foo/bar/baz", "  com/foo/bar/qux", "targets:", "  //com/foo/bar/baz:baz", "  //com/foo/bar/qux:quz");
}
Also used : MockExperimentService(com.google.idea.common.experiments.MockExperimentService) MockProjectViewManager(com.google.idea.blaze.base.MockProjectViewManager) BlazeJavaSyncPlugin(com.google.idea.blaze.java.sync.BlazeJavaSyncPlugin) ApplicationState(com.google.idea.blaze.base.model.primitives.Kind.ApplicationState) ErrorCollector(com.google.idea.blaze.base.scope.ErrorCollector) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) FileCacheAdapter(com.google.idea.blaze.android.libraries.RenderJarCache.FileCacheAdapter) AndroidBlazeRules(com.google.idea.blaze.java.AndroidBlazeRules) Kind(com.google.idea.blaze.base.model.primitives.Kind) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) DefaultPrefetcher(com.google.idea.blaze.base.prefetch.DefaultPrefetcher) File(java.io.File) ArtifactCache(com.google.idea.blaze.android.filecache.ArtifactCache) Before(org.junit.Before)

Example 13 with MockArtifactLocationDecoder

use of com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder in project intellij by bazelbuild.

the class BlazeModuleSystemTest method createMockBlazeProjectData.

private BlazeProjectData createMockBlazeProjectData() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(Label.create("//foo:bar")).setKind(AndroidBlazeRules.RuleTypes.ANDROID_LIBRARY.getKind()).setBuildFile(ArtifactLocation.builder().setRelativePath("foo/BUILD").build()).build()).build();
    ArtifactLocationDecoder decoder = new MockArtifactLocationDecoder() {

        @Override
        public File decode(ArtifactLocation artifactLocation) {
            return new File("/", artifactLocation.getRelativePath());
        }
    };
    return MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(targetMap).setArtifactLocationDecoder(decoder).build();
}
Also used : ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Aggregations

MockArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder)13 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)9 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)7 File (java.io.File)7 Test (org.junit.Test)7 FileOperationProvider (com.google.idea.blaze.base.io.FileOperationProvider)5 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)5 MockExperimentService (com.google.idea.common.experiments.MockExperimentService)5 DefaultPrefetcher (com.google.idea.blaze.base.prefetch.DefaultPrefetcher)4 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)3 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)3 BlazeImportSettings (com.google.idea.blaze.base.settings.BlazeImportSettings)3 BlazeImportSettingsManager (com.google.idea.blaze.base.settings.BlazeImportSettingsManager)3 Before (org.junit.Before)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 BlazeTestCase (com.google.idea.blaze.base.BlazeTestCase)2 MockBlazeExecutor (com.google.idea.blaze.base.async.executor.MockBlazeExecutor)2 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)2