# HG changeset patch # User Mario Torre # Date 1302037398 -7200 # Node ID 9c7b2324899625597bf02ea3ab87959538ca4035 # Parent 1366f29ac6fa665b7bc5e97b637efc2081f8524d Add new plugins to handle guilt patch queue. diff -r 1366f29ac6fa -r 9c7b23248996 src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueAdd.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueAdd.java Tue Apr 05 23:03:18 2011 +0200 @@ -0,0 +1,71 @@ +/* + * 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.util.LinkedList; +import java.util.List; +import joptsimple.OptionSet; +import org.icedrobot.ika.plugins.IkaPluginResult; +import org.icedrobot.ika.runtime.scm.GITPatchQueue; + +/** + * Handles patch queues in IcedRobot, abstracting the underliying patch queue + * system. + * + * This is the implementation of the qadd command. + */ +public class IkaPatchQueueAdd extends IkaPatchQueueHandler { + + @Override + public String getName() { + return "qapplied"; + } + + @Override + public String getDescription() { + return "print the list of applied patches int this ika managed " + + "patch queue"; + } + + @Override + public IkaPluginResult execute(String[] args) { + + OptionSet options = parser.parse(args); + if (options.has(PatchQueueOption.HELP.getOption())) { + displayUsage(); + } else { + + boolean force = options.has(PatchQueueOption.FORCE.getOption()); + List files = options.nonOptionArguments(); + if (files.size() < 2) { + displayUsage(); + } else { + List fileList = + new LinkedList(files.subList(1, files.size())); + GITPatchQueue.add(fileList, force); + } + } + return IkaPluginResult.OK; + } + + @Override + protected boolean hasArgument() { + return true; + } +} diff -r 1366f29ac6fa -r 9c7b23248996 src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueApplied.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueApplied.java Tue Apr 05 23:03:18 2011 +0200 @@ -0,0 +1,60 @@ +/* + * 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 joptsimple.OptionSet; +import org.icedrobot.ika.plugins.IkaPluginResult; +import org.icedrobot.ika.runtime.scm.GITPatchQueue; + +/** + * Handles patch queues in IcedRobot, abstracting the underliying patch queue + * system. + * + * This is the implementation of the qapplied command. + */ +public class IkaPatchQueueApplied extends IkaPatchQueueHandler { + + @Override + public String getName() { + return "qapplied"; + } + + @Override + public String getDescription() { + return "print the list of applied patches int this ika managed " + + "patch queue"; + } + + @Override + public IkaPluginResult execute(String[] args) { + + OptionSet options = parser.parse(args); + if (options.has(PatchQueueOption.HELP.getOption())) { + displayUsage(); + } else { + GITPatchQueue.applied(); + } + return IkaPluginResult.OK; + } + + @Override + protected boolean hasArgument() { + return false; + } +} diff -r 1366f29ac6fa -r 9c7b23248996 src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueHandler.java Tue Apr 05 23:03:18 2011 +0200 @@ -0,0 +1,57 @@ +/* + * 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.IOException; +import joptsimple.OptionParser; +import org.icedrobot.ika.plugins.IkaPlugin; + +/** + */ +abstract class IkaPatchQueueHandler implements IkaPlugin { + + static OptionParser parser; + + static { + parser = new OptionParser() { + { + accepts(PatchQueueOption.HELP.getOption(), + PatchQueueOption.HELP.getDescription()); + accepts(PatchQueueOption.FORCE.getOption(), + PatchQueueOption.FORCE.getDescription()); + accepts(PatchQueueOption.ALL.getOption(), + PatchQueueOption.ALL.getDescription()); + } + }; + } + + abstract protected boolean hasArgument(); + + protected void displayUsage() { + String fileName = "name.patch"; + if (hasArgument()) { + fileName = ""; + } + System.out.println("ika " + getName() + " [-f] " + fileName); + System.out.println(getDescription()); + try { + parser.printHelpOn(System.out); + + } catch (IOException ignore) {} + } +} diff -r 1366f29ac6fa -r 9c7b23248996 src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueNew.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueNew.java Tue Apr 05 23:03:18 2011 +0200 @@ -0,0 +1,68 @@ +/* + * 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.util.List; +import joptsimple.OptionSet; +import org.icedrobot.ika.plugins.IkaPluginResult; +import org.icedrobot.ika.runtime.scm.GITPatchQueue; + +/** + * Handles patch queues in IcedRobot, abstracting the underliying patch queue + * system. + * + * This is the implementation of the qnew command. + */ +public class IkaPatchQueueNew extends IkaPatchQueueHandler { + + @Override + public String getName() { + return "qnew"; + } + + @Override + public String getDescription() { + return "creates a new ika managed patch in the patch queue"; + } + + @Override + public IkaPluginResult execute(String[] args) { + + OptionSet options = parser.parse(args); + if (options.has(PatchQueueOption.HELP.getOption())) { + displayUsage(); + } else { + + boolean force = options.has(PatchQueueOption.FORCE.getOption()); + List files = options.nonOptionArguments(); + if (files.size() != 2) { + displayUsage(); + } else { + GITPatchQueue.newPatch(files.get(1), force); + } + } + + return IkaPluginResult.OK; + } + + @Override + protected boolean hasArgument() { + return true; + } +} diff -r 1366f29ac6fa -r 9c7b23248996 src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueuePop.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueuePop.java Tue Apr 05 23:03:18 2011 +0200 @@ -0,0 +1,71 @@ +/* + * 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.util.List; +import joptsimple.OptionSet; +import org.icedrobot.ika.plugins.IkaPluginResult; +import org.icedrobot.ika.runtime.scm.GITPatchQueue; + +/** + * Handles patch queues in IcedRobot, abstracting the underliying patch queue + * system. + * + * This is the implementation of the qpop command. + */ +public class IkaPatchQueuePop extends IkaPatchQueueHandler { + + @Override + public String getName() { + return "qpop"; + } + + @Override + public String getDescription() { + return "applies the patches to the managed source tree"; + } + + @Override + public IkaPluginResult execute(String[] args) { + + OptionSet options = parser.parse(args); + if (options.has(PatchQueueOption.HELP.getOption())) { + displayUsage(); + } else { + + boolean force = options.has(PatchQueueOption.FORCE.getOption()); + boolean all = options.has(PatchQueueOption.ALL.getOption()); + List files = options.nonOptionArguments(); + if (files.size() > 2) { + displayUsage(); + } else if (files.size() == 1) { + GITPatchQueue.pop(force, all); + } else { + GITPatchQueue.pop(files.get(1), force, all); + } + } + + return IkaPluginResult.OK; + } + + @Override + protected boolean hasArgument() { + return true; + } +} diff -r 1366f29ac6fa -r 9c7b23248996 src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueuePush.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueuePush.java Tue Apr 05 23:03:18 2011 +0200 @@ -0,0 +1,71 @@ +/* + * 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.util.List; +import joptsimple.OptionSet; +import org.icedrobot.ika.plugins.IkaPluginResult; +import org.icedrobot.ika.runtime.scm.GITPatchQueue; + +/** + * Handles patch queues in IcedRobot, abstracting the underliying patch queue + * system. + * + * This is the implementation of the qpush command. + */ +public class IkaPatchQueuePush extends IkaPatchQueueHandler { + + @Override + public String getName() { + return "qpush"; + } + + @Override + public String getDescription() { + return "applies the patches to the managed source tree"; + } + + @Override + public IkaPluginResult execute(String[] args) { + + OptionSet options = parser.parse(args); + if (options.has(PatchQueueOption.HELP.getOption())) { + displayUsage(); + } else { + + boolean force = options.has(PatchQueueOption.FORCE.getOption()); + boolean all = options.has(PatchQueueOption.ALL.getOption()); + List files = options.nonOptionArguments(); + if (files.size() > 2) { + displayUsage(); + } else if (files.size() == 1) { + GITPatchQueue.push(force, all); + } else { + GITPatchQueue.push(files.get(1), force, all); + } + } + + return IkaPluginResult.OK; + } + + @Override + protected boolean hasArgument() { + return true; + } +} diff -r 1366f29ac6fa -r 9c7b23248996 src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueRefresh.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueRefresh.java Tue Apr 05 23:03:18 2011 +0200 @@ -0,0 +1,60 @@ +/* + * 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 joptsimple.OptionSet; +import org.icedrobot.ika.plugins.IkaPluginResult; +import org.icedrobot.ika.runtime.scm.GITPatchQueue; + +/** + * Handles patch queues in IcedRobot, abstracting the underliying patch queue + * system. + * + * This is the implementation of the qrefresh command. + */ +public class IkaPatchQueueRefresh extends IkaPatchQueueHandler { + + @Override + public String getName() { + return "qrefresh"; + } + + @Override + public String getDescription() { + return "refreshes an ika managed patch in the patch queue"; + } + + @Override + public IkaPluginResult execute(String[] args) { + + OptionSet options = parser.parse(args); + if (options.has(PatchQueueOption.HELP.getOption())) { + displayUsage(); + } else { + boolean force = options.has(PatchQueueOption.FORCE.getDescription()); + GITPatchQueue.refresh(force); + } + return IkaPluginResult.OK; + } + + @Override + protected boolean hasArgument() { + return false; + } +} diff -r 1366f29ac6fa -r 9c7b23248996 src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueStatus.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/ika/plugins/scm/IkaPatchQueueStatus.java Tue Apr 05 23:03:18 2011 +0200 @@ -0,0 +1,60 @@ +/* + * 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 joptsimple.OptionSet; +import org.icedrobot.ika.plugins.IkaPluginResult; +import org.icedrobot.ika.runtime.scm.GITPatchQueue; + +/** + * Handles patch queues in IcedRobot, abstracting the underliying patch queue + * system. + * + * This is the implementation of the qstatus command. + */ +public class IkaPatchQueueStatus extends IkaPatchQueueHandler { + + @Override + public String getName() { + return "qstatus"; + } + + @Override + public String getDescription() { + return "print the status of the tracked files in an ika managed " + + "patch queue"; + } + + @Override + public IkaPluginResult execute(String[] args) { + + OptionSet options = parser.parse(args); + if (options.has(PatchQueueOption.HELP.getOption())) { + displayUsage(); + } else { + GITPatchQueue.status(); + } + return IkaPluginResult.OK; + } + + @Override + protected boolean hasArgument() { + return false; + } +} diff -r 1366f29ac6fa -r 9c7b23248996 src/main/java/org/icedrobot/ika/plugins/scm/PatchQueueOption.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/ika/plugins/scm/PatchQueueOption.java Tue Apr 05 23:03:18 2011 +0200 @@ -0,0 +1,42 @@ +/* + * 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; + +enum PatchQueueOption { + + FORCE("f", "force the execution of the command"), + ALL("all", "apply all"), + HELP("help", "display a short help"); + + final private String option; + final private String description; + + PatchQueueOption(String option, String description) { + this.option = option; + this.description = description; + } + + public String getOption() { + return option; + } + + public String getDescription() { + return description; + } +} diff -r 1366f29ac6fa -r 9c7b23248996 src/main/java/org/icedrobot/ika/runtime/scm/GITPatchQueue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/ika/runtime/scm/GITPatchQueue.java Tue Apr 05 23:03:18 2011 +0200 @@ -0,0 +1,104 @@ +/* + * 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.runtime.scm; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.icedrobot.ika.runtime.IkaRuntime; + +public class GITPatchQueue { + + public static void newPatch(String name, boolean force) { + String forceCmd = ""; + if (force) { + forceCmd = "-f"; + } + IkaRuntime.exec(new File("."), "guilt", "new", forceCmd, name); + } + + public static void refresh(boolean force) { + String forceCmd = ""; + if (force) { + forceCmd = "-f"; + } + IkaRuntime.exec(new File("."), "guilt", forceCmd, "refresh"); + } + + public static void status() { + IkaRuntime.exec(new File("."), "guilt", "status"); + } + + public static void applied() { + IkaRuntime.exec(new File("."), "guilt", "applied"); + } + + public static void add(List args, boolean force) { + + List argList = new ArrayList(); + argList.add("guilt"); + if (force) { + argList.add("-f"); + } + argList.add("add"); + argList.addAll(args); + + exec(args); + } + + public static void push(boolean force, boolean all) { + push(null, force, all); + } + + public static void push(String patchName, boolean force, boolean all) { + exec("push", patchName, force, all); + } + + public static void pop(boolean force, boolean all) { + push(null, force, all); + } + + public static void pop(String patchName, boolean force, boolean all) { + exec("pop", patchName, force, all); + } + + private static void exec(String command, String patchName, boolean force, + boolean all) { + List argList = new ArrayList(); + argList.add("guilt"); + argList.add(command); + + if (force) { + argList.add("-f"); + } + if (all) { + argList.add("--all"); + } + if (patchName != null) { + argList.add(patchName); + } + exec(argList); + } + + private static void exec(List args) { + String[] argsAsArray = args.toArray(new String[args.size()]); + IkaRuntime.exec(new File("."), argsAsArray); + } +} diff -r 1366f29ac6fa -r 9c7b23248996 src/main/resources/core_plugins.properties --- a/src/main/resources/core_plugins.properties Tue Apr 05 23:02:56 2011 +0200 +++ b/src/main/resources/core_plugins.properties Tue Apr 05 23:03:18 2011 +0200 @@ -2,3 +2,10 @@ version=org.icedrobot.ika.plugins.help.IkaVersion assimilate=org.icedrobot.ika.plugins.borg.IcedRobotCloner init=org.icedrobot.ika.plugins.scm.IkaInitRepository +qnew=org.icedrobot.ika.plugins.scm.IkaPatchQueueNew +qrefresh=org.icedrobot.ika.plugins.scm.IkaPatchQueueRefresh +qstatus=org.icedrobot.ika.plugins.scm.IkaPatchQueueStatus +qapplied=org.icedrobot.ika.plugins.scm.IkaPatchQueueApplied +qadd=org.icedrobot.ika.plugins.scm.IkaPatchQueueAdd +qpush=org.icedrobot.ika.plugins.scm.IkaPatchQueuePush +qpop=org.icedrobot.ika.plugins.scm.IkaPatchQueuePop