/**
   * Runs the console installer against a script with an alternative uninstaller name and path,
   * verifying that the correct uninstall JAR and registry value are created.
   *
   * @throws Exception for any error
   */
  @Test
  @InstallFile("samples/windows/consoleinstall_alt_uninstall.xml")
  public void testNonDefaultUninstaller() throws Exception {
    Assume.assumeTrue(
        "This test must be run as administrator, or with Windows UAC turned off",
        !skipTests && isAdminUser);

    assertFalse(registryKeyExists(handler, DEFAULT_UNINSTALL_KEY));

    TestConsole console = installer.getConsole();
    console.addScript("CheckedHelloPanel", "1");
    console.addScript("InfoPanel", "1");
    console.addScript("TargetPanel", "\n", "O", "1");

    // run installer and check that default uninstaller doesn't exist
    InstallData installData = getInstallData();
    checkInstall(installer, installData, false);

    // check that uninstaller exists as specified in install spec
    String installPath = installData.getInstallPath();
    assertTrue(new File(installPath, "/uninstallme.jar").exists());

    // check that the registry key has the correct value
    assertTrue(registryKeyExists(handler, DEFAULT_UNINSTALL_KEY));
    String command =
        "\""
            + installData.getVariable("JAVA_HOME")
            + "\\bin\\javaw.exe\" -jar \""
            + installPath
            + "\\uninstallme.jar\"";
    registryValueStringEquals(handler, DEFAULT_UNINSTALL_KEY, UNINSTALL_CMD_VALUE, command);
  }
  /**
   * Runs the console installer twice, verifying that a second uninstall key is created.
   *
   * @throws Exception for any error
   */
  @Test
  @InstallFile("samples/windows/install.xml")
  public void testRejectMultipleInstallation() throws Exception {
    Assume.assumeTrue(
        "This test must be run as administrator, or with Windows UAC turned off",
        !skipTests && isAdminUser);

    checkInstall(container, APP_NAME);

    removeLock();

    ConsoleInstallerContainer container2 = new TestConsoleInstallerContainer();
    TestConsoleInstaller installer2 = container2.getComponent(TestConsoleInstaller.class);
    RegistryDefaultHandler handler2 = container2.getComponent(RegistryDefaultHandler.class);
    InstallData installData2 = container2.getComponent(InstallData.class);

    TestConsole console2 = installer2.getConsole();
    console2.addScript("CheckedHelloPanel", "n");

    assertFalse(registryKeyExists(handler2, UNINSTALL_KEY2));
    installer2.run(Installer.CONSOLE_INSTALL, null, new String[0]);

    // verify the installation thinks it was unsuccessful
    assertFalse(installData2.isInstallSuccess());

    // make sure the script has completed
    TestConsole console = installer2.getConsole();
    assertTrue("Script still running panel: " + console.getScriptName(), console.scriptCompleted());

    // verify the second registry key hasn't been created
    assertFalse(registryKeyExists(handler2, UNINSTALL_KEY2));
  }
  /**
   * Helper to format a message to create shortcuts for the current platform.
   *
   * @return a formatted message
   */
  public String getCreateShortcutsPrompt() {
    Messages messages = installData.getMessages();
    String menuKind = messages.get("ShortcutPanel.regular.StartMenu:Start-Menu");

    if (installData.getPlatform().isA(UNIX) && UnixHelper.kdeIsInstalled()) {
      menuKind = messages.get("ShortcutPanel.regular.StartMenu:K-Menu");
    }

    return StringTool.replace(messages.get("ShortcutPanel.regular.create"), "StartMenu", menuKind);
  }
 @Override
 public boolean isTrue() {
   InstallData installData = getInstallData();
   if (installData != null) {
     String val = installData.getVariable(variablename);
     if (val == null) {
       return false;
     } else {
       Variables variables = installData.getVariables();
       return val.equals(variables.replace(value));
     }
   } else {
     return false;
   }
 }
