|
|
|
@@ -0,0 +1,110 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2000-2012 JetBrains s.r.o.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package com.intellij.lang.ant.config.actions;
|
|
|
|
|
|
|
|
|
|
import com.intellij.lang.ant.AntSupport;
|
|
|
|
|
import com.intellij.lang.ant.config.AntBuildFileBase;
|
|
|
|
|
import com.intellij.lang.ant.config.AntBuildListener;
|
|
|
|
|
import com.intellij.lang.ant.config.AntConfigurationBase;
|
|
|
|
|
import com.intellij.lang.ant.config.execution.ExecutionHandler;
|
|
|
|
|
import com.intellij.lang.ant.config.impl.BuildFileProperty;
|
|
|
|
|
import com.intellij.lang.ant.dom.AntDomTarget;
|
|
|
|
|
import com.intellij.lang.ant.resources.AntActionsBundle;
|
|
|
|
|
import com.intellij.openapi.actionSystem.*;
|
|
|
|
|
import com.intellij.openapi.editor.Editor;
|
|
|
|
|
import com.intellij.openapi.project.Project;
|
|
|
|
|
import com.intellij.openapi.util.Pair;
|
|
|
|
|
import com.intellij.openapi.vfs.VirtualFile;
|
|
|
|
|
import com.intellij.psi.PsiElement;
|
|
|
|
|
import com.intellij.psi.PsiFile;
|
|
|
|
|
import com.intellij.psi.PsiManager;
|
|
|
|
|
import com.intellij.psi.xml.XmlFile;
|
|
|
|
|
import com.intellij.psi.xml.XmlTag;
|
|
|
|
|
import com.intellij.util.xml.DomElement;
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by Eugene Petrenko (eugene.petrenko@gmail.com)
|
|
|
|
|
* Date: 28.05.12 16:07
|
|
|
|
|
*/
|
|
|
|
|
public class RunTargetAction extends AnAction {
|
|
|
|
|
public RunTargetAction() {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
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 AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(psiFile);
|
|
|
|
|
if (antFile == null) return null;
|
|
|
|
|
|
|
|
|
|
final XmlFile xmlFile = (XmlFile)psiFile;
|
|
|
|
|
PsiElement at = xmlFile.findElementAt(editor.getCaretModel().getOffset());
|
|
|
|
|
while (at != null && !(at instanceof XmlTag)) at = at.getParent();
|
|
|
|
|
if (at == null) return null;
|
|
|
|
|
|
|
|
|
|
DomElement dom = AntSupport.getAntDomElement((XmlTag)at);
|
|
|
|
|
while (dom != null && !(dom instanceof AntDomTarget)) dom = dom.getParent();
|
|
|
|
|
|
|
|
|
|
final AntDomTarget tar = (AntDomTarget)dom;
|
|
|
|
|
if (tar == null) return null;
|
|
|
|
|
return Pair.create(antFile, tar);
|
|
|
|
|
}
|
|
|
|
|
}
|