com.buildml.main.commands.CliCommandUpgrade.java Source code

Java tutorial

Introduction

Here is the source code for com.buildml.main.commands.CliCommandUpgrade.java

Source

/*******************************************************************************
 * Copyright (c) 2012 Arapiki Solutions Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    "Peter Smith <psmith@arapiki.com>" - initial API and 
 *        implementation and/or initial documentation
 *******************************************************************************/

package com.buildml.main.commands;

import java.io.FileNotFoundException;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;

import com.buildml.main.CliUtils;
import com.buildml.main.ICliCommand;
import com.buildml.model.BuildStoreFactory;
import com.buildml.model.BuildStoreVersionException;
import com.buildml.model.IBuildStore;

/**
 * BuildML CLI Command class that implements the "upgrade" command.
 * 
 * @author "Peter Smith <psmith@arapiki.com>"
 */
public class CliCommandUpgrade implements ICliCommand {

    /*=====================================================================================*
     * PUBLIC METHODS
     *=====================================================================================*/

    /* (non-Javadoc)
     * @see com.buildml.main.ICliCommand#getLongDescription()
     */
    @Override
    public String getLongDescription() {
        return CliUtils.genLocalizedMessage("#include commands/upgrade.txt");
    }

    /*-------------------------------------------------------------------------------------*/

    /* (non-Javadoc)
     * @see com.buildml.main.ICliCommand#getName()
     */
    @Override
    public String getName() {
        return "upgrade";
    }

    /*-------------------------------------------------------------------------------------*/

    /* (non-Javadoc)
     * @see com.buildml.main.ICliCommand#getOptions()
     */
    @Override
    public Options getOptions() {
        return new Options();
    }

    /*-------------------------------------------------------------------------------------*/

    /* (non-Javadoc)
     * @see com.buildml.main.ICliCommand#getParameterDescription()
     */
    @Override
    public String getParameterDescription() {
        return "";
    }

    /*-------------------------------------------------------------------------------------*/

    /* (non-Javadoc)
     * @see com.buildml.main.ICliCommand#getShortDescription()
     */
    @Override
    public String getShortDescription() {
        return "Upgrade an existing build.bml to the current schema version.";
    }

    /*-------------------------------------------------------------------------------------*/

    /* (non-Javadoc)
     * @see com.buildml.main.ICliCommand#processOptions(org.apache.commons.cli.CommandLine)
     */
    @Override
    public void processOptions(IBuildStore buildStore, CommandLine cmdLine) {
        /* empty */
    }

    /*-------------------------------------------------------------------------------------*/

    /* (non-Javadoc)
     * @see com.buildml.main.ICliCommand#invoke(com.buildml.model.BuildStore, java.lang.String[])
     */
    @Override
    public void invoke(IBuildStore buildStore, String buildStorePath, String[] args) {

        CliUtils.validateArgs(getName(), args, 0, 0,
                "No arguments required. Use -f global option to specify database name.");

        /* all is good */
        try {
            BuildStoreFactory.upgradeBuildStore(buildStorePath);
        } catch (FileNotFoundException e) {
            CliUtils.reportErrorAndExit(e.getMessage());
        } catch (BuildStoreVersionException e) {
            CliUtils.reportErrorAndExit(e.getMessage());
        }

        System.out.println("Database is now at correct schema version.");
    }

    /*-------------------------------------------------------------------------------------*/
}