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

(-)a/api.debugger.jpda/apichanges.xml (+18 lines)
Lines 816-821 Link Here
816
        <issue number="226029"/>
816
        <issue number="226029"/>
817
    </change>
817
    </change>
818
818
819
    <change>
820
        <api name="JPDADebuggerAPI"/>
821
        <summary>Breakpoints can deactivated.</summary>
822
        <version major="2" minor="42"/>
823
        <date day="27" month="2" year="2013"/>
824
        <author login="mentlicher"/>
825
        <compatibility addition="yes" source="compatible" binary="compatible"/>
826
        <description>
827
            Two methods are added to JPDADebugger class: areBreakpointsActive()
828
            and setBreakpointsActive(boolean). The set method fires PROP_BREAKPOINTS_ACTIVE
829
            event. <br/>
830
            These methods are used to activate/deactivate all breakpoints in the
831
            debugger session.
832
        </description>
833
        <class package="org.netbeans.api.debugger.jpda" name="JPDADebugger" />
834
        <issue number="79027"/>
835
    </change>
836
819
837
820
</changes>
838
</changes>
821
839
(-)a/api.debugger.jpda/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.api.debugger.jpda/2
2
OpenIDE-Module: org.netbeans.api.debugger.jpda/2
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/jpda/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/jpda/Bundle.properties
4
OpenIDE-Module-Specification-Version: 2.41
4
OpenIDE-Module-Specification-Version: 2.42
5
OpenIDE-Module-Package-Dependencies: com.sun.jdi[VirtualMachineManager]
5
OpenIDE-Module-Package-Dependencies: com.sun.jdi[VirtualMachineManager]
6
6
(-)a/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDADebugger.java (+29 lines)
Lines 107-112 Link Here
107
    /** Property name constant.
107
    /** Property name constant.
108
     * @since 2.25     */
108
     * @since 2.25     */
109
    public static final String          PROP_CLASSES_FIXED = "classesFixed";  // NOI18N
109
    public static final String          PROP_CLASSES_FIXED = "classesFixed";  // NOI18N
110
    /** Property name constant. Fired when breakpoints are activated / deactivated.
111
     * @since 2.42     */
112
    public static final String          PROP_BREAKPOINTS_ACTIVE = "breakpointsActive"; // NOI18N
110
    
113
    
111
    /** Suspend property value constant. */
114
    /** Suspend property value constant. */
112
    public static final int             SUSPEND_ALL = EventRequest.SUSPEND_ALL;
115
    public static final int             SUSPEND_ALL = EventRequest.SUSPEND_ALL;
Lines 488-493 Link Here
488
    }
491
    }
489
    
492
    
490
    /**
493
    /**
494
     * Test, if breakpoints are active.
495
     * @return <code>true</code> when breakpoints are active, <code>false</code>
496
     * otherwise. The default implementation returns <code>true</code>, to be overridden
497
     * when needed.
498
     * @since 2.42
499
     */
500
    public boolean areBreakpointsActive() {
501
        return true;
502
    }
503
    
504
    /**
505
     * Set all breakpoints to be active / inactive.
506
     * Activation or deactivation of breakpoints should not alter the enabled/disabled
507
     * state of individual breakpoints.
508
     * The default implementation throws UnsupportedOperationException, override
509
     * together with {@link #areBreakpointsActive()} when needed.
510
     * @param active <code>true</code> to make all breakpoints active,
511
     *               <code>false</code> to make all breakpoints inactive.
512
     * @throws UnsupportedOperationException when not supported.
513
     * @since 2.42
514
     */
515
    public void setBreakpointsActive(boolean active) {
516
        throw new UnsupportedOperationException("This method must be overridden."); 
517
    }
518
    
