001/*
002 * (C) Copyright 2006-2007 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 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.runtime.deployment.preprocessor.install.commands;
021
022import java.io.File;
023import java.io.IOException;
024
025import org.nuxeo.common.utils.Path;
026import org.nuxeo.runtime.deployment.preprocessor.install.Command;
027import org.nuxeo.runtime.deployment.preprocessor.install.CommandContext;
028
029/**
030 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
031 */
032public class MkdirCommand implements Command {
033
034    protected final Path path;
035
036    /**
037     * Constructor for mkdir command.
038     *
039     * @param path the path relative to the root container.
040     */
041    public MkdirCommand(Path path) {
042        this.path = path;
043    }
044
045    @Override
046    public void exec(CommandContext ctx) throws IOException {
047        File baseDir = ctx.getBaseDir();
048        File dir = new File(baseDir, ctx.expandVars(path.toString()));
049
050        dir.mkdirs();
051    }
052
053    @Override
054    public String toString() {
055        return "mkdir " + path.toString();
056    }
057
058    @Override
059    public String toString(CommandContext ctx) {
060        return "mkdir " + ctx.expandVars(path.toString());
061    }
062
063}