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