Exemple #5
0
  private Map<String, Pack> loadInstallationInformation(boolean modifyInstallation) {
    Map<String, Pack> installedpacks = new HashMap<String, Pack>();
    if (!modifyInstallation) {
      return installedpacks;
    }

    // installation shall be modified
    // load installation information
    ObjectInputStream oin = null;
    try {
      FileInputStream fin =
          new FileInputStream(
              new File(
                  installData.getInstallPath()
                      + File.separator
                      + InstallData.INSTALLATION_INFORMATION));
      oin = new ObjectInputStream(fin);
      List<Pack> packsinstalled = (List<Pack>) oin.readObject();
      for (Pack installedpack : packsinstalled) {
        installedpacks.put(installedpack.getName(), installedpack);
      }
      this.removeAlreadyInstalledPacks(installData.getSelectedPacks());
      logger.fine("Found " + packsinstalled.size() + " installed packs");

      Properties variables = (Properties) oin.readObject();

      for (Object key : variables.keySet()) {
        installData.setVariable((String) key, (String) variables.get(key));
      }
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      if (oin != null) {
        try {
          oin.close();
        } catch (IOException e) {
        }
      }
    }
    return installedpacks;
  }
Exemple #6
0
  /**
   * Select/Deselect pack(s) based on packsData mapping. This is related to the onSelect and
   * onDeselect attributes for packs. User is not allowed to has a required pack for onSelect and
   * onDeselect.
   *
   * @param packsData
   */
  private void selectionUpdate(Map<String, String> packsData) {
    RulesEngine rules = installData.getRules();
    for (Map.Entry<String, String> packData : packsData.entrySet()) {
      int value, packPos;
      String packName = packData.getKey();
      String condition = packData.getValue();

      if (condition != null && !rules.isConditionTrue(condition)) {
        return; // Do nothing if condition is false
      }

      Pack pack;

      if (packName.startsWith("!")) {
        packName = packName.substring(1);
        pack = nameToPack.get(packName);
        packPos = getPos(packName);
        value = DESELECTED;
      } else {
        pack = nameToPack.get(packName);
        packPos = getPos(packName);
        value = SELECTED;
      }
      if (!pack.isRequired() && dependenciesResolved(pack)) {
        checkValues[packPos] = value;
      }
    }
  }
 /**
  * Returns the anchor as value declared in GridBagConstraints. Possible are NORTH, NORTHWEST,
  * SOUTH, SOUTHWEST and CENTER. The values can be configured in the xml description file with the
  * variable "IzPanel.LayoutType". The old values "TOP" and "BOTTOM" from the xml file are mapped
  * to NORTH and SOUTH.
  *
  * @return the anchor defined in the IzPanel.LayoutType variable.
  */
 public int getAnchor() {
   if (ANCHOR >= 0) {
     return (ANCHOR);
   }
   String todo;
   if (installData instanceof GUIInstallData
       && ((GUIInstallData) installData).guiPrefs.modifier.containsKey("layoutAnchor")) {
     todo = ((GUIInstallData) installData).guiPrefs.modifier.get("layoutAnchor");
   } else {
     todo = installData.getVariable("IzPanel.LayoutType");
   }
   if (todo == null) // No command, no work.
   {
     ANCHOR = CENTER;
   } else if ("EAST".equalsIgnoreCase(todo)) {
     ANCHOR = EAST;
   } else if ("WEST".equalsIgnoreCase(todo)) {
     ANCHOR = WEST;
   } else if ("TOP".equalsIgnoreCase(todo) || "NORTH".equalsIgnoreCase(todo)) {
     ANCHOR = NORTH;
   } else if ("BOTTOM".equalsIgnoreCase(todo) || "SOUTH".equalsIgnoreCase(todo)) {
     ANCHOR = SOUTH;
   } else if ("SOUTHWEST".equalsIgnoreCase(todo) || "SOUTH_WEST".equalsIgnoreCase(todo)) {
     ANCHOR = SOUTH_WEST;
   } else if ("SOUTHEAST".equalsIgnoreCase(todo) || "SOUTH_EAST".equalsIgnoreCase(todo)) {
     ANCHOR = SOUTH_EAST;
   } else if ("NORTHWEST".equalsIgnoreCase(todo) || "NORTH_WEST".equalsIgnoreCase(todo)) {
     ANCHOR = NORTH_WEST;
   } else if ("NORTHEAST".equalsIgnoreCase(todo) || "NORTH_EAST".equalsIgnoreCase(todo)) {
     ANCHOR = NORTH_EAST;
   } else if ("CENTER".equalsIgnoreCase(todo)) {
     ANCHOR = CENTER;
   }
   return (ANCHOR);
 }
  /**
   * Attempt to read load specifications from OS specific shortcut specification file. If fail to
   * read from OS specific shortcut specification file, attempt to load general shortcut
   * specification file.
   *
   * @throws Exception for any problems in reading the specification TODO: If internal flag mapped
   *     installData.isDebug() print out information on substitutedSpec
   */
  private IXMLElement readShortcutSpec() throws Exception {
    IXMLElement spec = null;

    InputStream shortcutSpec = null;
    try {
      shortcutSpec = resources.getInputStream(TargetFactory.getCurrentOSPrefix() + SPEC_FILE_NAME);
    } catch (ResourceNotFoundException resourceNotFound) {
      try {
        shortcutSpec = resources.getInputStream(SPEC_FILE_NAME);
      } catch (ResourceNotFoundException shortcutsNotFound) {
        // Fail on next try block
      }
    }

    try {
      VariableSubstitutor replacer = new VariableSubstitutorImpl(installData.getVariables());
      String substitutedSpec = replacer.substitute(shortcutSpec, SubstitutionType.TYPE_XML);
      IXMLParser parser = new XMLParser();
      spec = parser.parse(substitutedSpec);
    } catch (Exception e) {
      return null;
    }

    shortcutSpec.close();
    return spec;
  }
 /**
  * This returns true if a Shortcut should or can be created. Returns false to suppress Creation
  *
  * @param shortcutSpec
  * @return true if condition is resolved positive
  */
 private boolean checkConditions(IXMLElement shortcutSpec) {
   boolean result = true;
   String condition = shortcutSpec.getAttribute(SPEC_ATTRIBUTE_CONDITION);
   if (condition != null) {
     result = installData.getRules().isConditionTrue(condition);
   }
   return result;
 }
