Search in sources :

Example 46 with TargetMap

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();
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) HtmlBuilder(com.android.utils.HtmlBuilder) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Map(java.util.Map) TransitiveDependencyMap(com.google.idea.blaze.base.targetmaps.TransitiveDependencyMap) SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) SortedMap(java.util.SortedMap)

Example 47 with TargetMap

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")));
}
Also used : TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 48 with TargetMap

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);
}
Also used : File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 49 with TargetMap

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)));
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 50 with TargetMap

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());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Aggregations

TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)77 Test (org.junit.Test)56 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)33 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)27 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)26 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)17 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)16 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)15 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)12 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)10 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)10 BlazeScalaImportResult (com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)10 File (java.io.File)10 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)9 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)9 ImmutableList (com.google.common.collect.ImmutableList)8 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)8 ImmutableSet (com.google.common.collect.ImmutableSet)7