# HG changeset patch # User Mario Torre # Date 1301435671 -7200 # Node ID ffeb5d49c3f2208db2acacd036298af30719b530 # Parent 5fa4fe467471bec21d02c5e0e2e1770ad922f132 New plugin to initialise ika managed repository, replaces git plugin. diff -r 5fa4fe467471 -r ffeb5d49c3f2 src/main/java/org/icedrobot/ika/plugins/scm/IkaInitRepository.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/ika/plugins/scm/IkaInitRepository.java Tue Mar 29 23:54:31 2011 +0200 @@ -0,0 +1,107 @@ +/* + * 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 . + */ +package org.icedrobot.ika.plugins.scm; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +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 + */ +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 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) { } + } +} diff -r 5fa4fe467471 -r ffeb5d49c3f2 src/main/resources/core_plugins.properties --- a/src/main/resources/core_plugins.properties Tue Mar 29 23:53:18 2011 +0200 +++ b/src/main/resources/core_plugins.properties Tue Mar 29 23:54:31 2011 +0200 @@ -1,4 +1,4 @@ # list of core plugins, the keys are the names and the values the class name version=org.icedrobot.ika.plugins.help.IkaVersion assimilate=org.icedrobot.ika.plugins.borg.IcedRobotCloner -git=org.icedrobot.ika.plugins.git.IkaGitWrapper +init=org.icedrobot.ika.plugins.scm.IkaInitRepository