public AntBuildTargetImpl(final AntDomTarget target, final AntBuildModelBase buildModel, final VirtualFile sourceFile, final boolean isImported, final boolean isDefault) { myModel = buildModel; myFile = sourceFile; myIsDefault = isDefault; myHashCode = target.hashCode(); myName = target.getName().getRawText(); String name = target.getName().getRawText(); if (isImported) { final String projectName = target.getAntProject().getName().getRawText(); name = projectName + "." + name; } myDisplayName = name; myProject = target.getManager().getProject(); final DomTarget domTarget = DomTarget.getTarget(target); if (domTarget != null) { myTextOffset = domTarget.getTextOffset(); } else { myTextOffset = target.getXmlTag().getTextOffset(); } final String desc = target.getDescription().getRawText(); myDescription = (desc != null && desc.trim().length() > 0) ? desc : null; }
public AntBuildTargetImpl(final AntDomTarget target, final AntBuildModelBase buildModel, final VirtualFile sourceFile, final boolean isImported, final boolean isDefault) { myModel = buildModel; myFile = sourceFile; myIsDefault = isDefault; myHashCode = target.hashCode(); myName = target.getName().getRawText(); String name = target.getName().getRawText(); if (isImported) { final String projectName = target.getAntProject().getName().getRawText(); name = projectName + "" + name; } myDisplayName = name; myProject = target.getManager().getProject(); final DomTarget domTarget = DomTarget.getTarget(target); if (domTarget != null) { myTextOffset = domTarget.getTextOffset(); } else { myTextOffset = target.getXmlTag().getTextOffset(); } final String desc = target.getDescription().getRawText(); myDescription = (desc != null && desc.trim().length() > 0) ? desc : null; }
@Override public void actionPerformed(AnActionEvent e) { Pair<AntBuildFileBase, AntDomTarget> antTarget = findAntTarget(e); if (antTarget == null) return; ExecutionHandler.runBuild( antTarget.first, new String[] {antTarget.second.getName().getValue() }, null, e.getDataContext(), Collections.<BuildFileProperty>emptyList(), AntBuildListener.NULL); }
@Override public void update(AnActionEvent e) { super.update(e); final Presentation presentation = e.getPresentation(); Pair<AntBuildFileBase, AntDomTarget> antTarget = findAntTarget(e); if (antTarget == null) { presentation.setEnabled(false); presentation.setText(AntActionsBundle.message("action.RunTargetAction.text", "")); } else { presentation.setEnabled(true); presentation.setText(AntActionsBundle.message("action.RunTargetAction.text", "'" + antTarget.second.getName().getValue() + "'")); } }
@Nullable public BuildTask findTask(final String taskName) { final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile); final AntDomProject domProject = AntSupport.getAntDomProject(psiFile); if (domProject != null) { final AntDomTarget antTarget = domProject.findDeclaredTarget(myName); if (antTarget != null) { final Ref<AntDomElement> result = new Ref<AntDomElement>(null); antTarget.accept(new AntDomRecursiveVisitor() { public void visitAntDomElement(AntDomElement element) { if (result.get() != null) { return; } if (element.isTask() && taskName.equals(element.getXmlElementName())) { result.set(element); return; } super.visitAntDomElement(element); } }); final AntDomElement task = result.get(); if (task != null) { return new BuildTask(this, task); } } } return null; }
@Nullable private static Pair<AntBuildFileBase, AntDomTarget> findAntTarget(@NotNull AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null || editor == null) { return null; } final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); if (file == null) { return null; } final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof XmlFile)) { return null; } final XmlFile xmlFile = (XmlFile)psiFile; final AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(xmlFile); if (antFile == null) { return null; } final PsiElement element = xmlFile.findElementAt(editor.getCaretModel().getOffset()); if (element == null) { return null; } final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (xmlTag == null) { return null; } DomElement dom = AntSupport.getAntDomElement(xmlTag); while (dom != null && !(dom instanceof AntDomTarget)) { dom = dom.getParent(); } final AntDomTarget domTarget = (AntDomTarget)dom; if (domTarget == null) { return null; } return Pair.create(antFile, domTarget); }
@Nullable private static Pair<AntBuildFileBase, AntDomTarget> findAntTarget(@NotNull AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); final Project project = PlatformDataKeys.PROJECT.getData(dataContext); if (project == null || editor == null) { return null; } final VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext); if (file == null) { return null; } final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof XmlFile)) { return null; } final XmlFile xmlFile = (XmlFile)psiFile; final AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(xmlFile); if (antFile == null) { return null; } final PsiElement element = xmlFile.findElementAt(editor.getCaretModel().getOffset()); if (element == null) { return null; } final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (xmlTag == null) { return null; } DomElement dom = AntSupport.getAntDomElement(xmlTag); while (dom != null && !(dom instanceof AntDomTarget)) { dom = dom.getParent(); } final AntDomTarget domTarget = (AntDomTarget)dom; if (domTarget == null) { return null; } return Pair.create(antFile, domTarget); }
@Nullable private static Pair<AntBuildFileBase, AntDomTarget> findAntTarget(@NotNull AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Editor editor = dataContext.getData(PlatformDataKeys.EDITOR); final Project project = dataContext.getData(PlatformDataKeys.PROJECT); if (project == null || editor == null) { return null; } final VirtualFile file = dataContext.getData(PlatformDataKeys.VIRTUAL_FILE); if (file == null) { return null; } final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof XmlFile)) { return null; } final XmlFile xmlFile = (XmlFile)psiFile; final AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(xmlFile); if (antFile == null) { return null; } final PsiElement element = xmlFile.findElementAt(editor.getCaretModel().getOffset()); if (element == null) { return null; } final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (xmlTag == null) { return null; } DomElement dom = AntSupport.getAntDomElement(xmlTag); while (dom != null && !(dom instanceof AntDomTarget)) { dom = dom.getParent(); } final AntDomTarget domTarget = (AntDomTarget)dom; if (domTarget == null) { return null; } return Pair.create(antFile, domTarget); }