Search in sources :

Example 1 with DefaultPrefetcher

use of com.google.idea.blaze.base.prefetch.DefaultPrefetcher in project intellij by bazelbuild.

the class LocalArtifactCacheTest method initTest.

@Before
public void initTest() throws IOException {
    intellijRule.registerApplicationService(FileOperationProvider.class, new FileOperationProvider());
    intellijRule.registerApplicationService(RemoteArtifactPrefetcher.class, new DefaultPrefetcher());
    workspaceRoot = new WorkspaceRoot(temporaryFolder.getRoot());
    ArtifactLocationDecoder artifactLocationDecoder = new MockArtifactLocationDecoder() {

        @Override
        public File decode(ArtifactLocation artifactLocation) {
            return new File(workspaceRoot.directory(), artifactLocation.getRelativePath());
        }
    };
    intellijRule.registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder().setArtifactLocationDecoder(artifactLocationDecoder).build()));
    blazeContext = BlazeContext.create();
    artifactCache = new LocalArtifactCache(intellijRule.getProject(), "TestArtifactCache", cacheDirectory.getRoot().toPath());
}
Also used : FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) DefaultPrefetcher(com.google.idea.blaze.base.prefetch.DefaultPrefetcher) 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) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) File(java.io.File) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Before(org.junit.Before)

Example 2 with DefaultPrefetcher

use of com.google.idea.blaze.base.prefetch.DefaultPrefetcher in project intellij by bazelbuild.

the class UnpackedAarsTest method initTest.

@Override
protected void initTest(Container applicationServices, Container projectServices) {
    writingOutputSink = new WritingOutputSink();
    context = BlazeContext.create();
    context.addOutputSink(PrintOutput.class, writingOutputSink);
    workspaceRoot = new WorkspaceRoot(folder.getRoot());
    localArtifactLocationDecoder = new MockArtifactLocationDecoder() {

        @Override
        public File decode(ArtifactLocation artifactLocation) {
            return new File(workspaceRoot.directory(), artifactLocation.getRelativePath());
        }
    };
    remoteArtifactLocationDecoder = new MockArtifactLocationDecoder() {

        @Override
        public File decode(ArtifactLocation artifactLocation) {
            return new File(workspaceRoot.directory(), artifactLocation.getRelativePath());
        }

        @Override
        public BlazeArtifact resolveOutput(ArtifactLocation artifact) {
            if (!artifact.isSource()) {
                File file = new File(workspaceRoot.directory(), artifact.getRelativePath());
                // when the remote artifact cannot be resolved, it will guess it as local artifact.
                return file.exists() ? new FakeRemoteOutputArtifact(file) : super.resolveOutput(artifact);
            }
            return super.resolveOutput(artifact);
        }
    };
    projectServices.register(BlazeImportSettingsManager.class, new BlazeImportSettingsManager(project));
    try {
        File projectDataDirectory = folder.newFolder("projectdata");
        BlazeImportSettings dummyImportSettings = new BlazeImportSettings("", "", projectDataDirectory.getAbsolutePath(), "", BuildSystemName.Bazel);
        BlazeImportSettingsManager.getInstance(project).setImportSettings(dummyImportSettings);
    } catch (IOException e) {
        throw new AssertionError("Fail to create directory for test", e);
    }
    applicationServices.register(FileOperationProvider.class, new FileOperationProvider());
    applicationServices.register(RemoteArtifactPrefetcher.class, new DefaultPrefetcher());
    projectServices.register(UnpackedAars.class, new UnpackedAars(project));
    registerExtensionPoint(FileCache.EP_NAME, FileCache.class).registerExtension(new FileCacheAdapter());
    registerExtensionPoint(BlazeSyncPlugin.EP_NAME, BlazeSyncPlugin.class).registerExtension(new BlazeAndroidSyncPlugin());
    registerExtensionPoint(BlazeLibrarySorter.EP_NAME, BlazeLibrarySorter.class);
    applicationServices.register(ExperimentService.class, new MockExperimentService());
}
Also used : BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) MockExperimentService(com.google.idea.common.experiments.MockExperimentService) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) BlazeAndroidSyncPlugin(com.google.idea.blaze.android.sync.BlazeAndroidSyncPlugin) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) IOException(java.io.IOException) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) FileCache(com.google.idea.blaze.base.filecache.FileCache) FileCacheAdapter(com.google.idea.blaze.android.libraries.UnpackedAars.FileCacheAdapter) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) DefaultPrefetcher(com.google.idea.blaze.base.prefetch.DefaultPrefetcher) File(java.io.File)

