SourcesHelper.registerExternalSourceRoots Javadoc states:
"You may _not_ call this method inside the project's constructor, as it requires the actual project to exist and be
registered in ProjectManager. Typically you would use Mutex.postWriteRequest to run it later, if you were creating the
helper in your constructor, since the project construction normally occurs in read access."
Unfortunately using pWR results in strange threading behavior, including unreliable tests (see #b5f07b919bea and
#abb8ce297ad9 for example).
Perhaps this weirdness could be avoided if the SourcesHelper constructor took an optional Project object (with the
understanding that it need not yet be registered in ProjectManager). Then it would not need to find the Project from the
AntProjectHelper, which would make it possible to register the external source roots synchronously.
Created attachment 69591 [details]
Start of a patch
Has been a problem since the creation of SourcesHelper.
Well, if that's all what needs to be done to resolve this issue then I wonder why have not we done it earlier. Patch
looks good to me. Thanks Jesse.
I would love to have this in 6.5, but if not, then I will need to work around the timing in the Eclipse project
importer: after creating a new j2seproject (or web project), it cannot immediately use ProjectClassPathModifier, as
external roots will not yet be owned; it needs to delay this action using postWriteRequest (to run after the
Let's fix it for 6.5. Have you intentionally passed it to Milan or would you implement it yourself Jesse? If you
introduce new API I'm happy to update Web/J2EE projects separately.
I just passed it to Milan as default owner and to get a review. I don't mind doing the work but it seems too late to
make a change like this for 6.5, isn't it?
Actually it seems that this is not such a high priority; in the case of the Eclipse project import, the roots are
actually registered inside the call to J2SEProjectGenerator.createProject, since we are running all this in write access:
There seems to be some other problem making Eclipse import with external roots be broken, but I am still investigating
what that might be.
*** Issue 142938 has been marked as a duplicate of this issue. ***
Lack of this seems to prevent a simple-looking patch to projectimport.eclipse.core from working (an AE is thrown similar
to issue #142938 when you try to import a project). I will attach that patch here.
Created attachment 75644 [details]
Reassigning to Jesse.
Created attachment 78555 [details]
Created attachment 79246 [details]
Running patch... still working on this, expect to commit soon
Integrated into 'main-golden', will be available in build *200904031400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
User: Jesse Glick <email@example.com>
Log: Issue #146852: accept Project in a constructor for SourcesHelper to permit registerExternalRoots to run synch.
Can help simplify tests, and makes control flow easier to understand and debug.
Also taking advantage of synchronous control flow to optimize class loading in the Eclipse importer.
*** Issue 154263 has been marked as a duplicate of this issue. ***