001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.connect.update.task.live.commands; 020 021import java.io.File; 022 023import org.nuxeo.connect.update.task.Command; 024import org.nuxeo.connect.update.task.update.Rollback; 025import org.nuxeo.connect.update.task.update.RollbackOptions; 026import org.nuxeo.connect.update.task.update.Update; 027import org.nuxeo.connect.update.task.update.UpdateManager; 028 029/** 030 * Live version of the update command, that handle hot-reloading of the jar by deploying it to the runtime. 031 * 032 * @since 5.6 033 */ 034public class UpdateAndDeploy extends Update { 035 036 // needed for deserialization 037 public UpdateAndDeploy() { 038 super(); 039 } 040 041 @Override 042 protected Command getDeployCommand(UpdateManager updateManager, Command rollbackCommand) { 043 // file is the file to be deployed, so it's not in its final place. 044 // But deploy should use the final place => extract info from the 045 // rollback command... 046 if (rollbackCommand instanceof Rollback) { 047 // FIXME: only handle one file right now => deploy the file 048 // with options given by rollback, only when it's not a composite 049 // command 050 Rollback rollback = (Rollback) rollbackCommand; 051 RollbackOptions opt = rollback.getRollbackOptions(); 052 File rollbackTarget = updateManager.getRollbackTarget(opt); 053 if (rollbackTarget != null) { 054 return new Deploy(rollbackTarget); 055 } else { 056 return null; 057 } 058 } 059 return new Deploy(file); 060 } 061 062}