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.util.Map;
021
022import org.nuxeo.connect.update.PackageException;
023import org.nuxeo.connect.update.PackageUpdateComponent;
024import org.nuxeo.connect.update.task.Command;
025import org.nuxeo.connect.update.task.Task;
026import org.nuxeo.connect.update.task.standalone.commands.InstallPlaceholder;
027import org.osgi.framework.Bundle;
028import org.osgi.framework.BundleContext;
029import org.osgi.framework.BundleException;
030
031/**
032 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
033 * @deprecated since 5.6, use {@link Deploy} instead
034 */
035@Deprecated
036public class Install extends InstallPlaceholder {
037
038    public Install() {
039        super();
040    }
041
042    public Install(File file) {
043        super(file);
044    }
045
046    @Override
047    protected Command doRun(Task task, Map<String, String> prefs) throws PackageException {
048        BundleContext ctx = PackageUpdateComponent.getContext().getBundle().getBundleContext();
049        try {
050            Bundle bundle = ctx.installBundle(file.getAbsolutePath());
051            if (bundle.getState() == Bundle.UNINSTALLED) {
052                ctx.installBundle(file.getAbsolutePath());
053            }
054            bundle.start();
055        } catch (BundleException e) {
056            throw new PackageException("Failed to install bundle " + file.getName());
057        }
058        return new Uninstall(file);
059    }
060
061}