This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 110465
Collapse All | Expand All

(-)a/o.apache.tools.ant.module/nbproject/project.xml (+1 lines)
Lines 97-102 Link Here
97
                    <compile-dependency/>
97
                    <compile-dependency/>
98
                    <run-dependency>
98
                    <run-dependency>
99
                        <release-version>1</release-version>
99
                        <release-version>1</release-version>
100
                        <specification-version>1.32</specification-version>
100
                    </run-dependency>
101
                    </run-dependency>
101
                </dependency>
102
                </dependency>
102
                <dependency>
103
                <dependency>
(-)a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/resources/AntModuleLayer.xml (-18 lines)
Lines 43-66 Link Here
43
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
43
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
44
<filesystem>
44
<filesystem>
45
45
46
    <folder name="Actions">
47
        <folder name="Build">
48
            <file name="org-apache-tools-ant-module-run-RunLastTargetAction.instance"/>
49
            <file name="org-apache-tools-ant-module-run-StopBuildingAction.instance"/>
50
        </folder>
51
    </folder>
52
53
    <folder name="Menu">
54
        <folder name="BuildProject">
55
            <file name="org-apache-tools-ant-module-run-RunLastTargetAction.shadow">
56
                <attr name="originalFile" stringvalue="Actions/Build/org-apache-tools-ant-module-run-RunLastTargetAction.instance"/>
57
                <attr name="position" intvalue="1000"/>
58
            </file>
59
            <file name="org-apache-tools-ant-module-run-StopBuildingAction.instance">
60
                <attr name="position" intvalue="1100"/>
61
            </file>
62
        </folder>
63
    </folder>
64
46
65
    <folder name="Templates">
47
    <folder name="Templates">
66
 
48
 
(-)a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/Bundle.properties (-16 / +1 lines)
Lines 77-97 Link Here
77
# {0} - display name of process, e.g. "myapp (jar)"
77
# {0} - display name of process, e.g. "myapp (jar)"
78
FMT_target_stopped_status=Build of {0} stopped.
78
FMT_target_stopped_status=Build of {0} stopped.
79
79
80
# StopBuildingAction
81
LBL_stop_building=&Stop Build/Run
82
# {0} - display name of previous build
83
LBL_stop_building_one=&Stop Build/Run: {0}
84
LBL_stop_building_many=&Stop Build/Run...
85
80
86
# StopBuildingAlert
87
LBL_SBA_intro=Multiple build/run processes are running simultaneously.
88
LBL_SBA_select=&Select the processes to stop:
89
TITLE_SBA=Stop Build/Run
90
LBL_SBA_stop=Stop
91
81
92
# RunLastTargetAction
82
93
LBL_RunLastTargetAction_general=Re&peat Build/Run
94
# {0} - display name of previous build
95
TIP_RunLastTargetAction_specific=Repeat Build/Run: {0}
96
# {0} - display name of previous build
97
LBL_RunLastTargetAction_specific=Re&peat Build/Run: {0}
(-)a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/LastTargetExecuted.java (-41 / +57 lines)
Lines 44-136 Link Here
44
import java.io.File;
44
import java.io.File;
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.util.Map;
46
import java.util.Map;
47
import javax.swing.event.ChangeListener;
47
import org.apache.tools.ant.module.AntModule;
48
import org.apache.tools.ant.module.api.AntProjectCookie;
48
import org.apache.tools.ant.module.api.AntProjectCookie;
49
import org.apache.tools.ant.module.api.support.AntScriptUtils;
49
import org.apache.tools.ant.module.api.support.AntScriptUtils;
50
import org.apache.tools.ant.module.bridge.AntBridge;
51
import org.netbeans.spi.project.ui.support.BuildExecutionSupport;
50
import org.openide.execution.ExecutorTask;
52
import org.openide.execution.ExecutorTask;
51
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.FileUtil;
54
import org.openide.filesystems.FileUtil;
53
import org.openide.util.ChangeSupport;
55
import org.openide.util.ChangeSupport;
56
import org.openide.util.RequestProcessor;
54
57
55
/**
58
/**
56
 * Records the last Ant target(s) that was executed.
59
 * Records the last Ant target(s) that was executed.
57
 * @author Jesse Glick
60
 * @author Jesse Glick
58
 */
