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 252283
Collapse All | Expand All

(-)a/extexecution/apichanges.xml (+14 lines)
Lines 117-122 Link Here
117
    <changes>
117
    <changes>
118
118
119
        <change>
119
        <change>
120
            <api name="extexecution_api"/>
121
            <summary>Rerun action callback</summary>
122
            <version major="1" minor="46"/>
123
            <date day="14" month="5" year="2015"/>
124
            <author login="phejl"/>
125
            <compatibility addition="yes"/>
126
            <description>
127
                Allows the user of the API to register a callback to be invoked
128
                on rerun action.
129
            </description>
130
            <class package="org.netbeans.api.extexecution" name="ExecutionDescriptor"/>
131
            <issue number="252283"/>
132
        </change>
133
        <change>
120
            <summary>API split and deprecation</summary>
134
            <summary>API split and deprecation</summary>
121
            <version major="1" minor="44"/>
135
            <version major="1" minor="44"/>
122
            <date day="1" month="6" year="2014"/>
136
            <date day="1" month="6" year="2014"/>
(-)a/extexecution/manifest.mf (-1 / +1 lines)
Lines 2-7 Link Here
2
AutoUpdate-Show-In-Client: false
2
AutoUpdate-Show-In-Client: false
3
OpenIDE-Module: org.netbeans.modules.extexecution/2
3
OpenIDE-Module: org.netbeans.modules.extexecution/2
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/extexecution/resources/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/extexecution/resources/Bundle.properties
5
OpenIDE-Module-Specification-Version: 1.45
5
OpenIDE-Module-Specification-Version: 1.46
6
OpenIDE-Module-Recommends: org.netbeans.spi.extexecution.open.OptionOpenHandler, org.netbeans.spi.extexecution.open.FileOpenHandler, org.netbeans.spi.extexecution.open.HttpOpenHandler
6
OpenIDE-Module-Recommends: org.netbeans.spi.extexecution.open.OptionOpenHandler, org.netbeans.spi.extexecution.open.FileOpenHandler, org.netbeans.spi.extexecution.open.HttpOpenHandler
7
7
(-)a/extexecution/src/org/netbeans/api/extexecution/ExecutionDescriptor.java (+54 lines)
Lines 43-48 Link Here
43
package org.netbeans.api.extexecution;
43
package org.netbeans.api.extexecution;
44
44
45
import java.nio.charset.Charset;
45
import java.nio.charset.Charset;
46
import java.util.concurrent.Future;
46
import java.util.logging.Level;
47
import java.util.logging.Level;
47
import java.util.logging.Logger;
48
import java.util.logging.Logger;
48
import javax.swing.event.ChangeListener;
49
import javax.swing.event.ChangeListener;
Lines 110-115 Link Here
110
111
111
    private final RerunCondition rerunCondition;
112
    private final RerunCondition rerunCondition;
112
113
114
    private final RerunCallback rerunCallback;
115
113
    private final String optionsPath;
116
    private final String optionsPath;
114
117
115
    private final Charset charset;
118
    private final Charset charset;
Lines 141-146 Link Here
141
        this.errProcessorFactory2 = data.errProcessorFactory2;
144
        this.errProcessorFactory2 = data.errProcessorFactory2;
142
        this.inputOutput = data.inputOutput;
145
        this.inputOutput = data.inputOutput;
143
        this.rerunCondition = data.rerunCondition;
146
        this.rerunCondition = data.rerunCondition;
147
        this.rerunCallback = data.rerunCallback;
144
        this.optionsPath = data.optionsPath;
148
        this.optionsPath = data.optionsPath;
145
        this.charset = data.charset;
149
        this.charset = data.charset;
146
        this.noReset = data.noReset;
150
        this.noReset = data.noReset;
Lines 661-666 Link Here
661
     *
665
     *
662
     * @param rerunCondition rerun condition, <code>null</code> allowed
