use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class BlazeRenderErrorContributor method reportGeneratedResources.
/**
* We can't find generated resources. If a layout uses them, the layout won't render correctly.
*/
private void reportGeneratedResources(AndroidResourceModule resourceModule, TargetMap targetMap, ArtifactLocationDecoder decoder) {
Map<String, Throwable> brokenClasses = logger.getBrokenClasses();
if (brokenClasses == null || brokenClasses.isEmpty()) {
return;
}
// Sorted entries for deterministic error message.
SortedMap<ArtifactLocation, TargetIdeInfo> generatedResources = Maps.newTreeMap(getGeneratedResources(targetMap.get(resourceModule.targetKey)));
for (TargetKey dependency : resourceModule.transitiveResourceDependencies) {
generatedResources.putAll(getGeneratedResources(targetMap.get(dependency)));
}
if (generatedResources.isEmpty()) {
return;
}
HtmlBuilder builder = new HtmlBuilder();
builder.add("Generated resources will not be discovered by the IDE:");
builder.beginList();
for (Map.Entry<ArtifactLocation, TargetIdeInfo> entry : generatedResources.entrySet()) {
ArtifactLocation resource = entry.getKey();
TargetIdeInfo target = entry.getValue();
builder.listItem().add(resource.getRelativePath()).add(" from ");
addTargetLink(builder, target, decoder);
}
builder.endList().add("Please avoid using generated resources, ").addLink("then ", "sync the project", " ", getLinkManager().createSyncProjectUrl()).addLink("and ", "refresh the layout", ".", getLinkManager().createRefreshRenderUrl());
addIssue().setSeverity(HighlightSeverity.ERROR, // Reported above broken classes
HIGH_PRIORITY + 1).setSummary("Generated resources").setHtmlContent(builder).build();
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class ReverseDependencyMapTest method testThreeLevelGraph.
@Test
public void testThreeLevelGraph() {
TargetMapBuilder builder = TargetMapBuilder.builder();
TargetMap targetMap = builder.addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l1").setKind("java_library").addDependency("//l:l3")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l2").addDependency("//l:l3").setKind("java_library")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l3").setKind("java_library")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l4").addDependency("//l:l3").setKind("java_library")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l5").addDependency("//l:l4").setKind("java_library")).build();
ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = ReverseDependencyMap.createRdepsMap(targetMap);
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l3")), TargetKey.forPlainTarget(Label.create("//l:l1")));
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l3")), TargetKey.forPlainTarget(Label.create("//l:l2")));
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l3")), TargetKey.forPlainTarget(Label.create("//l:l4")));
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l4")), TargetKey.forPlainTarget(Label.create("//l:l5")));
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class BlazeIdeInterfaceAspectsImplTest method testBlazeStateIsSerializable.
@Test
public void testBlazeStateIsSerializable() {
BlazeIdeInterfaceAspectsImpl.State state = new BlazeIdeInterfaceAspectsImpl.State();
state.fileToTargetMapKey = ImmutableBiMap.of(new File("fileName"), TargetIdeInfo.builder().setLabel(Label.create("//test:test")).build().key);
state.fileState = ImmutableMap.of();
state.targetMap = // Tested separately in testRuleIdeInfoIsSerializable
new TargetMap(ImmutableMap.of());
TestUtils.assertIsSerializable(state);
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class ScalaSyncTest method testSimpleSync.
@Test
public void testSimpleSync() throws Exception {
setProjectView("directories:", " src/main/scala/com/google", "targets:", " //src/main/scala/com/google:lib", "additional_languages:", " scala");
workspace.createFile(new WorkspacePath("src/main/scala/com/google/Source.scala"), "package com.google;", "public class Source {}");
workspace.createFile(new WorkspacePath("src/main/scala/com/google/Other.scala"), "package com.google;", "public class Other {}");
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("src/main/scala/com/google/BUILD")).setLabel("//src/main/scala/com/google:lib").setKind("scala_library").addSource(sourceRoot("src/main/scala/com/google/Source.scala")).addSource(sourceRoot("src/main/scala/com/google/Other.scala"))).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).isEqualTo(new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of(LanguageClass.GENERIC, LanguageClass.SCALA, LanguageClass.JAVA)));
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class ScalaSyncTest method testScalaClassesPresentInClassPath.
@Test
public void testScalaClassesPresentInClassPath() throws Exception {
setProjectView("directories:", " src/main/scala/com/google", "targets:", " //src/main/scala/com/google:lib", "additional_languages:", " scala");
workspace.createFile(new WorkspacePath("src/main/scala/com/google/ClassWithUniqueName1.scala"), "package com.google;", "public class ClassWithUniqueName1 {}");
workspace.createFile(new WorkspacePath("src/main/scala/com/google/ClassWithUniqueName2.scala"), "package com.google;", "public class ClassWithUniqueName2 {}");
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("src/main/scala/com/google/BUILD")).setLabel("//src/main/scala/com/google:lib").setKind("scala_library").addSource(sourceRoot("src/main/scala/com/google/ClassWithUniqueName1.scala")).addSource(sourceRoot("src/main/scala/com/google/ClassWithUniqueName2.scala")).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).isEqualTo(new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of(LanguageClass.GENERIC, LanguageClass.JAVA, LanguageClass.SCALA)));
BlazeJavaSyncData javaSyncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
assertThat(javaSyncData).isNotNull();
List<BlazeContentEntry> contentEntries = javaSyncData.importResult.contentEntries;
assertThat(contentEntries).hasSize(1);
BlazeContentEntry contentEntry = contentEntries.get(0);
assertThat(contentEntry.contentRoot.getPath()).isEqualTo(workspaceRoot.fileForPath(new WorkspacePath("src/main/scala/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("src/main/scala/com/google")).getPath());
}
Aggregations