[hg] main-silver: #118086: Assure that field or method breakpoin...

  • From:
  • To:
  • Subject: [hg] main-silver: #118086: Assure that field or method breakpoin...
  • Date: Sat, 01 Dec 2012 13:36:45 -0800

changeset 0498c49e74c5 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/0498c49e74c5
description:
        #118086: Assure that field or method breakpoint is not hit in 
disabled sources.

diffstat:

 
debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/ClassBasedBreakpoint.java
 |  126 ++++++++++
 
debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/FieldBreakpointImpl.java
  |   15 +
 
debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java
   |  103 --------
 
debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/MethodBreakpointImpl.java
 |   15 +
 4 files changed, 156 insertions(+), 103 deletions(-)

diffs (381 lines):

diff --git 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/ClassBasedBreakpoint.java
 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/ClassBasedBreakpoint.java
--- 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/ClassBasedBreakpoint.java
+++ 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/ClassBasedBreakpoint.java
@@ -64,12 +64,19 @@
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import javax.lang.model.element.TypeElement;
 import org.netbeans.api.debugger.Breakpoint.VALIDITY;
 import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint;
 
 import org.netbeans.api.debugger.jpda.JPDABreakpoint;
 import org.netbeans.api.debugger.Session;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.CompilationController;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.Task;
 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
+import org.netbeans.modules.debugger.jpda.SourcePath;
 import org.netbeans.modules.debugger.jpda.jdi.InternalExceptionWrapper;
 import 
org.netbeans.modules.debugger.jpda.jdi.InvalidRequestStateExceptionWrapper;
 import 
org.netbeans.modules.debugger.jpda.jdi.ObjectCollectedExceptionWrapper;
@@ -85,7 +92,9 @@
 import org.netbeans.modules.debugger.jpda.util.JPDAUtils;
 import org.netbeans.spi.debugger.jpda.BreakpointsClassFilter;
 import org.netbeans.spi.debugger.jpda.SourcePathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
 import org.openide.ErrorManager;
+import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 import org.openide.util.Exceptions;
 import org.openide.util.NbBundle;
@@ -234,6 +243,123 @@
         return compareSourceRoots(sourceRoot, urlRoot);
     }
     
