Search in sources :

Example 16 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class AndroidSyncTest method testSimpleSync.

@Test
public void testSimpleSync() throws Exception {
    setProjectView("directories:", "  java/com/google", "targets:", "  //java/com/google:lib", "android_sdk_platform: android-25");
    workspace.createFile(new WorkspacePath("java/com/google/Source.java"), "package com.google;", "public class Source {}");
    workspace.createFile(new WorkspacePath("java/com/google/Other.java"), "package com.google;", "public class Other {}");
    VirtualFile javaRoot = workspace.createDirectory(new WorkspacePath("java/com/google"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:lib").setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(sourceRoot("java/com/google/AndroidManifest.xml")).addResource(sourceRoot("java/com/google/res/values/strings.xml")).setResourceJavaPackage("com.google").setGenerateResourceClass(true)).addSource(sourceRoot("java/com/google/Source.java")).addSource(sourceRoot("java/com/google/Other.java"))).build();
    setTargetMap(targetMap);
    runBlazeSync(new BlazeSyncParams.Builder("Sync", SyncMode.INCREMENTAL).addProjectViewTargets(true).build());
    errorCollector.assertNoIssues();
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
    assertThat(blazeProjectData).isNotNull();
    assertThat(blazeProjectData.targetMap).isEqualTo(targetMap);
    assertThat(blazeProjectData.workspaceLanguageSettings.getWorkspaceType()).isEqualTo(WorkspaceType.ANDROID);
    ImmutableList<ContentEntry> contentEntries = getWorkspaceContentEntries();
    assertThat(contentEntries).hasSize(1);
    assertThat(findContentEntry(javaRoot)).isNotNull();
    assertThat(findContentEntry(javaRoot).getSourceFolders()).hasLength(1);
    // Check that the workspace is set to android
    Module workspaceModule = ModuleFinder.getInstance(getProject()).findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
    assertThat(workspaceModule).isNotNull();
    assertThat(AndroidFacet.getInstance(workspaceModule)).isNotNull();
    // Check that a resource module was created
    Module resourceModule = ModuleFinder.getInstance(getProject()).findModuleByName("java.com.google.lib");
    assertThat(resourceModule).isNotNull();
    assertThat(AndroidFacet.getInstance(resourceModule)).isNotNull();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentEntry(com.intellij.openapi.roots.ContentEntry) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Module(com.intellij.openapi.module.Module) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 17 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class BlazeClassJarProviderIntegrationTest method doSetup.

@Before
public void doSetup() {
    module = testFixture.getModule();
    ArtifactLocationDecoder decoder = (location) -> new File("/src", location.getExecutionRootRelativePath());
    BlazeProjectData blazeProjectData = MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(buildTargetMap()).setArtifactLocationDecoder(decoder).build();
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(blazeProjectData));
    classJarProvider = new BlazeClassJarProvider(getProject());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) RunWith(org.junit.runner.RunWith) ClassJarProvider(com.android.tools.idea.model.ClassJarProvider) AndroidIntegrationTestSetupRule(com.google.idea.blaze.android.AndroidIntegrationTestSetupRule) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeIntegrationTestCase(com.google.idea.blaze.base.BlazeIntegrationTestCase) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) Module(com.intellij.openapi.module.Module) Before(org.junit.Before) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) ResourceClassRegistry(com.android.tools.idea.res.ResourceClassRegistry) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) IOException(java.io.IOException) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) FacetManager(com.intellij.facet.FacetManager) AndroidFacetConfiguration(org.jetbrains.android.facet.AndroidFacetConfiguration) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) List(java.util.List) Rule(org.junit.Rule) Label(com.google.idea.blaze.base.model.primitives.Label) ApplicationManager(com.intellij.openapi.application.ApplicationManager) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) Mockito.mock(org.mockito.Mockito.mock) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Before(org.junit.Before)

Example 18 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class BlazeBuildSystemServiceTest method createMockBlazeProjectData.

private BlazeProjectData createMockBlazeProjectData() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(Label.create("//foo:bar")).setBuildFile(ArtifactLocation.builder().setRelativePath("foo/BUILD").build()).build()).build();
    ArtifactLocationDecoder decoder = (location) -> new File("/", location.getRelativePath());
    return MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(targetMap).setArtifactLocationDecoder(decoder).build();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) MockModule(com.intellij.mock.MockModule) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) BlazeBuildService(com.google.idea.blaze.base.actions.BlazeBuildService) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) VirtualFileSystemProvider(com.google.idea.blaze.base.io.VirtualFileSystemProvider) Module(com.intellij.openapi.module.Module) Blaze(com.google.idea.blaze.base.settings.Blaze) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) BuildReferenceManager(com.google.idea.blaze.base.lang.buildfile.references.BuildReferenceManager) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) BuildSystemService(com.android.tools.idea.project.BuildSystemService) MockVirtualFile(com.intellij.mock.MockVirtualFile) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) Mockito.mock(org.mockito.Mockito.mock) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) LazyRangeMarkerFactory(com.intellij.openapi.editor.LazyRangeMarkerFactory) RunWith(org.junit.runner.RunWith) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ArgumentCaptor(org.mockito.ArgumentCaptor) BlazeSyncManager(com.google.idea.blaze.base.sync.BlazeSyncManager) PsiElement(com.intellij.psi.PsiElement) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) PsiFile(com.intellij.psi.PsiFile) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) LazyRangeMarkerFactoryImpl(com.intellij.openapi.editor.impl.LazyRangeMarkerFactoryImpl) Nullable(javax.annotation.Nullable) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Maps(com.google.common.collect.Maps) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) TempFileSystem(com.intellij.openapi.vfs.ex.temp.TempFileSystem) Label(com.google.idea.blaze.base.model.primitives.Label) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Example 19 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class BlazeBuildService method buildTargetExpressions.

