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

(-)src/org/netbeans/modules/debugger/jpda/breakpoints/BreakpointImpl.java (-1 / +5 lines)
Lines 93-101 Link Here
93
             (getDebugger ().getState () == JPDADebugger.STATE_DISCONNECTED)
93
             (getDebugger ().getState () == JPDADebugger.STATE_DISCONNECTED)
94
        ) return;
94
        ) return;
95
        removeAllEventRequests ();
95
        removeAllEventRequests ();
96
        if (breakpoint.isEnabled ()) {
96
        if (breakpoint.isEnabled () && isEnabled()) {
97
            setRequests ();
97
            setRequests ();
98
        }
98
        }
99
    }
100
    
101
    protected boolean isEnabled() {
102
        return true;
99
    }
103
    }
100
104
101
    public void propertyChange (PropertyChangeEvent evt) {
105
    public void propertyChange (PropertyChangeEvent evt) {
(-)src/org/netbeans/modules/debugger/jpda/breakpoints/BreakpointsReader.java (-3 / +32 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
Lines 34-39 Link Here
34
public class BreakpointsReader implements Properties.Reader {
34
public class BreakpointsReader implements Properties.Reader {
35
    
35
    
36
    private Map cachedClassNames = new WeakHashMap();
36
    private Map cachedClassNames = new WeakHashMap();
37
    private Map cachedSourceRoots = new WeakHashMap();
37
    
38
    
38
    
39
    
39
    public String [] getSupportedClassNames () {
40
    public String [] getSupportedClassNames () {
Lines 46-51 Link Here
46
        return (String) cachedClassNames.get(b);
47
        return (String) cachedClassNames.get(b);
47
    }
48
    }
48
    
49
    
50
    synchronized String findCachedSourceRoot(JPDABreakpoint b) {
51
        return (String) cachedSourceRoots.get(b);
52
    }
53
    
49
    void storeCachedClassName(JPDABreakpoint b, String className) {
54
    void storeCachedClassName(JPDABreakpoint b, String className) {
50
        synchronized (this) {
55
        synchronized (this) {
51
            cachedClassNames.put(b, className);
56
            cachedClassNames.put(b, className);
Lines 53-58 Link Here
53
        PersistenceManager.storeBreakpoints();
58
        PersistenceManager.storeBreakpoints();
54
    }
59
    }
55
    
60
    
61
    void storeCachedSourceRoot(JPDABreakpoint b, String sourceRoot) {
62
        synchronized (this) {
63
            cachedSourceRoots.put(b, sourceRoot);
64
        }
65
        PersistenceManager.storeBreakpoints();
66
    }
67
    
56
    public Object read (String typeID, Properties properties) {
68
    public Object read (String typeID, Properties properties) {
57
        JPDABreakpoint b = null;
69
        JPDABreakpoint b = null;
58
        // Read both LineBreakpoint and LineBreakpoint$LineBreakpointImpl
70
        // Read both LineBreakpoint and LineBreakpoint$LineBreakpointImpl
Lines 67-72 Link Here
67
            );
79
            );
68
            synchronized (this) {
80
            synchronized (this) {
69
                cachedClassNames.put(lb, properties.getString("className", null));
81
                cachedClassNames.put(lb, properties.getString("className", null));
82
                cachedSourceRoots.put(lb, properties.getString("sourceRoot", null));
70
            }
83
            }
71
            b = lb;
84
            b = lb;
72
        }
85
        }
Lines 96-101 Link Here
96
                    MethodBreakpoint.TYPE_METHOD_ENTRY
109
                    MethodBreakpoint.TYPE_METHOD_ENTRY
97
                )
110
                )
98
            );
111
            );
112
            synchronized (this) {
113
                cachedSourceRoots.put(mb, properties.getString("sourceRoot", null));
114
            }
99
            b = mb;
115
            b = mb;
100
        }
116
        }
101
        if (typeID.equals (ClassLoadUnloadBreakpoint.class.getName ())) {
117
        if (typeID.equals (ClassLoadUnloadBreakpoint.class.getName ())) {
Lines 117-122 Link Here
117
                    new String [0]
133
                    new String [0]
118
                )
134
                )
119
            );
135
            );