519
    /**
491
     * Adds property change listener.
520
     * Adds property change listener.
492
     *
521
     *
493
     * @param l new listener.
522
     * @param l new listener.
(-)a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/BreakpointAnnotationProvider.java (-17 / +75 lines)
Lines 63-76 Link Here
63
import org.netbeans.api.debugger.Breakpoint.VALIDITY;
63
import org.netbeans.api.debugger.Breakpoint.VALIDITY;
64
import org.netbeans.api.debugger.DebuggerEngine;
64
import org.netbeans.api.debugger.DebuggerEngine;
65
import org.netbeans.api.debugger.DebuggerManager;
65
import org.netbeans.api.debugger.DebuggerManager;
66
import org.netbeans.api.debugger.DebuggerManagerAdapter;
66
import org.netbeans.api.debugger.DebuggerManagerListener;
67
import org.netbeans.api.debugger.DebuggerManagerListener;
68
import org.netbeans.api.debugger.LazyDebuggerManagerListener;
67
import org.netbeans.api.debugger.Session;
69
import org.netbeans.api.debugger.Session;
68
import org.netbeans.api.debugger.Watch;
70
import org.netbeans.api.debugger.Watch;
69
import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint;
71
import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint;
70
import org.netbeans.api.debugger.jpda.FieldBreakpoint;
72
import org.netbeans.api.debugger.jpda.FieldBreakpoint;
71
import org.netbeans.api.debugger.jpda.JPDABreakpoint;
73
import org.netbeans.api.debugger.jpda.JPDABreakpoint;
74
import org.netbeans.api.debugger.jpda.JPDADebugger;
72
import org.netbeans.api.debugger.jpda.LineBreakpoint;
75
import org.netbeans.api.debugger.jpda.LineBreakpoint;
73
import org.netbeans.api.debugger.jpda.MethodBreakpoint;
76
import org.netbeans.api.debugger.jpda.MethodBreakpoint;
77
import org.netbeans.spi.debugger.DebuggerServiceRegistration;
74
import org.netbeans.spi.debugger.jpda.EditorContext;
78
import org.netbeans.spi.debugger.jpda.EditorContext;
75
79
76
import org.openide.cookies.LineCookie;
80
import org.openide.cookies.LineCookie;
Lines 94-107 Link Here
94
 * @author Jan Jancura, Martin Entlicher
98
 * @author Jan Jancura, Martin Entlicher
95
 */
99
 */
96
@org.openide.util.lookup.ServiceProvider(service=org.openide.text.AnnotationProvider.class)
100
@org.openide.util.lookup.ServiceProvider(service=org.openide.text.AnnotationProvider.class)
97
public class BreakpointAnnotationProvider implements AnnotationProvider,
101
@DebuggerServiceRegistration(types=LazyDebuggerManagerListener.class)
98
                                                     DebuggerManagerListener {
102
public class BreakpointAnnotationProvider extends DebuggerManagerAdapter
103
                                          implements AnnotationProvider/*,
104
                                                     DebuggerManagerListener*/ {
99
105
100
    private final Map<JPDABreakpoint, Set<Annotation>> breakpointToAnnotations =
106
    private final Map<JPDABreakpoint, Set<Annotation>> breakpointToAnnotations =
101
            new IdentityHashMap<JPDABreakpoint, Set<Annotation>>();
107
            new IdentityHashMap<JPDABreakpoint, Set<Annotation>>();
102
    private final Set<FileObject> annotatedFiles = new WeakSet<FileObject>();
108
    private final Set<FileObject> annotatedFiles = new WeakSet<FileObject>();
103
    private Set<PropertyChangeListener> dataObjectListeners;
109
    private Set<PropertyChangeListener> dataObjectListeners;
104
    private boolean attachManagerListener = true;
110
    private boolean attachManagerListener = true;
111
    private volatile JPDADebugger currentDebugger = null;
112
    private volatile boolean breakpointsActive = true;
105
    private RequestProcessor annotationProcessor = new RequestProcessor("Annotation Refresh", 1);
113
    private RequestProcessor annotationProcessor = new RequestProcessor("Annotation Refresh", 1);
106
    private RequestProcessor contextWaitingProcessor = new RequestProcessor("Annotation Refresh Context Waiting", 1);
114
    private RequestProcessor contextWaitingProcessor = new RequestProcessor("Annotation Refresh Context Waiting", 1);
107
115
Lines 176-181 Link Here
176
    }
184
    }
177
185
178
    @Override
186
    @Override