@VisibleForTesting
void buildTargetExpressions(Project project, List<TargetExpression> targets, ProjectViewSet projectViewSet, NotificationScope notificationScope) {
    if (targets.isEmpty() || projectViewSet == null) {
        return;
    }
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return;
    }
    // go/futurereturn-lsc
    @SuppressWarnings("unused") Future<?> possiblyIgnoredError = ProgressiveTaskWithProgressIndicator.builder(project).setTitle("Building targets").submitTaskWithResult(new ScopedTask<Void>() {

        @Override
        public Void execute(BlazeContext context) {
            context.push(new ExperimentScope()).push(new BlazeConsoleScope.Builder(project).addConsoleFilters(new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), BlazeInvocationContext.Sync, true)).build()).push(new IssuesScope(project, true)).push(new IdeaLogScope()).push(new TimingScope("Make", EventType.BlazeInvocation)).push(notificationScope);
            WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
            SaveUtil.saveAllFiles();
            ShardedTargetsResult shardedTargets = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, projectViewSet, blazeProjectData.workspacePathResolver, targets);
            if (shardedTargets.buildResult.status == BuildResult.Status.FATAL_ERROR) {
                return null;
            }
            BuildResult buildResult = BlazeIdeInterface.getInstance().compileIdeArtifacts(project, context, workspaceRoot, projectViewSet, blazeProjectData.blazeVersionData, blazeProjectData.workspaceLanguageSettings, shardedTargets.shardedTargets);
            FileCaches.refresh(project);
            if (buildResult.status != BuildResult.Status.SUCCESS) {
                context.setHasError();
            }
            return null;
        }
    });
}
Also used : ShardedTargetsResult(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 20 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class BlazeAndroidProjectStructureSyncer method ensureRunConfigurationModule.

/**
 * Ensures a suitable module exists for the given android target.
 */
@Nullable
public static Module ensureRunConfigurationModule(Project project, Label label) {
    TargetKey targetKey = TargetKey.forPlainTarget(label);
    String moduleName = moduleNameForAndroidModule(targetKey);
    Module module = ModuleFinder.getInstance(project).findModuleByName(moduleName);
    if (module != null) {
        return module;
    }
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return null;
    }
    AndroidSdkPlatform androidSdkPlatform = SdkUtil.getAndroidSdkPlatform(blazeProjectData);
    if (androidSdkPlatform == null) {
        return null;
    }
    TargetIdeInfo target = blazeProjectData.targetMap.get(targetKey);
    if (target == null) {
        return null;
    }
    if (target.androidIdeInfo == null) {
        return null;
    }
    // invokeAndWait it because the caller may have a read action.
    if (!ApplicationManager.getApplication().isDispatchThread()) {
        return null;
    }
    BlazeSyncPlugin.ModuleEditor moduleEditor = ModuleEditorProvider.getInstance().getModuleEditor(project, BlazeImportSettingsManager.getInstance(project).getImportSettings());
    Module newModule = moduleEditor.createModule(moduleName, StdModuleTypes.JAVA);
    ApplicationManager.getApplication().runWriteAction(() -> {
        AndroidFacetModuleCustomizer.createAndroidFacet(newModule);
        moduleEditor.commit();
    });
    File moduleDirectory = moduleDirectoryForAndroidTarget(WorkspaceRoot.fromProject(project), target);
    updateModuleFacetInMemoryState(project, androidSdkPlatform, newModule, moduleDirectory, manifestFileForAndroidTarget(blazeProjectData.artifactLocationDecoder, target.androidIdeInfo, moduleDirectory), target.androidIdeInfo.resourceJavaPackage, ImmutableList.of(), null);
    return newModule;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) AndroidSdkPlatform(com.google.idea.blaze.android.sync.model.AndroidSdkPlatform) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Module(com.intellij.openapi.module.Module) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) File(java.io.File) Nullable(javax.annotation.Nullable)

Aggregations

BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)82 File (java.io.File)31 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)28 Nullable (javax.annotation.Nullable)24 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)23 Test (org.junit.Test)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)17 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)17 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)15 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)13 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)13 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)13 Project (com.intellij.openapi.project.Project)13 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)11 ImmutableList (com.google.common.collect.ImmutableList)10 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)10 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)8 List (java.util.List)8 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)7