136
            synchronized (this) {
137
                cachedSourceRoots.put(cb, properties.getString("sourceRoot", null));
138
            }
120
            b = cb;
139
            b = cb;
121
        }
140
        }
122
        if (typeID.equals (ExceptionBreakpoint.class.getName ())) {
141
        if (typeID.equals (ExceptionBreakpoint.class.getName ())) {
Lines 133-138 Link Here
133
            eb.setCondition (
152
            eb.setCondition (
134
                properties.getString (ExceptionBreakpoint.PROP_CONDITION, "")
153
                properties.getString (ExceptionBreakpoint.PROP_CONDITION, "")
135
            );
154
            );
155
            synchronized (this) {
156
                cachedSourceRoots.put(eb, properties.getString("sourceRoot", null));
157
            }
136
            b = eb;
158
            b = eb;
137
        }
159
        }
138
        if (typeID.equals (FieldBreakpoint.class.getName ())) {
160
        if (typeID.equals (FieldBreakpoint.class.getName ())) {
Lines 147-152 Link Here
147
            fb.setCondition (
169
            fb.setCondition (
148
                properties.getString (FieldBreakpoint.PROP_CONDITION, "")
170
                properties.getString (FieldBreakpoint.PROP_CONDITION, "")
149
            );
171
            );
172
            synchronized (this) {
173
                cachedSourceRoots.put(fb, properties.getString("sourceRoot", null));
174
            }
150
            b = fb;
175
            b = fb;
151
        }
176
        }
152
        if (typeID.equals (ThreadBreakpoint.class.getName ())) {
177
        if (typeID.equals (ThreadBreakpoint.class.getName ())) {
Lines 204-211 Link Here
204
                LineBreakpoint.PROP_CONDITION, 
229
                LineBreakpoint.PROP_CONDITION, 
205
                lb.getCondition ()
230
                lb.getCondition ()
206
            );
231
            );
207
            String className = findCachedClassName(lb);
232
            properties.setString("className", findCachedClassName(lb));
208
            properties.setString("className", className);
233
            properties.setString("sourceRoot", findCachedSourceRoot(lb));
209
            return;
234
            return;
210
        } else 
235
        } else 
211
        if (object instanceof MethodBreakpoint) {
236
        if (object instanceof MethodBreakpoint) {
Lines 230-235 Link Here
230
                MethodBreakpoint.PROP_BREAKPOINT_TYPE, 
255
                MethodBreakpoint.PROP_BREAKPOINT_TYPE, 
231
                mb.getBreakpointType ()
256
                mb.getBreakpointType ()
232
            );
257
            );
258
            properties.setString("sourceRoot", findCachedSourceRoot(mb));
233
            return;
259
            return;
234
        } else 
260
        } else 
235
        if (object instanceof ClassLoadUnloadBreakpoint) {
261
        if (object instanceof ClassLoadUnloadBreakpoint) {
Lines 246-251 Link Here
246
                ClassLoadUnloadBreakpoint.PROP_BREAKPOINT_TYPE, 
272
                ClassLoadUnloadBreakpoint.PROP_BREAKPOINT_TYPE, 
247
                cb.getBreakpointType ()
273
                cb.getBreakpointType ()
248
            );
274
            );
275
            properties.setString("sourceRoot", findCachedSourceRoot(cb));
249
            return;
276
            return;
250
        } else 
277
        } else 
251
        if (object instanceof ExceptionBreakpoint) {
278
        if (object instanceof ExceptionBreakpoint) {
Lines 262-267 Link Here
262
                ExceptionBreakpoint.PROP_CONDITION, 
289
                ExceptionBreakpoint.PROP_CONDITION, 
263
                eb.getCondition ()
290
                eb.getCondition ()
264
            );
291
            );
292
            properties.setString("sourceRoot", findCachedSourceRoot(eb));
265
            return;
293
            return;
266
        } else 
294
        } else 
267
        if (object instanceof FieldBreakpoint) {
295
        if (object instanceof FieldBreakpoint) {
Lines 282-287 Link Here
282
                FieldBreakpoint.PROP_BREAKPOINT_TYPE, 
310
                FieldBreakpoint.PROP_BREAKPOINT_TYPE, 
283
                fb.getBreakpointType ()
311
                fb.getBreakpointType ()
284
            );
312
            );