187
    public String[] getProperties() {
188
        return new String[] { DebuggerManager.PROP_BREAKPOINTS, DebuggerManager.PROP_DEBUGGER_ENGINES }; 
189
    }
190
191
    @Override
179
    public void breakpointAdded(Breakpoint breakpoint) {
192
    public void breakpointAdded(Breakpoint breakpoint) {
180
        if (isAnnotatable(breakpoint)) {
193
        if (isAnnotatable(breakpoint)) {
181
            JPDABreakpoint b = (JPDABreakpoint) breakpoint;
194
            JPDABreakpoint b = (JPDABreakpoint) breakpoint;
Lines 207-212 Link Here
207
        if (propertyName == null) {
220
        if (propertyName == null) {
208
            return;
221
            return;
209
        }
222
        }
223
        if (DebuggerManager.PROP_CURRENT_ENGINE.equals(propertyName)) {
224
            JPDADebugger oldDebugger = currentDebugger;
225
            if (oldDebugger != null) {
226
                oldDebugger.removePropertyChangeListener(JPDADebugger.PROP_BREAKPOINTS_ACTIVE, this);
227
            }
228
            DebuggerEngine engine = DebuggerManager.getDebuggerManager().getCurrentEngine();
229
            boolean active = true;
230
            JPDADebugger debugger = null;
231
            if (engine != null) {
232
                debugger = engine.lookupFirst(null, JPDADebugger.class);
233
                if (debugger != null) {
234
                    debugger.addPropertyChangeListener(JPDADebugger.PROP_BREAKPOINTS_ACTIVE, this);
235
                    active = debugger.areBreakpointsActive();
236
                }
237
            }
238
            currentDebugger = debugger;
239
            setBreakpointsActive(active);
240
        }
241
        if (JPDADebugger.PROP_BREAKPOINTS_ACTIVE.equals(propertyName)) {
242
            JPDADebugger debugger = currentDebugger;
243
            if (debugger != null) {
244
                setBreakpointsActive(debugger.areBreakpointsActive());
245
            }
246
        }
210
        if ( (!JPDABreakpoint.PROP_ENABLED.equals (propertyName)) &&
247
        if ( (!JPDABreakpoint.PROP_ENABLED.equals (propertyName)) &&
211
             (!JPDABreakpoint.PROP_VALIDITY.equals (propertyName)) &&
248
             (!JPDABreakpoint.PROP_VALIDITY.equals (propertyName)) &&
212
             (!LineBreakpoint.PROP_CONDITION.equals (propertyName)) &&
249
             (!LineBreakpoint.PROP_CONDITION.equals (propertyName)) &&
Lines 238-243 Link Here
238
        annotationProcessor.post(new AnnotationRefresh(b, true, true));
275
        annotationProcessor.post(new AnnotationRefresh(b, true, true));
239
    }
276
    }
240
    
277
    
278
    private void setBreakpointsActive(boolean active) {
279
        if (breakpointsActive == active) {
280
            return ;
281
        }
282
        annotationProcessor.post(new AnnotationRefresh(null, true, true));
283
    }
284
    
241
    private final class AnnotationRefresh implements Runnable {
285
    private final class AnnotationRefresh implements Runnable {
242
        
286
        
243
        private JPDABreakpoint b;
287
        private JPDABreakpoint b;
Lines 252-268 Link Here
252
        @Override
296
        @Override
253
        public void run() {
297
        public void run() {
254
            synchronized (breakpointToAnnotations) {
298
            synchronized (breakpointToAnnotations) {
255
                if (remove) {
299
                if (b != null) {
256
                    removeAnnotations(b);
300
                    refreshAnnotation(b);
257
                    if (!add) {
301
                } else {
258
                        breakpointToAnnotations.remove(b);
302
                    List<JPDABreakpoint> bpts = new ArrayList<JPDABreakpoint>(breakpointToAnnotations.keySet());
303
                    for (JPDABreakpoint bp : bpts) {
304
                        refreshAnnotation(bp);
259
                    }
305
                    }
260
                }
306
                }
261
                if (add) {
307
            }
262
                    breakpointToAnnotations.put(b, new WeakSet<Annotation>());
308
        }
263
                    for (FileObject fo : annotatedFiles) {
309
        
264
                        addAnnotationTo(b, fo);
310
        private void refreshAnnotation(JPDABreakpoint b) {
265
                    }
311
            if (remove) {
312
                removeAnnotations(b);
313
                if (!add) {
314
                    breakpointToAnnotations.remove(b);
315
                }
316
            }
317
            if (add) {
318
                breakpointToAnnotations.put(b, new WeakSet<Annotation>());
319
                for (FileObject fo : annotatedFiles) {
320
                    addAnnotationTo(b, fo);
266
                }
321
                }
267
            }
322
            }
268
        }
323
        }
Lines 277-283 Link Here
277
               !((JPDABreakpoint) b).isHidden();
332
               !((JPDABreakpoint) b).isHidden();
278
    }
333
    }
279
    
334
    
280
    private static String getAnnotationType(JPDABreakpoint b, boolean isConditional) {
335
    private static String getAnnotationType(JPDABreakpoint b, boolean isConditional,
336
                                            boolean active) {
281
        boolean isInvalid = b.getValidity() == VALIDITY.INVALID;
337
        boolean isInvalid = b.getValidity() == VALIDITY.INVALID;
282
        String annotationType;
338
        String annotationType;
283
        if (b instanceof LineBreakpoint) {
339
        if (b instanceof LineBreakpoint) {
Lines 301-308 Link Here
301
        } else {
357
        } else {
302
            throw new IllegalStateException(b.toString());
358
            throw new IllegalStateException(b.toString());
303
        }
359
        }
304
        if (isInvalid && b.isEnabled ()) {
360
        if (!active) {
305
            annotationType += "_broken";
361
            annotationType = annotationType + "_stroke";    // NOI18N
362
        } else if (isInvalid && b.isEnabled ()) {
363
            annotationType += "_broken";                    // NOI18N
306
        }
364
        }
307
        return annotationType;
365
        return annotationType;
308
    }
366
    }
Lines 481-487 Link Here
481
            throw new IllegalStateException(b.toString());
539
            throw new IllegalStateException(b.toString());
482
        }
540
        }
483
        boolean isConditional = (condition != null) && condition.trim().length() > 0;
541
        boolean isConditional = (condition != null) && condition.trim().length() > 0;
484
        String annotationType = getAnnotationType(b, isConditional);
542
        String annotationType = getAnnotationType(b, isConditional, breakpointsActive);
485
        DataObject dataObject;
543
        DataObject dataObject;
486
        try {
544
        try {
487
            dataObject = DataObject.find(fo);
545
            dataObject = DataObject.find(fo);
Lines 526-532 Link Here
526
        }
584
        }
527
    }
585
    }