666
     * @param rerunCondition rerun condition, <code>null</code> allowed
663
     * @return new descriptor with configured rerun condition
667
     * @return new descriptor with configured rerun condition
668
     * @see #rerunCallback(org.netbeans.api.extexecution.ExecutionDescriptor.RerunCallback)
664
     */
669
     */
665
    @NonNull
670
    @NonNull
666
    @CheckReturnValue
671
    @CheckReturnValue
Lines 674-679 Link Here
674
    }
679
    }
675
680
676
    /**
681
    /**
682
     * Returns a descriptor with configured rerun callback. The callback
683
     * is invoked when the execution is triggered by the rerun action.
684
     * <p>
685
     * The default (not configured) value is <code>null</code>.
686
     * <p>
687
     * All other properties of the returned descriptor are inherited from
688
     * <code>this</code>.
689
     *
690
     * @param rerunCallback rerun callback, <code>null</code> allowed
691
     * @return new descriptor with configured rerun callback
692
     * @see #rerunCondition(org.netbeans.api.extexecution.ExecutionDescriptor.RerunCondition) 
693
     * @since 1.46
694
     */
695
    @NonNull
696
    @CheckReturnValue
697
    public ExecutionDescriptor rerunCallback(@NullAllowed ExecutionDescriptor.RerunCallback rerunCallback) {
698
        DescriptorData data = new DescriptorData(this);
699
        return new ExecutionDescriptor(data.rerunCallback(rerunCallback));
700
    }
701
702
    RerunCallback getRerunCallback() {
703
        return rerunCallback;
704
    }
705
706
    /**
677
     * Returns a descriptor with configured options path. If configured
707
     * Returns a descriptor with configured options path. If configured
678
     * value is not <code>null</code> the {@link ExecutionService} will
708
     * value is not <code>null</code> the {@link ExecutionService} will
679
     * display the button in the output tab displaying the proper options
709
     * display the button in the output tab displaying the proper options
Lines 762-767 Link Here
762
    }
792
    }
763
793
764
    /**
794
    /**
795
     * Provides a callback to be invoked when rerun action is invoked.
796
     *
797
     * @since 1.46
798
     */
799
    public interface RerunCallback {
800
801
        /**
802
         * Called when rerun action is invoked.
803
         *
804
         * @param task the task created by the rerun action
805
         */
806
        void performed(Future<Integer> task);
807
808
    }
809
810
    /**
765
     * Factory creating the input processor.
811
     * Factory creating the input processor.
766
     * @deprecated use {@link InputProcessorFactory2}
812
     * @deprecated use {@link InputProcessorFactory2}
767
     */
813
     */
Lines 851-856 Link Here
851
897
852
        private ExecutionDescriptor.RerunCondition rerunCondition;
898
        private ExecutionDescriptor.RerunCondition rerunCondition;
853
899
900
        private ExecutionDescriptor.RerunCallback rerunCallback;
901
854
        private String optionsPath;
902
        private String optionsPath;
855
903
856
        private Charset charset;
904
        private Charset charset;
Lines 876-881 Link Here
876
            this.errProcessorFactory = descriptor.errProcessorFactory;
924
            this.errProcessorFactory = descriptor.errProcessorFactory;
877
            this.inputOutput = descriptor.inputOutput;
925
            this.inputOutput = descriptor.inputOutput;
878
            this.rerunCondition = descriptor.rerunCondition;
926
            this.rerunCondition = descriptor.rerunCondition;
927
            this.rerunCallback = descriptor.rerunCallback;
879
            this.optionsPath = descriptor.optionsPath;
928
            this.optionsPath = descriptor.optionsPath;
880
            this.charset = descriptor.charset;
929
            this.charset = descriptor.charset;
881
            this.noReset = descriptor.noReset;
930
            this.noReset = descriptor.noReset;
Lines 976-981 Link Here
976
            return this;
1025
            return this;
977
        }
1026
        }