313
            properties.setString("sourceRoot", findCachedSourceRoot(fb));
285
            return;
314
            return;
286
        } else 
315
        } else 
287
        if (object instanceof ThreadBreakpoint) {
316
        if (object instanceof ThreadBreakpoint) {
(-)src/org/netbeans/modules/debugger/jpda/breakpoints/ClassBasedBreakpoint.java (-1 / +56 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
Lines 21-26 Link Here
21
import com.sun.jdi.request.ClassPrepareRequest;
21
import com.sun.jdi.request.ClassPrepareRequest;
22
import com.sun.jdi.request.ClassUnloadRequest;
22
import com.sun.jdi.request.ClassUnloadRequest;
23
import com.sun.jdi.VirtualMachine;
23
import com.sun.jdi.VirtualMachine;
24
import java.beans.PropertyChangeEvent;
25
import java.beans.PropertyChangeListener;
24
26
25
import java.util.Iterator;
27
import java.util.Iterator;
26
import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint;
28
import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint;
Lines 28-33 Link Here
28
import org.netbeans.api.debugger.jpda.JPDABreakpoint;
30
import org.netbeans.api.debugger.jpda.JPDABreakpoint;
29
import org.netbeans.api.debugger.Session;
31
import org.netbeans.api.debugger.Session;
30
import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
32
import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
33
import org.netbeans.spi.debugger.jpda.SourcePathProvider;
34
import org.openide.util.WeakListeners;
31
35
32
/**
36
/**
33
* Implementation of breakpoint on method.
37
* Implementation of breakpoint on method.
Lines 36-41 Link Here
36
*/
40
*/
37
public abstract class ClassBasedBreakpoint extends BreakpointImpl {
41
public abstract class ClassBasedBreakpoint extends BreakpointImpl {
38
    
42
    
43
    private String sourceRoot;
44
    private final Object SOURCE_ROOT_LOCK = new Object();
45
    private SourceRootsChangedListener srChListener;
46
    
39
    private static boolean verbose = 
47
    private static boolean verbose = 
40
        System.getProperty ("netbeans.debugger.breakpoints") != null;
48
        System.getProperty ("netbeans.debugger.breakpoints") != null;
41
49
Lines 56-61 Link Here
56
        super (breakpoint, reader, debugger, session);
64
        super (breakpoint, reader, debugger, session);
57
    }
65
    }
58
    
66
    
67
    protected final void setSourceRoot(String sourceRoot) {
68
        synchronized (SOURCE_ROOT_LOCK) {
69
            this.sourceRoot = sourceRoot;
70
            if (sourceRoot != null && srChListener == null) {
71
                srChListener = new SourceRootsChangedListener();
72
                getDebugger().getEngineContext().addPropertyChangeListener(
73
                        WeakListeners.propertyChange(srChListener,
74
                                                     getDebugger().getEngineContext()));
75
            } else if (sourceRoot == null) {
76
                srChListener = null; // release the listener
77
            }
78
        }
79
    }
80
    
81
    protected final String getSourceRoot() {
82
        synchronized (SOURCE_ROOT_LOCK) {
83
            return sourceRoot;
84
        }
85
    }
86
    
87
    protected boolean isEnabled() {
88
        synchronized (SOURCE_ROOT_LOCK) {
89
            String sourceRoot = getSourceRoot();
90
            if (sourceRoot == null) {
91
                return true;
92
            }
93
            String[] sourceRoots = getDebugger().getEngineContext().getSourceRoots();
94
            for (int i = 0; i < sourceRoots.length; i++) {
95
                if (sourceRoot.equals(sourceRoots[i])) {
96
                    return true;
97
                }
98
            }
99
            return false;
100
        }
101
    }
102
    
59
    protected void setClassRequests (
103
    protected void setClassRequests (
60
        String[] classFilters,
104
        String[] classFilters,
61
        String[] classExclusionFilters,
105
        String[] classExclusionFilters,
Lines 153-157 Link Here
153
    
197
    
154
    protected void classLoaded (ReferenceType referenceType) {}
198
    protected void classLoaded (ReferenceType referenceType) {}
155
    protected void classUnloaded (String className) {}
199
    protected void classUnloaded (String className) {}
200
    
201
    
202
    private class SourceRootsChangedListener implements PropertyChangeListener {
203
        
204
        public void propertyChange(PropertyChangeEvent evt) {
205
            if (SourcePathProvider.PROP_SOURCE_ROOTS.equals(evt.getPropertyName())) {
206
                update();
207
            }
208
        }
209
        
210
    }
156
}
211
}
157
212
(-)src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java (-3 / +2 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
Lines 56-62 Link Here
56
56
57
    
57
    
58
    private LineBreakpoint      breakpoint;
58
    private LineBreakpoint      breakpoint;
59
    private SourcePath          sourcePath;
60
    private int                 lineNumber;
59
    private int                 lineNumber;
61
    private BreakpointsReader   reader;
60
    private BreakpointsReader   reader;
62
    
61
    
Lines 71-78 Link Here
71
        super (breakpoint, reader, debugger, session);
70
        super (breakpoint, reader, debugger, session);
72
        this.reader = reader;
71
        this.reader = reader;
73
        this.breakpoint = breakpoint;
72
        this.breakpoint = breakpoint;
74
        this.sourcePath = sourcePath;
75
        lineNumber = breakpoint.getLineNumber ();
73
        lineNumber = breakpoint.getLineNumber ();
74
        setSourceRoot(sourcePath.getSourceRoot(breakpoint.getURL()));
76
        set ();
75
        set ();
77
    }
76
    }
78
    
77
    
(-)test/unit/src/org/netbeans/api/debugger/jpda/LineBreakpointTest.java (+123 lines)
Lines 230-235 Link Here
230
    }
230
    }
