Search in sources :

Example 1 with LocalFileOutputArtifact

use of com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact in project intellij by bazelbuild.

the class LocalArtifactCacheTest method get_fetchesCorrectFileForArtifact.

@Test
public void get_fetchesCorrectFileForArtifact() throws IOException {
    // Create blaze artifacts in FS
    ImmutableList<OutputArtifact> outputArtifacts = ImmutableList.of(newLocalOutputArtifact("relative/path_1/artifact_1.jar"), newLocalOutputArtifact("relative/path_2/artifact_2.jar"), newLocalOutputArtifact("relative/path_3/artifact_3.jar"));
    for (OutputArtifact a : outputArtifacts) {
        File file = ((LocalFileOutputArtifact) a).getFile();
        assertThat(Paths.get(file.getParent()).toFile().mkdirs()).isTrue();
        assertThat(file.createNewFile()).isTrue();
    }
    // Add the artifacts to cache
    artifactCache.initialize();
    artifactCache.putAll(outputArtifacts, blazeContext, false);
    // Attempt to get an arbitraty artifact
    OutputArtifact artifactToFetch = outputArtifacts.get(1);
    // Check that the returned file matches the expected file
    File expectedFile = new File(cacheDirectory.getRoot(), CacheEntry.forArtifact(artifactToFetch).getFileName());
    Path returnedPath = artifactCache.get(artifactToFetch);
    assertThat(Collections.singleton(returnedPath)).doesNotContain(null);
    assertThat(returnedPath.toFile()).isEqualTo(expectedFile);
}
Also used : Path(java.nio.file.Path) LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) File(java.io.File) Test(org.junit.Test)

Example 2 with LocalFileOutputArtifact

use of com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact in project intellij by bazelbuild.

the class RenderJarCacheTest method setupProjectData.

/**
 * Sets up a mock {@link com.google.devtools.intellij.model.ProjectData} and creates the render
 * JARs in File System
 */
private void setupProjectData() throws IOException {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//com/foo/bar/baz:baz").setAndroidInfo(AndroidIdeInfo.builder().setRenderResolveJar(getArtifactLocation("com/foo/bar/baz/baz_render_jar.jar"))).setKind(RuleTypes.KT_ANDROID_LIBRARY_HELPER.getKind())).addTarget(TargetIdeInfo.builder().setLabel("//com/foo/bar/qux:qux").setAndroidInfo(AndroidIdeInfo.builder().setRenderResolveJar(getArtifactLocation("com/foo/bar/qux/qux_render_jar.jar"))).setKind(RuleTypes.KT_ANDROID_LIBRARY_HELPER.getKind()).build()).build();
    intellijRule.registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder().setArtifactLocationDecoder(artifactLocationDecoder).setTargetMap(targetMap).build()));
    // Create baz_render_jar.jar in FS
    BlazeArtifact bazRenderJar = artifactLocationDecoder.resolveOutput(getArtifactLocation("com/foo/bar/baz/baz_render_jar.jar"));
    File bazRenderJarFile = ((LocalFileOutputArtifact) bazRenderJar).getFile();
    assertThat(Paths.get(bazRenderJarFile.getParent()).toFile().mkdirs()).isTrue();
    assertThat(bazRenderJarFile.createNewFile()).isTrue();
    assertThat(bazRenderJarFile.setLastModified(100000L)).isTrue();
    // Create qux_render_jar.jar in FS
    BlazeArtifact quxRenderJar = artifactLocationDecoder.resolveOutput(getArtifactLocation("com/foo/bar/qux/qux_render_jar.jar"));
    File quxRenderJarFile = ((LocalFileOutputArtifact) quxRenderJar).getFile();
    assertThat(Paths.get(quxRenderJarFile.getParent()).toFile().mkdirs()).isTrue();
    assertThat(quxRenderJarFile.createNewFile()).isTrue();
    assertThat(quxRenderJarFile.setLastModified(100000L)).isTrue();
}
Also used : LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager)

