protected void saveParams(Map<String, String> params) throws PackageException { if (params == null || params.isEmpty()) { return; } try { Properties props = new Properties(); props.putAll(params); File file = pkg.getData().getEntry(LocalPackage.INSTALL_PROPERTIES); try (FileOutputStream out = new FileOutputStream(file)) { props.store(out, "user install parameters"); } } catch (IOException e) { throw new PackageException("Failed to save install parameters", e); } }
@Override @SuppressWarnings("hiding") public void initialize(LocalPackage pkg, boolean restart) throws PackageException { this.pkg = pkg; this.restart = restart; env.put(PKG_ID, pkg.getId()); env.put(PKG_NAME, pkg.getName()); env.put(PKG_VERSION, pkg.getVersion().toString()); env.put(PKG_ROOT, pkg.getData().getRoot().getAbsolutePath()); if (log.isDebugEnabled()) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream outPrint = new PrintStream(out); MapUtils.debugPrint(outPrint, null, env); log.debug(out.toString()); } }
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); } }
/** * Backup the given file to the package backup directory. The backup file will be returned. The backup file will be * named: MD5ofFilepath_filename. * * @return the name of the backup file. */ public static File backup(LocalPackage pkg, File file) throws IOException { file = file.getCanonicalFile(); String md5 = createMd5(file.getAbsolutePath()); File bak = pkg.getData().getEntry(LocalPackage.BACKUP_DIR); bak.mkdirs(); String name = file.getName(); File bakFile = new File(bak, md5 + "_" + name); FileUtils.copy(file, bakFile); return bakFile; }
@Override protected void doRun(Map<String, String> params) throws PackageException { try { super.doRun(params); } finally { // generate the uninstall.xml file File file = pkg.getData().getEntry(LocalPackage.UNINSTALL); writeLog(file); // No reload of components in standalone mode } }
public boolean pkgReset() { CommandInfo cmdInfo = cset.newCommandInfo(CommandInfo.CMD_RESET); if ("ask".equalsIgnoreCase(accept)) { accept = readConsole( "The reset will erase the Nuxeo Packages history.\n" + "Do you want to continue (yes/no)? [yes] ", "yes"); } if (!Boolean.parseBoolean(accept)) { cmdInfo.exitCode = 1; return false; } try { service.reset(); log.info("Packages reset done: all packages were marked as DOWNLOADED"); List<LocalPackage> localPackages = service.getPackages(); for (LocalPackage localPackage : localPackages) { localPackage.getUninstallFile().delete(); FileUtils.deleteDirectory(localPackage.getData().getEntry(LocalPackage.BACKUP_DIR)); newPackageInfo(cmdInfo, localPackage); } service.getRegistry().delete(); FileUtils.deleteDirectory(service.getBackupDir()); } catch (PackageException | IOException e) { log.error(e); cmdInfo.exitCode = 1; } return cmdInfo.exitCode == 0; }
if (pkg != null && installTask != null) { File file = pkg.getData().getEntry(LocalPackage.UNINSTALL); try { installTask.writeLog(file);