Exemple #10
0
  public PacksModel(InstallData idata) {
    this.installData = idata;
    this.rules = idata.getRules();
    try {
      this.messages = idata.getMessages().newMessages(PackHelper.LANG_FILE_NAME);
    } catch (com.izforge.izpack.api.exception.ResourceNotFoundException ex) {
      this.messages = idata.getMessages();
    }
    this.variables = idata.getVariables();
    this.packsToInstall = idata.getSelectedPacks();

    this.modifyInstallation = Boolean.valueOf(idata.getVariable(InstallData.MODIFY_INSTALLATION));
    this.installedPacks = loadInstallationInformation(modifyInstallation);

    this.packs = getVisiblePacks();
    this.hiddenPacks = getHiddenPacks();
    this.allPacks = idata.getAvailablePacks();
    this.nameToRow = getNametoRowMapping(packs);
    this.nameToPack = getNametoPackMapping(allPacks);

    this.packs = setPackProperties(packs, nameToPack);
    this.checkValues = initCheckValues(packs, packsToInstall);

    updateConditions(true);
    updatePacksToInstall();
  }
Exemple #11
0
 /** @return a list of visible packs */
 public List<Pack> getVisiblePacks() {
   List<Pack> visiblePacks = new ArrayList<Pack>();
   for (Pack availablePack : installData.getAvailablePacks()) {
     if (!availablePack.isHidden()) {
       visiblePacks.add(availablePack);
     }
   }
   return visiblePacks;
 }
