view src/main/java/org/icedrobot/ika/plugins/scm/IkaInitRepository.java @ 17:1366f29ac6fa

Remove debug output.
author Mario Torre <neugens.limasoftware@gmail.com>
date Tue, 05 Apr 2011 23:02:56 +0200
parents ffeb5d49c3f2
children
line wrap: on
line source

/*
 * IKA - IcedRobot Kiosk Application
 * Copyright (C) 2011  IcedRobot team
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.icedrobot.ika.plugins.scm;

import java.io.File;
import java.io.IOException;
import java.util.List;

import joptsimple.OptionParser;
import joptsimple.OptionSet;

import org.icedrobot.ika.plugins.IkaPlugin;
import org.icedrobot.ika.plugins.IkaPluginResult;
import org.icedrobot.ika.runtime.scm.GITRepository;
import org.icedrobot.ika.runtime.scm.HGRepository;
import org.icedrobot.ika.runtime.scm.Repository;

/**
 * @author Mario Torre <neugens.limasoftware@gmail.com>
 */
public class IkaInitRepository implements IkaPlugin {

    private static final String HELP = "help";
    private static final String HELP_DESC = "print this brief help";

    @Override
    public String getName() {
        return "init";
    }

    @Override
    public String getDescription() {
        return "creates a new ika managed repository";
    }

    @Override
    public IkaPluginResult execute(String[] args) {

        OptionParser parser = new OptionParser();
        parser.accepts(HELP, HELP_DESC);

        if (args == null) {
            displayUsage(parser);
            return IkaPluginResult.OK;
        }

        OptionSet options = parser.parse(args);
        if (options.has(HELP)) {
            displayUsage(parser);
            
        } else {
            List<String> files = options.nonOptionArguments();
            if (files.size() != 2) {
                displayUsage(parser);

            } else {
                String destinationDir = files.get(1);
                System.err.println("dest: " + destinationDir);
                File base = new File(destinationDir);
                if (!base.exists()) {
                    System.out.println("desitination directory doesn't exist");
                    return IkaPluginResult.FAILURE;
                }

                System.err.println("base.getName(): " + base.getName());
                Repository repository = new GITRepository(base.getName(), base,
                                                          "", "", "icedrobot");
                repository.create();

                repository.initPatchQueue();

                String s = File.separator;
                File basePath = new File(repository.getFullPath() + s +
                                         ".git" + s + "patches");

                Repository hgRepo = new HGRepository(base.getName(), basePath,
                                                     "", "");
                hgRepo.create();
            }
        }
        return IkaPluginResult.OK;
    }

    private void displayUsage(OptionParser parser) {
        System.out.println("ika " + getName() + " /directory/to/initialise");
        try {
            parser.printHelpOn(System.out);

        } catch (IOException ignore) { }
    }
}