Search in sources :

Example 1 with MockArtifactLocationDecoder

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

the class JarCacheTest method refresh_fllSync_localArtifact_lintJarCached.

@Test
public void refresh_fllSync_localArtifact_lintJarCached() throws IOException {
    ArtifactLocationDecoder localArtifactLocationDecoder = new MockArtifactLocationDecoder(workspaceRoot.directory(), /* isRemote= */
    false);
    testRefreshLintJarCached(localArtifactLocationDecoder, SyncMode.FULL);
}
Also used : 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) Test(org.junit.Test)

Example 2 with MockArtifactLocationDecoder

use of com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder 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 3 with MockArtifactLocationDecoder

use of com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder 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 4 with MockArtifactLocationDecoder

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

the class RenderJarClassFileFinderTest method initTest.

@Before
public void initTest() throws ArtifactNotFoundException {
    TargetMap targetMap = buildTargetMap();
    setTargetMap(targetMap);
    // Since this is not a light test, the ArtifactLocationDecoder points to the actual file in the
    // File System
    artifactLocationDecoder = new MockArtifactLocationDecoder() {

        @Override
        public File decode(ArtifactLocation artifactLocation) {
            File f = new File(fileSystem.getRootDir(), artifactLocation.getExecutionRootRelativePath());
            // Create the artifact if it does not exist
            // This allows us to set fileModifiedTime for the file which is used by RenderJarCache
            FileOperationProvider.getInstance().mkdirs(f);
            // Set last modified time for RenderJarCache to use
            FileOperationProvider.getInstance().setFileModifiedTime(f, 1000L);
            return f;
        }
    };
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(targetMap).setArtifactLocationDecoder(artifactLocationDecoder).build()));
    setProjectView("targets:", "  //com/google/example/simple/bin_a:bin_a", "  //com/google/example/simple/bin_b:bin_b", "  //com/google/example/simple/bin_c:bin_c");
    MockExperimentService experimentService = new MockExperimentService();
    registerApplicationComponent(ExperimentService.class, experimentService);
    experimentService.setExperiment(RenderResolveOutputGroupProvider.buildOnSync, true);
    // Disable resource resolution from Render Jars
    experimentService.setExperiment(RenderJarClassFileFinder.resolveResourceClasses, false);
    ApplicationManager.getApplication().runWriteAction(this::createAndRegisterModules);
    artifactCache = new MockArtifactCache();
    registerExtension(FileCache.EP_NAME, new RenderJarCache.FileCacheAdapter());
    registerProjectService(RenderJarCache.class, new RenderJarCache(getProject(), RenderJarCache.getCacheDirForProject(getProject()), artifactCache));
    createBinaryJars();
    FileCache.EP_NAME.extensions().forEach(ep -> ep.initialize(getProject()));
}
Also used : MockExperimentService(com.google.idea.common.experiments.MockExperimentService) MockArtifactCache(com.google.idea.blaze.android.filecache.MockArtifactCache) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) RenderJarCache(com.google.idea.blaze.android.libraries.RenderJarCache) Before(org.junit.Before)

Example 5 with MockArtifactLocationDecoder

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

the class FastBuildCompilerFactoryImplTest method setUp.

@Before
public void setUp() {
    BlazeProjectData projectData = MockBlazeProjectDataBuilder.builder().setArtifactLocationDecoder(new MockArtifactLocationDecoder()).build();
    BlazeProjectDataManager projectDataManager = new MockBlazeProjectDataManager(projectData);
    compilerFactory = FastBuildCompilerFactoryImpl.createForTest(projectDataManager, FAST_BUILD_JAVAC_JAR);
}
Also used : MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Before(org.junit.Before)

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