Exemple #12
0
 /** @return a list of hidden packs */
 private List<Pack> getHiddenPacks() {
   List<Pack> hiddenPacks = new ArrayList<Pack>();
   for (Pack availablePack : installData.getAvailablePacks()) {
     if (availablePack.isHidden()) {
       hiddenPacks.add(availablePack);
     }
   }
   return hiddenPacks;
 }
 /** Called by {@link Housekeeper} to cleanup after installation. */
 @Override
 public void cleanUp() {
   if (!installData.isInstallSuccess()) {
     // Shortcuts may have been deleted, but let's try to delete them once again
     for (String file : files) {
       File fl = new File(file);
       if (fl.exists()) {
         fl.delete();
       }
     }
   }
 }
  @Override
  public boolean runConsole(InstallData installData, Console console) {
    java.util.List<Pack> selectedPacks = new ArrayList<Pack>();
    String installationMode = null;

    do {
      installationMode =
          console.prompt("Do you to execute the defaut installation ? Y for yes, N for no", null);
    } while (!isGoodValue(installationMode));
    if (isYes(installationMode)) {
      for (Pack p : installData.getAvailablePacks()) {
        if (p.isRequired() || p.isPreselected()) {
          selectedPacks.add(p);
        }
      }
    } else if (isNo(installationMode)) {
      for (Pack p : installData.getAvailablePacks()) {

        if (p.isRequired()) {
          selectedPacks.add(p);
        } else {
          String packToInstall = null;

          do {
            packToInstall =
                console.prompt(
                    "Do you want to install  [" + p.getName() + "] Y for yes, N for no ", null);
          } while (!isGoodValue(packToInstall));

          if (isYes(packToInstall)) {
            selectedPacks.add(p);
          } else if (isNo(packToInstall)) {
            console.println("Installation of " + p.getName() + " skipped");
          }
        }
      }
    }
    installData.setSelectedPacks(selectedPacks);
    return promptEndPanel(installData, console);
  }
  /**
   * Runs the console installer twice, verifying that a second uninstall key is created.
   *
   * @throws Exception for any error
   */
  @Test
  @InstallFile("samples/windows/install.xml")
  public void testMultipleInstallation() throws Exception {
    Assume.assumeTrue(
        "This test must be run as administrator, or with Windows UAC turned off",
        !skipTests && isAdminUser);

    // run the install
    checkInstall(container, APP_NAME);

    // remove the lock file to enable second installation
    removeLock();

    // run the installation again
    ConsoleInstallerContainer container2 = new TestConsoleInstallerContainer();
    TestConsoleInstaller installer2 = container2.getComponent(TestConsoleInstaller.class);
    InstallData installData2 = container2.getComponent(InstallData.class);

    // copied from super.setUp()
    // write to temporary folder so the test doesn't need to be run with elevated permissions
    File installPath = new File(temporaryFolder.getRoot(), "izpackTest");
    installData2.setInstallPath(installPath.getAbsolutePath());
    installData2.setDefaultInstallPath(installPath.getAbsolutePath());

    TestConsole console2 = installer2.getConsole();
    console2.addScript("CheckedHelloPanel", "y", "1");
    console2.addScript("TargetPanel", "\n", "y", "1");
    console2.addScript("PacksPanel", "1");

    assertFalse(registryKeyExists(handler, UNINSTALL_KEY2));
    checkInstall(installer2, installData2);

    // verify the UNINSTALL_NAME has been updated
    assertEquals(APP_NAME + "(1)", installData2.getVariable("UNINSTALL_NAME"));

    // verify a second key is created
    assertTrue(registryKeyExists(handler, UNINSTALL_KEY2));
  }
  /**
   * Runs the installation, and verifies the uninstall key is created.
   *
   * @throws NativeLibException for any native library exception
   */
  private void checkInstall(TestConsoleInstallerContainer container, String uninstallName)
      throws NativeLibException {
    // UNINSTALL_NAME should be null prior to display of CheckedHelloPanel
    InstallData installData = container.getComponent(InstallData.class);
    TestConsoleInstaller installer = container.getComponent(TestConsoleInstaller.class);
    RegistryDefaultHandler handler = container.getComponent(RegistryDefaultHandler.class);

    assertNull(installData.getVariable("UNINSTALL_NAME"));

    assertFalse(registryKeyExists(handler, DEFAULT_UNINSTALL_KEY));

    TestConsole console = installer.getConsole();
    console.addScript("CheckedHelloPanel", "1");
    console.addScript("TargetPanel", "\n", "O", "1");
    console.addScript("PacksPanel", "1");
    console.addScript("ShortcutPanel", "N");

    checkInstall(installer, installData);

    // UNINSTALL_NAME should now be defined
    assertEquals(uninstallName, installData.getVariable("UNINSTALL_NAME"));

    assertTrue(registryKeyExists(handler, DEFAULT_UNINSTALL_KEY));
  }
