Sending call stacks.
authorTomas Zezula <tzezula@netbeans.org>
Thu, 30 Jan 2014 14:41:39 +0100
changeset 18137fa60f5cbc517
parent 18136 f7eb8650b427
child 18138 26ed57549dd5
Sending call stacks.
dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/ActiveSessions.java
dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/CompoundContextProvider.java
     1.1 --- a/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/ActiveSessions.java	Thu Jan 30 14:15:54 2014 +0100
     1.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/ActiveSessions.java	Thu Jan 30 14:41:39 2014 +0100
     1.3 @@ -47,6 +47,7 @@
     1.4  import java.beans.PropertyChangeEvent;
     1.5  import java.beans.PropertyChangeListener;
     1.6  import java.io.File;
     1.7 +import java.util.List;
     1.8  import java.util.concurrent.ConcurrentHashMap;
     1.9  import java.util.concurrent.ConcurrentMap;
    1.10  import java.util.concurrent.atomic.AtomicInteger;
    1.11 @@ -144,6 +145,7 @@
    1.12          final WorkspaceResolver.Context ctx;
    1.13          final EndPoint.Env env;
    1.14          final Session session;
    1.15 +        final SourcePathProvider sourcePath;
    1.16          final JPDADebugger jpda;
    1.17          volatile JPDAThread currentThread;
    1.18  
    1.19 @@ -161,6 +163,7 @@
    1.20              this.ctx = ctx;
    1.21              this.env = env;
    1.22              this.session = session;
    1.23 +            sourcePath = getContext(session);
    1.24              this.jpda = this.session.lookupFirst(null, JPDADebugger.class);
    1.25              if (!(jpda instanceof JPDADebuggerImpl)) {
    1.26                  throw new IllegalStateException("Wrong debugger service.");    //NOI18N
    1.27 @@ -212,7 +215,6 @@
    1.28                      throw new IllegalStateException("No workspace resolver.");  //NOI18N
    1.29                  }
    1.30                  final FileObject root = wr.resolveFile(ctx);
    1.31 -                final SourcePathProvider spp = session.lookupFirst(null, SourcePathProvider.class);
    1.32                  for (CallStackFrame csf : callStack) {
    1.33                      String relativePath;
    1.34                      try {
    1.35 @@ -220,7 +222,7 @@
    1.36                      } catch (AbsentInformationException e) {
    1.37                          relativePath = "<unknown>";
    1.38                      }
    1.39 -                    final String surl = spp.getURL (relativePath, true);
    1.40 +                    final String surl = sourcePath.getURL (relativePath, true);
    1.41                      if (surl != null) {
    1.42                          try {
    1.43                             final FileObject fo = URLMapper.findFileObject(new java.net.URL(surl));
    1.44 @@ -235,7 +237,7 @@
    1.45                          }
    1.46                      }
    1.47                      res.getStack().add(String.format(
    1.48 -                        "src/%s:%d",
    1.49 +                        "%s:%d",
    1.50                          relativePath,
    1.51                          csf.getLineNumber(null)));
    1.52                  }
    1.53 @@ -243,6 +245,18 @@
    1.54              return res;
    1.55           }
    1.56  
    1.57 +        private SourcePathProvider getContext (Session session) {
    1.58 +           List<? extends SourcePathProvider> l = session.lookup(null, SourcePathProvider.class);
    1.59 +           SourcePathProvider sourcePathProvider = l.get(0);
    1.60 +           int i, k = l.size ();
    1.61 +           for (i = 1; i < k; i++) {
    1.62 +               sourcePathProvider = new CompoundContextProvider (
    1.63 +                   (SourcePathProvider) l.get (i),
    1.64 +                   sourcePathProvider
    1.65 +               );
    1.66 +           }
    1.67 +           return sourcePathProvider;
    1.68 +        }
    1.69      }
    1.70  
    1.71  }
    1.72 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/CompoundContextProvider.java	Thu Jan 30 14:41:39 2014 +0100
     2.3 @@ -0,0 +1,228 @@
     2.4 +/*
     2.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     2.6 + *
     2.7 + * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
     2.8 + *
     2.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    2.10 + * Other names may be trademarks of their respective owners.
    2.11 + *
    2.12 + * The contents of this file are subject to the terms of either the GNU
    2.13 + * General Public License Version 2 only ("GPL") or the Common
    2.14 + * Development and Distribution License("CDDL") (collectively, the
    2.15 + * "License"). You may not use this file except in compliance with the
    2.16 + * License. You can obtain a copy of the License at
    2.17 + * http://www.netbeans.org/cddl-gplv2.html
    2.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    2.19 + * specific language governing permissions and limitations under the
    2.20 + * License.  When distributing the software, include this License Header
    2.21 + * Notice in each file and include the License file at
    2.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    2.23 + * particular file as subject to the "Classpath" exception as provided
    2.24 + * by Oracle in the GPL Version 2 section of the License file that
    2.25 + * accompanied this code. If applicable, add the following below the
    2.26 + * License Header, with the fields enclosed by brackets [] replaced by
    2.27 + * your own identifying information:
    2.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    2.29 + *
    2.30 + * If you wish your version of this file to be governed by only the CDDL
    2.31 + * or only the GPL Version 2, indicate your decision by adding
    2.32 + * "[Contributor] elects to include this software in this distribution
    2.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    2.34 + * single choice of license, a recipient has the option to distribute
    2.35 + * your version of this file under either the CDDL, the GPL Version 2 or
    2.36 + * to extend the choice of license to its licensees as provided above.
    2.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    2.38 + * Version 2 license, then the option applies only if the new code is
    2.39 + * made subject to such option by the copyright holder.
    2.40 + *
    2.41 + * Contributor(s):
    2.42 + *
    2.43 + * Portions Copyrighted 2014 Sun Microsystems, Inc.
    2.44 + */
    2.45 +
    2.46 +package org.netbeans.modules.dew4nb.services.debugger;
    2.47 +
    2.48 +import java.beans.PropertyChangeListener;
    2.49 +import java.lang.reflect.InvocationTargetException;
    2.50 +import java.util.logging.Level;
    2.51 +import java.util.logging.Logger;
    2.52 +import org.netbeans.api.debugger.jpda.JPDAClassType;
    2.53 +import org.netbeans.spi.debugger.jpda.SourcePathProvider;
    2.54 +
    2.55 +class CompoundContextProvider extends SourcePathProvider {
    2.56 +
    2.57 +        private SourcePathProvider cp1, cp2;
    2.58 +
    2.59 +        CompoundContextProvider (
    2.60 +            SourcePathProvider cp1,
    2.61 +            SourcePathProvider cp2
    2.62 +        ) {
    2.63 +            this.cp1 = cp1;
    2.64 +            this.cp2 = cp2;
    2.65 +        }
    2.66 +
    2.67 +        public String getURL (String relativePath, boolean global) {
    2.68 +            String p1 = cp1.getURL (relativePath, global);
    2.69 +            if (p1 != null) {
    2.70 +                try {
    2.71 +                    new java.net.URL(p1);
    2.72 +                    return p1;
    2.73 +                } catch (java.net.MalformedURLException muex) {
    2.74 +                    Logger.getLogger(CompoundContextProvider.class.getName()).log(Level.WARNING,
    2.75 +                            "Malformed URL '"+p1+"' produced by "+cp1, muex);
    2.76 +                }
    2.77 +            }
    2.78 +            p1 = cp2.getURL (relativePath, global);
    2.79 +            if (p1 != null) {
    2.80 +                try {
    2.81 +                    new java.net.URL(p1);
    2.82 +                } catch (java.net.MalformedURLException muex) {
    2.83 +                    Logger.getLogger(CompoundContextProvider.class.getName()).log(Level.WARNING,
    2.84 +                            "Malformed URL '"+p1+"' produced by "+cp2, muex);
    2.85 +                    p1 = null;
    2.86 +                }
    2.87 +            }
    2.88 +            return p1;
    2.89 +        }
    2.90 +
    2.91 +        public String getURL(JPDAClassType clazz, String stratum) {
    2.92 +            try {
    2.93 +                java.lang.reflect.Method getURLMethod = cp1.getClass().getMethod("getURL", JPDAClassType.class, String.class); // NOI18N
    2.94 +                String url = (String) getURLMethod.invoke(cp1, clazz, stratum);
    2.95 +                if (url != null) {
    2.96 +                    return url;
    2.97 +                }
    2.98 +            } catch (IllegalAccessException ex) {
    2.99 +            } catch (IllegalArgumentException ex) {
   2.100 +            } catch (NoSuchMethodException ex) {
   2.101 +            } catch (SecurityException ex) {
   2.102 +            } catch (InvocationTargetException ex) {
   2.103 +            }
   2.104 +            try {
   2.105 +                java.lang.reflect.Method getURLMethod = cp2.getClass().getMethod("getURL", JPDAClassType.class, String.class); // NOI18N
   2.106 +                String url = (String) getURLMethod.invoke(cp2, clazz, stratum);
   2.107 +                if (url != null) {
   2.108 +                    return url;
   2.109 +                }
   2.110 +            } catch (IllegalAccessException ex) {
   2.111 +            } catch (IllegalArgumentException ex) {
   2.112 +            } catch (NoSuchMethodException ex) {
   2.113 +            } catch (SecurityException ex) {
   2.114 +            } catch (InvocationTargetException ex) {
   2.115 +            }
   2.116 +            return null;
   2.117 +        }
   2.118 +
   2.119 +        public String getRelativePath (
   2.120 +            String url,
   2.121 +            char directorySeparator,
   2.122 +            boolean includeExtension
   2.123 +        ) {
   2.124 +            String p1 = cp1.getRelativePath (
   2.125 +                url,
   2.126 +                directorySeparator,
   2.127 +                includeExtension
   2.128 +            );
   2.129 +            if (p1 != null) return p1;
   2.130 +            return cp2.getRelativePath (
   2.131 +                url,
   2.132 +                directorySeparator,
   2.133 +                includeExtension
   2.134 +            );
   2.135 +        }
   2.136 +
   2.137 +        public String[] getSourceRoots () {
   2.138 +            String[] fs1 = cp1.getSourceRoots ();
   2.139 +            String[] fs2 = cp2.getSourceRoots ();
   2.140 +            String[] fs = new String [fs1.length + fs2.length];
   2.141 +            System.arraycopy (fs1, 0, fs, 0, fs1.length);
   2.142 +            System.arraycopy (fs2, 0, fs, fs1.length, fs2.length);
   2.143 +            return fs;
   2.144 +        }
   2.145 +
   2.146 +        public String[] getOriginalSourceRoots () {
   2.147 +            String[] fs1 = cp1.getOriginalSourceRoots ();
   2.148 +            String[] fs2 = cp2.getOriginalSourceRoots ();
   2.149 +            String[] fs = new String [fs1.length + fs2.length];
   2.150 +            System.arraycopy (fs1, 0, fs, 0, fs1.length);
   2.151 +            System.arraycopy (fs2, 0, fs, fs1.length, fs2.length);
   2.152 +            return fs;
   2.153 +        }
   2.154 +
   2.155 +        public void setSourceRoots (String[] sourceRoots) {
   2.156 +            cp1.setSourceRoots (sourceRoots);
   2.157 +            cp2.setSourceRoots (sourceRoots);
   2.158 +        }
   2.159 +
   2.160 +        public String[] getAdditionalSourceRoots() {
   2.161 +            String[] additionalSourceRoots1;
   2.162 +            String[] additionalSourceRoots2;
   2.163 +            //System.err.println("\nCompoundContextProvider["+toString()+"].getadditionalSourceRoots()...\n");
   2.164 +            try {
   2.165 +                java.lang.reflect.Method getAdditionalSourceRootsMethod = cp1.getClass().getMethod("getAdditionalSourceRoots", new Class[] {}); // NOI18N
   2.166 +                additionalSourceRoots1 = (String[]) getAdditionalSourceRootsMethod.invoke(cp1, new Object[] {});
   2.167 +            } catch (Exception ex) {
   2.168 +                additionalSourceRoots1 = new String[0];
   2.169 +            }
   2.170 +            try {
   2.171 +                java.lang.reflect.Method getAdditionalSourceRootsMethod = cp2.getClass().getMethod("getAdditionalSourceRoots", new Class[] {}); // NOI18N
   2.172 +                additionalSourceRoots2 = (String[]) getAdditionalSourceRootsMethod.invoke(cp2, new Object[] {});
   2.173 +            } catch (Exception ex) {
   2.174 +                additionalSourceRoots2 = new String[0];
   2.175 +            }
   2.176 +            if (additionalSourceRoots1.length == 0) {
   2.177 +                //System.err.println("\nCompoundContextProvider.getAdditionalSourceRoots() = "+java.util.Arrays.toString(additionalSourceRoots2)+"\n");
   2.178 +                return additionalSourceRoots2;
   2.179 +            }
   2.180 +            if (additionalSourceRoots2.length == 0) {
   2.181 +                //System.err.println("\nCompoundContextProvider.getAdditionalSourceRoots() = "+java.util.Arrays.toString(additionalSourceRoots1)+"\n");
   2.182 +                return additionalSourceRoots1;
   2.183 +            }
   2.184 +            String[] additionalSourceRoots = new String[additionalSourceRoots1.length + additionalSourceRoots2.length];
   2.185 +            System.arraycopy (additionalSourceRoots1, 0, additionalSourceRoots, 0, additionalSourceRoots1.length);
   2.186 +            System.arraycopy (additionalSourceRoots2, 0, additionalSourceRoots, additionalSourceRoots1.length, additionalSourceRoots2.length);
   2.187 +            //System.err.println("\nCompoundContextProvider.getAdditionalSourceRoots() = "+java.util.Arrays.toString(additionalSourceRoots)+"\n");
   2.188 +            return additionalSourceRoots;
   2.189 +        }
   2.190 +
   2.191 +        public void setSourceRoots (String[] sourceRoots, String[] additionalRoots) {
   2.192 +            try {
   2.193 +                java.lang.reflect.Method setSourceRootsMethod = cp1.getClass().getMethod("setSourceRoots", String[].class, String[].class); // NOI18N
   2.194 +                setSourceRootsMethod.invoke(cp1, new Object[] { sourceRoots, additionalRoots });
   2.195 +            } catch (Exception ex) {
   2.196 +                cp1.setSourceRoots(sourceRoots);
   2.197 +            }
   2.198 +            try {
   2.199 +                java.lang.reflect.Method setSourceRootsMethod = cp2.getClass().getMethod("setSourceRoots", String[].class, String[].class); // NOI18N
   2.200 +                setSourceRootsMethod.invoke(cp2, new Object[] { sourceRoots, additionalRoots });
   2.201 +            } catch (Exception ex) {
   2.202 +                cp2.setSourceRoots(sourceRoots);
   2.203 +            }
   2.204 +        }
   2.205 +
   2.206 +        public void reorderOriginalSourceRoots(int[] permutation) {
   2.207 +            try {
   2.208 +                java.lang.reflect.Method reorderOriginalSourceRootsMethod = cp1.getClass().getMethod("reorderOriginalSourceRoots", int[].class); // NOI18N
   2.209 +                reorderOriginalSourceRootsMethod.invoke(cp1, new Object[] { permutation });
   2.210 +            } catch (Exception ex) {
   2.211 +
   2.212 +            }
   2.213 +            try {
   2.214 +                java.lang.reflect.Method reorderOriginalSourceRootsMethod = cp2.getClass().getMethod("reorderOriginalSourceRoots", int[].class); // NOI18N
   2.215 +                reorderOriginalSourceRootsMethod.invoke(cp2, new Object[] { permutation });
   2.216 +            } catch (Exception ex) {
   2.217 +
   2.218 +            }
   2.219 +        }
   2.220 +
   2.221 +        public void addPropertyChangeListener (PropertyChangeListener l) {
   2.222 +            cp1.addPropertyChangeListener (l);
   2.223 +            cp2.addPropertyChangeListener (l);
   2.224 +        }
   2.225 +
   2.226 +        public void removePropertyChangeListener (PropertyChangeListener l) {
   2.227 +            cp1.removePropertyChangeListener (l);
   2.228 +            cp2.removePropertyChangeListener (l);
   2.229 +        }
   2.230 +}
   2.231 +