978
1027
1028
        public DescriptorData rerunCallback(ExecutionDescriptor.RerunCallback rerunCallback) {
1029
            this.rerunCallback = rerunCallback;
1030
            return this;
1031
        }
1032
979
        public DescriptorData optionsPath(String optionsPath) {
1033
        public DescriptorData optionsPath(String optionsPath) {
980
            this.optionsPath = optionsPath;
1034
            this.optionsPath = optionsPath;
981
            return this;
1035
            return this;
(-)a/extexecution/src/org/netbeans/api/extexecution/ExecutionService.java (+1 lines)
Lines 314-319 Link Here
314
                    synchronized (workingRerunAction) {
314
                    synchronized (workingRerunAction) {
315
                        workingRerunAction.setExecutionService(ExecutionService.this);
315
                        workingRerunAction.setExecutionService(ExecutionService.this);
316
                        workingRerunAction.setRerunCondition(descriptor.getRerunCondition());
316
                        workingRerunAction.setRerunCondition(descriptor.getRerunCondition());
317
                        workingRerunAction.setRerunCallback(descriptor.getRerunCallback());
317
                        workingRerunAction.setEnabled(false);
318
                        workingRerunAction.setEnabled(false);
318
                    }
319
                    }
319
                }
320
                }
(-)a/extexecution/src/org/netbeans/modules/extexecution/RerunAction.java (-2 / +15 lines)
Lines 48-57 Link Here
48
import java.util.concurrent.Future;
48
import java.util.concurrent.Future;
49
import javax.swing.AbstractAction;
49
import javax.swing.AbstractAction;
50
import javax.swing.Action;
50
import javax.swing.Action;
51
import javax.swing.ImageIcon;
52
51
53
import javax.swing.event.ChangeEvent;
52
import javax.swing.event.ChangeEvent;
54
import javax.swing.event.ChangeListener;
53
import javax.swing.event.ChangeListener;
54
import org.netbeans.api.extexecution.ExecutionDescriptor.RerunCallback;
55
import org.netbeans.api.extexecution.ExecutionDescriptor.RerunCondition;
55
import org.netbeans.api.extexecution.ExecutionDescriptor.RerunCondition;
56
import org.netbeans.api.extexecution.ExecutionService;
56
import org.netbeans.api.extexecution.ExecutionService;
57
import org.openide.util.ImageUtilities;
57
import org.openide.util.ImageUtilities;
Lines 74-79 Link Here
74
74
75
    private RerunCondition condition;
75
    private RerunCondition condition;
76
76
77
    private RerunCallback callback;
78
77
    private ChangeListener listener;
79
    private ChangeListener listener;
78
80
79
    public RerunAction() {
81
    public RerunAction() {
Lines 108-125 Link Here
108
        stateChanged(null);
110
        stateChanged(null);
109
    }
111
    }
110
112
113
    public void setRerunCallback(RerunCallback callback) {
114
        synchronized (this) {
115
            this.callback = callback;
116
        }
117
    }
118
111
    public void actionPerformed(ActionEvent e) {
119
    public void actionPerformed(ActionEvent e) {
112
        setEnabled(false); // discourage repeated clicking
120
        setEnabled(false); // discourage repeated clicking
113
121
114
        ExecutionService actionService;
122
        ExecutionService actionService;
123
        RerunCallback actionCallback;
115
        InputOutput required;
124
        InputOutput required;
116
        synchronized (this) {
125
        synchronized (this) {
117
            actionService = service;
126
            actionService = service;
127
            actionCallback = callback;
118
            required = parent;
128
            required = parent;
119
        }
129
        }
120
130
121
        if (actionService != null) {
131
        if (actionService != null) {
122
            Accessor.getDefault().run(actionService, required);
132
            Future<Integer> task = Accessor.getDefault().run(actionService, required);
133
            if (actionCallback != null) {
134
                actionCallback.performed(task);
135
            }
123
        }
136
        }
124
    }
137
    }