Exemple #17
0
  /**
   * Update packs to installed. A pack to be installed is: 1. A visible pack that has its checkbox
   * checked 2. A hidden pack that condition
   *
   * @return
   */
  public List<Pack> updatePacksToInstall() {
    packsToInstall.clear();
    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);
      if (isChecked(i) && !installedPacks.containsKey(pack.getName())) {
        packsToInstall.add(pack);
      } else if (installedPacks.containsKey(pack.getName())) {
        checkValues[i] = REQUIRED_PARTIAL_SELECTED;
      }
    }

    for (Pack hiddenPack : this.hiddenPacks) {
      if (this.rules.canInstallPack(hiddenPack.getName(), variables)) {
        packsToInstall.add(hiddenPack);
      }
    }

    installData.setSelectedPacks(packsToInstall);
    return packsToInstall;
  }
 public String getCreateStartupShortcutsPrompt() {
   return installData.getMessages().get("ShortcutPanel.regular.startup");
 }
 /**
  * Validate that groupName is a valid directory path
  *
  * @param groupName
  * @return
  */
 public String verifyProgramGroup(String groupName) {
   if (!platform.isValidDirectorySyntax(groupName)) {
     return installData.getMessages().get("ShortcutPanel.group.error");
   }
   return "";
 }
 /** @return the suggested program group */
 public String getSuggestedProgramGroup() {
   return installData.getVariables().replace(suggestedProgramGroup);
 }
 public String getCreateForAllUsersPrompt() {
   return installData.getMessages().get("ShortcutPanel.regular.allUsers");
 }
 public String getCreateForCurrentUserPrompt() {
   return installData.getMessages().get("ShortcutPanel.regular.currentUser");
 }
 /**
  * Helper to return a prompt to create desktop shortcuts.
  *
  * @return the desktop shortcut prompt
  */
 public String getCreateDesktopShortcutsPrompt() {
   return installData.getMessages().get("ShortcutPanel.regular.desktop");
 }
 public boolean isStartupShortcutCheckboxSelected() {
   return Boolean.valueOf(installData.getVariable("StartupShortcutCheckboxEnabled"));
 }
 public String getCreateForUserPrompt() {
   return installData.getMessages().get("ShortcutPanel.regular.userIntro");
 }
  /**
   * This method saves all shortcut information to a text file. TODO: Show an error dialog if fail
   * to write
   *
   * @param file to save the information to
   */
  public void saveToFile(File file) {
    FileWriter output = null;
    StringBuilder buffer = new StringBuilder();
    Messages messages = installData.getMessages();
    String header = messages.get("ShortcutPanel.textFile.header");

    String newline = System.getProperty("line.separator", "\n");

    try {
      output = new FileWriter(file);
    } catch (Throwable exception) {
      return;
    }

    /** Break the header down into multiple lines based on '\n' line breaks. */
    int nextIndex;
    int currentIndex = 0;
    do {
      nextIndex = header.indexOf("\\n", currentIndex);

      if (nextIndex > -1) {
        buffer.append(header.substring(currentIndex, nextIndex));
        buffer.append(newline);
        currentIndex = nextIndex + 2;
      } else {
        buffer.append(header.substring(currentIndex, header.length()));
        buffer.append(newline);
      }
    } while (nextIndex > -1);

    buffer.append(SEPARATOR_LINE);
    buffer.append(newline);
    buffer.append(newline);

    for (ShortcutData data : shortcuts) {
      buffer.append(messages.get("ShortcutPanel.textFile.name"));
      buffer.append(data.name);
      buffer.append(newline);

      buffer.append(messages.get("ShortcutPanel.textFile.location"));

      switch (data.type) {
        case Shortcut.DESKTOP:
          {
            buffer.append(messages.get("ShortcutPanel.location.desktop"));
            break;
          }

        case Shortcut.APPLICATIONS:
          {
            buffer.append(messages.get("ShortcutPanel.location.applications"));
            break;
          }

        case Shortcut.START_MENU:
          {
            buffer.append(messages.get("ShortcutPanel.location.startMenu"));
            break;
          }

        case Shortcut.START_UP:
          {
            buffer.append(messages.get("ShortcutPanel.location.startup"));
            break;
          }
      }

      buffer.append(newline);

      buffer.append(messages.get("ShortcutPanel.textFile.description"));
      buffer.append(data.description);
      buffer.append(newline);

      buffer.append(messages.get("ShortcutPanel.textFile.target"));
      buffer.append(data.target);
      buffer.append(newline);

      buffer.append(messages.get("ShortcutPanel.textFile.command"));
      buffer.append(data.commandLine);
      buffer.append(newline);

      buffer.append(messages.get("ShortcutPanel.textFile.iconName"));
      buffer.append(data.iconFile);
      buffer.append(newline);

      buffer.append(messages.get("ShortcutPanel.textFile.iconIndex"));
      buffer.append(data.iconIndex);
      buffer.append(newline);

      buffer.append(messages.get("ShortcutPanel.textFile.work"));
      buffer.append(data.workingDirectory);
      buffer.append(newline);

      buffer.append(newline);
      buffer.append(SEPARATOR_LINE);
      buffer.append(newline);
      buffer.append(newline);
    }

    try {
      output.write(buffer.toString());
    } catch (Throwable exception) {
    } finally {
      try {
        output.flush();
        output.close();
        files.add(file.getPath());
      } catch (Throwable exception) {
        // not really anything I can do here, maybe should show a dialog that
        // tells the user that installDataGUI might not have been saved completely!?
      }
    }
  }