Search in sources :

Example 1 with CacheEntry

use of com.google.idea.blaze.android.filecache.CacheEntry in project intellij by bazelbuild.

the class RenderJarClassFileFinderTest method resourceModule_canFindDependencyClasses.

/**
 * Tests that resource modules can find classes from dependencies of source targets that comprise
 * the resource module.
 */
@Test
public void resourceModule_canFindDependencyClasses() throws ArtifactNotFoundException {
    AndroidResourceModuleRegistry moduleRegistry = AndroidResourceModuleRegistry.getInstance(getProject());
    Module aResourceModule = moduleRegistry.getModuleContainingResourcesOf(getTargetKey("/src_a:src_a"));
    RenderJarClassFileFinder aClassFileFinder = new RenderJarClassFileFinder(aResourceModule);
    File cacheDir = RenderJarCache.getInstance(getProject()).getCacheDir();
    CacheEntry binACacheEntry = CacheEntry.forArtifact((LocalFileOutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_a.jar")));
    String binAJar = cacheDir.getAbsoluteFile() + "/" + binACacheEntry.getFileName();
    CacheEntry binBCacheEntry = CacheEntry.forArtifact((LocalFileOutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_b.jar")));
    String binBJar = cacheDir.getAbsoluteFile() + "/" + binBCacheEntry.getFileName();
    CacheEntry binCCacheEntry = CacheEntry.forArtifact((LocalFileOutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_c.jar")));
    String binCJar = cacheDir.getAbsoluteFile() + "/" + binCCacheEntry.getFileName();
    assertThat(aClassFileFinder.findClassFile("com.google.example.simple.trans_dep_a.TransDepA")).isEqualTo(fileSystem.findFile(binAJar + "!/com/google/example/simple/trans_dep_a/TransDepA.class"));
    assertThat(aClassFileFinder.findClassFile("com.google.example.simple.trans_dep_a.TransDepA$Inner")).isEqualTo(fileSystem.findFile(binAJar + "!/com/google/example/simple/trans_dep_a/TransDepA$Inner.class"));
    assertThat(aClassFileFinder.findClassFile("com.google.example.simple.trans_dep_b.TransDepB")).isEqualTo(fileSystem.findFile(binBJar + "!/com/google/example/simple/trans_dep_b/TransDepB.class"));
    assertThat(aClassFileFinder.findClassFile("com.google.example.simple.trans_dep_b.TransDepB$Inner")).isEqualTo(fileSystem.findFile(binBJar + "!/com/google/example/simple/trans_dep_b/TransDepB$Inner.class"));
    Module cResourceModule = moduleRegistry.getModuleContainingResourcesOf(getTargetKey("/src_c:src_c"));
    RenderJarClassFileFinder cClassFileFinder = new RenderJarClassFileFinder(cResourceModule);
    assertThat(cClassFileFinder.findClassFile("com.google.example.simple.trans_dep_c.TransDepC")).isEqualTo(fileSystem.findFile(binCJar + "!/com/google/example/simple/trans_dep_c/TransDepC.class"));
    assertThat(cClassFileFinder.findClassFile("com.google.example.simple.trans_dep_c.TransDepC$Inner")).isEqualTo(fileSystem.findFile(binCJar + "!/com/google/example/simple/trans_dep_c/TransDepC$Inner.class"));
}
Also used : AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) BlazeAndroidProjectStructureSyncer.moduleNameForAndroidModule(com.google.idea.blaze.android.sync.projectstructure.BlazeAndroidProjectStructureSyncer.moduleNameForAndroidModule) Module(com.intellij.openapi.module.Module) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) CacheEntry(com.google.idea.blaze.android.filecache.CacheEntry) File(java.io.File) Test(org.junit.Test)

Example 2 with CacheEntry

use of com.google.idea.blaze.android.filecache.CacheEntry in project intellij by bazelbuild.

the class RenderJarClassFileFinderTest method resourceModule_canFindSourceClasses.

/**
 * Tests that resource modules can correctly find classes corresponding to sources of the targets
 * that comprise the resource module.
 */
@Test
public void resourceModule_canFindSourceClasses() throws ArtifactNotFoundException {
    AndroidResourceModuleRegistry moduleRegistry = AndroidResourceModuleRegistry.getInstance(getProject());
    Module aResourceModule = moduleRegistry.getModuleContainingResourcesOf(getTargetKey("/src_a:src_a"));
    RenderJarClassFileFinder aClassFileFinder = new RenderJarClassFileFinder(aResourceModule);
    File cacheDir = RenderJarCache.getInstance(getProject()).getCacheDir();
    CacheEntry binACacheEntry = CacheEntry.forArtifact((LocalFileOutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_a.jar")));
    String binAJar = cacheDir.getAbsoluteFile() + "/" + binACacheEntry.getFileName();
    CacheEntry binBCacheEntry = CacheEntry.forArtifact((LocalFileOutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_b.jar")));
    String binBJar = cacheDir.getAbsoluteFile() + "/" + binBCacheEntry.getFileName();
    CacheEntry binCCacheEntry = CacheEntry.forArtifact((LocalFileOutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_c.jar")));
    String binCJar = cacheDir.getAbsoluteFile() + "/" + binCCacheEntry.getFileName();
    assertThat(aClassFileFinder.findClassFile("com.google.example.simple.src_a.SrcA")).isEqualTo(fileSystem.findFile(binAJar + "!/com/google/example/simple/src_a/SrcA.class"));
    assertThat(aClassFileFinder.findClassFile("com.google.example.simple.src_a.SrcA$Inner")).isEqualTo(fileSystem.findFile(binAJar + "!/com/google/example/simple/src_a/SrcA$Inner.class"));
    assertThat(aClassFileFinder.findClassFile("com.google.example.simple.src_b.SrcB")).isEqualTo(fileSystem.findFile(binBJar + "!/com/google/example/simple/src_b/SrcB.class"));
    assertThat(aClassFileFinder.findClassFile("com.google.example.simple.src_b.SrcB$Inner")).isEqualTo(fileSystem.findFile(binBJar + "!/com/google/example/simple/src_b/SrcB$Inner.class"));
    Module cResourceModule = moduleRegistry.getModuleContainingResourcesOf(getTargetKey("/src_c:src_c"));
    RenderJarClassFileFinder cClassFileFinder = new RenderJarClassFileFinder(cResourceModule);
    assertThat(cClassFileFinder.findClassFile("com.google.example.simple.src_c.SrcC")).isEqualTo(fileSystem.findFile(binCJar + "!/com/google/example/simple/src_c/SrcC.class"));
    assertThat(cClassFileFinder.findClassFile("com.google.example.simple.src_c.SrcC$Inner")).isEqualTo(fileSystem.findFile(binCJar + "!/com/google/example/simple/src_c/SrcC$Inner.class"));
}
Also used : AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) BlazeAndroidProjectStructureSyncer.moduleNameForAndroidModule(com.google.idea.blaze.android.sync.projectstructure.BlazeAndroidProjectStructureSyncer.moduleNameForAndroidModule) Module(com.intellij.openapi.module.Module) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) CacheEntry(com.google.idea.blaze.android.filecache.CacheEntry) File(java.io.File) Test(org.junit.Test)

Example 3 with CacheEntry

use of com.google.idea.blaze.android.filecache.CacheEntry in project intellij by bazelbuild.

the class RenderJarClassFileFinderTest method workspaceModule_canFindAllClassesInAllBinaries.

/**
 * Tests that .workspace module can find classes from all binaries in the projectview.
 */
@Test
public void workspaceModule_canFindAllClassesInAllBinaries() throws ArtifactNotFoundException {
    Module workspaceModule = ModuleManager.getInstance(getProject()).findModuleByName(WORKSPACE_MODULE_NAME);
    assertThat(workspaceModule).isNotNull();
    RenderJarClassFileFinder classFileFinder = new RenderJarClassFileFinder(workspaceModule);
    File cacheDir = RenderJarCache.getInstance(getProject()).getCacheDir();
    CacheEntry binACacheEntry = CacheEntry.forArtifact((LocalFileOutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_a.jar")));
    String binAJar = cacheDir.getAbsoluteFile() + "/" + binACacheEntry.getFileName();
    CacheEntry binBCacheEntry = CacheEntry.forArtifact((LocalFileOutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_b.jar")));
    String binBJar = cacheDir.getAbsoluteFile() + "/" + binBCacheEntry.getFileName();
    CacheEntry binCCacheEntry = CacheEntry.forArtifact((LocalFileOutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_c.jar")));
    String binCJar = cacheDir.getAbsoluteFile() + "/" + binCCacheEntry.getFileName();
    assertThat(classFileFinder.findClassFile("com.google.example.simple.src_a.SrcA")).isEqualTo(fileSystem.findFile(binAJar + "!/com/google/example/simple/src_a/SrcA.class"));
    assertThat(classFileFinder.findClassFile("com.google.example.simple.src_a.SrcA$Inner")).isEqualTo(fileSystem.findFile(binAJar + "!/com/google/example/simple/src_a/SrcA$Inner.class"));
    assertThat(classFileFinder.findClassFile("com.google.example.simple.src_b.SrcB")).isEqualTo(fileSystem.findFile(binBJar + "!/com/google/example/simple/src_b/SrcB.class"));
    assertThat(classFileFinder.findClassFile("com.google.example.simple.src_b.SrcB$Inner")).isEqualTo(fileSystem.findFile(binBJar + "!/com/google/example/simple/src_b/SrcB$Inner.class"));
    assertThat(classFileFinder.findClassFile("com.google.example.simple.src_c.SrcC")).isEqualTo(fileSystem.findFile(binCJar + "!/com/google/example/simple/src_c/SrcC.class"));
    assertThat(classFileFinder.findClassFile("com.google.example.simple.src_c.SrcC$Inner")).isEqualTo(fileSystem.findFile(binCJar + "!/com/google/example/simple/src_c/SrcC$Inner.class"));
    assertThat(classFileFinder.findClassFile("com.google.example.simple.trans_dep_a.TransDepA")).isEqualTo(fileSystem.findFile(binAJar + "!/com/google/example/simple/trans_dep_a/TransDepA.class"));
    assertThat(classFileFinder.findClassFile("com.google.example.simple.trans_dep_a.TransDepA$Inner")).isEqualTo(fileSystem.findFile(binAJar + "!/com/google/example/simple/trans_dep_a/TransDepA$Inner.class"));
    assertThat(classFileFinder.findClassFile("com.google.example.simple.trans_dep_b.TransDepB")).isEqualTo(fileSystem.findFile(binBJar + "!/com/google/example/simple/trans_dep_b/TransDepB.class"));
    assertThat(classFileFinder.findClassFile("com.google.example.simple.trans_dep_b.TransDepB$Inner")).isEqualTo(fileSystem.findFile(binBJar + "!/com/google/example/simple/trans_dep_b/TransDepB$Inner.class"));
    assertThat(classFileFinder.findClassFile("com.google.example.simple.trans_dep_c.TransDepC")).isEqualTo(fileSystem.findFile(binCJar + "!/com/google/example/simple/trans_dep_c/TransDepC.class"));
    assertThat(classFileFinder.findClassFile("com.google.example.simple.trans_dep_c.TransDepC$Inner")).isEqualTo(fileSystem.findFile(binCJar + "!/com/google/example/simple/trans_dep_c/TransDepC$Inner.class"));
}
Also used : BlazeAndroidProjectStructureSyncer.moduleNameForAndroidModule(com.google.idea.blaze.android.sync.projectstructure.BlazeAndroidProjectStructureSyncer.moduleNameForAndroidModule) Module(com.intellij.openapi.module.Module) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) CacheEntry(com.google.idea.blaze.android.filecache.CacheEntry) File(java.io.File) Test(org.junit.Test)

Example 4 with CacheEntry

use of com.google.idea.blaze.android.filecache.CacheEntry in project intellij by bazelbuild.

the class RenderJarClassFileFinderTest method createBinaryJars.

/**
 * Creates empty files corresponding to content entries in a JAR. Doesn't create an actual
 * archive, only mimics the archive roots in file system.
 */
private void createBinaryJars() throws ArtifactNotFoundException {
    File cacheDirFile = RenderJarCache.getInstance(getProject()).getCacheDir();
    fileSystem.createDirectory(cacheDirFile.getAbsolutePath());
    String cacheDir = cacheDirFile.getPath();
    OutputArtifact binAArtifact = (OutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_a.jar"));
    CacheEntry binACacheEntry = CacheEntry.forArtifact(binAArtifact);
    String binAJar = cacheDir + "/" + binACacheEntry.getFileName();
    fileSystem.createFile(binAJar);
    fileSystem.createFile(binAJar + "!/com/google/example/simple/bin_a/MainActivity.class");
    fileSystem.createFile(binAJar + "!/com/google/example/simple/bin_a/R$color.class");
    fileSystem.createFile(binAJar + "!/com/google/example/simple/src_a/SrcA.class");
    fileSystem.createFile(binAJar + "!/com/google/example/simple/src_a/SrcA$Inner.class");
    fileSystem.createFile(binAJar + "!/com/google/example/simple/src_a/R$attr.class");
    fileSystem.createFile(binAJar + "!/com/google/example/simple/trans_dep_a/TransDepA.class");
    fileSystem.createFile(binAJar + "!/com/google/example/simple/trans_dep_a/TransDepA$Inner.class");
    fileSystem.createFile(binAJar + "!/com/google/example/simple/trans_dep_a/R$dimen.class");
    artifactCache.addTrackedFile(binAArtifact, binAJar);
    OutputArtifact binBArtifact = (OutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_b.jar"));
    CacheEntry binBCacheEntry = CacheEntry.forArtifact(binBArtifact);
    String binBJar = cacheDir + "/" + binBCacheEntry.getFileName();
    fileSystem.createFile(binBJar);
    fileSystem.createFile(binBJar + "!/com/google/example/simple/bin_b/MainActivity.class");
    fileSystem.createFile(binBJar + "!/com/google/example/simple/bin_b/R$color.class");
    fileSystem.createFile(binBJar + "!/com/google/example/simple/src_b/SrcB.class");
    fileSystem.createFile(binBJar + "!/com/google/example/simple/src_b/SrcB$Inner.class");
    fileSystem.createFile(binBJar + "!/com/google/example/simple/src_b/R$attr.class");
    fileSystem.createFile(binBJar + "!/com/google/example/simple/trans_dep_b/TransDepB.class");
    fileSystem.createFile(binBJar + "!/com/google/example/simple/trans_dep_b/TransDepB$Inner.class");
    fileSystem.createFile(binBJar + "!/com/google/example/simple/trans_dep_b/R$dimen.class");
    artifactCache.addTrackedFile(binBArtifact, binBJar);
    OutputArtifact binCArtifact = (OutputArtifact) artifactLocationDecoder.resolveOutput(getArtifactLocation("com/google/example/simple/bin_c.jar"));
    CacheEntry binCCacheEntry = CacheEntry.forArtifact(binCArtifact);
    String binCJar = cacheDir + "/" + binCCacheEntry.getFileName();
    fileSystem.createFile(binCJar);
    fileSystem.createFile(binCJar + "!/com/google/example/simple/bin_c/MainActivity.class");
    fileSystem.createFile(binCJar + "!/com/google/example/simple/bin_c/R$color.class");
    fileSystem.createFile(binCJar + "!/com/google/example/simple/src_c/SrcC.class");
    fileSystem.createFile(binCJar + "!/com/google/example/simple/src_c/SrcC$Inner.class");
    fileSystem.createFile(binCJar + "!/com/google/example/simple/src_c/R$attr.class");
    fileSystem.createFile(binCJar + "!/com/google/example/simple/trans_dep_c/TransDepC.class");
    fileSystem.createFile(binCJar + "!/com/google/example/simple/trans_dep_c/TransDepC$Inner.class");
    fileSystem.createFile(binCJar + "!/com/google/example/simple/trans_dep_c/R$dimen.class");
    artifactCache.addTrackedFile(binCArtifact, binCJar);
}
Also used : LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) CacheEntry(com.google.idea.blaze.android.filecache.CacheEntry) File(java.io.File)

Aggregations

CacheEntry (com.google.idea.blaze.android.filecache.CacheEntry)4 File (java.io.File)4 AndroidResourceModule (com.google.idea.blaze.android.sync.model.AndroidResourceModule)3 BlazeAndroidProjectStructureSyncer.moduleNameForAndroidModule (com.google.idea.blaze.android.sync.projectstructure.BlazeAndroidProjectStructureSyncer.moduleNameForAndroidModule)3 Module (com.intellij.openapi.module.Module)3 Test (org.junit.Test)3 AndroidResourceModuleRegistry (com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry)2 LocalFileOutputArtifact (com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact)1 OutputArtifact (com.google.idea.blaze.base.command.buildresult.OutputArtifact)1