Search in sources :

Example 1 with AntBuildTarget

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

the class AntBeforeRunTaskProvider method configureTask.

public boolean configureTask(RunConfiguration runConfiguration, AntBeforeRunTask task) {
    AntBuildTarget buildTarget = findTargetToExecute(task);
    final TargetChooserDialog dlg = new TargetChooserDialog(myProject, buildTarget);
    if (dlg.showAndGet()) {
        task.setTargetName(null);
        task.setAntFileUrl(null);
        buildTarget = dlg.getSelectedTarget();
        if (buildTarget != null) {
            final VirtualFile vFile = buildTarget.getModel().getBuildFile().getVirtualFile();
            if (vFile != null) {
                task.setAntFileUrl(vFile.getUrl());
                task.setTargetName(buildTarget.getName());
            }
        }
        return true;
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AntBuildTarget(com.intellij.lang.ant.config.AntBuildTarget)

Example 2 with AntBuildTarget

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

the class ExecutionHandler method executeRunConfiguration.

@Nullable
public static ProcessHandler executeRunConfiguration(AntRunConfiguration antRunConfiguration, final DataContext dataContext, List<BuildFileProperty> additionalProperties, @NotNull final AntBuildListener antBuildListener) {
    AntBuildTarget target = antRunConfiguration.getTarget();
    if (target == null)
        return null;
    FutureResult<ProcessHandler> result = runBuildImpl((AntBuildFileBase) target.getModel().getBuildFile(), new String[] { target.getName() }, null, dataContext, additionalProperties, antBuildListener, false);
    if (result != null) {
        try {
            return result.get();
        } catch (InterruptedException | java.util.concurrent.ExecutionException e) {
            LOG.warn(e);
        }
    }
    return null;
}
Also used : ExecutionException(com.intellij.execution.ExecutionException) AntBuildTarget(com.intellij.lang.ant.config.AntBuildTarget) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with AntBuildTarget

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

the class TargetChooserDialog method processFileTargets.

private DefaultMutableTreeNode processFileTargets(final AntBuildTarget[] targets, final AntBuildFile buildFile, final DefaultMutableTreeNode buildFileNode) {
    DefaultMutableTreeNode result = null;
    for (AntBuildTarget target : targets) {
        if (target.getName() == null)
            continue;
        final AntTargetNodeDescriptor descriptor = new AntTargetNodeDescriptor(target, buildFile);
        final DefaultMutableTreeNode node = new DefaultMutableTreeNode(descriptor);
        if (isSelected(descriptor)) {
            result = node;
        }
        buildFileNode.add(node);
    }
    return result;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AntBuildTarget(com.intellij.lang.ant.config.AntBuildTarget)

Example 4 with AntBuildTarget

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

the class TargetChooserDialog method initTree.

private Tree initTree() {
    @NonNls final DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    final Tree tree = new Tree(root);
    tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            final TreePath selectionPath = tree.getSelectionPath();
            if (selectionPath != null) {
                final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
                final Object userObject = node.getUserObject();
                if (userObject instanceof AntTargetNodeDescriptor) {
                    final AntTargetNodeDescriptor antBuildTarget = (AntTargetNodeDescriptor) userObject;
                    mySelectedTarget = antBuildTarget.getAntTarget();
                } else {
                    mySelectedTarget = null;
                }
            }
        }
    });
    tree.setCellRenderer(new MyTreeCellRenderer());
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setLineStyleAngled();
    TreeUtil.installActions(tree);
    new TreeSpeedSearch(tree, new Convertor<TreePath, String>() {

        public String convert(final TreePath path) {
            final Object userObject = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
            if (userObject instanceof AntTargetNodeDescriptor) {
                final AntBuildTarget target = ((AntTargetNodeDescriptor) userObject).getAntTarget();
                return target.getDisplayName();
            }
            return null;
        }
    });
    DefaultMutableTreeNode selectedNode = null;
    final AntConfiguration antConfiguration = AntConfigurationImpl.getInstance(myProject);
    for (AntBuildFile buildFile : antConfiguration.getBuildFileList()) {
        final DefaultMutableTreeNode buildFileNode = new DefaultMutableTreeNode(buildFile);
        DefaultMutableTreeNode selection = processFileTargets(antConfiguration.getMetaTargets(buildFile), buildFile, buildFileNode);
        if (selection != null) {
            selectedNode = selection;
        }
        selection = processFileTargets(antConfiguration.getModel(buildFile).getTargets(), buildFile, buildFileNode);
        if (selection != null) {
            selectedNode = selection;
        }
        root.add(buildFileNode);
    }
    TreeUtil.expandAll(tree);
    TreeUtil.selectInTree(selectedNode, true, tree);
    return tree;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSelectionListener(javax.swing.event.TreeSelectionListener) AntConfiguration(com.intellij.lang.ant.config.AntConfiguration) AntBuildFile(com.intellij.lang.ant.config.AntBuildFile) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) AntBuildTarget(com.intellij.lang.ant.config.AntBuildTarget)

Example 5 with AntBuildTarget

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

the class AntArtifactProperties method runAntTarget.

private void runAntTarget(CompileContext compileContext, final Artifact artifact) {
    if (myExtensionProperties.myEnabled) {
        final Project project = compileContext.getProject();
        final AntBuildTarget target = findTarget(AntConfiguration.getInstance(project));
        if (target != null) {
            final DataContext dataContext = SimpleDataContext.getProjectContext(project);
            List<BuildFileProperty> properties = getAllProperties(artifact);
            final boolean success = AntConfigurationImpl.executeTargetSynchronously(dataContext, target, properties);
            if (!success) {
                compileContext.addMessage(CompilerMessageCategory.ERROR, "Cannot build artifact '" + artifact.getName() + "': ant target '" + target.getDisplayName() + "' failed with error", null, -1, -1);
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) BuildFileProperty(com.intellij.lang.ant.config.impl.BuildFileProperty) 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