Mercurial > hg > icedrobot > ika
view src/main/java/org/icedrobot/ika/plugins/borg/IcedRobotCloner.java @ 12:5fa4fe467471
Refactor framework and plugins.
author | Mario Torre <neugens.limasoftware@gmail.com> |
---|---|
date | Tue, 29 Mar 2011 23:53:18 +0200 |
parents | b2827d00500a |
children | 17afcf8034a6 |
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.borg; import org.icedrobot.ika.runtime.scm.Repository; import org.icedrobot.ika.runtime.scm.HGRepository; import java.io.File; import java.io.IOException; import java.util.Properties; import joptsimple.OptionParser; import joptsimple.OptionSet; import org.icedrobot.ika.plugins.IkaPlugin; import org.icedrobot.ika.plugins.IkaPluginException; import org.icedrobot.ika.plugins.IkaPluginResult; /** * @author Mario Torre <neugens.limasoftware@gmail.com> */ public class IcedRobotCloner implements IkaPlugin { static final String ICEDROBOT_REPOS_CONFIGS = "/org/icedrobot/ika/plugins/borg/icedrobot.properties"; @Override public String getName() { return "assimilate"; } @Override public String getDescription() { return "clone the necessary Android respositories and " + "assimilate IcedRobot"; } @Override public IkaPluginResult execute(String[] args) { String destinationDir = null; String icedrobot = null; if (args != null) { OptionParser parser = new OptionParser(); parser.accepts("dest").withRequiredArg(); parser.accepts("icedrobot").withRequiredArg(); parser.accepts("help"); OptionSet options = parser.parse(args); if (options.has("help")) { displayUsage(); return IkaPluginResult.OK; } if (options.has("dest")) { destinationDir = (String) options.valueOf("dest"); } if (options.has("icedrobot")) { icedrobot = (String) options.valueOf("icedrobot"); } } if (icedrobot == null) { Properties configs = new Properties(); try { configs.load(IcedRobotCloner.class. getResourceAsStream(ICEDROBOT_REPOS_CONFIGS)); icedrobot = configs.getProperty("icedrobot"); } catch (IOException ex) { throw new IkaPluginException("cannot determine icedrobot " + "repository location", ex); } } if (destinationDir == null) { displayUsage(); return IkaPluginResult.FAILURE; } // create first the main source directory System.out.println("creating main repository container into " + "directory \"" + destinationDir + "\"..."); File repositoryLocation = new File(destinationDir); if (repositoryLocation.exists()) { throw new IkaPluginException("destination directory " + repositoryLocation + " already existing"); } if (!repositoryLocation.mkdir()) { throw new IkaPluginException("cannot create directory " + repositoryLocation); } // now clone the icedrobot reposutory System.out.println("...done... now cloning icedrobot: " + icedrobot); Repository icedrobotRepository = new HGRepository("icedrobot", repositoryLocation, "icedrobot", icedrobot); icedrobotRepository.createRoot(); icedrobotRepository.makeClone(); // now assimilate! System.out.println("cloning repositories..."); AndroidAssimilator.assimilate(repositoryLocation); System.out.println("creating main repository container..."); System.out.println("resistance is futile, IcedRobot assimilated"); return IkaPluginResult.OK; } private void displayUsage() { System.out.println("Usage: ika assimilate --dest=" + "<destination directory> " + "--icedrobot=<source repository>"); System.out.println("\t--dest"); System.out.println("\t\t\tdirectory where to create the " + "IcedRobot snapshot"); System.out.println("\t\t\tThis argument is mandatory."); System.out.println("\t--icedrobot"); System.out.println("\t\t\tlocation of the remote repository"); System.out.println("\t\t\tThis argument is optional, if not given"); System.out.println("\t\t\tthen the default is retrived from " + "the configuration files"); System.out.println("\t--help"); System.out.println("\t\t\tprint usage information"); } }