231
231
232
    
232
    
233
    /**
234
     * Tests debugger's ability to make difference between different projects
235
     * with the same classes while getting the locations during class-loaded event.
236
     *
237
     * 1. The user creates 2 classes: ${test.dir.src}/.../LineBreakpointApp.java
238
     *    and ${test.dir.src_2}/.../LineBreakpointApp.java
239
     * 2. Then set a breakpoint in ${test.dir.src_2}/.../LineBreakpointApp.java.
240
     * 
241
     * Debugger should stop _only_ in the second project. If debugger stopped in
242
     * the first one, then assertion violation would arise because of source path
243
     * equality test.
244
     */
245
    public void testBreakpointUnambiguity1 () throws Exception {
246
        try {
247
            LineBreakpoint lb1 = LineBreakpoint.create (TEST_APP, 33);
248
//            lb1.setSourceRoot(System.getProperty ("test.dir.src"));
249
            DebuggerManager dm = DebuggerManager.getDebuggerManager ();
250
            dm.addBreakpoint (lb1);
251
            
252
            TestBreakpointListener tb1 = new TestBreakpointListener (lb1);
253
            lb1.addJPDABreakpointListener (tb1);
254
            
255
            support = JPDASupport.attach (
256
                "org.netbeans.api.debugger.jpda.testapps.LineBreakpointApp"
257
            );
258
            JPDADebugger debugger = support.getDebugger();
259
260
            support.waitState (JPDADebugger.STATE_STOPPED);  // breakpoint hit, the source root is correct
261
            assertEquals (
262
                "Debugger stopped at wrong line", 
263
                lb1.getLineNumber (), 
264
                debugger.getCurrentCallStackFrame ().getLineNumber (null)
265
            );
266
267
            tb1.checkResult ();
268
            support.doContinue();
269
            support.waitState (JPDADebugger.STATE_DISCONNECTED);
270
            dm.removeBreakpoint (lb1);
271
            support.doFinish ();
272
            /*
273
            // Second run - BP should not be hit with a different source root - viz testBreakpointUnambiguity2()
274
            support = null;
275
            lb1 = LineBreakpoint.create (TEST_APP, 33);
276
            lb1.setSourceRoot(System.getProperty ("test.dir.src")+"_2");
277
            dm = DebuggerManager.getDebuggerManager ();
278
            dm.addBreakpoint (lb1);
279
            
280
            tb1 = new TestBreakpointListener (lb1);
281
            lb1.addJPDABreakpointListener (tb1);
282
            
283
            support = JPDASupport.attach (
284
                "org.netbeans.api.debugger.jpda.testapps.LineBreakpointApp"
285
            );
286
            debugger = support.getDebugger();
287
            
288
            support.waitState (JPDADebugger.STATE_STOPPED); // Stopped or disconnected
289
            assertEquals(
290
                    "Debugger should not stop on BP with faked source root",
291
                    debugger.getState(),
292
                    JPDADebugger.STATE_DISCONNECTED
293
            );
294
            tb1.checkNotNotified();
295
            dm.removeBreakpoint (lb1);
296
             */
297
        } finally {
298
            if (support != null) support.doFinish ();
299
        }
300
    }