Example 3 with DefaultPrefetcher

use of com.google.idea.blaze.base.prefetch.DefaultPrefetcher in project intellij by bazelbuild.

the class JarCacheTest method initTest.

@Override
protected void initTest(Container applicationServices, Container projectServices) {
    context = BlazeContext.create();
    context.addOutputSink(PrintOutput.class, new WritingOutputSink());
    workspaceRoot = new WorkspaceRoot(folder.getRoot());
    fakeJarRepackager = new FakeJarRepackager();
    BlazeImportSettingsManager blazeImportSettingsManager = new BlazeImportSettingsManager(project);
    try {
        File projectDataDirectory = folder.newFolder("projectdata");
        BlazeImportSettings dummyImportSettings = new BlazeImportSettings("", "", projectDataDirectory.getAbsolutePath(), "", BuildSystemName.Blaze);
        blazeImportSettingsManager.setImportSettings(dummyImportSettings);
    } catch (IOException e) {
        throw new AssertionError("Failed to create a directory for test", e);
    }
    projectServices.register(BlazeImportSettingsManager.class, blazeImportSettingsManager);
    applicationServices.register(FileOperationProvider.class, new FileOperationProvider());
    applicationServices.register(RemoteArtifactPrefetcher.class, new DefaultPrefetcher());
    projectServices.register(JarCacheFolderProvider.class, new JarCacheFolderProvider(project));
    applicationServices.register(JarRepackager.class, fakeJarRepackager);
    JarCache jarCache = new JarCache(project);
    jarCache.enableForTest();
    projectServices.register(JarCache.class, jarCache);
    registerExtensionPoint(FileCache.EP_NAME, FileCache.class).registerExtension(new JarCache.FileCacheAdapter(), testDisposable);
    registerExtensionPoint(BlazeSyncPlugin.EP_NAME, BlazeSyncPlugin.class).registerExtension(new BlazeJavaSyncPlugin(), testDisposable);
    registerExtensionPoint(BlazeLibrarySorter.EP_NAME, BlazeLibrarySorter.class);
    applicationServices.register(BlazeJavaUserSettings.class, new BlazeJavaUserSettings());
    applicationServices.register(ExperimentService.class, new MockExperimentService());
    applicationServices.register(BlazeExecutor.class, new MockBlazeExecutor());
}
Also used : BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) MockExperimentService(com.google.idea.common.experiments.MockExperimentService) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) BlazeJavaSyncPlugin(com.google.idea.blaze.java.sync.BlazeJavaSyncPlugin) IOException(java.io.IOException) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) FileCache(com.google.idea.blaze.base.filecache.FileCache) BlazeJavaUserSettings(com.google.idea.blaze.java.settings.BlazeJavaUserSettings) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) DefaultPrefetcher(com.google.idea.blaze.base.prefetch.DefaultPrefetcher) File(java.io.File)

Example 4 with DefaultPrefetcher

use of com.google.idea.blaze.base.prefetch.DefaultPrefetcher 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)

Aggregations

FileOperationProvider (com.google.idea.blaze.base.io.FileOperationProvider)4 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)4 DefaultPrefetcher (com.google.idea.blaze.base.prefetch.DefaultPrefetcher)4 File (java.io.File)4 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)3 MockArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder)3 MockExperimentService (com.google.idea.common.experiments.MockExperimentService)3 MockBlazeExecutor (com.google.idea.blaze.base.async.executor.MockBlazeExecutor)2 FileCache (com.google.idea.blaze.base.filecache.FileCache)2 BlazeImportSettings (com.google.idea.blaze.base.settings.BlazeImportSettings)2 BlazeImportSettingsManager (com.google.idea.blaze.base.settings.BlazeImportSettingsManager)2 BlazeSyncPlugin (com.google.idea.blaze.base.sync.BlazeSyncPlugin)2 BlazeJavaSyncPlugin (com.google.idea.blaze.java.sync.BlazeJavaSyncPlugin)2 IOException (java.io.IOException)2 Before (org.junit.Before)2 ArtifactCache (com.google.idea.blaze.android.filecache.ArtifactCache)1 FileCacheAdapter (com.google.idea.blaze.android.libraries.RenderJarCache.FileCacheAdapter)1 FileCacheAdapter (com.google.idea.blaze.android.libraries.UnpackedAars.FileCacheAdapter)1 BlazeAndroidSyncPlugin (com.google.idea.blaze.android.sync.BlazeAndroidSyncPlugin)1 MockProjectViewManager (com.google.idea.blaze.base.MockProjectViewManager)1