125
138
(-)a/extexecution/test/unit/src/org/netbeans/modules/extexecution/RerunActionTest.java (+86 lines)
Lines 42-50 Link Here
42
42
43
package org.netbeans.modules.extexecution;
43
package org.netbeans.modules.extexecution;
44
44
45
import java.io.ByteArrayInputStream;
46
import java.io.IOException;
47
import java.io.InputStream;
48
import java.io.OutputStream;
49
import java.util.concurrent.Callable;
50
import java.util.concurrent.CountDownLatch;
51
import java.util.concurrent.Future;
52
import java.util.concurrent.TimeUnit;
45
import javax.swing.event.ChangeListener;
53
import javax.swing.event.ChangeListener;
54
import org.netbeans.api.extexecution.ExecutionDescriptor;
46
import org.netbeans.junit.NbTestCase;
55
import org.netbeans.junit.NbTestCase;
56
import org.netbeans.api.extexecution.ExecutionDescriptor.RerunCallback;
47
import org.netbeans.api.extexecution.ExecutionDescriptor.RerunCondition;
57
import org.netbeans.api.extexecution.ExecutionDescriptor.RerunCondition;
58
import org.netbeans.api.extexecution.ExecutionService;
48
import org.openide.util.ChangeSupport;
59
import org.openide.util.ChangeSupport;
49
60
50
/**
61
/**
Lines 94-99 Link Here
94
        assertFalse(action.isEnabled());
105
        assertFalse(action.isEnabled());
95
    }
106
    }
96
107
108
    public void testCallback() throws InterruptedException {
109
        ExecutionDescriptor desc = new ExecutionDescriptor();
110
        ExecutionService service = ExecutionService.newService(new Callable<Process>() {
111
112
            @Override
113
            public Process call() throws Exception {
114
                return new TestProcess();
115
            }
116
        }, desc, "Test"); // NOI18N
117
118
        CountDownLatch latch = new CountDownLatch(1);
119
        TestCallback callback = new TestCallback(latch);
120
        RerunAction action = new RerunAction();
121
        action.setExecutionService(service);
122
        action.setRerunCallback(callback);
123
        action.actionPerformed(null);
124
        assertTrue(latch.await(5, TimeUnit.SECONDS));
125
    }
126
97
    private static class TestCondition implements RerunCondition {
127
    private static class TestCondition implements RerunCondition {
98
128
99
        private boolean rerunPossible;
129
        private boolean rerunPossible;
Lines 121-124 Link Here
121
            changeSupport.removeChangeListener(listener);
151
            changeSupport.removeChangeListener(listener);
122
        }
152
        }
123
    }
153
    }
154
155
    private static class TestProcess extends Process {
156
157
        private final InputStream is = new ByteArrayInputStream(new byte[]{});
158
159
        @Override
160
        public OutputStream getOutputStream() {
161
            return new OutputStream() {
162
163
                @Override
164
                public void write(int b) throws IOException {
165
                }
166
            };
167
        }
168
169
        @Override
170
        public InputStream getInputStream() {
171
            return is;
172
        }
173
174
        @Override
175
        public InputStream getErrorStream() {
176
            return is;
177
        }
178
179
        @Override
180
        public int waitFor() throws InterruptedException {
181
            return 0;
182
        }
183
184
        @Override
185
        public int exitValue() {
186
            return 0;
187
        }
188
189
        @Override
190
        public void destroy() {
191
        }
192
193
    }
194
195
    private static class TestCallback implements RerunCallback {
196
197
        private final CountDownLatch latch;
198
199
        public TestCallback(CountDownLatch latch) {
200
            this.latch = latch;
201
        }
202
203
        @Override
204
        public void performed(Future<Integer> task) {
205
            if (task != null) {
206
                latch.countDown();
207
            }
208
        }
209
    }
124
}
210
}

Return to bug 252283