Search in sources :

Example 6 with AntBuildTarget

use of com.intellij.lang.ant.config.AntBuildTarget in project intellij-community by JetBrains.

the class AntToolwindowRegistrar method projectOpened.

@Override
public void projectOpened() {
    final KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    final String prefix = AntConfiguration.getActionIdPrefix(myProject);
    final ActionManager actionManager = ActionManager.getInstance();
    for (Keymap keymap : keymapManager.getAllKeymaps()) {
        for (String id : keymap.getActionIdList()) {
            if (id.startsWith(prefix) && actionManager.getAction(id) == null) {
                actionManager.registerAction(id, new TargetActionStub(id, myProject));
            }
        }
    }
    final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
    compilerManager.addBeforeTask(new CompileTask() {

        @Override
        public boolean execute(CompileContext context) {
            final AntConfiguration config = AntConfiguration.getInstance(myProject);
            ((AntConfigurationBase) config).ensureInitialized();
            return config.executeTargetBeforeCompile(createDataContext(context));
        }
    });
    compilerManager.addAfterTask(new CompileTask() {

        @Override
        public boolean execute(CompileContext context) {
            final AntConfigurationBase config = (AntConfigurationBase) AntConfiguration.getInstance(myProject);
            config.ensureInitialized();
            if (context.getMessageCount(CompilerMessageCategory.ERROR) > 0) {
                final AntBuildTarget target = config.getTargetForEvent(ExecuteAfterCompilationEvent.getInstance());
                if (target != null) {
                    context.addMessage(CompilerMessageCategory.INFORMATION, "Skipping ant target \"" + target.getDisplayName() + "\" because of compilation errors", null, -1, -1);
                }
                return true;
            }
            return config.executeTargetAfterCompile(createDataContext(context));
        }
    });
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) TargetActionStub(com.intellij.lang.ant.config.actions.TargetActionStub) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) AntConfiguration(com.intellij.lang.ant.config.AntConfiguration) AntBuildTarget(com.intellij.lang.ant.config.AntBuildTarget) Keymap(com.intellij.openapi.keymap.Keymap) AntConfigurationBase(com.intellij.lang.ant.config.AntConfigurationBase)

Example 7 with AntBuildTarget

use of com.intellij.lang.ant.config.AntBuildTarget in project intellij-community by JetBrains.

the class GlobalAntConfiguration method findTarget.

public AntBuildTarget findTarget(Project project, String fileUrl, String targetName) {
    if (fileUrl == null || targetName == null || project == null) {
        return null;
    }
    final VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileUrl);
    if (vFile == null) {
        return null;
    }
    final AntConfigurationImpl antConfiguration = (AntConfigurationImpl) AntConfiguration.getInstance(project);
    for (AntBuildFile buildFile : antConfiguration.getBuildFileList()) {
        if (vFile.equals(buildFile.getVirtualFile())) {
            final AntBuildTarget target = buildFile.getModel().findTarget(targetName);
            if (target != null) {
                return target;
            }
            for (AntBuildTarget metaTarget : antConfiguration.getMetaTargets(buildFile)) {
                if (targetName.equals(metaTarget.getName())) {
                    return metaTarget;
                }
            }
            return null;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AntBuildFile(com.intellij.lang.ant.config.AntBuildFile) AntBuildTarget(com.intellij.lang.ant.config.AntBuildTarget)

Aggregations

AntBuildTarget (com.intellij.lang.ant.config.AntBuildTarget)7 AntBuildFile (com.intellij.lang.ant.config.AntBuildFile)2 AntConfiguration (com.intellij.lang.ant.config.AntConfiguration)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 ExecutionException (com.intellij.execution.ExecutionException)1 AntConfigurationBase (com.intellij.lang.ant.config.AntConfigurationBase)1 TargetActionStub (com.intellij.lang.ant.config.actions.TargetActionStub)1 BuildFileProperty (com.intellij.lang.ant.config.impl.BuildFileProperty)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)1 Keymap (com.intellij.openapi.keymap.Keymap)1 KeymapManagerEx (com.intellij.openapi.keymap.ex.KeymapManagerEx)1 Project (com.intellij.openapi.project.Project)1 Tree (com.intellij.ui.treeStructure.Tree)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 TreePath (javax.swing.tree.TreePath)1 NonNls (org.jetbrains.annotations.NonNls)1