adding support for innocent classes in componnent matching uihandlerserver_merge_071122
authorjsedek@netbeans.org
Tue, 20 Nov 2007 18:46:51 +0000
changeset 271582895a9569d1
parent 2714 ce44f22faa67
child 2716 d2184754846a
adding support for innocent classes in componnent matching
logger/uihandlerserver/src/java/org/netbeans/server/componentsmatch/Matcher.java
logger/uihandlerserver/test/org/netbeans/server/componentsmatch/MatcherTest.java
     1.1 --- a/logger/uihandlerserver/src/java/org/netbeans/server/componentsmatch/Matcher.java	Tue Nov 20 18:45:53 2007 +0000
     1.2 +++ b/logger/uihandlerserver/src/java/org/netbeans/server/componentsmatch/Matcher.java	Tue Nov 20 18:46:51 2007 +0000
     1.3 @@ -50,6 +50,8 @@
     1.4  import java.util.List;
     1.5  import java.util.Map;
     1.6  import java.util.StringTokenizer;
     1.7 +import org.netbeans.modules.exceptions.entity.InnocentClass;
     1.8 +import org.netbeans.modules.exceptions.utils.PersistenceUtils;
     1.9  
    1.10  /**
    1.11   * convert stacktrace to Component
    1.12 @@ -58,6 +60,7 @@
    1.13      static Matcher packageMerger;
    1.14      
    1.15      static List<Package> allPackages;
    1.16 +    static List<InnocentClass> innocents;
    1.17      
    1.18      static Matcher defaultMatcher;
    1.19      static final String ORG_NETBEANS_MODULES = "org.netbeans.modules";
    1.20 @@ -108,6 +111,7 @@
    1.21       * @param stes exception stacktrace
    1.22       */
    1.23      public Component match(StackTraceElement[] stes){
    1.24 +        innocents = PersistenceUtils.getInstance().getAll(InnocentClass.class);
    1.25          Component[] comp = Matcher.getDefault().matchAll(stes);
    1.26          for (int i=0; i<comp.length; i++){
    1.27              if (comp[i] == null){
    1.28 @@ -122,6 +126,9 @@
    1.29      
    1.30      private  Component match(StackTraceElement ste) {
    1.31          String className = ste.getClassName();
    1.32 +        if (isInnocent(className)){
    1.33 +            return null;
    1.34 +        }
    1.35          int index = 0;
    1.36          while ((index = className.indexOf('.',index)) != -1) {
    1.37              if ( index + 1 < className.length()) {
    1.38 @@ -206,6 +213,15 @@
    1.39          }
    1.40      }
    1.41      
    1.42 +    private boolean isInnocent(String className){
    1.43 +        for (InnocentClass innocent : innocents) {
    1.44 +            if (className.contains(innocent.getClassname())){
    1.45 +                return true;
    1.46 +            }
    1.47 +        }
    1.48 +        return false;
    1.49 +    }
    1.50 +    
    1.51      private static boolean checkNetBeansOrgSubPackage(String pack) {
    1.52          for (String prefix : NB_ORG_PREFIXES) {
    1.53              if (pack.startsWith(prefix)) {
     2.1 --- a/logger/uihandlerserver/test/org/netbeans/server/componentsmatch/MatcherTest.java	Tue Nov 20 18:45:53 2007 +0000
     2.2 +++ b/logger/uihandlerserver/test/org/netbeans/server/componentsmatch/MatcherTest.java	Tue Nov 20 18:46:51 2007 +0000
     2.3 @@ -1,23 +1,25 @@
     2.4  
     2.5  package org.netbeans.server.componentsmatch;
     2.6  
     2.7 -import org.netbeans.server.componentsmatch.Package;
     2.8  import java.io.IOException;
     2.9  import java.io.InputStreamReader;
    2.10 -import junit.framework.TestCase;
    2.11 +import java.io.StringReader;
    2.12 +import org.netbeans.modules.exceptions.entity.InnocentClass;
    2.13 +import org.netbeans.server.uihandler.DatabaseTestCase;
    2.14  
    2.15  /**
    2.16   *
    2.17   * @author pzajac
    2.18   */
    2.19 -public class MatcherTest extends TestCase{
    2.20 +public class MatcherTest extends DatabaseTestCase{
    2.21      
    2.22      /** Creates a new instance of MatcherTest */
    2.23      public MatcherTest(String name) {
    2.24          super(name);
    2.25      }
    2.26      
    2.27 -    public void testSimple() {
    2.28 +    public void testSimple() throws IOException {
    2.29 +        Matcher.read(new StringReader(""));//clean Matcher
    2.30          Package fsPack = new Package("org.openide.filesystems");
    2.31          Component fsComp = new Component("openide","filesystems",4);
    2.32          Component openideCodeComp = new Component("openide","code",2);
    2.33 @@ -137,4 +139,40 @@
    2.34          assertFalse("core".equals(comp.getComponent()));
    2.35     }
    2.36   
    2.37 +    public void testInnocent() throws IOException{
    2.38 +        Matcher.read(new InputStreamReader (Matcher.class.getResourceAsStream("componentmapping.txt")));
    2.39 +        Matcher matcher = Matcher.getDefault();
    2.40 +        
    2.41 +        Component comp = matcher.match(new StackTraceElement[] {
    2.42 +            new StackTraceElement("org.openide.util.lookup.InstanceContent$SimpleItem","<init>","file",45)
    2.43 +        });
    2.44 +        assertNotNull(comp);//no Innocent
    2.45 +        
    2.46 +        comp = matcher.match(new StackTraceElement[] {
    2.47 +            new StackTraceElement("org.openide.util.lookup.SimpleLookup","<init>","file",45)
    2.48 +        });
    2.49 +        assertNotNull(comp);//no Innocent
    2.50 +
    2.51 +        perUtils.persist(new InnocentClass("org.openide.util.lookup")); // look up is innocent
    2.52 +
    2.53 +        comp = matcher.match(new StackTraceElement[] {
    2.54 +            new StackTraceElement("org.openide.util.lookup.InstanceContent$SimpleItem","<init>","file",45)
    2.55 +        });
    2.56 +        assertNull(comp);
    2.57 +        
    2.58 +        comp = matcher.match(new StackTraceElement[] {
    2.59 +            new StackTraceElement("org.openide.util.lookup.SimpleLookup","<init>","file",45)
    2.60 +        });
    2.61 +        assertNull(comp);
    2.62 +        
    2.63 +        comp = matcher.match(new StackTraceElement[] {
    2.64 +            new StackTraceElement("org.openide.util.lookup.Lookups","<init>","file",45)
    2.65 +        });
    2.66 +        assertNull(comp);
    2.67 +
    2.68 +        comp = matcher.match(new StackTraceElement[] {
    2.69 +            new StackTraceElement("org.openide.util.Enumerations","<init>","file",45)
    2.70 +        });
    2.71 +        assertNotNull(comp);
    2.72 +    }
    2.73  }