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;
020import java.io.IOException;
021import java.util.Map;
022
023import org.nuxeo.connect.update.PackageException;
024import org.nuxeo.connect.update.task.Command;
025import org.nuxeo.connect.update.task.Task;
026import org.nuxeo.connect.update.task.update.Rollback;
027import org.nuxeo.connect.update.task.update.RollbackOptions;
028import org.nuxeo.runtime.api.Framework;
029import org.nuxeo.runtime.reload.ReloadService;
030
031/**
032 * @since 5.6
033 */
034public class RollbackAndUndeploy extends Rollback {
035
036    // needed for deserialization
037    public RollbackAndUndeploy() {
038        super();
039    }
040
041    public RollbackAndUndeploy(RollbackOptions opt) {
042        super(opt);
043    }
044
045    @Override
046    protected Command doRun(Task task, Map<String, String> prefs) throws PackageException {
047        Command res = null;
048        try {
049            res = super.doRun(task, prefs);
050
051            // then re-build the war now that jar is deleted
052            ReloadService srv = Framework.getLocalService(ReloadService.class);
053            srv.runDeploymentPreprocessor();
054        } catch (PackageException | IOException e) {
055            // ignore uninstall -> this may break the entire chain. Usually
056            // uninstall is done only when rollbacking or uninstalling => force
057            // restart required
058            task.setRestartRequired(true);
059            throw new PackageException("Failed to undeploy bundle", e);
060        }
061        return res;
062    }
063
064    protected Command getUndeployCommand(File targetFile) {
065        return new Undeploy(targetFile);
066    }
067
068}