Aug 212012
 

The NetBeans Platform Application I am working on is required to update itself silently, before the user interface appears. Most of what we used comes from Jiri Rechtacek’s excellent post How to update NetBeans Platform Application silently? It is highly recommended that you read that before reading the rest of this post, otherwise this will make no sense! :)

Edit: Also have a look at Geertjan’s blog entry entitled How to Push NetBeans Plugins Silently to End Users? for related information.

I ran into one interesting problem, probably due to the fact that all the update stuff happens before the GUI is ready in our particular implementation. When there are updates available for the first time, unit.getAvailableUpdates() is always empty. Only once the updates have been found while running the user interface, would the updates appear in that list on next start up. So after much debugging through the NetBeans Platform source code, I found out that the update items are read from a cache. And I had to force the providers to read from the update server to overcome that. The solution finally was as simple as just adding this:

List updateUnitProviders = 
        UpdateUnitProviderFactory.getDefault().getUpdateUnitProviders(true);
for (UpdateUnitProvider provider : updateUnitProviders) {
    ProgressHandle handle = ProgressHandleFactory.createHandle(
            provider.getDisplayName());
    try {
        // the second parameter forces update from server when true
        provider.refresh(handle, true);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}

On a related topic: there is another way to update an application. Simply put the .nbms in the update/download folder as described by Geertjan in hist post update/download.

  7 Responses to “Really Silently Updating a NetBeans Platform Application”

  1. Hello!
    are you simply replacing getSilentUpdateProvider() method in UpdateHandler class with your code? Thanks!

    • I added this code to doRealCheck() from Jiri’s post, just before calling getUpdateUnits().

      • Hello.
        how do you do it before UI is ready? do you just comment out the “WindowManager.getDefault().invokeWhenUIReady(new Runnable () {….” part?

        Thanks!

        • Yes. Take out that invokeWhenUIReady() part, and replace it with a direct call to doRealCheck().

          • when you do that, you didn’t run into a problem with main window starting up with size (0,0)? I am not sure why but it’s doing that so I have to get the main window and set the min size to prevent it from shrinking to size 0,0.

          • That will happen whenever the platform is shut down before the main window has been displayed. The same happened if the user cancelled out of our login dialog, which is displayed before the main window. I have logged this bug about it: http://netbeans.org/bugzilla/show_bug.cgi?id=212389 Vote for it if you want it to have more visibility to the engineering team. :-)

  2. Voted! Thanks again :)

 Leave a Reply

(required)

(required)


9 − = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>