Exemplo n.º 1
0
 public void readLog(Reader reader) throws PackageException {
   try {
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     factory.setNamespaceAware(true);
     DocumentBuilder builder = factory.newDocumentBuilder();
     Document document = builder.parse(new InputSource(reader));
     Element root = document.getDocumentElement();
     Node node = root.getFirstChild();
     while (node != null) {
       if (node.getNodeType() == Node.ELEMENT_NODE) {
         Element element = (Element) node;
         String id = node.getNodeName();
         Command cmd = service.getCommand(id);
         if (cmd == null) { // may be the name of an embedded class
           try {
             cmd = (Command) pkg.getData().loadClass(id).getConstructor().newInstance();
           } catch (ReflectiveOperationException t) {
             throw new PackageException("Unknown command: " + id);
           }
         }
         cmd.initialize(element);
         cmd.setPackageUpdateService(service);
         commands.add(cmd);
       }
       node = node.getNextSibling();
     }
   } catch (ParserConfigurationException | SAXException | IOException e) {
     throw new PackageException("Failed to read commands", e);
   }
 }
Exemplo n.º 2
0
 @Override
 public void doValidate(ValidationStatus status) throws PackageException {
   // the target platform is not checked at install
   // check that commands can be run
   for (Command cmd : commands) {
     cmd.validate(this, status);
   }
 }
 @Override
 protected Command doRun(Task task, Map<String, String> prefs) throws PackageException {
   CompositeCommand rollbackCommand = new CompositeCommand();
   for (Command command : commands) {
     rollbackCommand.addCommand(command.run(task, prefs));
   }
   return rollbackCommand;
 }
Exemplo n.º 4
0
 /** User parameters are not handled by default. You need to implement your own task to do this. */
 @Override
 protected void doRun(Map<String, String> params) throws PackageException {
   for (Command cmd : commands) {
     Command rollbackCmd = cmd.run(this, params);
     if (rollbackCmd != null) {
       if (rollbackCmd.isPostInstall()) {
         commandLog.add(rollbackCmd);
       } else {
         commandLog.addFirst(rollbackCmd);
       }
     }
   }
   // XXX: force a flush?
   flush();
 }
Exemplo n.º 5
0
 public void writeLog(File file) throws PackageException {
   XmlWriter writer = new XmlWriter();
   writer.start("uninstall");
   writer.startContent();
   for (Command cmd : commandLog) {
     cmd.writeTo(writer);
   }
   writer.end("uninstall");
   try {
     // replace all occurrences of the installation path with the corresponding variable otherwise
     // the uninstall
     // will not work after renaming the installation directory
     String content = parametrizePaths(writer.toString());
     // replace '//' by '/' if any
     content = content.replace(File.separator.concat(File.separator), File.separator);
     FileUtils.writeFile(file, content);
   } catch (IOException e) {
     throw new PackageException("Failed to write commands", e);
   }
 }
 @Override
 protected void doValidate(Task task, ValidationStatus status) throws PackageException {
   for (Command command : commands) {
     command.validate(task, status);
   }
 }
 @Override
 public void writeTo(XmlWriter writer) {
   for (Command command : commands) {
     command.writeTo(writer);
   }
 }