301
302
    /**
303
     * Tests debugger's ability to make difference between different projects
304
     * with the same classes while getting the locations during class-loaded event.
305
     *
306
     * 1. The user creates 2 classes: ${test.dir.src}/.../LineBreakpointApp.java
307
     *    and ${test.dir.src_2}/.../LineBreakpointApp.java
308
     * 2. Then set a breakpoint in ${test.dir.src_2}/.../LineBreakpointApp.java.
309
     * 
310
     * Debugger should stop _only_ in the second project. If debugger stopped in
311
     * the first one, then assertion violation would arise because of source path
312
     * equality test.
313
     */
314
    public void testBreakpointUnambiguity2 () throws Exception {
315
        try {
316
            LineBreakpoint lb1 = LineBreakpoint.create(
317
                    System.getProperty("user.home") + java.io.File.separator +
318
                    //System.getProperty ("test.dir.src") +
319
                    "org/netbeans/api/debugger/jpda/testapps/LineBreakpointApp.java", 33);
320
            //lb1.setSourceRoot(System.getProperty ("test.dir.src") + "_2");
321
            DebuggerManager dm = DebuggerManager.getDebuggerManager ();
322
            dm.addBreakpoint (lb1);
323
            
324
            TestBreakpointListener tb1 = new TestBreakpointListener (lb1);
325
            lb1.addJPDABreakpointListener (tb1);
326
            
327
            support = JPDASupport.attach (
328
                "org.netbeans.api.debugger.jpda.testapps.LineBreakpointApp"
329
            );
330
            JPDADebugger debugger = support.getDebugger();
331
332
            support.waitState (JPDADebugger.STATE_STOPPED); // Stopped or disconnected
333
            assertEquals(
334
                    "Debugger should not stop on BP with faked source root",
335
                    debugger.getState(),
336
                    JPDADebugger.STATE_DISCONNECTED
337
            );
338
            
339
            tb1.checkNotNotified();
340
            dm.removeBreakpoint (lb1);
341
        } finally {
342
            if (support != null) support.doFinish ();
343
        }
344
    }
345
233
    // innerclasses ............................................................
346
    // innerclasses ............................................................
234
    
347
    
235
    private class TestBreakpointListener implements JPDABreakpointListener {
348
    private class TestBreakpointListener implements JPDABreakpointListener {
Lines 296-301 Link Here
296
                }
409
                }
297
                throw new AssertionError (
410
                throw new AssertionError (
298
                    "Breakpoint was not hit (listener was not notified) " + ln
411
                    "Breakpoint was not hit (listener was not notified) " + ln
412
                );
413
            }
414
            if (failure != null) throw failure;
415
        }
416
        
417
        public void checkNotNotified() {
418
            if (event != null) {
419
                JPDAThread t = event.getThread();
420
                throw new AssertionError (
421
                    "Breakpoint was hit (listener was notified) in thread " + t
299
                );
422
                );
300
            }
423
            }
301
            if (failure != null) throw failure;
424
            if (failure != null) throw failure;
(-)src/org/netbeans/modules/debugger/jpda/SourcePath.java (-1 / +20 lines)
Lines 83-88 Link Here
83
        return getContext ().getRelativePath 
83
        return getContext ().getRelativePath 
84
            (url, directorySeparator, includeExtension);
84
            (url, directorySeparator, includeExtension);
85
    }
85
    }
86
    
87
    /**
88
     * Returns the source root (if any) for given url.
89
     *
90
     * @param url a url of resource file
91
     *
92
     * @return the source root or <code>null</code> when no source root was found.
93
     */
94
    public String getSourceRoot(String url) {
95
        return getContext().getSourceRoot(url);
96
    }