Example 3 with LocalFileOutputArtifact

use of com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact in project intellij by bazelbuild.

the class LocalArtifactCacheTest method newLocalOutputArtifact.

private LocalFileOutputArtifact newLocalOutputArtifact(String path) {
    String execRoot = workspaceRoot.directory().getAbsolutePath();
    String mnemonic = "k8-opt";
    return new LocalFileOutputArtifact(new File(execRoot + "/blaze-out" + mnemonic + "/" + path), mnemonic + "/" + path, mnemonic);
}
Also used : LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) File(java.io.File)

Example 4 with LocalFileOutputArtifact

use of com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact in project intellij by bazelbuild.

the class LocalArtifactCacheTest method put_addsArtifactInDirectory.

@Test
public void put_addsArtifactInDirectory() throws IOException {
    // Create blaze artifacts in FS
    ImmutableList<OutputArtifact> outputArtifacts = ImmutableList.of(newLocalOutputArtifact("relative/path_1/artifact_1.jar"), newLocalOutputArtifact("relative/path_2/artifact_2.jar"), newLocalOutputArtifact("relative/path_3/artifact_3.jar"));
    for (OutputArtifact a : outputArtifacts) {
        File file = ((LocalFileOutputArtifact) a).getFile();
        assertThat(Paths.get(file.getParent()).toFile().mkdirs()).isTrue();
        assertThat(file.createNewFile()).isTrue();
    }
    // Put blaze artifacts in cache
    artifactCache.initialize();
    artifactCache.putAll(outputArtifacts, blazeContext, false);
    // Check that the artifacts were added to the cache.
    ImmutableList<File> expectedFiles = Stream.concat(outputArtifacts.stream().map(a -> {
        try {
            return CacheEntry.forArtifact(a);
        } catch (ArtifactNotFoundException e) {
            return null;
        }
    }).filter(Objects::nonNull).map(CacheEntry::getFileName), Stream.of(CACHE_DATA_FILENAME)).map(f -> new File(cacheDirectory.getRoot(), f)).collect(ImmutableList.toImmutableList());
    assertThat(cacheDirectory.getRoot().listFiles()).asList().containsExactlyElementsIn(expectedFiles);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) RunWith(org.junit.runner.RunWith) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) ImmutableList(com.google.common.collect.ImmutableList) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) Path(java.nio.file.Path) IntellijRule(com.google.idea.testing.IntellijRule) Before(org.junit.Before) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) CACHE_DATA_FILENAME(com.google.idea.blaze.android.filecache.LocalArtifactCache.CACHE_DATA_FILENAME) IOException(java.io.IOException) Test(org.junit.Test) RemoteArtifactPrefetcher(com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) Objects(java.util.Objects) Stream(java.util.stream.Stream) Rule(org.junit.Rule) Paths(java.nio.file.Paths) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) DefaultPrefetcher(com.google.idea.blaze.base.prefetch.DefaultPrefetcher) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) Objects(java.util.Objects) LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) File(java.io.File) Test(org.junit.Test)

Aggregations

LocalFileOutputArtifact (com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact)4 File (java.io.File)4 OutputArtifact (com.google.idea.blaze.base.command.buildresult.OutputArtifact)2 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)2 Path (java.nio.file.Path)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 CACHE_DATA_FILENAME (com.google.idea.blaze.android.filecache.LocalArtifactCache.CACHE_DATA_FILENAME)1 BlazeArtifact (com.google.idea.blaze.base.command.buildresult.BlazeArtifact)1 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)1 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)1 FileOperationProvider (com.google.idea.blaze.base.io.FileOperationProvider)1 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)1 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)1 DefaultPrefetcher (com.google.idea.blaze.base.prefetch.DefaultPrefetcher)1 RemoteArtifactPrefetcher (com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher)1 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)1 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)1 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)1