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.

Bug 194703 - Placing java.j2seproject (+ deps) in CP no longer suffices to load a j2seproject
Summary: Placing java.j2seproject (+ deps) in CP no longer suffices to load a j2seproject
Status: RESOLVED DUPLICATE of bug 166782
Alias: None
Product: projects
Classification: Unclassified
Component: Ant Project (show other bugs)
Version: 6.x
Hardware: All All
: P3 normal (vote)
Assignee: Jaroslav Tulach
URL:
Keywords: ERGONOMICS, REGRESSION
Depends on:
Blocks: 153655
  Show dependency tree
 
Reported: 2011-01-25 17:59 UTC by Jesse Glick
Modified: 2011-02-05 06:07 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2011-01-25 17:59:21 UTC
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.
Comment 1 Jaroslav Tulach 2011-01-31 20:41:50 UTC
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.
Comment 2 Jesse Glick 2011-01-31 21:20:18 UTC
(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 ***
Comment 3 Jaroslav Tulach 2011-01-31 22:15:20 UTC
> 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.
Comment 4 Jesse Glick 2011-01-31 22:25:46 UTC
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.
Comment 5 Jaroslav Tulach 2011-02-03 20:33:04 UTC
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.
Comment 6 Jesse Glick 2011-02-03 22:36:23 UTC
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.
Comment 7 Quality Engineering 2011-02-05 06:07:20 UTC
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.