86
97
87
    /**
98
    /**
88
     * Translates a relative path ("java/lang/Thread.java") to url 
99
     * Translates a relative path ("java/lang/Thread.java") to url 
Lines 359-365 Link Here
359
                includeExtension
370
                includeExtension
360
            );
371
            );
361
        }
372
        }
362
    
373
374
        public String getSourceRoot(String url) {
375
            String sourceRoot = cp1.getSourceRoot(url);
376
            if (sourceRoot == null) {
377
                sourceRoot = cp2.getSourceRoot(url);
378
            }
379
            return sourceRoot;
380
        }
381
        
363
        public String[] getSourceRoots () {
382
        public String[] getSourceRoots () {
364
            String[] fs1 = cp1.getSourceRoots ();
383
            String[] fs1 = cp1.getSourceRoots ();
365
            String[] fs2 = cp2.getSourceRoots ();
384
            String[] fs2 = cp2.getSourceRoots ();
(-)api/src/org/netbeans/spi/debugger/jpda/SourcePathProvider.java (-1 / +13 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Micro//S ystems, Inc. Portions Copyright 1997-2001 Sun
10
 * Code is Sun Micro//S ystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Micro//S ystems, Inc. All Rights Reserved.
11
 * Micro//S ystems, Inc. All Rights Reserved.
12
 */
12
 */
13
package org.netbeans.spi.debugger.jpda;
13
package org.netbeans.spi.debugger.jpda;
Lines 60-65 Link Here
60
     */
60
     */
61
    public abstract String getURL (String relativePath, boolean global);
61
    public abstract String getURL (String relativePath, boolean global);
62
    
62
    
63
    /**
64
     * Returns the source root (if any) for given url.
65
     *
66
     * @param url a url of resource file
67
     *
68
     * @return the source root or <code>null</code> when no source root was found.
69
     * @since 2.6
70
     */
71
    public String getSourceRoot(String url) {
72
        return null;
73
    }
74
        
63
    /**
75
    /**
64
     * Returns array of source roots.
76
     * Returns array of source roots.
65
     */
77
     */
(-)ant/src/org/netbeans/modules/debugger/projects/SourcePathProviderImpl.java (-1 / +32 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
Lines 184-189 Link Here
184
            directorySeparator,
184
            directorySeparator,
185
            includeExtension
185
            includeExtension
186
        );
186
        );
187
    }
188
    
189
    /**
190
     * Returns the source root (if any) for given url.
191
     *
192
     * @param url a url of resource file
193
     *
194
     * @return the source root or <code>null</code> when no source root was found.
195
     */
196
    public String getSourceRoot(String url) {
197
        Iterator it = GlobalPathRegistry.getDefault().getSourceRoots().iterator();
198
        while (it.hasNext()) {
199
            FileObject fileObject = (FileObject) it.next ();
200
            try {
201
                String rootURL = fileObject.getURL().toString();
202
                if (url.startsWith(rootURL)) {
203
                    File f = null;
204
                    if (fileObject.getFileSystem () instanceof JarFileSystem)
205
                        f = ((JarFileSystem) fileObject.getFileSystem ()).
206
                            getJarFile ();
207
                    else
208
                        f = FileUtil.toFile (fileObject);
209
                    if (f != null) {
210
                        return f.getAbsolutePath ();
211
                    }
212
                }
213
            } catch (FileStateInvalidException ex) {
214
                // Invalid source root - skip
215
            }
216
        }
217
        return null; // not found
187
    }
218
    }
188
    
219
    
