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;
}
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;
}
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();
}
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));
}
}
Aggregations