001/*
002 * (C) Copyright 2006-2010 Nuxeo SAS (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 *     bstefanescu
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.standalone.commands.UndeployConfigPlaceholder;
027import org.nuxeo.runtime.api.Framework;
028
029/**
030 * Undeploys runtime configuration files to the framework.
031 * <p>
032 * The inverse of this command is Deploy.
033 *
034 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
035 */
036public class UndeployConfig extends UndeployConfigPlaceholder {
037
038    public UndeployConfig() {
039        super();
040    }
041
042    public UndeployConfig(File file) {
043        super(file);
044    }
045
046    @Override
047    protected Command doRun(Task task, Map<String, String> prefs) throws PackageException {
048        try {
049            Framework.getRuntime().getContext().undeploy(file.toURI().toURL());
050        } catch (IOException e) {
051            throw new PackageException("Failed to undeploy configuration file " + file, e);
052        }
053        return new DeployConfig(file);
054    }
055
056}