public ConnectBroker(Environment env) throws IOException, PackageException {
   this.env = env;
   service = new StandaloneUpdateService(env);
   service.initialize();
   cbHolder = new StandaloneCallbackHolder(env, service);
   NuxeoConnectClient.setCallBackHolder(cbHolder);
   targetPlatform =
       env.getProperty(Environment.DISTRIBUTION_NAME)
           + "-"
           + env.getProperty(Environment.DISTRIBUTION_VERSION);
   distributionMPDir = env.getProperty(PARAM_MP_DIR, DISTRIBUTION_MP_DIR_DEFAULT);
 }
 /**
  * Install a local package.
  *
  * @param pkgId Package ID or Name
  * @return The installed LocalPackage or null if failed
  */
 public LocalPackage pkgInstall(String pkgId) {
   if (env.getProperty(LAUNCHER_CHANGED_PROPERTY, "false").equals("true")) {
     System.exit(LAUNCHER_CHANGED_EXIT_CODE);
   }
   CommandInfo cmdInfo = cset.newCommandInfo(CommandInfo.CMD_INSTALL);
   cmdInfo.param = pkgId;
   try {
     LocalPackage pkg = getLocalPackage(pkgId);
     if (pkg == null) {
       // We don't know this package, try to add it first
       pkg = pkgAdd(pkgId);
     }
     if (pkg == null) {
       // Nothing worked - can't find the package anywhere
       throw new PackageException("Package not found: " + pkgId);
     }
     pkgId = pkg.getId();
     cmdInfo.param = pkgId;
     log.info("Installing " + pkgId);
     Task installTask = pkg.getInstallTask();
     try {
       performTask(installTask);
     } catch (PackageException e) {
       installTask.rollback();
       throw e;
     }
     // Refresh state
     pkg = service.getPackage(pkgId);
     newPackageInfo(cmdInfo, pkg);
     return pkg;
   } catch (Exception e) {
     log.error(String.format("Failed to install package: %s (%s)", pkgId, e.getMessage()));
     cmdInfo.exitCode = 1;
     cmdInfo.newMessage(e);
     return null;
   }
 }
 /**
  * Uninstall a local package. The package is not removed from cache.
  *
  * @param pkgId Package ID or Name
  * @return The uninstalled LocalPackage or null if failed
  */
 public LocalPackage pkgUninstall(String pkgId) {
   if (env.getProperty(LAUNCHER_CHANGED_PROPERTY, "false").equals("true")) {
     System.exit(LAUNCHER_CHANGED_EXIT_CODE);
   }
   CommandInfo cmdInfo = cset.newCommandInfo(CommandInfo.CMD_UNINSTALL);
   cmdInfo.param = pkgId;
   try {
     LocalPackage pkg = service.getPackage(pkgId);
     if (pkg == null) {
       // Check whether this is the name of an installed package
       String realPkgId = getInstalledPackageIdFromName(pkgId);
       if (realPkgId != null) {
         pkgId = realPkgId;
         pkg = service.getPackage(realPkgId);
       }
     }
     if (pkg == null) {
       throw new PackageException("Package not found: " + pkgId);
     }
     log.info("Uninstalling " + pkgId);
     Task uninstallTask = pkg.getUninstallTask();
     try {
       performTask(uninstallTask);
     } catch (PackageException e) {
       uninstallTask.rollback();
       throw e;
     }
     // Refresh state
     pkg = service.getPackage(pkgId);
     newPackageInfo(cmdInfo, pkg);
     return pkg;
   } catch (Exception e) {
     log.error("Failed to uninstall package: " + pkgId, e);
     cmdInfo.exitCode = 1;
     return null;
   }
 }