528
    
586
    
529
587
    /*
530
    // Not used
588
    // Not used
531
    @Override
589
    @Override
532
    public Breakpoint[] initBreakpoints() { return new Breakpoint[] {}; }
590
    public Breakpoint[] initBreakpoints() { return new Breakpoint[] {}; }
Lines 558-562 Link Here
558
    // Not used
616
    // Not used
559
    @Override
617
    @Override
560
    public void engineRemoved(DebuggerEngine engine) {}
618
    public void engineRemoved(DebuggerEngine engine) {}
561
619
    */
562
}
620
}
(-)a/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/resources/mf-layer.xml (+17 lines)
Lines 291-296 Link Here
291
        </folder>
291
        </folder>
292
    </folder>
292
    </folder>
293
293
294
    <folder name="Debugger">
295
        <folder name="netbeans-JPDASession">
296
        <folder name="BreakpointsView">
297
            <folder name="Toolbar">
298
                <file name="org-netbeans-modules-debugger-jpda-ui-models-BreakpointModelActiveSessionFilter-createActivateBreakpointsActionButton.instance">
299
                    <!--attr name="serviceName" stringvalue="org.netbeans.modules.debugger.jpda.actions.ContinueActionProvider"/-->
300
                    <attr name="serviceClass" stringvalue="java.awt.Component"/>
301
                    <attr name="instanceOf" stringvalue="java.awt.Component"/>
302
                    <attr
