Search in sources :

Example 1 with SourceProviderImpl

use of com.google.idea.blaze.android.sync.model.idea.SourceProviderImpl in project intellij by bazelbuild.

the class BlazeAndroidProjectPathsTest method mockWorkspaceFacet.

private AndroidFacet mockWorkspaceFacet() {
    String name = ".workspace";
    File rootFile = VfsUtilCore.virtualToIoFile(root);
    SourceProvider sourceProvider = new SourceProviderImpl(name, new File(rootFile, "AndroidManifest.xml"), ImmutableList.of());
    return new MockAndroidFacet(project, name, root, sourceProvider);
}
Also used : SourceProvider(com.android.builder.model.SourceProvider) SourceProviderImpl(com.google.idea.blaze.android.sync.model.idea.SourceProviderImpl) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File)

Example 2 with SourceProviderImpl

use of com.google.idea.blaze.android.sync.model.idea.SourceProviderImpl in project intellij by bazelbuild.

the class BlazeAndroidProjectPathsTest method mockResourceFacet.

private AndroidFacet mockResourceFacet() {
    String name = "com.google.resource";
    File resourceFile = VfsUtilCore.virtualToIoFile(resource);
    SourceProvider sourceProvider = new SourceProviderImpl(name, new File(resourceFile, "AndroidManifest.xml"), ImmutableList.of(new File(resourceFile, "res")));
    return new MockAndroidFacet(project, name, resource, sourceProvider);
}
Also used : SourceProvider(com.android.builder.model.SourceProvider) SourceProviderImpl(com.google.idea.blaze.android.sync.model.idea.SourceProviderImpl) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File)

Example 3 with SourceProviderImpl

use of com.google.idea.blaze.android.sync.model.idea.SourceProviderImpl in project intellij by bazelbuild.

the class BlazeAndroidProjectStructureSyncer method updateModuleFacetInMemoryState.

/**
 * @param resourceRepositoryExecutor a single thread executor to execute resource repository
 *     creation in the background, off the EDT, and in smart mode. This prevents hanging if we let
 *     it happen later on the EDT, and deadlocks if we let it happen during dumb mode.
 *     <p>{@link ModuleResourceRepository#getOrCreateInstance} and {@link
 *     ModuleResourceRepository#getItems} grabs {@link MultiResourceRepository#ITEM_MAP_LOCK} and
 *     the read lock in reverse order, so if the following scenario occurs:
 *     <ol>
 *       <li>Thread A enters getItems and grabs the ITEM_MAP_LOCK
 *       <li>Thread B enters getOrCreateInstance and grabs the read lock
 *       <li>The EDT tries run a write action, but gets blocked by Thread B
 *       <li>Thread B tries to grab the ITEM_MAP_LOCK but gets blocked by Thread A
 *       <li>Thread A tries to grab the read lock, but gets blocked by the EDT
 *     </ol>
 *     we will get a 3-way deadlock. To prevent this, we use a single thread executor, so
 *     getOrCreateInstance and getItems cannot happen concurrently.
 */
private static void updateModuleFacetInMemoryState(Project project, AndroidSdkPlatform androidSdkPlatform, Module module, File moduleDirectory, File manifest, String resourceJavaPackage, Collection<File> resources, @Nullable Executor resourceRepositoryExecutor) {
    SourceProvider sourceProvider = new SourceProviderImpl(module.getName(), manifest, resources);
    BlazeAndroidModel androidModel = new BlazeAndroidModel(project, module, moduleDirectory, sourceProvider, manifest, resourceJavaPackage, androidSdkPlatform.androidMinSdkLevel);
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet != null) {
        facet.setAndroidModel(androidModel);
        if (resourceRepositoryExecutor != null) {
            // Create resource repository and table early so it doesn't hold up the EDT later.
            resourceRepositoryExecutor.execute(() -> {
                DumbService.getInstance(project).waitForSmartMode();
                ModuleResourceRepository.getOrCreateInstance(facet).getItems();
            });
        }
    }
}
Also used : BlazeAndroidModel(com.google.idea.blaze.android.sync.model.idea.BlazeAndroidModel) SourceProvider(com.android.builder.model.SourceProvider) SourceProviderImpl(com.google.idea.blaze.android.sync.model.idea.SourceProviderImpl) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

SourceProvider (com.android.builder.model.SourceProvider)3 SourceProviderImpl (com.google.idea.blaze.android.sync.model.idea.SourceProviderImpl)3 MockVirtualFile (com.intellij.mock.MockVirtualFile)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 BlazeAndroidModel (com.google.idea.blaze.android.sync.model.idea.BlazeAndroidModel)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1