001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.connect.update.task.live.commands; 018 019import java.io.File; 020 021import org.nuxeo.connect.update.task.Command; 022import org.nuxeo.connect.update.task.update.Rollback; 023import org.nuxeo.connect.update.task.update.RollbackOptions; 024import org.nuxeo.connect.update.task.update.Update; 025import org.nuxeo.connect.update.task.update.UpdateManager; 026 027/** 028 * Live version of the update command, that handle hot-reloading of the jar by deploying it to the runtime. 029 * 030 * @since 5.6 031 */ 032public class UpdateAndDeploy extends Update { 033 034 // needed for deserialization 035 public UpdateAndDeploy() { 036 super(); 037 } 038 039 @Override 040 protected Command getDeployCommand(UpdateManager updateManager, Command rollbackCommand) { 041 // file is the file to be deployed, so it's not in its final place. 042 // But deploy should use the final place => extract info from the 043 // rollback command... 044 if (rollbackCommand instanceof Rollback) { 045 // FIXME: only handle one file right now => deploy the file 046 // with options given by rollback, only when it's not a composite 047 // command 048 Rollback rollback = (Rollback) rollbackCommand; 049 RollbackOptions opt = rollback.getRollbackOptions(); 050 File rollbackTarget = updateManager.getRollbackTarget(opt); 051 if (rollbackTarget != null) { 052 return new Deploy(rollbackTarget); 053 } else { 054 return null; 055 } 056 } 057 return new Deploy(file); 058 } 059 060}