private AntBuildFileBase findBuildFile(final File dir) { final File buildxml = new File(dir, HybrisConstants.ANT_BUILD_XML); if (!buildxml.exists()) { return null; } final VirtualFile buildFile = VfsUtil.findFileByIoFile(buildxml, true); if (buildFile == null) { return null; } final AntBuildFile antBuildFile; try { antBuildFile = antConfiguration.addBuildFile(buildFile); } catch (AntNoFileException e) { return null; } if (antBuildFile instanceof AntBuildFileBase) { return (AntBuildFileBase) antBuildFile; } return null; }
private static void removeOldProjectData(@NotNull final Project project) { final ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel(); for (Module module : moduleModel.getModules()) { moduleModel.disposeModule(module); } final LibraryTable.ModifiableModel libraryModel = ProjectLibraryTable.getInstance(project).getModifiableModel(); for (Library library : libraryModel.getLibraries()) { libraryModel.removeLibrary(library); } ApplicationManager.getApplication().runWriteAction(() -> { moduleModel.commit(); libraryModel.commit(); }); final GradleSupport gradleSupport = GradleSupport.getInstance(); if (gradleSupport != null) { gradleSupport.clearLinkedProjectSettings(project); } final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(project); for (AntBuildFile antBuildFile : antConfiguration.getBuildFiles()) { antConfiguration.removeBuildFile(antBuildFile); } }
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 customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof DefaultMutableTreeNode) { final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)value; final Object userObject = treeNode.getUserObject(); if (userObject instanceof AntBuildFile) { append(((AntBuildFile)userObject).getPresentableName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); } else if (userObject instanceof AntTargetNodeDescriptor) { final AntTargetNodeDescriptor descriptor = (AntTargetNodeDescriptor)userObject; final AntBuildTarget antTarget = descriptor.getAntTarget(); final String antTargetName = antTarget.getName(); append(antTargetName, SimpleTextAttributes.REGULAR_ATTRIBUTES); boolean isMeta = antTarget instanceof MetaTarget; setIcon(isMeta ? AntIcons.MetaTarget : AntIcons.Target); } } }
private static void runBuild(final ProgressIndicator progress, @NotNull final AntBuildMessageView errorView, @NotNull final AntBuildFile buildFile, @NotNull final AntBuildListener antBuildListener, @NotNull GeneralCommandLine commandLine) { final Project project = buildFile.getProject(); final long startTime = System.currentTimeMillis(); LocalHistory.getInstance().putSystemLabel(project, AntBundle.message("ant.build.local.history.label", buildFile.getName())); final JUnitProcessHandler handler; try { handler = JUnitProcessHandler.runCommandLine(commandLine); } catch (final ExecutionException e) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { ExecutionErrorDialog.show(e, AntBundle.message("could.not.start.process.erorr.dialog.title"), project); } }); antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0); return; } processRunningAnt(progress, handler, errorView, buildFile, startTime, antBuildListener); handler.waitFor(); }
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof DefaultMutableTreeNode) { final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)value; final Object userObject = treeNode.getUserObject(); if (userObject instanceof AntBuildFile) { append(((AntBuildFile)userObject).getPresentableName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); } else if (userObject instanceof AntTargetNodeDescriptor) { final AntTargetNodeDescriptor descriptor = (AntTargetNodeDescriptor)userObject; final AntBuildTarget antTarget = descriptor.getAntTarget(); final String antTargetName = antTarget.getName(); append(antTargetName, SimpleTextAttributes.REGULAR_ATTRIBUTES); boolean isMeta = antTarget instanceof MetaTarget; setIcon(isMeta ? AllIcons.Ant.MetaTarget : AllIcons.Ant.Target); } } }
@NotNull public AnAction[] getChildren(@Nullable AnActionEvent e) { if (e == null) return AnAction.EMPTY_ARRAY; Project project = e.getProject(); if (project == null) return AnAction.EMPTY_ARRAY; final List<AnAction> children = new ArrayList<AnAction>(); final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(project); for (final AntBuildFile buildFile : antConfiguration.getBuildFiles()) { final String name = buildFile.getPresentableName(); DefaultActionGroup subgroup = new DefaultActionGroup(); subgroup.getTemplatePresentation().setText(name, false); subgroup.setPopup(true); fillGroup(buildFile, subgroup, antConfiguration); if (subgroup.getChildrenCount() > 0) { children.add(subgroup); } } return children.toArray(new AnAction[children.size()]); }
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); } }
private static void addGroupOfTargets(final AntBuildFile buildFile, final AntBuildTarget[] targets, final Set<String> addedTargetNames, final DefaultActionGroup group) { final DefaultActionGroup subgroup = new DefaultActionGroup(); for (final AntBuildTarget target : targets) { final String displayName = target.getName(); if (addedTargetNames.contains(displayName)) { continue; } addedTargetNames.add(displayName); final String[] targetsToRun = (target instanceof MetaTarget) ? ((MetaTarget)target).getTargetNames() : new String[]{displayName}; subgroup.add(getOrCreateAction(buildFile, displayName, targetsToRun, target.getNotEmptyDescription(), ((AntBuildTargetBase)target).getActionId())); } if (subgroup.getChildrenCount() > 0) { group.add(subgroup); } }
@Override public void moveToGroup(@NotNull AntBuildFile file, @Nullable AntBuildFileGroup group) { for (Map.Entry<AntBuildFileGroup, List<VirtualFile>> entry : myFileGroupList.entrySet()) { if (entry.getValue().contains(file.getVirtualFile())) { entry.getValue().remove(file.getVirtualFile()); break; } } if (group == null) { return; } List<VirtualFile> virtualFiles = myFileGroupList.get(group); if (virtualFiles == null) { myFileGroupList.put(group, virtualFiles = new ArrayList<VirtualFile>()); } virtualFiles.add(file.getVirtualFile()); }
@Override public AntBuildFile[] getFilesForGroup(@NotNull AntBuildFileGroup group) { final List<VirtualFile> virtualFiles = myFileGroupList.get(group); if (virtualFiles == null || virtualFiles.isEmpty()) { return AntBuildFile.EMPTY_ARRAY; } List<AntBuildFile> files = new ArrayList<AntBuildFile>(); final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(myProject); final PsiManager manager = PsiManager.getInstance(myProject); for (VirtualFile virtualFile : virtualFiles) { final PsiFile file = manager.findFile(virtualFile); if (!(file instanceof XmlFile)) { continue; } final AntBuildFileBase antBuildFile = antConfiguration.getAntBuildFile(file); if (antBuildFile == null) { continue; } files.add(antBuildFile); } return files.toArray(new AntBuildFile[files.size()]); }
private void writeToElement(AntBuildFileGroup group, Element parent) { final Element element = new Element("ant-group"); element.setAttribute("name", group.getName()); for (AntBuildFileGroup childGroup : group.getChildren()) { writeToElement(childGroup, element); } for (AntBuildFile file : getFilesForGroup(group)) { final Element fileElement = new Element("file"); fileElement.setText(file.getVirtualFile().getUrl()); element.addContent(fileElement); } parent.addContent(element); }
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof DefaultMutableTreeNode) { final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)value; final Object userObject = treeNode.getUserObject(); if (userObject instanceof AntBuildFile) { append(((AntBuildFile)userObject).getPresentableName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); } else if (userObject instanceof AntTargetNodeDescriptor) { final AntTargetNodeDescriptor descriptor = (AntTargetNodeDescriptor)userObject; final AntBuildTarget antTarget = descriptor.getAntTarget(); final String antTargetName = antTarget.getName(); append(antTargetName, SimpleTextAttributes.REGULAR_ATTRIBUTES); boolean isMeta = antTarget instanceof MetaTarget; setIcon(isMeta ? ApacheAntIcons.MetaTarget : ApacheAntIcons.Target); } } }
public SaveMetaTargetDialog(final Component parent, final ExecuteCompositeTargetEvent event, final AntConfigurationBase antConfiguration, final AntBuildFile buildFile) { super(parent, true); myInitialEvent = event; myAntConfiguration = antConfiguration; myBuildFile = buildFile; setModal(true); init(); }
public TargetAction(final AntBuildFile buildFile, final String displayName, final String[] targets, final String description) { Presentation templatePresentation = getTemplatePresentation(); templatePresentation.setText(displayName, false); templatePresentation.setDescription(description); myBuildName = buildFile.getPresentableName(); myTargets = targets; myDebugString = "Target action: " + displayName + "; Build: " + buildFile.getPresentableName() + "; Project: " + buildFile.getProject().getPresentableUrl(); }
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 static OutputParser attachParser(final Project myProject, JUnitProcessHandler handler, final AntBuildMessageView errorView, final ProgressIndicator progress, final AntBuildFile buildFile) { final OutputParser2 parser = new OutputParser2(myProject, handler, errorView, progress, buildFile.getName()); final DeferredActionsQueue queue = new DeferredActionsQueueImpl(); handler.getErr().setPacketDispatcher(parser, queue); return parser; }
public TreeView(final Project project, final AntBuildFile buildFile) { myProject = project; myBuildFile = buildFile; myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() { protected boolean isAutoScrollMode() { return AntConfigurationBase.getInstance(myProject).isAutoScrollToSource(); } protected void setAutoScrollMode(boolean state) { AntConfigurationBase.getInstance(myProject).setAutoScrollToSource(state); } }; myPanel = createPanel(); }
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 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; }
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; } } }
private static void processRunningAnt(final ProgressIndicator progress, final JUnitProcessHandler handler, final AntBuildMessageView errorView, final AntBuildFile buildFile, final long startTime, final AntBuildListener antBuildListener) { final Project project = buildFile.getProject(); final StatusBar statusbar = WindowManager.getInstance().getStatusBar(project); if (statusbar != null) { statusbar.setInfo(AntBundle.message("ant.build.started.status.message")); } final CheckCancelTask checkCancelTask = new CheckCancelTask(progress, handler); checkCancelTask.start(0); final OutputParser parser = OutputParser2.attachParser(project, handler, errorView, progress, buildFile); handler.addProcessListener(new ProcessAdapter() { public void processTerminated(ProcessEvent event) { final long buildTime = System.currentTimeMillis() - startTime; checkCancelTask.cancel(); parser.setStopped(true); final OutputPacketProcessor dispatcher = handler.getErr().getEventsDispatcher(); errorView.buildFinished(progress != null && progress.isCanceled(), buildTime, antBuildListener, dispatcher); ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { if (project.isDisposed()) { return; } errorView.removeProgressPanel(); ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW); if (toolWindow != null) { // can be null if project is closed toolWindow.activate(null, false); } } }, ModalityState.NON_MODAL); } }); handler.startNotify(); }
@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; }
public void removeBuildFile() { final AntBuildFile buildFile = getCurrentBuildFile(); if (buildFile == null) { return; } final String fileName = buildFile.getPresentableUrl(); final int result = Messages.showYesNoDialog(myProject, AntBundle.message("remove.the.reference.to.file.confirmation.text", fileName), AntBundle.message("confirm.remove.dialog.title"), Messages.getQuestionIcon()); if (result != 0) { return; } myConfig.removeBuildFile(buildFile); }
private boolean canRunSelection() { if (myTree == null) { return false; } final TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) { return false; } final AntBuildFile buildFile = getCurrentBuildFile(); if (buildFile == null || !buildFile.exists()) { return false; } for (final TreePath path : paths) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); final Object userObject = node.getUserObject(); final AntBuildFileNodeDescriptor buildFileNodeDescriptor; if (userObject instanceof AntTargetNodeDescriptor) { buildFileNodeDescriptor = (AntBuildFileNodeDescriptor)((DefaultMutableTreeNode)node.getParent()).getUserObject(); } else if (userObject instanceof AntBuildFileNodeDescriptor){ buildFileNodeDescriptor = (AntBuildFileNodeDescriptor)userObject; } else { buildFileNodeDescriptor = null; } if (buildFileNodeDescriptor == null || buildFileNodeDescriptor.getBuildFile() != buildFile) { return false; } } return true; }
public void actionPerformed(AnActionEvent e) { final AntBuildFile buildFile = getCurrentBuildFile(); final String[] targets = getTargetNamesFromPaths(myTree.getSelectionPaths()); final ExecuteCompositeTargetEvent event = new ExecuteCompositeTargetEvent(targets); final SaveMetaTargetDialog dialog = new SaveMetaTargetDialog(myTree, event, AntConfigurationBase.getInstance(myProject), buildFile); dialog.setTitle(e.getPresentation().getText()); dialog.show(); if (dialog.isOK()) { myBuilder.queueUpdate(); myTree.repaint(); } }