Search in sources :

Example 56 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData 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 57 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData 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 58 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class ClassFileManifestBuilder method buildManifest.

/**
 * Builds a .class file manifest, then diffs against any previously calculated manifest for this
 * debugging session.
 *
 * @return null if no diff is available (either no manifest could be calculated, or no previously
 *     calculated manifest is available.
 */
@Nullable
public static ClassFileManifest.Diff buildManifest(ExecutionEnvironment env, @Nullable HotSwapProgress progress) throws ExecutionException {
    if (!HotSwapUtils.canHotSwap(env)) {
        return null;
    }
    BlazeCommandRunConfiguration configuration = getConfiguration(env);
    Project project = configuration.getProject();
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (projectData == null) {
        throw new ExecutionException("Not synced yet; please sync project");
    }
    JavaClasspathAspectStrategy aspectStrategy = JavaClasspathAspectStrategy.findStrategy(projectData.blazeVersionData);
    if (aspectStrategy == null) {
        return null;
    }
    try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> true)) {
        ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeBuild(configuration, buildResultHelper, aspectStrategy.getBuildFlags(), ImmutableList.of(), "Building debug binary");
        if (progress != null) {
            progress.setCancelWorker(() -> buildOperation.cancel(true));
        }
        try {
            SaveUtil.saveAllFiles();
            BuildResult result = buildOperation.get();
            if (result.status != BuildResult.Status.SUCCESS) {
                throw new ExecutionException("Blaze failure building debug binary");
            }
        } catch (InterruptedException | CancellationException e) {
            buildOperation.cancel(true);
            throw new RunCanceledByUserException();
        } catch (java.util.concurrent.ExecutionException e) {
            throw new ExecutionException(e);
        }
        ImmutableList<File> jars = buildResultHelper.getArtifactsForOutputGroups(ImmutableSet.of(JavaClasspathAspectStrategy.OUTPUT_GROUP)).stream().filter(f -> f.getName().endsWith(".jar")).collect(toImmutableList());
        ClassFileManifest oldManifest = getManifest(env);
        ClassFileManifest newManifest = ClassFileManifest.build(jars, oldManifest);
        env.getCopyableUserData(MANIFEST_KEY).set(newManifest);
        return oldManifest != null ? ClassFileManifest.modifiedClasses(oldManifest, newManifest) : null;
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CancellationException(java.util.concurrent.CancellationException) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) RunProfile(com.intellij.execution.configurations.RunProfile) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) AtomicReference(java.util.concurrent.atomic.AtomicReference) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) WrappingRunConfiguration(com.intellij.execution.configurations.WrappingRunConfiguration) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeBeforeRunCommandHelper(com.google.idea.blaze.base.run.BlazeBeforeRunCommandHelper) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ImmutableList(com.google.common.collect.ImmutableList) HotSwapProgress(com.intellij.debugger.impl.HotSwapProgress) Project(com.intellij.openapi.project.Project) SaveUtil(com.google.idea.blaze.base.util.SaveUtil) GuavaHelper.toImmutableList(com.google.idea.common.guava.GuavaHelper.toImmutableList) Nullable(javax.annotation.Nullable) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) Project(com.intellij.openapi.project.Project) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) CancellationException(java.util.concurrent.CancellationException) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Nullable(javax.annotation.Nullable)

Example 59 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class CombinedTestHeuristicTest method doSetup.

@Before
public final void doSetup() {
    BlazeProjectData blazeProjectData = MockBlazeProjectDataBuilder.builder(workspaceRoot).build();
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(blazeProjectData));
    // required for IntelliJ to recognize annotations, JUnit version, etc.
    workspace.createPsiFile(new WorkspacePath("org/junit/runner/RunWith.java"), "package org.junit.runner;" + "public @interface RunWith {" + "    Class<? extends Runner> value();" + "}");
    workspace.createPsiFile(new WorkspacePath("org/junit/Test"), "package org.junit;", "public @interface Test {}");
    workspace.createPsiFile(new WorkspacePath("org/junit/runners/JUnit4"), "package org.junit.runners;", "public class JUnit4 {}");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Before(org.junit.Before)

Example 60 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData 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)

Aggregations

BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)82 File (java.io.File)31 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)28 Nullable (javax.annotation.Nullable)24 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)23 Test (org.junit.Test)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)17 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)17 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)15 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)13 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)13 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)13 Project (com.intellij.openapi.project.Project)13 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)11 ImmutableList (com.google.common.collect.ImmutableList)10 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)10 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)8 List (java.util.List)8 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)7