? test/unit/src/org/openide/util/data/services-jar-1/META-INF/services/java.lang.Runnable ? test/unit/src/org/openide/util/data/services-jar-1/org/foo/impl/Runnable1.java ? test/unit/src/org/openide/util/data/services-jar-2/META-INF/services/java.lang.Runnable Index: src/org/openide/util/MetaInfServicesLookup.java =================================================================== RCS file: /cvs/openide/src/org/openide/util/MetaInfServicesLookup.java,v retrieving revision 1.2 diff -c -r1.2 MetaInfServicesLookup.java *** src/org/openide/util/MetaInfServicesLookup.java 5 Feb 2002 12:34:31 -0000 1.2 --- src/org/openide/util/MetaInfServicesLookup.java 26 Jul 2002 09:22:00 -0000 *************** *** 96,102 **** // has the same entry in it (and they load to the same class). // Probably would not happen, assuming JARs only list classes // they own, but just in case... ! Set foundClasses = new HashSet(); // Set boolean foundOne = false; while (en.hasMoreElements()) { --- 96,103 ---- // has the same entry in it (and they load to the same class). // Probably would not happen, assuming JARs only list classes // they own, but just in case... ! Collection foundClasses = new ArrayList (); // Collection ! Collection removeClasses = new ArrayList (); // Collection boolean foundOne = false; while (en.hasMoreElements()) { *************** *** 139,152 **** line = line.trim(); if (line.length() == 0) continue; if (line.charAt(0) == '#') continue; // NOI18N // Most lines are fully-qualified class names. Class inst = Class.forName(line, false, loader); if (!clazz.isAssignableFrom(inst)) { throw new ClassNotFoundException(inst.getName() + " not a subclass of " + clazz.getName()); // NOI18N } ! if (foundClasses.add(inst)) { ! result.add(new P(inst)); } } } finally { --- 140,161 ---- line = line.trim(); if (line.length() == 0) continue; if (line.charAt(0) == '#') continue; // NOI18N + + boolean remove = line.charAt (0) == '-'; // NOI18N + if (remove) { + line = line.substring (1); + } // Most lines are fully-qualified class names. Class inst = Class.forName(line, false, loader); if (!clazz.isAssignableFrom(inst)) { throw new ClassNotFoundException(inst.getName() + " not a subclass of " + clazz.getName()); // NOI18N } ! ! if (remove) { ! removeClasses.add (inst); ! } else { ! foundClasses.add(inst); } } } finally { *************** *** 157,162 **** --- 166,178 ---- } catch (IOException ex) { ErrorManager.getDefault().notify(ex); } + } + + foundClasses.removeAll (removeClasses); + Iterator it = foundClasses.iterator (); + while (it.hasNext ()) { + Class inst = (Class)it.next (); + result.add(new P(inst)); } } Index: test/unit/src/org/openide/util/MetaInfServicesLookupTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/util/MetaInfServicesLookupTest.java,v retrieving revision 1.2 diff -c -r1.2 MetaInfServicesLookupTest.java *** test/unit/src/org/openide/util/MetaInfServicesLookupTest.java 5 Feb 2002 12:34:31 -0000 1.2 --- test/unit/src/org/openide/util/MetaInfServicesLookupTest.java 26 Jul 2002 09:22:01 -0000 *************** *** 89,92 **** --- 89,101 ---- assertEquals(first, second); } + public void testMaskingOfResources () throws Exception { + Lookup l1 = new MetaInfServicesLookup (c1); + Lookup l2 = new MetaInfServicesLookup (c2); + Lookup l4 = new MetaInfServicesLookup (c4); + + assertNotNull ("services1.jar defines a class that implements runnable", l1.lookup (Runnable.class)); + assertNull ("services2.jar does not defines a class that implements runnable", l2.lookup (Runnable.class)); + assertNull ("services1.jar defines Runnable, but services2.jar masks it out", l4.lookup (Runnable.class)); + } }