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);
}
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();
}
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);
}
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);
}
Aggregations