61
 */
59
public class LastTargetExecuted {
62
public class LastTargetExecuted implements BuildExecutionSupport.Item {
60
    
63
    
61
    private LastTargetExecuted() {}
64
    private LastTargetExecuted() {}
62
    
65
    
63
    private static File buildScript;
66
    private File buildScript;
64
    //private static int verbosity;
67
    //private static int verbosity;
65
    private static String[] targets;
68
    private String[] targets;
66
    private static Map<String,String> properties;
69
    private Map<String,String> properties;
67
    private static String displayName;
70
    private String displayName;
71
    private Thread thread;
68
    
72
    
69
    /** Called from {@link TargetExecutor}. */
73
    /** Called from {@link TargetExecutor}. */
70
    static void record(File buildScript, String[] targets, Map<String,String> properties, String displayName) {
74
    static LastTargetExecuted record(File buildScript, String[] targets, Map<String,String> properties, String displayName, Thread thread) {
71
        LastTargetExecuted.buildScript = buildScript;
75
        LastTargetExecuted rec = new LastTargetExecuted();
76
        rec.buildScript = buildScript;
72
        //LastTargetExecuted.verbosity = verbosity;
77
        //LastTargetExecuted.verbosity = verbosity;
73
        LastTargetExecuted.targets = targets;
78
        rec.targets = targets;
74
        LastTargetExecuted.properties = properties;
79
        rec.properties = properties;
75
        LastTargetExecuted.displayName = displayName;
80
        rec.displayName = displayName;
76
        cs.fireChange();
81
        rec.thread = thread;
82
        BuildExecutionSupport.registerRunningItem(rec);
83
        return rec;
84
    }
85
86
    static void finish(LastTargetExecuted exc) {
87
        BuildExecutionSupport.registerFinishedItem(exc);
77
    }
88
    }
78
    
89
    
79
    /**
90
    /**
80
     * Get the last build script to be run.
91
     * Get the last build script to be run.
81
     * @return the last-run build script, or null if nothing has been run yet (or the build script disappeared etc.)
92
     * @return the last-run build script, or null if nothing has been run yet (or the build script disappeared etc.)
82
     */
93
     */
83
    public static AntProjectCookie getLastBuildScript() {
94
    public static AntProjectCookie getLastBuildScript(LastTargetExecuted ext) {
84
        if (buildScript != null && buildScript.isFile()) {
95
        if (ext.buildScript != null && ext.buildScript.isFile()) {
85
            FileObject fo = FileUtil.toFileObject(buildScript);
96
            FileObject fo = FileUtil.toFileObject(ext.buildScript);
86
            assert fo != null;
97
            assert fo != null;
87
            return AntScriptUtils.antProjectCookieFor(fo);
98
            return AntScriptUtils.antProjectCookieFor(fo);
88
        }
99
        }
89
        return null;
100
        return null;
90
    }
101
    }
91
    
102
    
92
    /**
103
93
     * Get the last target names to be run.
94
     * @return a list of one or more targets, or null for the default target
95
     */
96
    public static String[] getLastTargets() {
97
        return targets;
98
    }
99
    
100
    /**
101
     * Get a display name (as it would appear in the Output Window) for the last process.
102
     * @return a process display name, or null if nothing has been run yet
103
     */
104
    public static String getProcessDisplayName() {
105
        return displayName;
106
    }
107
    
108
    /**
104
    /**
109
     * Try to rerun the last task.
105
     * Try to rerun the last task.
110
     */
106
     */
111
    public static ExecutorTask rerun() throws IOException {
107
    public static ExecutorTask rerun(LastTargetExecuted exec) throws IOException {
112
        AntProjectCookie apc = getLastBuildScript();
108
        AntProjectCookie apc = getLastBuildScript(exec);
113
        if (apc == null) {
109
        if (apc == null) {
114
            // Can happen in case the build script was deleted (similar to #84874).
110
            // Can happen in case the build script was deleted (similar to #84874).
115
            // Also make sure to disable RunLastTargetAction.
111
            // Also make sure to disable RunLastTargetAction.
116
            cs.fireChange();
112
            cs.fireChange();
117
            return null;
113
            return null;
118
        }
114
        }
119
        TargetExecutor t = new TargetExecutor(apc, targets);
115
        TargetExecutor t = new TargetExecutor(apc, exec.targets);
120
        //t.setVerbosity(verbosity);
116
        //t.setVerbosity(verbosity);
121
        t.setProperties(properties);
117
        t.setProperties(exec.properties);
122
        t.setDisplayName(displayName); // #140999: do not recalculate
118
        t.setDisplayName(exec.displayName); // #140999: do not recalculate
123
        return t.execute();
119
        return t.execute();
124
    }
120
    }
125
    
121
    
126
    private static final ChangeSupport cs = new ChangeSupport(LastTargetExecuted.class);
122
    private static final ChangeSupport cs = new ChangeSupport(LastTargetExecuted.class);
127
    
123
    
128
    public static void addChangeListener(ChangeListener l) {
124
 
129
        cs.addChangeListener(l);
125
126
    public String getDisplayName() {
127
        return displayName;
130
    }
128
    }
131
    
129
132
    public static void removeChangeListener(ChangeListener l) {
130
    public void repeatExecution() {
133
        cs.removeChangeListener(l);
131
       RequestProcessor.getDefault().post(new Runnable() {
132
            public void run() {
133
                try {
134
                    rerun(LastTargetExecuted.this);
135
                } catch (IOException ioe) {
136
                    AntModule.err.notify(ioe);
137
                }
138
            }
139
        });
140
    }
141
142
    public boolean isRunning() {
143
        return thread != null ? thread.isAlive() : false;
144
    }
145
146
    public void stopRunning() {
147
        if (thread != null) {
148
            AntBridge.getInterface().stop(thread);
149
        }
134
    }
150
    }
135
    
151
    
136
}
152
}
(-)a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/RunLastTargetAction.java (-140 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.apache.tools.ant.module.run;
43
44
import java.awt.Component;
45
import java.awt.event.ActionEvent;
46
import java.io.IOException;
47
import javax.swing.AbstractAction;
48
import javax.swing.Action;
49
import javax.swing.JButton;
50
import javax.swing.JComponent;
51
import javax.swing.JMenuItem;
52
import javax.swing.event.ChangeEvent;
53
import javax.swing.event.ChangeListener;
54
import org.apache.tools.ant.module.AntModule;
55
import org.openide.awt.Actions;
56
import org.openide.awt.DynamicMenuContent;
57
import org.openide.awt.Mnemonics;
58
import org.openide.util.NbBundle;
59
import org.openide.util.RequestProcessor;
60
import org.openide.util.WeakListeners;
61
import org.openide.util.actions.Presenter;
62
63
/**
64
 * An action to run the last Ant build.
65
 * @see "#47925"
66
 */
67
public final class RunLastTargetAction extends AbstractAction implements ChangeListener, Presenter.Menu, Presenter.Toolbar {
68
    
69
    public RunLastTargetAction() {
70
        super(NbBundle.getMessage(RunLastTargetAction.class, "LBL_RunLastTargetAction_general")/*,
71
                new ImageIcon(Utilities.loadImage("org/apache/tools/ant/module/resources/AntIcon.gif", true))*/);
72
        LastTargetExecuted.addChangeListener(WeakListeners.change(this, LastTargetExecuted.class));
73
    }
74
    
75
    @Override
76
    public boolean isEnabled() {
77
        return LastTargetExecuted.getLastBuildScript() != null;
78
    }
79
    
80
    @Override
81
    public Object getValue(String key) {
82
        if (key.equals(Action.SHORT_DESCRIPTION)) {
83
            String display = LastTargetExecuted.getProcessDisplayName();
84
            if (display != null) {
85
                return NbBundle.getMessage(RunLastTargetAction.class, "TIP_RunLastTargetAction_specific", display);
86
            } else {
87
                return null;
88
            }
89
        } else {
90
            return super.getValue(key);
91
        }
92
    }
93
    
94
    public void actionPerformed(ActionEvent e) {
95
        RequestProcessor.getDefault().post(new Runnable() {
96
            public void run() {
97
                try {
98
                    LastTargetExecuted.rerun();
99
                } catch (IOException ioe) {
100
                    AntModule.err.notify(ioe);
101
                }
102
            }
103
        });
104
    }
105
106
    public void stateChanged(ChangeEvent e) {
107
        firePropertyChange("enabled", null, Boolean.valueOf(isEnabled())); // NOI18N
108
        firePropertyChange(Action.SHORT_DESCRIPTION, null, null);
109
    }
110
111
    public JMenuItem getMenuPresenter() {
112
        class SpecialMenuItem extends JMenuItem implements DynamicMenuContent {
113
            public SpecialMenuItem() {
114
                super(RunLastTargetAction.this);
115
            }
116
            public JComponent[] getMenuPresenters() {
117
                String label;
118
                String display = LastTargetExecuted.getProcessDisplayName();
119
                if (display != null) {
120
                    label = NbBundle.getMessage(RunLastTargetAction.class, "LBL_RunLastTargetAction_specific", display);
121
                } else {
122
                    label = (String) getValue(Action.NAME);
123
                }
124
                Mnemonics.setLocalizedText(this, label);
125
                return new JComponent[] {this};
126
            }
127
            public JComponent[] synchMenuPresenters(JComponent[] items) {
128
                return getMenuPresenters();
129
            }
130
        }
131
        return new SpecialMenuItem();
132
    }
133
134
    public Component getToolbarPresenter() {
135
        JButton button = new JButton();
136
        Actions.connect(button, this);
137
        return button;
138
    }
139
140
}
(-)a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/StopBuildingAction.java (-180 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.apache.tools.ant.module.run;
43
44
import java.awt.EventQueue;
45
import java.util.HashMap;
46
import java.util.Map;
47
import java.util.WeakHashMap;
48
import javax.swing.JComponent;
49
import javax.swing.JMenuItem;
50
import org.openide.awt.DynamicMenuContent;
51
import org.openide.awt.Mnemonics;
52
import org.openide.util.HelpCtx;
53
import org.openide.util.NbBundle;
54
import org.openide.util.actions.CallableSystemAction;
55
import org.openide.util.actions.SystemAction;
56
57
/**
58
 * Action which stops the currently running Ant process.
59
 * If there is more than one, a dialog appears asking you to select one.
60
 * @author Jesse Glick
61
 * @see "issue #43143"
62
 */
63
public final class StopBuildingAction extends CallableSystemAction {
64
    
65
    /**
66
     * Map from active processing threads to their process display names.
67
     */
68
    private static final Map<Thread,String> activeProcesses = new WeakHashMap<Thread,String>();
69
    
70
    static void registerProcess(Thread t, String displayName) {
71
        synchronized (activeProcesses) {
72
            assert !activeProcesses.containsKey(t);
73
            activeProcesses.put(t, displayName);
74
        }
75
        EventQueue.invokeLater(new Runnable() {
76
            public void run() {
77
                SystemAction.get(StopBuildingAction.class).setEnabled(true);
78
            }
79
        });
80
    }
81
    
82
    static void unregisterProcess(Thread t) {
83
        final boolean enable;
84
        synchronized (activeProcesses) {
85
            assert activeProcesses.containsKey(t);
86
            activeProcesses.remove(t);
87
            enable = !activeProcesses.isEmpty();
88
        }
89
        EventQueue.invokeLater(new Runnable() {
90
            public void run() {
91
                SystemAction.get(StopBuildingAction.class).setEnabled(enable);
92
            }
93
        });
94
    }
95
    
96
    @Override
97
    public void performAction() {
98
        Thread[] toStop = null;
99
        synchronized (activeProcesses) {
100
            assert !activeProcesses.isEmpty();
101
            if (activeProcesses.size() == 1) {
102
                toStop = activeProcesses.keySet().toArray(new Thread[1]);
103
            }
104
        }
105
        if (toStop == null) {
106
            // More than one, need to select one.
107
            Map<Thread,String> activeProcessesClone;
108
            synchronized (activeProcesses) {
109
                activeProcessesClone = new HashMap<Thread,String>(activeProcesses);
110
            }
111
            toStop = StopBuildingAlert.selectProcessToKill(activeProcessesClone);
112
            synchronized (activeProcesses) {
113
                for (int i = 0; i < toStop.length; i++) {
114
                    if (!activeProcesses.containsKey(toStop[i])) {
115
                        // Oops, process ended while it was being selected... just ignore.
116
                        toStop[i] = null;
117
                    }
118
                }
119
            }
120
        }
121
        for (Thread t : toStop) {
122
            if (t != null) {
123
                TargetExecutor.stopProcess(t);
124
            }
125
        }
126
    }
127
128
    @Override
129
    public String getName() {
130
        return NbBundle.getMessage(StopBuildingAction.class, "LBL_stop_building");
131
    }
132
133
    @Override
134
    public HelpCtx getHelpCtx() {
135
        return null;
136
    }
137
138
    @Override
139
    protected void initialize() {
140
        super.initialize();
141
        setEnabled(false); // no processes initially
142
    }
143
144
    @Override
145
    protected boolean asynchronous() {
146
        return false;
147
    }
148
    
149
    @Override
150
    public JMenuItem getMenuPresenter() {
151
        class SpecialMenuItem extends JMenuItem implements DynamicMenuContent {
152
            public SpecialMenuItem() {
153
                super(StopBuildingAction.this);
154
            }
155
            public JComponent[] getMenuPresenters() {
156
                String label;
157
                synchronized (activeProcesses) {
158
                    switch (activeProcesses.size()) {
159
                        case 0:
160
                            label = NbBundle.getMessage(StopBuildingAction.class, "LBL_stop_building");
161
                            break;
162
                        case 1:
163
                            label = NbBundle.getMessage(StopBuildingAction.class, "LBL_stop_building_one",
164
                                    activeProcesses.values().iterator().next());
165
                            break;
166
                        default:
167
                            label = NbBundle.getMessage(StopBuildingAction.class, "LBL_stop_building_many");
168
                    }
169
                }
170
                Mnemonics.setLocalizedText(this, label);
171
                return new JComponent[] {this};
172
            }
173
            public JComponent[] synchMenuPresenters(JComponent[] items) {
174
                return getMenuPresenters();
175
            }
176
        }
177
        return new SpecialMenuItem();
178
    }
179
    
180
}
(-)a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/StopBuildingAlert.form (-80 lines)
Removed Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.3" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
6
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="2"/>
7
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
8
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="1"/>
9
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
10
  </AuxValues>
11
12
  <Layout>
13
    <DimensionLayout dim="0">
14
      <Group type="103" groupAlignment="0" attributes="0">
15
          <Group type="102" alignment="0" attributes="0">
16
              <EmptySpace max="-2" attributes="0"/>
17
              <Group type="103" groupAlignment="0" max="-2" attributes="0">
18
                  <Group type="102" alignment="0" attributes="1">
19
                      <Component id="buildsScrollPane" pref="376" max="32767" attributes="1"/>
20
                      <EmptySpace max="-2" attributes="0"/>
21
                  </Group>
22
                  <Group type="102" alignment="0" attributes="0">
23
                      <Group type="103" groupAlignment="0" max="-2" attributes="0">
24
                          <Component id="buildsLabel" alignment="0" min="-2" max="-2" attributes="0"/>
25
                          <Component id="introLabel" alignment="0" max="32767" attributes="0"/>
26
                      </Group>
27
                      <EmptySpace min="-2" pref="28" max="-2" attributes="0"/>
28
                  </Group>
29
              </Group>
30
          </Group>
31
      </Group>
32
    </DimensionLayout>
33
    <DimensionLayout dim="1">
34
      <Group type="103" groupAlignment="0" attributes="0">
35
          <Group type="102" attributes="0">
36
              <EmptySpace max="-2" attributes="0"/>
37
              <Component id="introLabel" min="-2" max="-2" attributes="0"/>
38
              <EmptySpace max="-2" attributes="0"/>
39
              <Component id="buildsLabel" min="-2" max="-2" attributes="0"/>
40
              <EmptySpace max="-2" attributes="0"/>
41
              <Component id="buildsScrollPane" pref="234" max="32767" attributes="0"/>
42
              <EmptySpace max="-2" attributes="0"/>
43
          </Group>
44
      </Group>
45
    </DimensionLayout>
46
  </Layout>
47
  <SubComponents>
48
    <Component class="javax.swing.JLabel" name="introLabel">
49
      <Properties>
50
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
51
          <ResourceString bundle="org/apache/tools/ant/module/run/Bundle.properties" key="LBL_SBA_intro" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
52
        </Property>
53
      </Properties>
54
      <AuxValues>
55
        <AuxValue name="generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
56
      </AuxValues>
57
    </Component>
58
    <Component class="javax.swing.JLabel" name="buildsLabel">
59
      <Properties>
60
        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
61
          <ComponentRef name="buildsList"/>
62
        </Property>
63
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
64
          <ResourceString bundle="org/apache/tools/ant/module/run/Bundle.properties" key="LBL_SBA_select" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
65
        </Property>
66
      </Properties>
67
      <AuxValues>
68
        <AuxValue name="generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
69
      </AuxValues>
70
    </Component>
71
    <Container class="javax.swing.JScrollPane" name="buildsScrollPane">
72
73
      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
74
      <SubComponents>
75
        <Component class="javax.swing.JList" name="buildsList">
76
        </Component>
77
      </SubComponents>
78
    </Container>
79
  </SubComponents>
80
</Form>
(-)a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/StopBuildingAlert.java (-199 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.apache.tools.ant.module.run;
43
44
import java.awt.Component;
45
import java.text.Collator;
46
import java.util.Comparator;
47
import java.util.Map;
48
import java.util.SortedSet;
49
import java.util.TreeSet;
50
import javax.swing.DefaultListCellRenderer;
51
import javax.swing.DefaultListModel;
52
import javax.swing.JButton;
53
import javax.swing.JList;
54
import javax.swing.JPanel;
55
import javax.swing.event.ListSelectionEvent;
56
import javax.swing.event.ListSelectionListener;
57
import org.openide.DialogDescriptor;
58
import org.openide.DialogDisplayer;
59
import org.openide.NotifyDescriptor;
60
import org.openide.util.NbBundle;
61
62
/**
63
 * Displays an alert asking user to pick a running build to stop.
64
 * @author Jesse Glick
65
 */
66
final class StopBuildingAlert extends JPanel {
67
    
68
    /**
69
     * Select one or more processes to kill among several choices.
70
     * @param processesWithDisplayNames a list of possible threads to kill, mapped to display names
71
     * @return the selection(s) (or empty if cancelled)
72
     */
73
    public static Thread[] selectProcessToKill(final Map<Thread,String> processesWithDisplayNames) {
74
        StopBuildingAlert alert = new StopBuildingAlert(processesWithDisplayNames);
75
        final JList list = alert.buildsList;
76
        // Add all threads, sorted by display name.
77
        DefaultListModel model = new DefaultListModel();
78
        Comparator<Thread> comp = new Comparator<Thread>() {
79
            private final Collator coll = Collator.getInstance();
80
            public int compare(Thread t1, Thread t2) {
81
                String n1 = processesWithDisplayNames.get(t1);
82
                String n2 = processesWithDisplayNames.get(t2);
83
                int r = coll.compare(n1, n2);
84
                if (r != 0) {
85
                    return r;
86
                } else {
87
                    // Arbitrary. XXX Note that there is no way to predict which is
88
                    // which if you have more than one build running. Ideally it
89
                    // would be subsorted by creation time, probably.
90
                    return System.identityHashCode(t1) - System.identityHashCode(t2);
91
                }
92
            }
93
        };
94
        SortedSet<Thread> threads = new TreeSet<Thread>(comp);
95
        threads.addAll(processesWithDisplayNames.keySet());
96
        for (Thread t : threads) {
97
            model.addElement(t);
98
        }
99
        list.setModel(model);
100
        list.setSelectedIndex(0);
101
        // Make a dialog with buttons "Stop Building" and "Cancel".
102
        DialogDescriptor dd = new DialogDescriptor(alert, NbBundle.getMessage(StopBuildingAlert.class, "TITLE_SBA"));
103
        dd.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
104
        final JButton stopButton = new JButton(NbBundle.getMessage(StopBuildingAlert.class, "LBL_SBA_stop"));
105
        list.addListSelectionListener(new ListSelectionListener() {
106
            public void valueChanged(ListSelectionEvent e) {
107
                stopButton.setEnabled(list.getSelectedValue() != null);
108
            }
109
        });
110
        dd.setOptions(new Object[] {stopButton, DialogDescriptor.CANCEL_OPTION});
111
        DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
112
        if (dd.getValue() == stopButton) {
113
            Object[] _selectedThreads = list.getSelectedValues();
114
            Thread[] selectedThreads = new Thread[_selectedThreads.length];
115
            for (int i = 0; i < _selectedThreads.length; i++) {
116
                selectedThreads[i] = (Thread) _selectedThreads[i];
117
            }
118
            return selectedThreads;
119
        } else {
120
            return new Thread[0];
121
        }
122
    }
123
    
124
    private final Map<Thread,String> processesWithDisplayNames;
125
    
126
    private StopBuildingAlert(Map<Thread,String> processesWithDisplayNames) {
127
        this.processesWithDisplayNames = processesWithDisplayNames;
128
        initComponents();
129
        buildsList.setCellRenderer(new ProcessCellRenderer());
130
    }
131
    
132
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
133
    private void initComponents() {
134
        java.awt.GridBagConstraints gridBagConstraints;
135
136
        introLabel = new javax.swing.JLabel();
137
        buildsLabel = new javax.swing.JLabel();
138
        buildsScrollPane = new javax.swing.JScrollPane();
139
        buildsList = new javax.swing.JList();
140
141
        org.openide.awt.Mnemonics.setLocalizedText(introLabel, org.openide.util.NbBundle.getMessage(StopBuildingAlert.class, "LBL_SBA_intro"));
142
143
        buildsLabel.setLabelFor(buildsList);
144
        org.openide.awt.Mnemonics.setLocalizedText(buildsLabel, org.openide.util.NbBundle.getMessage(StopBuildingAlert.class, "LBL_SBA_select"));
145
146
        buildsScrollPane.setViewportView(buildsList);
147
148
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
149
        this.setLayout(layout);
150
        layout.setHorizontalGroup(
151
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
152
            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
153
                .addContainerGap()
154
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
155
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
156
                        .add(buildsScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
157
                        .addContainerGap())
158
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
159
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
160
                            .add(buildsLabel)
161
                            .add(introLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
162
                        .add(28, 28, 28))))
163
        );
164
        layout.setVerticalGroup(
165
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
166
            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
167
                .addContainerGap()
168
                .add(introLabel)
169
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
170
                .add(buildsLabel)
171
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
172
                .add(buildsScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
173
                .addContainerGap())
174
        );
175
    }
176
    // </editor-fold>//GEN-END:initComponents
177
    
178
    
179
    // Variables declaration - do not modify//GEN-BEGIN:variables
180
    public javax.swing.JLabel buildsLabel;
181
    public javax.swing.JList buildsList;
182
    public javax.swing.JScrollPane buildsScrollPane;
183
    public javax.swing.JLabel introLabel;
184
    // End of variables declaration//GEN-END:variables
185
186
    private final class ProcessCellRenderer extends DefaultListCellRenderer/*<Thread>*/ {
187
        
188
        public ProcessCellRenderer() {}
189
190
        @Override
191
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
192
            Thread t = (Thread) value;
193
            String displayName = processesWithDisplayNames.get(t);
194
            return super.getListCellRendererComponent(list, displayName, index, isSelected, cellHasFocus);
195
        }
196
        
197
    }
198
    
199
}
(-)a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java (-10 / +8 lines)
Lines 175-181 Link Here
175
175
176
    private static final class StopAction extends AbstractAction {
176
    private static final class StopAction extends AbstractAction {
177
177
178
        public Thread t;
178
        public LastTargetExecuted t;
179
179
180
        public StopAction() {
180
        public StopAction() {
181
            setEnabledEQ(this, false); // initially, until ready
181
            setEnabledEQ(this, false); // initially, until ready
Lines 195-201 Link Here
195
        public void actionPerformed(ActionEvent e) {
195
        public void actionPerformed(ActionEvent e) {
196
            setEnabled(false); // discourage repeated clicking
196
            setEnabled(false); // discourage repeated clicking
197
            if (t != null) { // #84688
197
            if (t != null) { // #84688
198
                stopProcess(t);
198
                t.stopRunning();
199
            }
199
            }
200
        }
200
        }
201
201
Lines 394-400 Link Here
394
    /** Call execute(), not this method directly!
394
    /** Call execute(), not this method directly!
395
     */
395
     */
396
    synchronized public void run () {
396
    synchronized public void run () {
397
        final Thread[] thisProcess = new Thread[1];
397
        final LastTargetExecuted[] thisExec = new LastTargetExecuted[1];
398
        final StopAction sa = stopActions.get(io);
398
        final StopAction sa = stopActions.get(io);
399
        assert sa != null;
399
        assert sa != null;
400
        RerunAction ra = rerunActions.get(io);
400
        RerunAction ra = rerunActions.get(io);
Lines 429-438 Link Here
429
        }
429
        }
430
430
431
        // #139185: do not record verbosity level; always pick it up from Ant Settings.
431
        // #139185: do not record verbosity level; always pick it up from Ant Settings.
432
        LastTargetExecuted.record(buildFile, /*verbosity,*/
432
        thisExec[0] = LastTargetExecuted.record(buildFile, /*verbosity,*/
433
                targetNames != null ? targetNames.toArray(new String[targetNames.size()]) : null,
433
                targetNames != null ? targetNames.toArray(new String[targetNames.size()]) : null,
434
                properties,
434
                properties,
435
                suggestedDisplayName != null ? suggestedDisplayName : getProcessDisplayName(pcookie, targetNames));
435
                suggestedDisplayName != null ? suggestedDisplayName : getProcessDisplayName(pcookie, targetNames), Thread.currentThread());
436
        sa.t = thisExec[0];
436
        
437
        
437
        // Don't hog the CPU, the build might take a while:
438
        // Don't hog the CPU, the build might take a while:
438
        Thread.currentThread().setPriority((Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) / 2);
439
        Thread.currentThread().setPriority((Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) / 2);
Lines 478-486 Link Here
478
            }
479
            }
479
        }
480
        }
480
        
481
        
481
        thisProcess[0] = Thread.currentThread();
482
        StopBuildingAction.registerProcess(thisProcess[0], displayName);
483
        sa.t = thisProcess[0];
484
	    // #58513, #87801: register a progress handle for the task too.
482
	    // #58513, #87801: register a progress handle for the task too.
485
        ProgressHandle handle = ProgressHandleFactory.createHandle(displayName, new Cancellable() {
483
        ProgressHandle handle = ProgressHandleFactory.createHandle(displayName, new Cancellable() {
486
            public boolean cancel() {
484
            public boolean cancel() {
Lines 504-511 Link Here
504
                    freeTabs.put(io, displayName);
502
                    freeTabs.put(io, displayName);
505
                }
503
                }
506
            }
504
            }
507
            if (thisProcess[0] != null) {
505
            if (thisExec[0] != null) {
508
                StopBuildingAction.unregisterProcess(thisProcess[0]);
506
                LastTargetExecuted.finish(thisExec[0]);
509
            }
507
            }
510
            sa.t = null;
508
            sa.t = null;
511
            setEnabledEQ(sa, false);
509
            setEnabledEQ(sa, false);

Return to bug 110465