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.
After the fix of bug #153655, AntBasedGenericType instances are registered in the Services folder in the SFS. This is very awkward for unit tests and standalone apps using NB modules as libraries, because it forces you to load the module system for FolderLookup[Services, or at least define a custom global Lookup: public class Main extends ProxyLookup { public static void main(String[] args) throws Exception { System.setProperty(Lookup.class.getName(), Main.class.getName()); ((Main) Lookup.getDefault()).init(); FileObject fo = ...; Project p = ProjectManager.getDefault().findProject(fo); // use p... } public Main() { super(Lookups.fixed(Main.class.getClassLoader()), Lookups.metaInfServices(Main.class.getClassLoader())); } private void init() { setLookups(Lookups.fixed(Main.class.getClassLoader()), Lookups.metaInfServices(Main.class.getClassLoader()), Lookups.forPath("Services")); } } The most general fix would of course be for Lookup.getDefault to include Services without doing anything special, though this could potentially break various tests; it would also not be trivial since you need to load all subdirs of Services/ in general (this seems to happen automatically when deps of java.j2seproject are in CP, not sure how). But the simpler thing to do is change how AntBasedProcessor registers instances, and how AntBasedProjectFactorySingleton looks for them. Currently the processor dumps them all in Services/AntBasedProjectTypes/ and forces all the registrations to be loaded, which seems silly. Simpler would be to register AntBasedProjectType/$type/*.instance, and make AntBasedProjectFactorySingleton.findAntBasedProjectType check Lookups.forPath("AntBasedProjectType/" + type), later checking antBasedProjectTypes for compatibility. This would be slightly more efficient than the current state, and would work smoothly without the module system. Not sure what the impact on ide.ergonomics would be; probably would need a small tweak to match.
Changing the default is impossible. That would break some tests (I already tried). Instead I created a property http://bits.netbeans.org/dev/javadoc/org-openide-util-lookup/apichanges.html#org.openide.util.Lookup.paths Set it in your test to "Services". If the previous advice works I don't see a need for any further changes.
(In reply to comment #1) > Changing the default is impossible. That would break some tests (I already > tried). You tried registering AntBasedProjectType's in a specific folder already? What broke exactly? AFAIK only project.ant and ide.ergonomics should be affected. *** This bug has been marked as a duplicate of bug 166782 ***
> The most general fix would of course be for Lookup.getDefault to include > Services without doing anything special Re. "changing the default" - I tried to change the above and that has led to a lot of test failures.
Understood that the more general fix is problematic, but what is wrong with the simpler fix? As far as I can tell this would not have any broad-ranging effects, and Ant-based project types would work "out of the box" in standalone mode without having to know about and employ special tricks like Lookup.paths - a major stumbling block for people just trying to get something to work. I could certainly do the project.ant portion of such a fix, but I am unsure what assumptions ide.ergonomics is making about the current system.
The basic problem as far as I can tell is that Lookup.getDefault() does not include Lookups.forPath("Services") by default. Certainly, I'd like to change that, but the amount of tests that would need to be fixed (by System.setProperty("org.openide.util.Lookup.paths", "")) would be probably really high and I don't feel I have time for that now.
But changing the processor to put factories in specified folders and then checking Lookups.forPath("AntBasedProjectType/" + type) preferentially at runtime would have no effect on other code. Doing the change would be trivial except for ergonomics which seems to be making assumptions about the current layout.
Integrated into 'main-golden', will be available in build *201102050000* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main/rev/17b96241f15c User: Jesse Glick <jglick@netbeans.org> Log: Diagnostics for random SourceLevelQueryImplTest.testGetSourceLevelWithBrokenPlatform failure in NB-Core-Build #5932 and earlier. Hypothesizing that #194703 is related to instability, but may be something else in loaders/lookups.