189
    /**
220
    /**
(-)test/unit/src/org/netbeans/api/debugger/jpda/test/TestEngineContextProvider.java (-2 / +44 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 *
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
Lines 23-28 Link Here
23
import java.net.URL;
23
import java.net.URL;
24
import java.net.MalformedURLException;
24
import java.net.MalformedURLException;
25
import java.io.File;
25
import java.io.File;
26
import org.openide.filesystems.FileObject;
27
import org.openide.filesystems.FileStateInvalidException;
28
import org.openide.filesystems.FileUtil;
29
import org.openide.filesystems.JarFileSystem;
26
30
27
31
28
/**
32
/**
Lines 33-46 Link Here
33
public class TestEngineContextProvider extends SourcePathProvider {
37
public class TestEngineContextProvider extends SourcePathProvider {
34
38
35
    private String          sourceRoot = System.getProperty ("test.dir.src");
39
    private String          sourceRoot = System.getProperty ("test.dir.src");
40
    private String          home = System.getProperty("user.home");
36
    private String[]        originalSourceRoots = new String[] {
41
    private String[]        originalSourceRoots = new String[] {
37
                                sourceRoot
42
                                sourceRoot, home
38
                            };
43
                            };
39
    private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
44
    private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
40
45
41
    
46
    
42
    public TestEngineContextProvider (ContextProvider ctxProvider) {
47
    public TestEngineContextProvider (ContextProvider ctxProvider) {
43
    //    this.session = (Session) ctxProvider.lookupFirst (null, Session.class);
48
    //    this.session = (Session) ctxProvider.lookupFirst (null, Session.class);
49
        for (int i = 0; i < originalSourceRoots.length; i++) {
50
            while (originalSourceRoots[i].endsWith(File.separator)) {
51
                originalSourceRoots[i] = originalSourceRoots[i].substring(0, originalSourceRoots[i].length() - 1);
52
            }
53
        }
44
    }
54
    }
45
55
46
    /**
56
    /**
Lines 108-113 Link Here
108
    public void setSourceRoots (String[] sourceRoots) {
118
    public void setSourceRoots (String[] sourceRoots) {
109
    }
119
    }
110
120
121
    public String getSourceRoot(String url) {
122
        for (int i = 0; i < originalSourceRoots.length; i++) {
123
            String sourceRoot = originalSourceRoots[i];
124
            FileObject fileObject = FileUtil.toFileObject(new File(sourceRoot));
125
            String rootURL;
126
            try {
127
                if (fileObject == null) {
128
                    rootURL = sourceRoot;
129
                } else {
130
                    rootURL = fileObject.getURL().toString();
131
                }
132
                if (url.startsWith(rootURL)) {
133
                    File f = null;
134
                    if (fileObject != null) {
135
                        if (fileObject.getFileSystem () instanceof JarFileSystem)
136
                            f = ((JarFileSystem) fileObject.getFileSystem ()).getJarFile ();
137
                        else
138
                            f = FileUtil.toFile (fileObject);
139
                    } else {
140
                        f = new File(sourceRoot);
141
                    }
142
                    if (f != null) {
143
                        return f.getAbsolutePath ();
144
                    }
145
                }
146
            } catch (FileStateInvalidException ex) {
147
                // Invalid source root - skip
148
            }
149
        }
150
        return null; // not found
151
    }
152
    
111
    /**
153
    /**
112
     * Adds property change listener.
154
     * Adds property change listener.
113
     *
155
     *
(-)api/apichanges.xml (+17 lines)
Lines 365-370 Link Here
365
        <class package="org.netbeans.api.debugger.jpda" name="JPDADebugger" />
365
        <class package="org.netbeans.api.debugger.jpda" name="JPDADebugger" />
366
        <issue number="67046"/>
366
        <issue number="67046"/>
367
    </change>
367
    </change>
368
    <change>
369
        <api name="JPDADebuggerAPI"/>
370
        <summary>Added getSourceRoot() method to SourcePathProvider class</summary>
371
        <version major="2" minor="6"/>
372
        <date day="3" month="5" year="2006"/>
373
        <author login="mentlicher"/>
374
        <compatibility addition="yes" source="compatible" binary="compatible"/>
375
        <description>
376
            <p>
377
                Retrieves a source root for a given URL. This is necessary to
378
                match breakpoint locations with the sources selected fopr debugging.
379
                It returns <code>null</code> by default.
380
            </p>
381
        </description>
382
        <class package="org.netbeans.spi.debugger.jpda" name="SourcePathProvider" />
383
        <issue number="52180"/>
384
    </change>
368
385
369
</changes>
386
</changes>
370
387
(-)api/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.5
4
OpenIDE-Module-Specification-Version: 2.6
5
OpenIDE-Module-Package-Dependencies: com.sun.jdi[VirtualMachineManager]
5
OpenIDE-Module-Package-Dependencies: com.sun.jdi[VirtualMachineManager]
6
6

Return to bug 52180