Search in sources :

Example 41 with TargetMap

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

Example 42 with TargetMap

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

Example 43 with TargetMap

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());
}
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) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 44 with TargetMap

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;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Dependency(com.google.idea.blaze.base.ideinfo.Dependency) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Nullable(javax.annotation.Nullable)

Example 45 with TargetMap

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;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Dependency(com.google.idea.blaze.base.ideinfo.Dependency) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

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