+    /**
+     * Returns list of class names that are a sub-set of provided class 
names,
+     * which does not belong to disabled source roots.
+     * @param classNames List of class names
+     */
+    protected final String[] checkSourcesEnabled(String[] classNames, 
String[] srcRootPtr) {
+        List<String> enabledClassNames = new 
ArrayList<String>(classNames.length);
+        for (String className : classNames) {
+            String relPath = 
SourcePath.convertClassNameToRelativePath(className);
+            String globalURL = 
getDebugger().getEngineContext().getURL(relPath, true);
+            if (globalURL != null) {
+                if (getDebugger().getEngineContext().getURL(relPath, false) 
== null) {
+                    // Is disabled
+                    srcRootPtr[0] = 
getDebugger().getEngineContext().getSourceRoot(globalURL);
+                    continue;
+                }
+            }
+            enabledClassNames.add(className);
+        }
+        return enabledClassNames.toArray(new String[] {});
+    }
+    
+    protected static boolean classExistsInSources(final String className, 
String[] projectSourceRoots) {
+        /*
+        ClassIndexManager cim = ClassIndexManager.getDefault();
+        List<FileObject> sourcePaths = new 
ArrayList<FileObject>(projectSourceRoots.length);
+        for (String sr : projectSourceRoots) {
+            FileObject fo = getFileObject(sr);
+            if (fo != null) {
+                sourcePaths.add(fo);
+                ClassIndexImpl ci;
+                try {
+                    ci = cim.getUsagesQuery(fo.getURL());
+                    if (ci != null) {
+                        String sourceName = ci.getSourceName(className);
+                        if (sourceName != null) {
+                            return true;
+                        }
+                    }
+                } catch (FileStateInvalidException ex) {
+                    continue;
+                } catch (java.io.IOException ioex) {
+                    continue;
+                }
+            }
+        }
+        return false;
+         */
+        List<FileObject> sourcePaths = new 
ArrayList<FileObject>(projectSourceRoots.length);
+        for (String sr : projectSourceRoots) {
+            FileObject fo = getFileObject(sr);
+            if (fo != null) {
+                sourcePaths.add(fo);
+            }
+        }
+        ClassPath cp = 
ClassPathSupport.createClassPath(sourcePaths.toArray(new FileObject[0]));
+        //ClassPathSupport.createClassPath(new FileObject[] {});
+        ClasspathInfo cpInfo = 
ClasspathInfo.create(ClassPathSupport.createClassPath(new FileObject[] {}),
+                                                    
ClassPathSupport.createClassPath(new FileObject[] {}),
+                                                    cp);
+        //ClassIndex ci = cpInfo.getClassIndex();
+        JavaSource js = JavaSource.create(cpInfo);
+        final boolean[] found = new boolean[] { false };
+        try {
+            js.runUserActionTask(new Task<CompilationController>() {
+                @Override
+                public void run(CompilationController cc) throws Exception {
+                    cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
+                    TypeElement te = 
cc.getElements().getTypeElement(className);
+                    if (te != null) { // found
+                        found[0] = true;
+                    }
+                }
+            }, true);
+        } catch (IOException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        return found[0];
+        /*
+        SourceUtils.getFile(null, null);
+        ClasspathInfo.create(null, null, cp);
+
+        cp = 
org.netbeans.modules.java.source.classpath.SourcePath.create(cp, true);
+        try {
+            ClassLoader cl = cp.getClassLoader(true);
+            FileObject fo = cp.findResource(className.replace('.', 
'/').concat(".class"));
+            Class c = cl.loadClass(className);
+            System.err.println("classExistsInSources("+className+"): fo = 
"+fo+", class = "+c);
+            return c != null;
+        } catch (ClassNotFoundException ex) {
+            return false;
+        }
+        */
+    }
+    
+    /**
+     * Returns FileObject for given String.
+     */
+    private static FileObject getFileObject (String file) {
+        File f = new File (file);
+        FileObject fo = FileUtil.toFileObject (f);
+        String path = null;
+        if (fo == null && file.contains("!/")) {
+            int index = file.indexOf("!/");
+            f = new File(file.substring(0, index));
+            fo = FileUtil.toFileObject (f);
+            path = file.substring(index + "!/".length());
+        }
+        if (fo != null && FileUtil.isArchiveFile (fo)) {
+            fo = FileUtil.getArchiveRoot (fo);
+            if (path !=null) {
+                fo = fo.getFileObject(path);
+            }
+        }
+        return fo;
+    }
+
     protected final void setClassRequests (
         String[] classFilters,
         String[] classExclusionFilters,
diff --git 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/FieldBreakpointImpl.java
 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/FieldBreakpointImpl.java
--- 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/FieldBreakpointImpl.java
+++ 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/FieldBreakpointImpl.java
@@ -103,10 +103,16 @@
     public FieldBreakpointImpl (FieldBreakpoint breakpoint, JPDADebuggerImpl 
debugger, Session session) {
         super (breakpoint, debugger, session);
         this.breakpoint = breakpoint;
+        setSourceRoot(""); // Just to setup source change listener
         set ();
     }
     
     @Override
+    protected boolean isEnabled() {
+        return true; // Check is in setRequests()
+    }
+    
+    @Override
     protected void setRequests () {
         ClassNames classNames = getClassFilter().filterClassNames(
                 new ClassNames(
@@ -116,6 +122,15 @@
                     new String [0]),
                 breakpoint);
         String[] names = classNames.getClassNames();
+        String[] disabledRootPtr = new String[] { null };
+        names = checkSourcesEnabled(names, disabledRootPtr);
+        if (names.length == 0) {
+            setValidity(VALIDITY.INVALID,
+                        NbBundle.getMessage(ClassBasedBreakpoint.class,
+                                    "MSG_DisabledSourceRoot",
+                                    disabledRootPtr[0]));
+            return ;
+        }
         String[] excludedNames = classNames.getExcludedClassNames();
         
         boolean access = (breakpoint.getBreakpointType () & 
diff --git 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java
 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java
--- 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java
+++ 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java
@@ -63,7 +63,6 @@
 import com.sun.source.util.SourcePositions;
 import com.sun.source.util.TreePath;
 import java.beans.PropertyChangeEvent;
-import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -71,12 +70,10 @@
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import java.util.concurrent.Future;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import javax.lang.model.element.TypeElement;
 import org.netbeans.api.debugger.Breakpoint;
 import org.netbeans.api.debugger.DebuggerManager;
 import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint;
@@ -84,13 +81,10 @@
 import org.netbeans.api.debugger.Session;
 import org.netbeans.api.debugger.jpda.JPDAThread;
 import org.netbeans.api.debugger.jpda.ObjectVariable;
-import org.netbeans.api.java.classpath.ClassPath;
 import org.netbeans.api.java.source.CancellableTask;
-import org.netbeans.api.java.source.ClasspathInfo;
 import org.netbeans.api.java.source.CompilationController;
 import org.netbeans.api.java.source.JavaSource;
 import org.netbeans.api.java.source.JavaSource.Phase;
-import org.netbeans.api.java.source.Task;
 import org.netbeans.api.java.source.TreeUtilities;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.Utilities;
@@ -111,11 +105,9 @@
 import 
org.netbeans.modules.debugger.jpda.jdi.request.EventRequestManagerWrapper;
 import org.netbeans.modules.debugger.jpda.models.JPDAThreadImpl;
 import org.netbeans.spi.debugger.jpda.BreakpointsClassFilter.ClassNames;
-import org.netbeans.spi.java.classpath.support.ClassPathSupport;
 import org.openide.ErrorManager;
 import org.openide.cookies.EditorCookie;
 import org.openide.filesystems.FileObject;
-import org.openide.filesystems.FileUtil;
 import org.openide.filesystems.URLMapper;
 import org.openide.loaders.DataObject;
 import org.openide.loaders.DataObjectNotFoundException;
@@ -294,101 +286,6 @@
         setValidity(Breakpoint.VALIDITY.INVALID, reason);
     }
 
-    private static boolean classExistsInSources(final String className, 
String[] projectSourceRoots) {
-        /*
-        ClassIndexManager cim = ClassIndexManager.getDefault();
-        List<FileObject> sourcePaths = new 
ArrayList<FileObject>(projectSourceRoots.length);
-        for (String sr : projectSourceRoots) {
-            FileObject fo = getFileObject(sr);
-            if (fo != null) {
-                sourcePaths.add(fo);
-                ClassIndexImpl ci;
-                try {
-                    ci = cim.getUsagesQuery(fo.getURL());
-                    if (ci != null) {
-                        String sourceName = ci.getSourceName(className);
-                        if (sourceName != null) {
-                            return true;
-                        }
-                    }
-                } catch (FileStateInvalidException ex) {
-                    continue;
-                } catch (java.io.IOException ioex) {
-                    continue;
-                }
-            }
-        }
-        return false;
-         */
-        List<FileObject> sourcePaths = new 
ArrayList<FileObject>(projectSourceRoots.length);
-        for (String sr : projectSourceRoots) {
-            FileObject fo = getFileObject(sr);
-            if (fo != null) {
-                sourcePaths.add(fo);
-            }
-        }
-        ClassPath cp = 
ClassPathSupport.createClassPath(sourcePaths.toArray(new FileObject[0]));
-        ClassPathSupport.createClassPath(new FileObject[] {});
-        ClasspathInfo cpInfo = 
ClasspathInfo.create(ClassPathSupport.createClassPath(new FileObject[] {}),
-                                                    
ClassPathSupport.createClassPath(new FileObject[] {}),
-                                                    cp);
-        //ClassIndex ci = cpInfo.getClassIndex();
-        JavaSource js = JavaSource.create(cpInfo);
-        final boolean[] found = new boolean[] { false };
-        try {
-            js.runUserActionTask(new Task<CompilationController>() {
-                @Override
-                public void run(CompilationController cc) throws Exception {
-                    cc.toPhase(Phase.ELEMENTS_RESOLVED);
-                    TypeElement te = 
cc.getElements().getTypeElement(className);
-                    if (te != null) { // found
-                        found[0] = true;
-                    }
-                }
-            }, true);
-        } catch (IOException ex) {
-            Exceptions.printStackTrace(ex);
-        }
-        return found[0];
-        /*
-        SourceUtils.getFile(null, null);
-        ClasspathInfo.create(null, null, cp);
-
-        cp = 
org.netbeans.modules.java.source.classpath.SourcePath.create(cp, true);
-        try {
-            ClassLoader cl = cp.getClassLoader(true);
-            FileObject fo = cp.findResource(className.replace('.', 
'/').concat(".class"));
-            Class c = cl.loadClass(className);
-            System.err.println("classExistsInSources("+className+"): fo = 
"+fo+", class = "+c);
-            return c != null;
-        } catch (ClassNotFoundException ex) {
-            return false;
-        }
-        */
-    }
-
-    /**
-     * Returns FileObject for given String.
-     */
-    private static FileObject getFileObject (String file) {
-        File f = new File (file);
-        FileObject fo = FileUtil.toFileObject (f);
-        String path = null;
-        if (fo == null && file.contains("!/")) {
-            int index = file.indexOf("!/");
-            f = new File(file.substring(0, index));
-            fo = FileUtil.toFileObject (f);
-            path = file.substring(index + "!/".length());
-        }
-        if (fo != null && FileUtil.isArchiveFile (fo)) {
-            fo = FileUtil.getArchiveRoot (fo);
-            if (path !=null) {
-                fo = fo.getFileObject(path);
-            }
-        }
-        return fo;
-    }
-
     @Override
     protected void classLoaded (List<ReferenceType> referenceTypes) {
         LineBreakpoint breakpoint = getBreakpoint();
diff --git 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/MethodBreakpointImpl.java
 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/MethodBreakpointImpl.java
--- 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/MethodBreakpointImpl.java
+++ 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/MethodBreakpointImpl.java
@@ -111,10 +111,16 @@
     public MethodBreakpointImpl (MethodBreakpoint breakpoint, 
JPDADebuggerImpl debugger, Session session) {
         super (breakpoint, debugger, session);
         this.breakpoint = breakpoint;
+        setSourceRoot(""); // Just to setup source change listener
         set ();
     }
     
     @Override
+    protected boolean isEnabled() {
+        return true; // Check is in setRequests()
+    }
+    
+    @Override
     protected void setRequests () {
         ClassNames classNames = getClassFilter().filterClassNames(
                 new ClassNames(
@@ -122,6 +128,15 @@
                     breakpoint.getClassExclusionFilters()),
                 breakpoint);
         String[] names = classNames.getClassNames();
+        String[] disabledRootPtr = new String[] { null };
+        names = checkSourcesEnabled(names, disabledRootPtr);
+        if (names.length == 0) {
+            setValidity(VALIDITY.INVALID,
+                        NbBundle.getMessage(ClassBasedBreakpoint.class,
+                                    "MSG_DisabledSourceRoot",
+                                    disabledRootPtr[0]));
+            return ;
+        }
         String[] excludedNames = classNames.getExcludedClassNames();
         setClassRequests (
             names,

[hg] main-silver: #118086: Assure that field or method breakpoin...

mentlicher 12/01/2012

Project Features

About this Project

Debugger was started in November 2009, is owned by tpavek, and has 29 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close