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();
}
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;
}
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);
}
}
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;
}
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));
}
});
}
Aggregations