001/*
002 * (C) Copyright 2006-2008 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 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.webengine.install;
021
022import java.io.File;
023import java.io.IOException;
024
025import org.nuxeo.common.utils.FileUtils;
026import org.nuxeo.common.xmap.annotation.XNode;
027import org.nuxeo.common.xmap.annotation.XObject;
028
029/**
030 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
031 */
032@XObject("copy")
033public class CopyOperation {
034
035    @XNode("@path")
036    protected String path;
037
038    @XNode("@target")
039    protected String target;
040
041    public void run(Installer installer, File bundleDir, File installDir) throws IOException {
042        File dest = new File(installDir, target);
043        if (path.endsWith("/*")) {
044            dest.mkdirs();
045            File file = new File(bundleDir, path.substring(0, path.length() - 1));
046            FileUtils.copy(file.listFiles(), dest);
047        } else {
048            File file = new File(bundleDir, path);
049            FileUtils.copy(file, dest);
050        }
051    }
052
053}