@Nullable @Override public ExecutionResult execute(Executor executor, @NotNull ProgramRunner runner) throws ExecutionException { RunProfile profile = myEnvironment.getRunProfile(); if (profile instanceof AntRunConfiguration) { AntRunConfiguration antRunConfiguration = (AntRunConfiguration)profile; AntBuildTarget target = antRunConfiguration.getTarget(); if (target == null) return null; ProcessHandler processHandler = ExecutionHandler .executeRunConfiguration(antRunConfiguration, myEnvironment.getDataContext(), new ArrayList<BuildFileProperty>(), new AntBuildListener() { @Override public void buildFinished(int state, int errorCount) { } }); if (processHandler == null) return null; return new DefaultExecutionResult(null, processHandler); } return null; }
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 boolean configureTask(RunConfiguration runConfiguration, AntBeforeRunTask task) { AntBuildTarget buildTarget = findTargetToExecute(task); final TargetChooserDialog dlg = new TargetChooserDialog(myProject, buildTarget); if (dlg.showAndGet()) { task.setTargetName(null); task.setAntFileUrl(null); buildTarget = dlg.getSelectedTarget(); if (buildTarget != null) { final VirtualFile vFile = buildTarget.getModel().getBuildFile().getVirtualFile(); if (vFile != null) { task.setAntFileUrl(vFile.getUrl()); task.setTargetName(buildTarget.getName()); } } return true; } return false; }
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); } } }
public boolean configureTask(RunConfiguration runConfiguration, AntBeforeRunTask task) { AntBuildTarget buildTarget = findTargetToExecute(task); final TargetChooserDialog dlg = new TargetChooserDialog(myProject, buildTarget); dlg.show(); if (dlg.isOK()) { task.setTargetName(null); task.setAntFileUrl(null); buildTarget = dlg.getSelectedTarget(); if (buildTarget != null) { final VirtualFile vFile = buildTarget.getModel().getBuildFile().getVirtualFile(); if (vFile != null) { task.setAntFileUrl(vFile.getUrl()); task.setTargetName(buildTarget.getName()); } } return true; } return false; }
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); } } }
private static String[] getTargetNamesFromPaths(TreePath[] paths) { final List<String> targets = new ArrayList<String>(); for (final TreePath path : paths) { final Object userObject = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject(); if (!(userObject instanceof AntTargetNodeDescriptor)) { continue; } final AntBuildTarget target = ((AntTargetNodeDescriptor)userObject).getTarget(); if (target instanceof MetaTarget) { ContainerUtil.addAll(targets, ((MetaTarget)target).getTargetNames()); } else { targets.add(target.getName()); } } return ArrayUtil.toStringArray(targets); }
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); } }
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 boolean acceptSettings(AntBuildTarget target) { VirtualFile virtualFile = target.getModel().getBuildFile().getVirtualFile(); if (virtualFile == null) return false; mySettings.myFileUrl = virtualFile.getUrl(); mySettings.myTargetName = target.getName(); return true; }
public boolean isRunningTarget(AntBuildTarget target) { final VirtualFile vFile = target.getModel().getBuildFile().getVirtualFile(); if (vFile == null) { return false; } if (myAntFileUrl == null || !FileUtil.pathsEqual(myAntFileUrl, vFile.getUrl())) { return false; } return Comparing.equal(myTargetName, target.getName()); }
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 boolean executeTask(DataContext context, RunConfiguration configuration, ExecutionEnvironment env, AntBeforeRunTask task) { final AntBuildTarget target = findTargetToExecute(task); if (target != null) { return AntConfigurationImpl.executeTargetSynchronously(context, target); } return true; }
public TargetChooserDialog(final Project project, final AntBuildTarget selectedTarget) { super(project, false); myProject = project; mySelectedTarget = selectedTarget; setTitle(AntBundle.message("ant.target.choser.title")); init(); }
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; }
@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; }
private static AntBuildTarget[] getTargetObjectsFromPaths(TreePath[] paths) { final List<AntBuildTargetBase> targets = new ArrayList<AntBuildTargetBase>(); for (final TreePath path : paths) { final Object userObject = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject(); if (!(userObject instanceof AntTargetNodeDescriptor)) { continue; } final AntBuildTargetBase target = ((AntTargetNodeDescriptor)userObject).getTarget(); targets.add(target); } return targets.toArray(new AntBuildTargetBase[targets.size()]); }
private void doAction() { final TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) { return; } try { // try to remove build file if (paths.length == 1) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)paths[0].getLastPathComponent(); if (node.getUserObject() instanceof AntBuildFileNodeDescriptor) { final AntBuildFileNodeDescriptor descriptor = (AntBuildFileNodeDescriptor)node.getUserObject(); if (descriptor.getBuildFile().equals(getCurrentBuildFile())) { removeBuildFile(); return; } } } // try to remove meta targets final AntBuildTarget[] targets = getTargetObjectsFromPaths(paths); final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(myProject); for (final AntBuildTarget buildTarget : targets) { if (buildTarget instanceof MetaTarget) { for (final ExecutionEvent event : antConfiguration.getEventsForTarget(buildTarget)) { if (event instanceof ExecuteCompositeTargetEvent) { antConfiguration.clearTargetForEvent(event); } } } } } finally { myBuilder.queueUpdate(); myTree.repaint(); } }
@Override public boolean isTargetVisible(final AntBuildTarget target) { final TargetFilter filter = findFilter(target.getName()); if(filter == null) { return target.isDefault() || target.getNotEmptyDescription() != null; } return filter.isVisible(); }
public AntExecuteBeforeRunDialog(final Project project, final AntBuildTarget target) { super(project); myTarget = target; init(); }
@Override public String suggestedName() { AntBuildTarget target = getTarget(); return target != null ? target.getDisplayName() : ""; }
public AntBuildTarget getTarget() { return GlobalAntConfiguration.getInstance().findTarget(getProject(), mySettings.myFileUrl, mySettings.myTargetName); }
public void updateDescription(AntBuildTarget target) { if (target == null) return; myDescription = target.getNotEmptyDescription(); }
public static TargetFilter fromTarget(AntBuildTarget target) { TargetFilter filter = new TargetFilter(target.getName(), target.isDefault()); filter.myDescription = target.getNotEmptyDescription(); filter.myVisible = (filter.myDescription != null); return filter; }
@Override public Icon getTaskIcon(AntBeforeRunTask task) { AntBuildTarget antTarget = findTargetToExecute(task); return antTarget instanceof MetaTarget ? AntIcons.MetaTarget : AntIcons.Target; }