Search in sources :

Example 1 with TargetName

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

the class BlazeGoTestLocator method getGoTestTarget.

@Nullable
private static TargetIdeInfo getGoTestTarget(Project project, String path) {
    WorkspacePath targetPackage = WorkspacePath.createIfValid(PathUtil.getParentPath(path));
    if (targetPackage == null) {
        return null;
    }
    TargetName targetName = TargetName.createIfValid(PathUtil.getFileName(path));
    if (targetName == null) {
        return null;
    }
    Label label = Label.create(targetPackage, targetName);
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (projectData == null) {
        return null;
    }
    TargetIdeInfo target = projectData.targetMap.get(TargetKey.forPlainTarget(label));
    if (target != null && target.kind.languageClass.equals(LanguageClass.GO) && target.kind.ruleType.equals(RuleType.TEST)) {
        return target;
    }
    return null;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) TargetName(com.google.idea.blaze.base.model.primitives.TargetName) Nullable(javax.annotation.Nullable)

Example 2 with TargetName

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

the class WorkspaceHelper method deriveLabel.

private static Label deriveLabel(Project project, Workspace workspace, WorkspacePath workspacePath) {
    BuildSystemProvider provider = Blaze.getBuildSystemProvider(project);
    File file = workspace.root.fileForPath(workspacePath);
    if (provider.isBuildFile(file.getName())) {
        return Label.create(workspace.externalWorkspaceName, workspace.root.workspacePathFor(file.getParentFile()), TargetName.create("__pkg__"));
    }
    WorkspacePath packagePath = getPackagePath(provider, workspace.root, workspacePath);
    if (packagePath == null) {
        return null;
    }
    TargetName targetName = TargetName.createIfValid(FileUtil.getRelativePath(workspace.root.fileForPath(packagePath), file));
    return targetName != null ? Label.create(workspace.externalWorkspaceName, packagePath, targetName) : null;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildSystemProvider(com.google.idea.blaze.base.bazel.BuildSystemProvider) TargetName(com.google.idea.blaze.base.model.primitives.TargetName) File(java.io.File)

Example 3 with TargetName

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

the class NewBlazePackageDialog method doOKAction.

@Override
protected void doOKAction() {
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    logger.assertTrue(parentDirectory.getVirtualFile().isInLocalFileSystem());
    File parentDirectoryFile = new File(parentDirectory.getVirtualFile().getPath());
    String newPackageName = packageNameField.getText();
    File newPackageDirectory = new File(parentDirectoryFile, newPackageName);
    WorkspacePath newPackagePath = workspaceRoot.workspacePathFor(newPackageDirectory);
    TargetName newTargetName = newRuleUI.getRuleName();
    Label newRule = Label.create(newPackagePath, newTargetName);
    Kind ruleKind = newRuleUI.getSelectedRuleKind();
    try {
        parentDirectory.checkCreateSubdirectory(newPackageName);
    } catch (IncorrectOperationException ex) {
        showErrorDialog(CreateElementActionBase.filterMessage(ex.getMessage()));
        // do not close the dialog
        return;
    }
    this.newRule = newRule;
    this.newRuleKind = ruleKind;
    super.doOKAction();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Kind(com.google.idea.blaze.base.model.primitives.Kind) JBLabel(com.intellij.ui.components.JBLabel) Label(com.google.idea.blaze.base.model.primitives.Label) IncorrectOperationException(com.intellij.util.IncorrectOperationException) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetName(com.google.idea.blaze.base.model.primitives.TargetName) File(java.io.File)

Example 4 with TargetName

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

the class NewBlazeRuleDialog method doOKAction.

@Override
protected void doOKAction() {
    TargetName targetName = newRuleUI.getRuleName();
    Kind ruleKind = newRuleUI.getSelectedRuleKind();
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    WorkspacePath workspacePath = workspaceRoot.workspacePathFor(new File(buildFile.getParent().getPath()));
    Label newRule = Label.create(workspacePath, targetName);
    BuildFileModifier buildFileModifier = BuildFileModifier.getInstance();
    String commandName = String.format("Add %s %s rule '%s'", buildSystemName, ruleKind, newRule);
    boolean success = new WriteCommandAction<Boolean>(project, commandName) {

        @Override
        protected void run(@NotNull Result<Boolean> result) throws Throwable {
            LocalHistory localHistory = LocalHistory.getInstance();
            LocalHistoryAction action = localHistory.startAction(commandName);
            try {
                result.setResult(buildFileModifier.addRule(project, newRule, ruleKind));
            } finally {
                action.finish();
            }
        }
    }.execute().getResultObject();
    if (success) {
        super.doOKAction();
    } else {
        super.setErrorText(String.format("Could not create new rule, see %s Console for details", buildSystemName));
    }
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Label(com.google.idea.blaze.base.model.primitives.Label) TargetName(com.google.idea.blaze.base.model.primitives.TargetName) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) Kind(com.google.idea.blaze.base.model.primitives.Kind) LocalHistoryAction(com.intellij.history.LocalHistoryAction) BuildFileModifier(com.google.idea.blaze.base.buildmodifier.BuildFileModifier) LocalHistory(com.intellij.history.LocalHistory) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

TargetName (com.google.idea.blaze.base.model.primitives.TargetName)4 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)4 Label (com.google.idea.blaze.base.model.primitives.Label)3 File (java.io.File)3 Kind (com.google.idea.blaze.base.model.primitives.Kind)2 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)2 BuildSystemProvider (com.google.idea.blaze.base.bazel.BuildSystemProvider)1 BuildFileModifier (com.google.idea.blaze.base.buildmodifier.BuildFileModifier)1 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)1 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)1 LocalHistory (com.intellij.history.LocalHistory)1 LocalHistoryAction (com.intellij.history.LocalHistoryAction)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 JBLabel (com.intellij.ui.components.JBLabel)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 Nullable (javax.annotation.Nullable)1 NotNull (org.jetbrains.annotations.NotNull)1