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(); }
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.getBuildFiles()) { 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; }
@Nullable public AntBuildTarget findTarget(final AntConfiguration antConfiguration) { String fileUrl = getFileUrl(); String targetName = getTargetName(); if (fileUrl == null || targetName == null) return null; final AntBuildFile[] buildFiles = antConfiguration.getBuildFiles(); for (AntBuildFile buildFile : buildFiles) { 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; }
public void actionPerformed(AnActionEvent event) { DataContext dataContext = event.getDataContext(); Project project = PlatformDataKeys.PROJECT.getData(dataContext); VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext); AntConfiguration antConfiguration = AntConfiguration.getInstance(project); try { antConfiguration.addBuildFile(file); ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.ANT_BUILD).activate(null); } catch (AntNoFileException e) { String message = e.getMessage(); if (message == null || message.length() == 0) { message = AntBundle.message("cannot.add.build.files.from.excluded.directories.error.message", e.getFile().getPresentableUrl()); } Messages.showWarningDialog(project, message, AntBundle.message("cannot.add.build.file.dialog.title")); } }
public void actionPerformed(AnActionEvent e) { Project project = e.getProject(); VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE); AntConfiguration antConfiguration = AntConfiguration.getInstance(project); try { antConfiguration.addBuildFile(file); ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.ANT_BUILD).activate(null); } 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()); } Messages.showWarningDialog(project, message, AntBundle.message("cannot.add.build.file.dialog.title")); } }
private static void fillGroup(final AntBuildFile buildFile, final DefaultActionGroup group, final AntConfiguration antConfiguration) { final AntBuildModelBase model = (AntBuildModelBase)buildFile.getModel(); if (model.getDefaultTargetName() != null) { DefaultActionGroup subgroup = new DefaultActionGroup(); subgroup.add(getOrCreateAction(buildFile, TargetAction.DEFAULT_TARGET_NAME, new String[]{TargetAction.DEFAULT_TARGET_NAME}, null, model.getDefaultTargetActionId())); group.add(subgroup); } final Set<String> addedTargetNames = StringSetSpinAllocator.alloc(); try { addGroupOfTargets(buildFile, model.getFilteredTargets(), addedTargetNames, group); addGroupOfTargets(buildFile, antConfiguration.getMetaTargets(buildFile), addedTargetNames, group); } finally { StringSetSpinAllocator.dispose(addedTargetNames); } }
public AntExplorerTreeBuilder(Project project, JTree tree, DefaultTreeModel treeModel) { super(tree, treeModel, new AntExplorerTreeStructure(project), IndexComparator.INSTANCE); myProject = project; myAntBuildListener = new ConfigurationListener(); myConfig = AntConfiguration.getInstance(myProject); myConfig.addAntConfigurationListener(myAntBuildListener); myExpansionListener = new ExpandedStateUpdater(); tree.addTreeExpansionListener(myExpansionListener); initRootNode(); }
public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) return; for (final AntBuildFile buildFile : AntConfiguration.getInstance(project).getBuildFiles()) { final String name = buildFile.getPresentableName(); if (name != null && myBuildName.equals(name)) { String[] targets = myTargets.length == 1 && DEFAULT_TARGET_NAME.equals(myTargets[0]) ? ArrayUtil.EMPTY_STRING_ARRAY : myTargets; ExecutionHandler.runBuild((AntBuildFileBase)buildFile, targets, null, dataContext, Collections.<BuildFileProperty>emptyList(), AntBuildListener.NULL); return; } } }
public void dispose() { final AntConfiguration configuration = myConfig; final AntConfigurationListener listener = myListener; myConfig = null; myListener = null; if (configuration != null && listener != null) { configuration.removeAntConfigurationListener(listener); } }
@Override public void checkConfiguration() throws RuntimeConfigurationException { if (!AntConfiguration.getInstance(getProject()).isInitialized()) { throw new RuntimeConfigurationException("Ant Configuration still haven't been initialized"); } if (getTarget() == null) throw new RuntimeConfigurationException("Target is not specified", "Missing parameters"); }
public void projectClosed() { final ActionManagerEx actionManager = ActionManagerEx.getInstanceEx(); final String[] oldIds = actionManager.getActionIds(AntConfiguration.getActionIdPrefix(myProject)); for (String oldId : oldIds) { actionManager.unregisterAction(oldId); } }
public void writeExternal(Element parentNode) throws WriteExternalException { DefaultJDOMExternalizer.writeExternal(this, parentNode); for (final AntBuildFile buildFile : AntConfiguration.getInstance(myProject).getBuildFiles()) { Element element = new Element(BUILD_FILE); element.setAttribute(URL, buildFile.getVirtualFile().getUrl()); ((AntBuildFileBase)buildFile).writeWorkspaceProperties(element); parentNode.addContent(element); } }
public void loadFileProperties() throws InvalidDataException { final Element properties = myProperties.getAndSet(null); if (properties == null) { return; } for (final AntBuildFile buildFile : AntConfiguration.getInstance(myProject).getBuildFiles()) { final Element fileElement = findChildByUrl(properties, buildFile.getVirtualFile().getUrl()); if (fileElement == null) { continue; } ((AntBuildFileBase)buildFile).readWorkspaceProperties(fileElement); } }
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); } } } }
public void reset() { myRunTargetCheckBox.setSelected(myProperties.isEnabled()); myTarget = myProperties.findTarget(AntConfiguration.getInstance(myContext.getProject())); final List<BuildFileProperty> properties = new ArrayList<BuildFileProperty>(); for (BuildFileProperty property : myProperties.getAllProperties(myContext.getArtifact())) { properties.add(new BuildFileProperty(property.getPropertyName(), property.getPropertyValue())); } myContainer = new SinglePropertyContainer<ListProperty>(ANT_PROPERTIES, properties); myBinding.loadValues(myContainer); updatePanel(); }
public KeymapGroup createGroup(final Condition<AnAction> filtered, Project project) { final Map<AntBuildFile, KeymapGroup> buildFileToGroup = new HashMap<AntBuildFile, KeymapGroup>(); 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(new Runnable() { public void run() { 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; }
public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); Project project = PlatformDataKeys.PROJECT.getData(dataContext); if (project == null) return; for (final AntBuildFile buildFile : AntConfiguration.getInstance(project).getBuildFiles()) { final String name = buildFile.getPresentableName(); if (name != null && myBuildName.equals(name)) { String[] targets = myTargets.length == 1 && DEFAULT_TARGET_NAME.equals(myTargets[0]) ? ArrayUtil.EMPTY_STRING_ARRAY : myTargets; ExecutionHandler.runBuild((AntBuildFileBase)buildFile, targets, null, dataContext, Collections.<BuildFileProperty>emptyList(), AntBuildListener.NULL); return; } } }
@Nullable private AntBuildTarget findTargetToExecute(AntBeforeRunTask task) { final String fileUrl = task.getAntFileUrl(); final String targetName = task.getTargetName(); if (fileUrl == null || targetName == null) { return null; } final VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileUrl); if (vFile == null) { return null; } final AntConfigurationImpl antConfiguration = (AntConfigurationImpl)AntConfiguration.getInstance(myProject); for (AntBuildFile buildFile : antConfiguration.getBuildFiles()) { 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; }
@Override public boolean execute(CompileContext compileContext) { final DataContext dataContext = SimpleDataContext.getProjectContext(compileContext.getProject()); final AntConfiguration config = AntConfiguration.getInstance(compileContext.getProject()); ((AntConfigurationBase)config).ensureInitialized(); return config.executeTargetBeforeCompile(dataContext); }
@Override public boolean execute(CompileContext compileContext) { final DataContext dataContext = SimpleDataContext.getProjectContext(compileContext.getProject()); final AntConfiguration config = AntConfiguration.getInstance(compileContext.getProject()); ((AntConfigurationBase)config).ensureInitialized(); return config.executeTargetAfterCompile(dataContext); }
private void addBuildFile(final VirtualFile[] files) { if (files.length == 0) { return; } ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { final AntConfiguration antConfiguration = myConfig; if (antConfiguration == null) { return; } final List<VirtualFile> ignoredFiles = new ArrayList<VirtualFile>(); for (VirtualFile file : files) { try { antConfiguration.addBuildFile(file); } catch (AntNoFileException e) { ignoredFiles.add(e.getFile()); } } if (ignoredFiles.size() != 0) { String messageText; final StringBuilder message = StringBuilderSpinAllocator.alloc(); try { String separator = ""; for (final VirtualFile virtualFile : ignoredFiles) { message.append(separator); message.append(virtualFile.getPresentableUrl()); separator = "\n"; } messageText = message.toString(); } finally { StringBuilderSpinAllocator.dispose(message); } Messages.showWarningDialog(myProject, messageText, AntBundle.message("cannot.add.ant.files.dialog.title")); } } }); }
public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); Project project = e.getProject(); if (project == null) return; for (final AntBuildFile buildFile : AntConfiguration.getInstance(project).getBuildFiles()) { final String name = buildFile.getPresentableName(); if (name != null && myBuildName.equals(name)) { String[] targets = myTargets.length == 1 && DEFAULT_TARGET_NAME.equals(myTargets[0]) ? ArrayUtil.EMPTY_STRING_ARRAY : myTargets; ExecutionHandler.runBuild((AntBuildFileBase)buildFile, targets, null, dataContext, Collections.<BuildFileProperty>emptyList(), AntBuildListener.NULL); return; } } }
@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.getActionIds()) { if (id.startsWith(prefix) && actionManager.getAction(id) == null) { actionManager.registerAction(id, new TargetActionStub(id, myProject)); } } } }
@Override public void projectClosed() { final ActionManagerEx actionManager = ActionManagerEx.getInstanceEx(); final String[] oldIds = actionManager.getActionIds(AntConfiguration.getActionIdPrefix(myProject)); for (String oldId : oldIds) { actionManager.unregisterAction(oldId); } }