views:

14

answers:

1

How can I find the version of an installed NetBeans module ?

My purpose is to make my module display its own specification number to the user without having to change its display code at each release.

A: 
import org.netbeans.api.autoupdate.UpdateElement;
import org.netbeans.api.autoupdate.UpdateManager;
import org.netbeans.api.autoupdate.UpdateUnit;

public class VersionUtil {

  public static String getVersion(String codename) {
    for (UpdateUnit updateUnit : UpdateManager.getDefault().getUpdateUnits()) {
      UpdateElement updateElement = updateUnit.getInstalled();
      if (updateElement != null)
        if (codename.equals(updateElement.getCodeName()))
          return updateElement.getSpecificationVersion();
    }

    return "unknown";
  }
}
Vincent