Search in sources :

Example 6 with WorkspacePath

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

the class ProjectViewLabelReferenceTest method testDirectoryReference.

@Test
public void testDirectoryReference() {
    PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("foo/bar"));
    PsiFile projectView = workspace.createPsiFile(new WorkspacePath(".bazelproject"), "directories:", "  foo/bar");
    ProjectViewPsiSectionItem importItem = PsiUtils.findFirstChildOfClassRecursive(projectView, ProjectViewPsiSectionItem.class);
    assertThat(importItem).isNotNull();
    assertThat(importItem.getReference().resolve()).isEqualTo(directory);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) PsiDirectory(com.intellij.psi.PsiDirectory) ProjectViewPsiSectionItem(com.google.idea.blaze.base.lang.projectview.psi.ProjectViewPsiSectionItem) PsiFile(com.intellij.psi.PsiFile) Test(org.junit.Test)

Example 7 with WorkspacePath

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

the class ProjectViewLabelReferenceTest method testFileReference.

@Test
public void testFileReference() {
    PsiFile referencedFile = workspace.createPsiFile(new WorkspacePath("ijwb.bazelproject"), "directories:", "  java/com/google/foo", "targets:", "  //java/com/google/foo/...");
    PsiFile file = workspace.createPsiFile(new WorkspacePath(".bazelproject"), "import ijwb.bazelproject");
    ProjectViewPsiSectionItem importItem = PsiUtils.findFirstChildOfClassRecursive(file, ProjectViewPsiSectionItem.class);
    assertThat(importItem).isNotNull();
    assertThat(importItem.getReference().resolve()).isEqualTo(referencedFile);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectViewPsiSectionItem(com.google.idea.blaze.base.lang.projectview.psi.ProjectViewPsiSectionItem) PsiFile(com.intellij.psi.PsiFile) Test(org.junit.Test)

Example 8 with WorkspacePath

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

the class TestTargetHeuristicTest method testNoMatchFallBackToFirstTarget.

@Test
public void testNoMatchFallBackToFirstTarget() {
    File source = workspaceRoot.fileForPath(new WorkspacePath("java/com/foo/FooTest.java"));
    ImmutableList<TargetInfo> targets = ImmutableList.of(TargetIdeInfo.builder().setLabel("//bar:BarTest").setKind("java_test").setTestInfo(TestIdeInfo.builder().setTestSize(TestSize.MEDIUM)).build().toTargetInfo(), TargetIdeInfo.builder().setLabel("//foo:OtherTest").setKind("java_test").setTestInfo(TestIdeInfo.builder().setTestSize(TestSize.SMALL)).build().toTargetInfo());
    TargetInfo match = TestTargetHeuristic.chooseTestTargetForSourceFile(getProject(), null, source, targets, TestSize.LARGE);
    assertThat(match.label).isEqualTo(Label.create("//bar:BarTest"));
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

Example 9 with WorkspacePath

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

the class RunConfigurationSerializerTest method testConvertAbsolutePathToWorkspacePathVariableWhenSerializing.

@Test
public void testConvertAbsolutePathToWorkspacePathVariableWhenSerializing() {
    if (isAndroidStudio()) {
        // #api171: disable for android studio -- path variable substitution isn't working in 2017.1
        return;
    }
    WorkspacePath binaryPath = WorkspacePath.createIfValid("path/to/binary/blaze");
    String absoluteBinaryPath = workspaceRoot.fileForPath(binaryPath).getPath();
    setBlazeBinaryPath(configuration, absoluteBinaryPath);
    Element element = RunConfigurationSerializer.writeToXml(configuration);
    assertThat(element.getAttribute("blaze-binary").getValue()).isEqualTo(String.format("$%s$/%s", RunConfigurationSerializer.WORKSPACE_ROOT_VARIABLE_NAME, binaryPath));
    // remove configuration from project
    clearRunManager();
    RunConfigurationSerializer.loadFromXmlElementIgnoreExisting(getProject(), element);
    RunConfiguration config = runManager.getAllConfigurations()[0];
    assertThat(config).isInstanceOf(BlazeCommandRunConfiguration.class);
    assertThat(getBlazeBinaryPath((BlazeCommandRunConfiguration) config)).isEqualTo(absoluteBinaryPath);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Element(org.jdom.Element) Test(org.junit.Test)

Example 10 with WorkspacePath

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

the class AllInPackageBlazeConfigurationProducerTest method testDirectoryWithoutBlazePackageChildIsIgnored.

@Test
public void testDirectoryWithoutBlazePackageChildIsIgnored() {
    PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
    ConfigurationContext context = createContextFromPsi(directory);
    AllInPackageBlazeConfigurationProducer producer = new AllInPackageBlazeConfigurationProducer();
    assertThat(producer.createConfigurationFromContext(context)).isNull();
    workspace.createPsiDirectory(new WorkspacePath("java/com/google/test/child_dir"));
    workspace.createPsiFile(new WorkspacePath("java/com/google/test/child_dir/BUILD"));
    assertThat(producer.createConfigurationFromContext(context)).isNotNull();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) AllInPackageBlazeConfigurationProducer(com.google.idea.blaze.base.run.producers.AllInPackageBlazeConfigurationProducer) PsiDirectory(com.intellij.psi.PsiDirectory) Test(org.junit.Test)

Aggregations

WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)509 Test (org.junit.Test)454 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)197 PsiFile (com.intellij.psi.PsiFile)84 File (java.io.File)75 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)53 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)48 Editor (com.intellij.openapi.editor.Editor)46 VirtualFile (com.intellij.openapi.vfs.VirtualFile)41 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)40 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)37 PsiReference (com.intellij.psi.PsiReference)37 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)34 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)34 BlazeContentEntry (com.google.idea.blaze.java.sync.model.BlazeContentEntry)33 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)29 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)26 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)26 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)25 PsiElement (com.intellij.psi.PsiElement)25