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 195252 - Offer to download JUnit before creating tests
Summary: Offer to download JUnit before creating tests
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: JUnit (show other bugs)
Version: 7.0
Hardware: All All
: P1 normal (vote)
Assignee: Jesse Glick
URL:
Keywords:
: 195182 (view as bug list)
Depends on:
Blocks: 195849
  Show dependency tree
 
Reported: 2011-02-09 20:36 UTC by Jesse Glick
Modified: 2011-03-01 17:50 UTC (History)
5 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2011-02-09 20:36:04 UTC
New File wizards in the JUnit category, and Tools > Create JUnit Tests, should offer to install the JUnit library before proceeding. The easiest way to do this is to depend on java.project 1.35 and call:

for (LibraryDefiner definer : Lookup.getDefault().lookupAll(LibraryDefiner.class)) {
  Callable<Library> download = definer.missingLibrary("junit_4"); // or "junit"
  if (download != null) {
    // if in a background thread, else post to an RP when ready to proceed:
    try {
      Library found = download.call();
      // use it...
    } catch (Exception x) {
      // notify at INFO only
    }
  }
}

Note that the callable must have completed before DefaultPlugin.storeProjectSettingsJUnitVer, even if the project is a Maven project, since the current ProjectClassPathModifier API requires an actual Library instance to be passed (while Maven projects only pay attention to the special maven-pom volume).
Comment 1 John Jullion-ceccarelli 2011-02-10 08:56:50 UTC
I'm not sure that the New File wizard is the right place for this. I'd say finish the wizard, then show the warning dialog box that JUnit isn't installed with the option to install it right from the dialog box.
Comment 2 Jesse Glick 2011-02-10 14:01:48 UTC
For technical reasons the junit module (i.e. "JUnit Tests", ~ tooling) cannot work that way. It has to add a JUnit library dependency when making the test, and it cannot do that until _after_ the JUnit NBMs have been installed so the library actually exists. (This is different from opening a project with a broken JUnit library reference, which can be resolved at any time.)

Probably the easiest way to do this is just to let the user click Finish (New File) / OK (Create Tests) as usual, and then if the library is missing and could be installed, do so (the Callable<Library> will prompt for the license and all that in its own wizard dialog). To be a little fancier you could try to create but not call the Callable<Library> while the wizard/dialog is open if the right library is not yet present, and disable Finish/OK with an appropriate error message if there is no available definer.
Comment 3 Jesse Glick 2011-02-10 15:51:19 UTC
After #195123 you can just call DownloadLibraryTask.perhapsDownload().
Comment 4 Jesse Glick 2011-02-10 17:54:04 UTC
*** Bug 195182 has been marked as a duplicate of this bug. ***
Comment 5 John Jullion-ceccarelli 2011-02-15 08:51:17 UTC
I think it's fine to add the broken dependency and then warn the user that it's broken and offer them to download and fix it. If they cancel out of it they have a broken project, but they've been warned.
Comment 6 Antonin Nebuzelsky 2011-02-23 18:35:36 UTC
Jesse, thanks for helping.

I discussed with Jano which solution will be suitable for 7.0 and it is OK if New File wizard for unit test and Create JUnit Tests action displays the message to the user asking him if he wants to install JUnit and proceeds with the regular Autoupdate installation wizard for JUnit lib modules.

Just, can the test creation wait before the user completes the AU installation wizard, so that the newly created test appears in the project and in editor window after the JUnit dependency is satisfied for the project? We should prevent the project being marked as broken in the meantime...
Comment 7 Jesse Glick 2011-02-28 23:09:31 UTC
core-main #85234ac997d9
Comment 8 Quality Engineering 2011-03-01 17:50:20 UTC
Integrated into 'main-golden', will be available in build *201103011142* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/85234ac997d9
User: Jesse Glick <jglick@netbeans.org>
Log: #195252: Offer to download JUnit before creating tests