303
                        methodvalue="org.netbeans.modules.debugger.jpda.ui.models.BreakpointModelActiveSessionFilter.createActivateBreakpointsActionButton" name="instanceCreate"/>
304
                    <attr intvalue="150" name="position"/>
305
                </file>
306
            </folder>
307
        </folder>
308
        </folder>
309
    </folder>    
310
    
294
    <folder name="Shortcuts">
311
    <folder name="Shortcuts">
295
        <file name="SO-9.shadow">
312
        <file name="SO-9.shadow">
296
            <attr name="originalFile" stringvalue="Actions/Window/Debug/org-netbeans-modules-debugger-jpda-ui-actions-DebuggingViewAction.instance"/>
313
            <attr name="originalFile" stringvalue="Actions/Window/Debug/org-netbeans-modules-debugger-jpda-ui-actions-DebuggingViewAction.instance"/>
(-)a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/JPDADebuggerImpl.java (+17 lines)
Lines 206-211 Link Here
206
    private boolean                     doContinue = true; // Whether resume() will actually resume
206
    private boolean                     doContinue = true; // Whether resume() will actually resume
207
    private Boolean                     singleThreadStepResumeDecision = null;
207
    private Boolean                     singleThreadStepResumeDecision = null;
208
    private Boolean                     stepInterruptByBptResumeDecision = null;
208
    private Boolean                     stepInterruptByBptResumeDecision = null;
209
    private boolean                     breakpointsActive = true;
209
    
210
    
210
    private InputOutput                 io;
211
    private InputOutput                 io;
211
212
Lines 554-559 Link Here
554
        }
555
        }
555
    }
556
    }
556
557
558
    @Override
559
    public boolean areBreakpointsActive() {
560
        return breakpointsActive;
561
    }
562
563
    @Override
564
    public void setBreakpointsActive(boolean active) {
565
        synchronized (this) {
566
            if (breakpointsActive == active) {
567
                return ;
568
            }
569
            breakpointsActive = active;
570
        }
571
        firePropertyChange(PROP_BREAKPOINTS_ACTIVE, !active, active);
572
    }
573
    
557
    public Session getSession() {
574
    public Session getSession() {
558
        return lookupProvider.lookupFirst(null, Session.class);
575
        return lookupProvider.lookupFirst(null, Session.class);
559
    }
576
    }
(-)a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/BreakpointImpl.java (-2 / +4 lines)
Lines 133-138 Link Here
133
     */
133
     */
134
    final void set () {
134
    final void set () {
135
        breakpoint.addPropertyChangeListener (this);
135
        breakpoint.addPropertyChangeListener (this);
136
        debugger.addPropertyChangeListener(JPDADebugger.PROP_BREAKPOINTS_ACTIVE, this);
136
        if (breakpoint instanceof PropertyChangeListener && isApplicable()) {
137
        if (breakpoint instanceof PropertyChangeListener && isApplicable()) {
137
            Session s = debugger.getSession();
138
            Session s = debugger.getSession();
138
            DebuggerEngine de = s.getEngineForLanguage ("Java");
139
            DebuggerEngine de = s.getEngineForLanguage ("Java");
Lines 159-165 Link Here
159
             (getDebugger ().getState () == JPDADebugger.STATE_DISCONNECTED)
160
             (getDebugger ().getState () == JPDADebugger.STATE_DISCONNECTED)
160
        ) return;
161
        ) return;
161
        removeAllEventRequests ();
162
        removeAllEventRequests ();
162
        if (breakpoint.isEnabled () && isEnabled()) {
163
        if (breakpoint.isEnabled () && isEnabled() && debugger.areBreakpointsActive()) {
163
            setRequests ();
164
            setRequests ();
164
        }
165
        }
165
    }
166
    }
