use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class JavaSyncTest method testSimpleSyncLogging.
@Test
public void testSimpleSyncLogging() throws Exception {
setProjectView("directories:", " java/com/google", "targets:", " //java/com/google:lib");
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 {}");
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:lib").setKind("java_library").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.JAVA);
List<SyncStats> syncStatsList = getSyncStats();
assertThat(syncStatsList).hasSize(1);
SyncStats syncStats = syncStatsList.get(0);
assertThat(syncStats).isNotNull();
assertThat(syncStats.workspaceType()).isEqualTo(WorkspaceType.JAVA);
assertThat(syncStats.blazeProjectTargets()).containsExactly(TargetExpression.fromString("//java/com/google:lib"));
assertThat(syncStats.syncMode()).isEqualTo(SyncMode.INCREMENTAL);
assertThat(syncStats.syncResult()).isEqualTo(SyncResult.SUCCESS);
assertThat(syncStats.startTimeInEpochTime()).isNotEqualTo(0);
assertThat(syncStats.timedEvents()).isNotEmpty();
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class JavaSyncTest method testSimpleSync.
@Test
public void testSimpleSync() throws Exception {
setProjectView("directories:", " java/com/google", "targets:", " //java/com/google:lib");
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 {}");
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:lib").setKind("java_library").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.JAVA);
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class JavaSyncTest method testJavaClassesPresentInClassPath.
@Test
public void testJavaClassesPresentInClassPath() throws Exception {
setProjectView("directories:", " java/com/google", "targets:", " //java/com/google:lib");
workspace.createFile(new WorkspacePath("java/com/google/ClassWithUniqueName1.java"), "package com.google;", "public class ClassWithUniqueName1 {}");
workspace.createFile(new WorkspacePath("java/com/google/ClassWithUniqueName2.java"), "package com.google;", "public class ClassWithUniqueName2 {}");
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:lib").setKind("java_library").addSource(sourceRoot("java/com/google/ClassWithUniqueName1.java")).addSource(sourceRoot("java/com/google/ClassWithUniqueName2.java")).setJavaInfo(JavaIdeInfo.builder())).build();
setTargetMap(targetMap);
BlazeSyncParams syncParams = new BlazeSyncParams.Builder("Full Sync", BlazeSyncParams.SyncMode.FULL).addProjectViewTargets(true).build();
runBlazeSync(syncParams);
errorCollector.assertNoIssues();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
assertThat(blazeProjectData).isNotNull();
assertThat(blazeProjectData.targetMap).isEqualTo(targetMap);
assertThat(blazeProjectData.workspaceLanguageSettings.getWorkspaceType()).isEqualTo(WorkspaceType.JAVA);
BlazeJavaSyncData javaSyncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
List<BlazeContentEntry> contentEntries = javaSyncData.importResult.contentEntries;
assertThat(contentEntries).hasSize(1);
BlazeContentEntry contentEntry = contentEntries.get(0);
assertThat(contentEntry.contentRoot.getPath()).isEqualTo(workspaceRoot.fileForPath(new WorkspacePath("java/com/google")).getPath());
assertThat(contentEntry.sources).hasSize(1);
BlazeSourceDirectory sourceDir = contentEntry.sources.get(0);
assertThat(sourceDir.getPackagePrefix()).isEqualTo("com.google");
assertThat(sourceDir.getDirectory().getPath()).isEqualTo(workspaceRoot.fileForPath(new WorkspacePath("java/com/google")).getPath());
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class BlazeAndroidTestRunConfigurationHandler method getInstrumentationBinary.
@Nullable
private Label getInstrumentationBinary(Label label) {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(configuration.getProject()).getBlazeProjectData();
if (projectData == null) {
return null;
}
TargetMap targetMap = projectData.targetMap;
TargetIdeInfo instrumentationTest = targetMap.get(TargetKey.forPlainTarget(label));
for (Dependency dependency : instrumentationTest.dependencies) {
TargetIdeInfo dependencyInfo = targetMap.get(dependency.targetKey);
// Should exist via test_app attribute, and be unique.
if (dependencyInfo != null && dependencyInfo.kind == Kind.ANDROID_BINARY) {
return dependency.targetKey.label;
}
}
return null;
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class BlazeApkBuildStepNormalBuild method getTargetToBuild.
/**
* In case we're dealing with an {@link Kind#ANDROID_INSTRUMENTATION_TEST}, build the underlying
* {@link Kind#ANDROID_BINARY} instead.
*/
private Label getTargetToBuild() {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (projectData == null) {
return label;
}
TargetMap targetMap = projectData.targetMap;
TargetIdeInfo target = targetMap.get(TargetKey.forPlainTarget(label));
if (target == null || target.kind != Kind.ANDROID_INSTRUMENTATION_TEST) {
return label;
}
for (Dependency dependency : target.dependencies) {
TargetIdeInfo dependencyInfo = targetMap.get(dependency.targetKey);
// Should exist via test_app attribute, and be unique.
if (dependencyInfo != null && dependencyInfo.kind == Kind.ANDROID_BINARY) {
return dependency.targetKey.label;
}
}
return label;
}
Aggregations