# HG changeset patch # User Mario Torre # Date 1299540049 -3600 # Node ID 82de5424529c53dc15163f16a436d56003f89e1b # Parent 8c6dc2a5506bb266513ac45eea16e15cae911288 Moved SCM Repository abstraction to different location. diff -r 8c6dc2a5506b -r 82de5424529c src/org/icedrobot/ika/plugins/borg/AndroidAssimilator.java --- a/src/org/icedrobot/ika/plugins/borg/AndroidAssimilator.java Tue Mar 08 00:04:51 2011 +0100 +++ b/src/org/icedrobot/ika/plugins/borg/AndroidAssimilator.java Tue Mar 08 00:20:49 2011 +0100 @@ -18,6 +18,8 @@ package org.icedrobot.ika.plugins.borg; +import org.icedrobot.ika.plugins.scm.Repository; +import org.icedrobot.ika.plugins.scm.GITRepository; import java.io.File; import java.io.IOException; import java.util.Properties; diff -r 8c6dc2a5506b -r 82de5424529c src/org/icedrobot/ika/plugins/borg/ClonerTask.java --- a/src/org/icedrobot/ika/plugins/borg/ClonerTask.java Tue Mar 08 00:04:51 2011 +0100 +++ b/src/org/icedrobot/ika/plugins/borg/ClonerTask.java Tue Mar 08 00:20:49 2011 +0100 @@ -18,6 +18,8 @@ package org.icedrobot.ika.plugins.borg; +import org.icedrobot.ika.plugins.scm.Repository; +import org.icedrobot.ika.plugins.scm.HGRepository; import java.io.File; import java.util.Properties; @@ -70,9 +72,8 @@ new HGRepository(repo, subRepository.getFullPath(), ".git" + sep + "patches", repository.getBaseDirectory() + - sep + "icedrobot" + sep + - "projects" + sep + - subRepository.getName() + sep + + sep + "icedrobot" + sep + "projects" + + sep + subRepository.getName() + sep + "patches"); hgPatchQueue.createRoot(); hgPatchQueue.makeClone(); diff -r 8c6dc2a5506b -r 82de5424529c src/org/icedrobot/ika/plugins/borg/GITRepository.java --- a/src/org/icedrobot/ika/plugins/borg/GITRepository.java Tue Mar 08 00:04:51 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* - * 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.borg; - -import java.io.File; -import java.io.IOException; -import org.icedrobot.ika.plugins.IkaPluginException; - -/** - * @author Mario Torre - */ -public class GITRepository extends Repository { - - /** - * Creates a new git Repository with the give name as ID, the - * base directory as the location where the clone will be performed, the - * relativePath as the name of the cloned repository, the remotePath as the - * location of the source repository and branch as the version of the - * repository to clone. - */ - public GITRepository(String name, File baseDirectory, String relativePath, - String remotePath, String branch) { - - this.name = name; - this.baseDirectory = baseDirectory; - this.relativePath = relativePath; - this.remotePath = remotePath; - - this.branch = branch; - - String canonicalPath; - try { - canonicalPath = baseDirectory.getCanonicalPath(); - } catch (IOException ex) { - throw new IkaPluginException(ex.getMessage(), ex); - } - - this.fullPath = new File(canonicalPath + File.separator + relativePath); - } - - /** - * - */ - @Override - public void makeClone() { - String command = "git clone -b " + getBranch() + " " + remotePath; - System.err.println(command); - exec(command, getFullPath()); - } - - /** - * - */ - @Override - public Repository makeSubRepository(String name, String relativePath, - String branch) { - - if (name.equals(".")) { - name = this.getName(); - } - Repository subRepository = - new GITRepository(name, new File(getFullPath() + File.separator + - getName()), - relativePath, null, branch); - - String command = "git init ."; - System.err.println(command); - exec(command, subRepository.getFullPath()); - - command = "git add --all"; - System.err.println(command); - exec(command, subRepository.getFullPath()); - - command = "git commit -m initial_repository --verbose"; - System.err.println(command); - exec(command, subRepository.getFullPath()); - - command = "git branch " + branch; - System.err.println(command); - exec(command, subRepository.getFullPath()); - - command = "git checkout " + branch; - System.err.println(command); - exec(command, subRepository.getFullPath()); - - System.err.println(">>>>>>>> done: " + subRepository + " <<<<<<<<"); - - return subRepository; - } - - @Override - public void applyPatchQueue() { - String command = "guilt push --all"; - System.err.println(command); - exec(command, getFullPath()); - } -} diff -r 8c6dc2a5506b -r 82de5424529c src/org/icedrobot/ika/plugins/borg/HGRepository.java --- a/src/org/icedrobot/ika/plugins/borg/HGRepository.java Tue Mar 08 00:04:51 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * 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.borg; - -import java.io.File; - -/** - * @author Mario Torre - */ -public class HGRepository extends Repository { - - /** - * Creates a new mercurial forest Repository with the give name as ID, the - * base directory as the location where the clone will be performed, the - * relativePath as the name of the cloned repository, the remotePath as the - * location of the source repository. The Forest extension is needed - * to create the repository. The branch is always HEAD. - */ - public HGRepository(String name, File baseDirectory, - String relativePath, - String remotePath) { - - this.name = name; - this.baseDirectory = baseDirectory; - this.relativePath = relativePath; - this.remotePath = remotePath; - - this.fullPath = new File(baseDirectory.getAbsolutePath() + - File.separator + relativePath); - } - - /** - * - */ - @Override - public void makeClone() { - String command = "hg clone " + remotePath + " " + getFullPath(); - System.err.println(command); - exec(command, getFullPath()); - } - - @Override - public String getBranch() { - // only HEAD is supported - return "HEAD"; - } - - /** - * - */ - @Override - public Repository makeSubRepository(String name, String relativePath, - String branch) { - - throw new UnsupportedOperationException("not supported yet"); - } - - @Override - public void applyPatchQueue() { - throw new UnsupportedOperationException("Not supported yet."); - } -} diff -r 8c6dc2a5506b -r 82de5424529c src/org/icedrobot/ika/plugins/borg/IcedRobotCloner.java --- a/src/org/icedrobot/ika/plugins/borg/IcedRobotCloner.java Tue Mar 08 00:04:51 2011 +0100 +++ b/src/org/icedrobot/ika/plugins/borg/IcedRobotCloner.java Tue Mar 08 00:20:49 2011 +0100 @@ -18,6 +18,8 @@ package org.icedrobot.ika.plugins.borg; +import org.icedrobot.ika.plugins.scm.Repository; +import org.icedrobot.ika.plugins.scm.HGRepository; import java.io.File; import java.io.IOException; import java.util.Properties; diff -r 8c6dc2a5506b -r 82de5424529c src/org/icedrobot/ika/plugins/borg/Repository.java --- a/src/org/icedrobot/ika/plugins/borg/Repository.java Tue Mar 08 00:04:51 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -/* - * 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.borg; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.icedrobot.ika.plugins.IkaPluginException; - -/** - * @author Mario Torre - */ -public abstract class Repository { - - protected String name; - protected File baseDirectory; - protected File fullPath; - - protected String relativePath; - protected String remotePath; - protected String branch; - - public abstract void applyPatchQueue(); - public abstract void makeClone(); - public abstract Repository makeSubRepository(String name, - String relativePath, - String branch); - - protected static void exec(String command, File path) { - try { - System.err.println("command: " + command + ", path: " + path); - Process process = Runtime.getRuntime().exec(command, null, path); - - InputStream is = process.getInputStream(); - InputStreamReader reader = new InputStreamReader(is); - - BufferedReader br = new BufferedReader(reader); - - String line; - while ((line = br.readLine()) != null) { - System.out.println(line); - } - - } catch (IOException ex) { - Logger.getLogger(AndroidAssimilator.class.getName()). - log(Level.SEVERE, "cannot execute: " + command, ex); - throw new IkaPluginException("cannot execute: " + command, ex); - } - } - - /** - * - */ - public void createRoot() { - getFullPath().mkdir(); - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @return the baseDirectory - */ - public File getBaseDirectory() { - return baseDirectory; - } - - /** - * @return the fullPath - */ - public File getFullPath() { - try { - return fullPath.getCanonicalFile(); - } catch (IOException ex) { - throw new IkaPluginException(ex.toString(), ex); - } - } - - /** - * @return the relativePath - */ - public String getRelativePath() { - return relativePath; - } - - /** - * @return the remotePath - */ - public String getRemotePath() { - return remotePath; - } - - /** - * @return the branch - */ - public String getBranch() { - return branch; - } - - @Override - public String toString() { - return fullPath.toString(); - } -} diff -r 8c6dc2a5506b -r 82de5424529c src/org/icedrobot/ika/plugins/scm/GITRepository.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/icedrobot/ika/plugins/scm/GITRepository.java Tue Mar 08 00:20:49 2011 +0100 @@ -0,0 +1,113 @@ +/* + * 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 org.icedrobot.ika.plugins.IkaPluginException; + +/** + * @author Mario Torre + */ +public class GITRepository extends Repository { + + /** + * Creates a new git Repository with the give name as ID, the + * base directory as the location where the clone will be performed, the + * relativePath as the name of the cloned repository, the remotePath as the + * location of the source repository and branch as the version of the + * repository to clone. + */ + public GITRepository(String name, File baseDirectory, String relativePath, + String remotePath, String branch) { + + this.name = name; + this.baseDirectory = baseDirectory; + this.relativePath = relativePath; + this.remotePath = remotePath; + + this.branch = branch; + + String canonicalPath; + try { + canonicalPath = baseDirectory.getCanonicalPath(); + } catch (IOException ex) { + throw new IkaPluginException(ex.getMessage(), ex); + } + + this.fullPath = new File(canonicalPath + File.separator + relativePath); + } + + /** + * + */ + @Override + public void makeClone() { + String command = "git clone -b " + getBranch() + " " + remotePath; + System.err.println(command); + exec(command, getFullPath()); + } + + /** + * + */ + @Override + public Repository makeSubRepository(String name, String relativePath, + String branch) { + + if (name.equals(".")) { + name = this.getName(); + } + Repository subRepository = + new GITRepository(name, new File(getFullPath() + File.separator + + getName()), + relativePath, null, branch); + + String command = "git init ."; + System.err.println(command); + exec(command, subRepository.getFullPath()); + + command = "git add --all"; + System.err.println(command); + exec(command, subRepository.getFullPath()); + + command = "git commit -m initial_repository --verbose"; + System.err.println(command); + exec(command, subRepository.getFullPath()); + + command = "git branch " + branch; + System.err.println(command); + exec(command, subRepository.getFullPath()); + + command = "git checkout " + branch; + System.err.println(command); + exec(command, subRepository.getFullPath()); + + System.err.println(">>>>>>>> done: " + subRepository + " <<<<<<<<"); + + return subRepository; + } + + @Override + public void applyPatchQueue() { + String command = "guilt push --all"; + System.err.println(command); + exec(command, getFullPath()); + } +} diff -r 8c6dc2a5506b -r 82de5424529c src/org/icedrobot/ika/plugins/scm/HGRepository.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/icedrobot/ika/plugins/scm/HGRepository.java Tue Mar 08 00:20:49 2011 +0100 @@ -0,0 +1,78 @@ +/* + * 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; + +/** + * @author Mario Torre + */ +public class HGRepository extends Repository { + + /** + * Creates a new mercurial forest Repository with the give name as ID, the + * base directory as the location where the clone will be performed, the + * relativePath as the name of the cloned repository, the remotePath as the + * location of the source repository. The Forest extension is needed + * to create the repository. The branch is always HEAD. + */ + public HGRepository(String name, File baseDirectory, + String relativePath, + String remotePath) { + + this.name = name; + this.baseDirectory = baseDirectory; + this.relativePath = relativePath; + this.remotePath = remotePath; + + this.fullPath = new File(baseDirectory.getAbsolutePath() + + File.separator + relativePath); + } + + /** + * + */ + @Override + public void makeClone() { + String command = "hg clone " + remotePath + " " + getFullPath(); + System.err.println(command); + exec(command, getFullPath()); + } + + @Override + public String getBranch() { + // only HEAD is supported + return "HEAD"; + } + + /** + * + */ + @Override + public Repository makeSubRepository(String name, String relativePath, + String branch) { + + throw new UnsupportedOperationException("not supported yet"); + } + + @Override + public void applyPatchQueue() { + throw new UnsupportedOperationException("Not supported yet."); + } +} diff -r 8c6dc2a5506b -r 82de5424529c src/org/icedrobot/ika/plugins/scm/Repository.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/icedrobot/ika/plugins/scm/Repository.java Tue Mar 08 00:20:49 2011 +0100 @@ -0,0 +1,130 @@ +/* + * 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.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.icedrobot.ika.plugins.IkaPluginException; + +/** + * @author Mario Torre + */ +public abstract class Repository { + + protected String name; + protected File baseDirectory; + protected File fullPath; + + protected String relativePath; + protected String remotePath; + protected String branch; + + public abstract void applyPatchQueue(); + public abstract void makeClone(); + public abstract Repository makeSubRepository(String name, + String relativePath, + String branch); + + protected static void exec(String command, File path) { + try { + System.err.println("command: " + command + ", path: " + path); + Process process = Runtime.getRuntime().exec(command, null, path); + + InputStream is = process.getInputStream(); + InputStreamReader reader = new InputStreamReader(is); + + BufferedReader br = new BufferedReader(reader); + + String line; + while ((line = br.readLine()) != null) { + System.out.println(line); + } + + } catch (IOException ex) { + Logger.getLogger(Repository.class.getName()). + log(Level.SEVERE, "cannot execute: " + command, ex); + throw new IkaPluginException("cannot execute: " + command, ex); + } + } + + /** + * + */ + public void createRoot() { + getFullPath().mkdir(); + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @return the baseDirectory + */ + public File getBaseDirectory() { + return baseDirectory; + } + + /** + * @return the fullPath + */ + public File getFullPath() { + try { + return fullPath.getCanonicalFile(); + } catch (IOException ex) { + throw new IkaPluginException(ex.toString(), ex); + } + } + + /** + * @return the relativePath + */ + public String getRelativePath() { + return relativePath; + } + + /** + * @return the remotePath + */ + public String getRemotePath() { + return remotePath; + } + + /** + * @return the branch + */ + public String getBranch() { + return branch; + } + + @Override + public String toString() { + return fullPath.toString(); + } +}