Search in sources :

Example 1 with AntBuildFile

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

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

the class AntWorkspaceConfiguration method loadFileProperties.

public void loadFileProperties() throws InvalidDataException {
    final Element properties = myProperties.getAndSet(null);
    if (properties == null) {
        return;
    }
    for (final AntBuildFile buildFile : AntConfiguration.getInstance(myProject).getBuildFileList()) {
        final Element fileElement = findChildByUrl(properties, buildFile.getVirtualFile().getUrl());
        if (fileElement == null) {
            continue;
        }
        ((AntBuildFileBase) buildFile).readWorkspaceProperties(fileElement);
    }
}
Also used : AntBuildFile(com.intellij.lang.ant.config.AntBuildFile) AntBuildFileBase(com.intellij.lang.ant.config.AntBuildFileBase) Element(org.jdom.Element)

Example 3 with AntBuildFile

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

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

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

the class AntArtifactProperties method findTarget.

@Nullable
public AntBuildTarget findTarget(final AntConfiguration antConfiguration) {
    String fileUrl = getFileUrl();
    String targetName = getTargetName();
    if (fileUrl == null || targetName == null)
        return null;
    for (AntBuildFile buildFile : antConfiguration.getBuildFileList()) {
        final VirtualFile file = buildFile.getVirtualFile();
        if (file != null && file.getUrl().equals(fileUrl)) {
            final AntBuildModel buildModel = buildFile.getModel();
            return buildModel != null ? buildModel.findTarget(targetName) : null;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AntBuildModel(com.intellij.lang.ant.config.AntBuildModel) AntBuildFile(com.intellij.lang.ant.config.AntBuildFile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AntBuildFile (com.intellij.lang.ant.config.AntBuildFile)8 AntConfiguration (com.intellij.lang.ant.config.AntConfiguration)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 AntBuildFileBase (com.intellij.lang.ant.config.AntBuildFileBase)2 AntBuildTarget (com.intellij.lang.ant.config.AntBuildTarget)2 Project (com.intellij.openapi.project.Project)2 Element (org.jdom.Element)2 AntBuildModel (com.intellij.lang.ant.config.AntBuildModel)1 AntNoFileException (com.intellij.lang.ant.config.AntNoFileException)1 ActionManagerEx (com.intellij.openapi.actionSystem.ex.ActionManagerEx)1 KeymapGroup (com.intellij.openapi.keymap.KeymapGroup)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 TreePath (javax.swing.tree.TreePath)1 NonNls (org.jetbrains.annotations.NonNls)1 Nullable (org.jetbrains.annotations.Nullable)1