Search in sources :

Example 1 with AntConfiguration

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

the class AntExplorerTreeBuilder method dispose.

public void dispose() {
    final AntConfiguration config = myConfig;
    if (config != null) {
        config.removeAntConfigurationListener(myAntBuildListener);
        myConfig = null;
    }
    final ExpandedStateUpdater expansionListener = myExpansionListener;
    final JTree tree = getTree();
    if (expansionListener != null && tree != null) {
        tree.removeTreeExpansionListener(expansionListener);
        myExpansionListener = null;
    }
    super.dispose();
}
Also used : AntConfiguration(com.intellij.lang.ant.config.AntConfiguration)

Example 2 with AntConfiguration

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

the class AntKeymapExtension method createGroup.

public KeymapGroup createGroup(final Condition<AnAction> filtered, Project project) {
    final Map<AntBuildFile, KeymapGroup> buildFileToGroup = new HashMap<>();
    final KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(KeyMapBundle.message("ant.targets.group.title"), AllIcons.Nodes.KeymapAnt);
    final ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    final String[] ids = actionManager.getActionIds(project != null ? AntConfiguration.getActionIdPrefix(project) : AntConfiguration.ACTION_ID_PREFIX);
    Arrays.sort(ids);
    if (project != null) {
        final AntConfiguration antConfiguration = AntConfiguration.getInstance(project);
        ApplicationManager.getApplication().runReadAction(() -> {
            for (final String id : ids) {
                if (filtered != null && !filtered.value(actionManager.getActionOrStub(id))) {
                    continue;
                }
                final AntBuildFile buildFile = antConfiguration.findBuildFileByActionId(id);
                if (buildFile != null) {
                    KeymapGroup subGroup = buildFileToGroup.get(buildFile);
                    if (subGroup == null) {
                        subGroup = KeymapGroupFactory.getInstance().createGroup(buildFile.getPresentableName());
                        buildFileToGroup.put(buildFile, subGroup);
                        result.addGroup(subGroup);
                    }
                    subGroup.addActionId(id);
                } else {
                    LOG.info("no buildfile found for actionId=" + id);
                }
            }
        });
    }
    return result;
}
Also used : AntBuildFile(com.intellij.lang.ant.config.AntBuildFile) HashMap(com.intellij.util.containers.HashMap) KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) AntConfiguration(com.intellij.lang.ant.config.AntConfiguration) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx)

Example 3 with AntConfiguration

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

the class AddAntBuildFile method actionPerformed.

public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
        return;
    }
    final VirtualFile[] contextFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (contextFiles == null || contextFiles.length == 0) {
        return;
    }
    final AntConfiguration antConfiguration = AntConfiguration.getInstance(project);
    final Set<VirtualFile> files = new HashSet<>();
    files.addAll(Arrays.asList(contextFiles));
    for (AntBuildFile buildFile : antConfiguration.getBuildFileList()) {
        files.remove(buildFile.getVirtualFile());
    }
    int filesAdded = 0;
    final StringBuilder errors = new StringBuilder();
    for (VirtualFile file : files) {
        try {
            antConfiguration.addBuildFile(file);
            filesAdded++;
        } catch (AntNoFileException ex) {
            String message = ex.getMessage();
            if (message == null || message.length() == 0) {
                message = AntBundle.message("cannot.add.build.files.from.excluded.directories.error.message", ex.getFile().getPresentableUrl());
            }
            if (errors.length() > 0) {
                errors.append("\n");
            }
            errors.append(message);
        }
    }
    if (errors.length() > 0) {
        Messages.showWarningDialog(project, errors.toString(), AntBundle.message("cannot.add.build.file.dialog.title"));
    }
    if (filesAdded > 0) {
        ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.ANT_BUILD).activate(null);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AntBuildFile(com.intellij.lang.ant.config.AntBuildFile) AntNoFileException(com.intellij.lang.ant.config.AntNoFileException) AntConfiguration(com.intellij.lang.ant.config.AntConfiguration) HashSet(java.util.HashSet)

Example 4 with AntConfiguration

use of com.intellij.lang.ant.config.AntConfiguration 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 AntConfiguration

use of com.intellij.lang.ant.config.AntConfiguration 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)

Aggregations

AntConfiguration (com.intellij.lang.ant.config.AntConfiguration)6 AntBuildFile (com.intellij.lang.ant.config.AntBuildFile)3 AntBuildTarget (com.intellij.lang.ant.config.AntBuildTarget)2 AntConfigurationBase (com.intellij.lang.ant.config.AntConfigurationBase)1 AntConfigurationListener (com.intellij.lang.ant.config.AntConfigurationListener)1 AntNoFileException (com.intellij.lang.ant.config.AntNoFileException)1 TargetActionStub (com.intellij.lang.ant.config.actions.TargetActionStub)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 ActionManagerEx (com.intellij.openapi.actionSystem.ex.ActionManagerEx)1 Keymap (com.intellij.openapi.keymap.Keymap)1 KeymapGroup (com.intellij.openapi.keymap.KeymapGroup)1 KeymapManagerEx (com.intellij.openapi.keymap.ex.KeymapManagerEx)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Tree (com.intellij.ui.treeStructure.Tree)1 HashMap (com.intellij.util.containers.HashMap)1 HashSet (java.util.HashSet)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1