Lines 186-192 Link Here
186
        } else if (!Breakpoint.PROP_VALIDITY.equals(propertyName) &&
187
        } else if (!Breakpoint.PROP_VALIDITY.equals(propertyName) &&
187
                   !Breakpoint.PROP_GROUP_NAME.equals(propertyName) &&
188
                   !Breakpoint.PROP_GROUP_NAME.equals(propertyName) &&
188
                   !Breakpoint.PROP_GROUP_PROPERTIES.equals(propertyName)) {
189
                   !Breakpoint.PROP_GROUP_PROPERTIES.equals(propertyName)) {
189
            if (reader != null) {
190
            if (reader != null && !JPDADebugger.PROP_BREAKPOINTS_ACTIVE.equals(propertyName)) {
190
                reader.storeCachedClassName(breakpoint, null);
191
                reader.storeCachedClassName(breakpoint, null);
191
            }
192
            }
192
            debugger.getRequestProcessor().post(new Runnable() {
193
            debugger.getRequestProcessor().post(new Runnable() {
Lines 214-219 Link Here
214
            removeAllEventRequests ();
215
            removeAllEventRequests ();
215
        }
216
        }
216
        breakpoint.removePropertyChangeListener(this);
217
        breakpoint.removePropertyChangeListener(this);
218
        debugger.removePropertyChangeListener(JPDADebugger.PROP_BREAKPOINTS_ACTIVE, this);
217
        setValidity(Breakpoint.VALIDITY.UNKNOWN, null);
219
        setValidity(Breakpoint.VALIDITY.UNKNOWN, null);
218
        if (breakpoint instanceof PropertyChangeListener) {
220
        if (breakpoint instanceof PropertyChangeListener) {
219
            Session s = debugger.getSession();
221
            Session s = debugger.getSession();
(-)d86a5e4e1ac5 (+216 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.api.debugger.jpda;
46
47
import junit.framework.Test;
48
import org.netbeans.api.debugger.DebuggerManager;
49
import org.netbeans.api.debugger.jpda.event.JPDABreakpointEvent;
50
import org.netbeans.api.debugger.jpda.event.JPDABreakpointListener;
51
import org.netbeans.junit.NbTestCase;
52
53
/**
54
 * Tests breakpoints deactivation.
55
 *
56
 */
57
public class BreakpointsDeactivationTest extends NbTestCase {
58
59
    private static final String TEST_APP_PATH = System.getProperty ("test.dir.src") + 
60
        "org/netbeans/api/debugger/jpda/testapps/LineBreakpointApp.java";
61
    
62
    private JPDASupport support;
63
    
64
    
65
    public BreakpointsDeactivationTest (String s) {
66
        super (s);
67
    }
68
69
    public static Test suite() {
70
        return JPDASupport.createTestSuite(BreakpointsDeactivationTest.class);
71
    }
72
    
73
    public void testBreakpointsDeactivation () throws Exception {
74
        try {
75
            Utils.BreakPositions bp = Utils.getBreakPositions(TEST_APP_PATH);
76
            LineBreakpoint[] lb = bp.getBreakpoints().toArray(new LineBreakpoint[0]);
77
            {
78
                LineBreakpoint b;
79
                b = lb[4];
80
                lb[4] = lb[2];
81
                lb[2] = b;
82
            }
83
            /*
84
            LineBreakpoint lb1 = LineBreakpoint.create (TEST_APP, 32);
85
            LineBreakpoint lb2 = LineBreakpoint.create (TEST_APP, 37);
86
            LineBreakpoint lb3 = LineBreakpoint.create (TEST_APP, 109);
87
            lb3.setPreferredClassName("org.netbeans.api.debugger.jpda.testapps.LineBreakpointApp$Inner");
88
            LineBreakpoint lb4 = LineBreakpoint.create (TEST_APP, 92);
89
            lb4.setPreferredClassName("org.netbeans.api.debugger.jpda.testapps.LineBreakpointApp$InnerStatic");
90
            LineBreakpoint lb5 = LineBreakpoint.create (TEST_APP, 41);
91
            */
92
            DebuggerManager dm = DebuggerManager.getDebuggerManager ();
93
            for (int i = 0; i < lb.length; i++) {
94
                dm.addBreakpoint (lb[i]);
95
            }
96
97
            TestBreakpointListener[] tb = new TestBreakpointListener[lb.length];
98
            for (int i = 0; i < lb.length; i++) {
99
                tb[i] = new TestBreakpointListener (lb[i]);
100
                lb[i].addJPDABreakpointListener (tb[i]);
101
            }
102
            support = JPDASupport.attach (
103
                "org.netbeans.api.debugger.jpda.testapps.LineBreakpointApp"
104
            );
105
            JPDADebugger debugger = support.getDebugger();
106
            assertEquals("Breakpoints should be active initially.", true, debugger.areBreakpointsActive());
107
            
108
            support.waitState (JPDADebugger.STATE_STOPPED);  // stopped on the first breakpoint
109
            
110
            debugger.setBreakpointsActive(false);
111
            assertEquals("Breakpoints should be inactive after deactivation.", false, debugger.areBreakpointsActive());
112
            
113
            int j = 0;
114
            assertEquals (
115
                "Debugger stopped at wrong line for breakpoint " + j, 
116
                lb[j].getLineNumber (), 
117
                debugger.getCurrentCallStackFrame ().getLineNumber (null)
118
            );
119
            for (int i = j+1; i < tb.length; i++) {
120
                tb[i].checkNotNotified();
121
            }
122
            if (j < lb.length - 1) {
123
                support.doContinue();
124
            }
125
            
126
            for (int i = 0; i < tb.length; i++) {
127
                dm.removeBreakpoint (lb[i]);
128
            }
129
            support.waitState (JPDADebugger.STATE_DISCONNECTED);
130
        } finally {
131
            if (support != null) support.doFinish ();
132
        }
133
    }
134
135
    // innerclasses ............................................................
136
    
137
    private class TestBreakpointListener implements JPDABreakpointListener {
138
139
        private LineBreakpoint  lineBreakpoint;
140
        private int             conditionResult;
141
142
        private JPDABreakpointEvent event;
143
        private AssertionError      failure;
144
145
        public TestBreakpointListener (LineBreakpoint lineBreakpoint) {
146
            this (lineBreakpoint, JPDABreakpointEvent.CONDITION_NONE);
147
        }
148
149
        public TestBreakpointListener (
150
            LineBreakpoint lineBreakpoint, 
151
            int conditionResult
152
        ) {
153
            this.lineBreakpoint = lineBreakpoint;
154
            this.conditionResult = conditionResult;
155
        }
156
157
        public void breakpointReached (JPDABreakpointEvent event) {
158
            try {
159
                checkEvent (event);
160
            } catch (AssertionError e) {
161
                failure = e;
162
            } catch (Throwable e) {
163
                failure = new AssertionError (e);
164
            }
165
        }
166
167
        private void checkEvent (JPDABreakpointEvent event) {
168
            this.event = event;
169
            assertEquals (
170
                "Breakpoint event: Wrong source breakpoint", 
171
                lineBreakpoint, 
172
                event.getSource ()
173
            );
174
            assertNotNull (
175
                "Breakpoint event: Context thread is null", 
176
                event.getThread ()
177
            );
178
179
            int result = event.getConditionResult ();
180
            if ( result == JPDABreakpointEvent.CONDITION_FAILED && 
181
                 conditionResult != JPDABreakpointEvent.CONDITION_FAILED
182
            )
183
                failure = new AssertionError (event.getConditionException ());
184
            else 
185
            if (result != conditionResult)
186
                failure = new AssertionError (
187
                    "Unexpected breakpoint condition result: " + result
188
                );
189
        }
190
191
        public void checkResult () {
192
            if (event == null) {
193
                CallStackFrame f = support.getDebugger ().
194
                    getCurrentCallStackFrame ();
195
                int ln = -1;
196
                if (f != null) {
197
                    ln = f.getLineNumber (null);
198
                }
199
                throw new AssertionError (
200
                    "Breakpoint was not hit (listener was not notified) " + ln
201
                );
202
            }
203
            if (failure != null) throw failure;
204
        }
205
        
206
        public void checkNotNotified() {
207
            if (event != null) {
208
                JPDAThread t = event.getThread();
209
                throw new AssertionError (
210
                    "Breakpoint was hit (listener was notified) in thread " + t
211
                );
212
            }
213
            if (failure != null) throw failure;
214
        }
215
    }
216
}

Return to bug 79027