Author: tchemit Date: 2008-04-05 20:43:32 +0000 (Sat, 05 Apr 2008) New Revision: 370 Modified: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSConnexion.java trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHandler.java trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHelper.java trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNConnexion.java trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHandler.java trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHelper.java Log: refactor PRovider, Handler and Connexion Modified: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSConnexion.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSConnexion.java 2008-04-05 20:41:33 UTC (rev 369) +++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSConnexion.java 2008-04-05 20:43:32 UTC (rev 370) @@ -14,23 +14,119 @@ */ package org.codelutin.vcs.impl.cvs; +import org.codelutin.vcs.CVSProvider; +import org.codelutin.vcs.VCSConnexionConfig; +import org.codelutin.vcs.VCSConnexionMode; +import org.codelutin.vcs.VCSException; import org.codelutin.vcs.util.AbstractVCSConnexion; -import org.codelutin.vcs.VCSConfig; -import org.codelutin.vcs.VCSHandler; +import org.netbeans.lib.cvsclient.CVSRoot; +import org.netbeans.lib.cvsclient.Client; +import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; +import org.netbeans.lib.cvsclient.command.GlobalOptions; +import org.netbeans.lib.cvsclient.connection.Connection; +import org.netbeans.lib.cvsclient.connection.PServerConnection; /** @author chemit */ public class CVSConnexion extends AbstractVCSConnexion { - public void init(VCSConfig config, VCSHandler handler) { + public CVSConnexion(VCSConnexionMode mode, CVSProvider provider) { + super(mode, provider); } + public void init(VCSConnexionConfig config) { + //TODO + this.config = config; + } + + public void testConnection() throws VCSException { + //TODO + } + @Override public void close() throws IllegalStateException { + //TODO checkInit(); } @Override public void open() throws IllegalStateException { + //TODO checkInit(); } + + public String getRemoteUrl() { + checkInit(); + return (config.isUseSshConnexion() ? ":ext:" : ":pserver:") + config.getUserName() + "@" + config.getHostName() + config.getRemotePath(); + } + + protected Client getClient() { + checkInit(); + // WARNING TO DEVELOPERS: + // Please be warned that attempting to reuse one open connection for + // more commands is not supported by cvs servers very well. + // You are advised to open a new Connection each time. + // If you still want to proceed, please do: + // System.setProperty("javacvs.multiple_commands_warning", "false") + // That will disable this message. + + // d'ou l'initialisation syst�matique de la connexion. + + String hostName = getConfig().getHostName(); + + // R�pertoire distant du CVS + String repository = getConfig().getRemotePath(); + + String userName = getConfig().getUserName(); + + Connection connection; + if (getConfig().isUseSshConnexion()) { + throw new RuntimeException(CVSHelper.class + " you can not used a ssh connexion with CVS, use instead SVN configuration"); + // connexion ssh2 + //TODO Make this works + // Localisation de la clef priv�e (pour la connexion ssh2). + //File keyFile = new File(config.getKeyFile()); + // Stockage des cl�s publics pour les hosts ou il y a eu connexion en ssh2 + //String host = config.getHost(); + // Localisation de la clef priv�e (pour la connexion ssh2). + //File keyFile = new File(IsisConfig.getProperties().getProperty( + // IsisConfig.CVS_KEY_FILE)); + // Stockage des cl�s publics pour les hosts ou il y a eu connexion en ssh2 + //String host = IsisConfig.getProperties().getProperty( + // IsisConfig.CVS_HOST); + +// Ssh2Connexion ssh2Connection = new Ssh2Connexion(); +// ssh2Connection.setUserName(userName); +// ssh2Connection.setHostName(hostName); +// ssh2Connection.setKeyFile(keyFile); +// ssh2Connection.setHost(host); +// ssh2Connection.setRepository(repository); +// connection = ssh2Connection; + } else { + String cvsrootString = ":pserver:" + userName + "@" + hostName + repository; + CVSRoot cvsroot = CVSRoot.parse(cvsrootString); + // connexion pserver + PServerConnection PServerConnection; + PServerConnection = new PServerConnection(cvsroot); +// PServerConnection.setUserName(userName); +// // PServerConnection.setEncodedPassword(encodedPassword); +// PServerConnection.setHostName(hostName); +// PServerConnection.setRepository(repository); + connection = PServerConnection; + } + + // Le connexion est ouverte automatiquement � l'�x�cution de la + // commande CVS si elle n'a pas �t� ouverte pr�c�dement. Je l'ouvre pour + // obtenir les messages d'erreurs plus clair. + // connection.open(); + + return new Client(connection, new StandardAdminHandler()); + } + + public GlobalOptions getGlobalOptions() { + checkInit(); + GlobalOptions result = new GlobalOptions(); + String repository = getConfig().getRemotePath(); + result.setCVSRoot(repository); + return result; + } } \ No newline at end of file Modified: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHandler.java 2008-04-05 20:41:33 UTC (rev 369) +++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHandler.java 2008-04-05 20:43:32 UTC (rev 370) @@ -2,10 +2,10 @@ import static org.codelutin.i18n.I18n._; import org.codelutin.util.FileUtil; -import org.codelutin.vcs.util.AbstractVCSHandler; -import org.codelutin.vcs.VCSConfig; +import org.codelutin.vcs.VCSConnexionConfig; import org.codelutin.vcs.VCSException; import org.codelutin.vcs.VCSState; +import org.codelutin.vcs.util.AbstractVCSHandler; import org.netbeans.lib.cvsclient.command.FileInfoContainer; import org.netbeans.lib.cvsclient.command.log.LogInformation; import org.netbeans.lib.cvsclient.command.status.StatusInformation; @@ -23,27 +23,25 @@ * @author chemit */ -public class CVSHandler extends AbstractVCSHandler { +public class CVSHandler extends AbstractVCSHandler<CVSConnexion> { - public CVSHandler(VCSConfig config) { - super(config, "CVS", "Entries"); + public CVSHandler() { + super("CVS", "Entries"); } - public void initWorkingCopy() throws VCSException { + public void initWorkingCopy(CVSConnexion connexion) throws VCSException { + VCSConnexionConfig config = connexion.getConfig(); File root = config.getLocalDatabasePath(); - if (!root.exists()) getLocalDatabasePath().mkdirs(); + if (!root.exists()) config.getLocalDatabasePath().mkdirs(); //TODO Should checkout root remote directory unrecurse ? //TODO to have vcs configuration file present in local database directory //CVSHelper.checkout(root,""); } - public String getRemoteUrl() { - return (config.isUseSshConnexion() ? ":ext:" : ":pserver:") + config.getUserName() + "@" + config.getHostName() + config.getRemotePath(); - } - public boolean isOnRemote(File file) { + public boolean isOnRemote(CVSConnexion connexion, File file) { boolean result = false; if (file.isDirectory()) { File cvsdir = new File(file, confLocalDirName); @@ -64,9 +62,9 @@ return result; } - public boolean isUpToDate(File file) throws VCSException { + public boolean isUpToDate(CVSConnexion connexion, File file) throws VCSException { - CVSCommandResult cvsResult = CVSHelper.cvsStatus(file); + CVSCommandResult cvsResult = CVSHelper.cvsStatus(connexion, file); if (cvsResult.isError()) { throw new VCSException(_("lutinvcs.error.status.files", cvsResult.getTrace().toString())); } @@ -86,12 +84,12 @@ return result; } - public void makeRemoteDir(String msg, String... dirNames) throws VCSException { + public void makeRemoteDir(CVSConnexion connexion, String msg, String... dirNames) throws VCSException { //TODO throw new RuntimeException(getClass().getName() + "#makeRemoteDir is not actually implemented"); } - public void deleteRemoteDir(String commitMessage, String... dirNames) throws VCSException { + public void deleteRemoteDir(CVSConnexion connexion, String commitMessage, String... dirNames) throws VCSException { throw new RuntimeException(getClass().getName() + "#deleteRemoteDir is not actually implemented"); //TODO } @@ -101,52 +99,52 @@ //TODO }*/ - public VCSState getState(File fileState, Collection tmp) throws VCSException { - return getState(fileState, tmp, true); + public VCSState getState(CVSConnexion connexion, File fileState, Collection tmp) throws VCSException { + return getState(connexion, fileState, tmp, true); } - public VCSState getState(File file, Collection tmp, boolean noremote) throws VCSException { + public VCSState getState(CVSConnexion connexion, File file, Collection tmp, boolean noremote) throws VCSException { throw new RuntimeException(getClass().getName() + "#getState(File) is not actually implemented"); //TODO } - public long add(List<File> files, String msg) throws VCSException { + public long add(CVSConnexion connexion, List<File> files, String msg) throws VCSException { log.debug("files to add: " + files); - CVSCommandResult result = CVSHelper.cvsAdd(files); + CVSCommandResult result = CVSHelper.cvsAdd(connexion, files); assertCommandResult(result, "Can''t add files: {0}"); - result = CVSHelper.cvsCommit(files, msg); + result = CVSHelper.cvsCommit(connexion, files, msg); assertCommandResult(result, "Can''t commit files: {0}"); return -1; } - public void delete(List<File> files, String msg) throws VCSException { + public void delete(CVSConnexion connexion, List<File> files, String msg) throws VCSException { - CVSCommandResult result = CVSHelper.cvsRemove(files); + CVSCommandResult result = CVSHelper.cvsRemove(connexion, files); assertCommandResult(result, "Can''t remove files: {0}"); - result = CVSHelper.cvsCommit(files, msg); + result = CVSHelper.cvsCommit(connexion, files, msg); assertCommandResult(result, "Can''t commit deleted files: {0}"); } - public long commit(List<File> files, String msg) throws VCSException { - add(files, msg); + public long commit(CVSConnexion connexion, List<File> files, String msg) throws VCSException { + add(connexion, files, msg); return 0; } - public void update(File file) throws VCSException { - CVSCommandResult result = CVSHelper.cvsUpdate(file); + public void update(CVSConnexion connexion, File file) throws VCSException { + CVSCommandResult result = CVSHelper.cvsUpdate(connexion, file); assertCommandResult(result, "Can''t update files: {0}"); } - public void checkout(File destDir, String module, boolean recurse) throws VCSException { - CVSCommandResult result = CVSHelper.checkout(destDir, module); + public void checkout(CVSConnexion connexion, File destDir, String module, boolean recurse) throws VCSException { + CVSCommandResult result = CVSHelper.checkout(connexion, destDir, module); assertCommandResult(result, "Can''t checkout files: {0}"); } - public void checkoutFile(File destDir, String module) throws VCSException { + public void checkoutFile(CVSConnexion connexion, File destDir, String module) throws VCSException { /*try { new File(destDir,module).createNewFile(); } catch (IOException e) { @@ -156,10 +154,10 @@ } - public List<String> getRemoteStorageNames(File directory) { + public List<String> getRemoteStorageNames(CVSConnexion connexion, File directory) { List<String> result = new ArrayList<String>(); try { - CVSCommandResult cvsResult = CVSHelper.cvsLog(directory); + CVSCommandResult cvsResult = CVSHelper.cvsLog(connexion, directory); for (FileInfoContainer info : cvsResult.getFileInfo()) { if (info instanceof LogInformation) { LogInformation status = (LogInformation) info; @@ -177,14 +175,15 @@ * Retourne les messages de logs entre la version local et la remote ou null * si les deux fichiers ont la meme version * - * @param file TODO - * @param logInfo TODO + * @param connexion connexion to be used + * @param file TODO + * @param logInfo TODO * @return le log ou null * @throws VCSException TODO */ @SuppressWarnings("unchecked") - public String getLogMessage(File file, LogInformation logInfo) throws VCSException { - CVSCommandResult cvsResult = CVSHelper.cvsStatus(file); + public String getLogMessage(CVSConnexion connexion, File file, LogInformation logInfo) throws VCSException { + CVSCommandResult cvsResult = CVSHelper.cvsStatus(connexion, file); if (cvsResult.isError()) { throw new VCSException(_("lutinvcs.error.get.status.files", cvsResult.getTrace().toString())); } @@ -234,27 +233,27 @@ } } - public void revert(List<File> files) throws VCSException { + public void revert(CVSConnexion connexion, List<File> files) throws VCSException { throw new RuntimeException(getClass().getName() + "#revert is not actually implemented"); //TODO } - public Object getRevision(File f) throws VCSException { + public Object getRevision(CVSConnexion connexion, File f) throws VCSException { throw new RuntimeException(getClass().getName() + "#getRevision is not actually implemented"); //TODO } - public void update(File file, Object revision) throws VCSException { + public void update(CVSConnexion connexion, File file, Object revision) throws VCSException { throw new RuntimeException(getClass().getName() + "#update(File,Object) is not actually implemented"); //TODO } - public String getDiff(File file) throws VCSException { + public String getDiff(CVSConnexion connexion, File file) throws VCSException { throw new RuntimeException(getClass().getName() + "#getDiff(File,OutputStream) is not actually implemented"); //TODO } - public String getDiff(File file, Object againstRevision) throws VCSException { + public String getDiff(CVSConnexion connexion, File file, Object againstRevision) throws VCSException { throw new RuntimeException(getClass().getName() + "#getDiff(File,Object,OutputStream) is not actually implemented"); //TODO } @@ -263,27 +262,27 @@ //TODO } - public boolean hasProtocoleChanged() { + public boolean hasProtocoleChanged(CVSConnexion connexion) { throw new RuntimeException(getClass().getName() + "#hasProtocoleChanged() is not actually implemented"); } - public String getChangeLog(File file) throws VCSException { + public String getChangeLog(CVSConnexion connexion, File file) throws VCSException { throw new RuntimeException(getClass().getName() + "#getChangeLog((File) is not actually implemented"); //TODO } - public List getLog(Object startRevision, Object endRevision, File file) throws VCSException { + public List getLog(CVSConnexion connexion, Object startRevision, Object endRevision, File file) throws VCSException { throw new RuntimeException(getClass().getName() + "#getLog(Object,Object,File) is not actually implemented"); //TODO } - public String getFileContent(File file, Object revision) throws VCSException { + public String getFileContent(CVSConnexion connexion, File file, Object revision) throws VCSException { throw new RuntimeException(getClass().getName() + "#getFileContent(File,Object) is not actually implemented"); //TODO } - public long checkoutOnlyTheDirectory(File root, Object revision) throws VCSException { - checkoutFile(root.getParentFile(), root.getName()); + public long checkoutOnlyTheDirectory(CVSConnexion connexion, File root, Object revision) throws VCSException { + checkoutFile(connexion, root.getParentFile(), root.getName()); return -1; //throw new RuntimeException(getClass().getName() + "#checkoutOnlyTheDirectory(File,Object) is not actually implemented"); //TODO Modified: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHelper.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHelper.java 2008-04-05 20:41:33 UTC (rev 369) +++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHelper.java 2008-04-05 20:43:32 UTC (rev 370) @@ -34,11 +34,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import static org.codelutin.i18n.I18n._; -import org.codelutin.vcs.VCSConfig; import org.codelutin.vcs.VCSException; -import org.codelutin.vcs.VCSRuntimeException; -import org.codelutin.vcs.VCSType; -import org.netbeans.lib.cvsclient.CVSRoot; import org.netbeans.lib.cvsclient.Client; import org.netbeans.lib.cvsclient.admin.Entry; import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; @@ -53,8 +49,6 @@ import org.netbeans.lib.cvsclient.command.status.StatusCommand; import org.netbeans.lib.cvsclient.command.update.UpdateCommand; import org.netbeans.lib.cvsclient.connection.AuthenticationException; -import org.netbeans.lib.cvsclient.connection.Connection; -import org.netbeans.lib.cvsclient.connection.PServerConnection; import org.netbeans.lib.cvsclient.event.BinaryMessageEvent; import org.netbeans.lib.cvsclient.event.CVSListener; import org.netbeans.lib.cvsclient.event.FileAddedEvent; @@ -71,108 +65,31 @@ import java.util.ArrayList; import java.util.List; -/** @author poussin */ +/** + * @author poussin + * @author tchemit + */ public class CVSHelper { - private static VCSConfig config; /** Logger for this class */ private static final Log log = LogFactory.getLog(CVSHelper.class); - static protected Client getClient() { - // WARNING TO DEVELOPERS: - // Please be warned that attempting to reuse one open connection for - // more commands is not supported by cvs servers very well. - // You are advised to open a new Connection each time. - // If you still want to proceed, please do: - // System.setProperty("javacvs.multiple_commands_warning", "false") - // That will disable this message. - // d'ou l'initialisation syst�matique de la connexion. - - String hostName = getConfig().getHostName(); - - // R�pertoire distant du CVS - String repository = getConfig().getRemotePath(); - - String userName = getConfig().getUserName(); - - Connection connection; - if (getConfig().isUseSshConnexion()) { - throw new RuntimeException(CVSHelper.class + " you can not used a ssh connexion with CVS, use instead SVN configuration"); - // connexion ssh2 - // Localisation de la clef priv�e (pour la connexion ssh2). - //File keyFile = new File(config.getKeyFile()); - // Stockage des cl�s publics pour les hosts ou il y a eu connexion en ssh2 - //String host = config.etHost(); - // Localisation de la clef priv�e (pour la connexion ssh2). - //File keyFile = new File(IsisConfig.getProperties().getProperty( - // IsisConfig.CVS_KEY_FILE)); - // Stockage des cl�s publics pour les hosts ou il y a eu connexion en ssh2 - //String host = IsisConfig.getProperties().getProperty( - // IsisConfig.CVS_HOST); - -// Ssh2Connexion ssh2Connection = new Ssh2Connexion(); -// ssh2Connection.setUserName(userName); -// ssh2Connection.setHostName(hostName); -// ssh2Connection.setKeyFile(keyFile); -// ssh2Connection.setHost(host); -// ssh2Connection.setRepository(repository); -// connection = ssh2Connection; - } else { - String cvsrootString = ":pserver:" + userName + "@" + hostName + repository; - CVSRoot cvsroot = CVSRoot.parse(cvsrootString); - // connexion pserver - PServerConnection PServerConnection; - PServerConnection = new PServerConnection(cvsroot); -// PServerConnection.setUserName(userName); -// // PServerConnection.setEncodedPassword(encodedPassword); -// PServerConnection.setHostName(hostName); -// PServerConnection.setRepository(repository); - connection = PServerConnection; - } - - // Le connexion est ouverte automatiquement � l'�x�cution de la - // commande CVS si elle n'a pas �t� ouverte pr�c�dement. Je l'ouvre pour - // obtenir les messages d'erreurs plus clair. - // connection.open(); - - return new Client(connection, new StandardAdminHandler()); - } - - private static VCSConfig getConfig() { - if (config == null) { - throw new IllegalStateException("config is null, should use provider to init config, or setConfig method"); - } - if (config.getType() != VCSType.CVS) { - throw new VCSRuntimeException("can not execute CVS command with " + - "a [" + config.getType() + "] handler"); - } - return config; - } - - static public GlobalOptions getGlobalOptions() { - GlobalOptions result = new GlobalOptions(); - //String repository = IsisConfig.getProperties().getProperty( - // IsisConfig.CVS_REPOSITORY); - String repository = getConfig().getRemotePath(); - result.setCVSRoot(repository); - return result; - } - /** * Permet de r�cuperer un nouveau module depuis le serveur * Les donn�es sur le serveur sont dans /cvsroot/isis-fish/data/... * on ne souhaite pas voir apparaitre data en local, on utilise donc * le renomage du module a l'arrive pour retirer data * - * @param destdir le repertoire local ou il faut mettre le module - * @param module le nom du module a recuperer + * @param connexion connexion to be used + * @param destdir le repertoire local ou il faut mettre le module + * @param module le nom du module a recuperer * @return result of command - * @throws org.codelutin.vcs.VCSException TODO + * @throws VCSException TODO */ - static public CVSCommandResult checkout(File destdir, String module) throws VCSException { - String data = getConfig().getRemoteDatabase(); + static public CVSCommandResult checkout(CVSConnexion connexion, File destdir, String module) throws VCSException { + String data = connexion.getConfig().getRemoteDatabase(); //TODO Fix bug when module is a multi path one, check there is no //TODO File.separator String sep = File.separator; @@ -183,8 +100,8 @@ // connexion ssh ou pserver, globalOption et initialisation client // Intitialistion des options globals - GlobalOptions globalOptions = getGlobalOptions(); - Client client = getClient(); + GlobalOptions globalOptions = connexion.getGlobalOptions(); + Client client = connexion.getClient(); client.setLocalPath(destdir.getPath()); @@ -215,13 +132,14 @@ /** * Permet de recuperer les mises a jours faite depuis le serveur * - * @param file le fichier ou repertoire a mettre a jour recursivement + * @param connexion connexion to be used + * @param file le fichier ou repertoire a mettre a jour recursivement * @return the result of the command * @throws VCSException if any problem while updating */ - static public CVSCommandResult cvsUpdate(File file) throws VCSException { - GlobalOptions globalOptions = getGlobalOptions(); - Client client = getClient(); + static public CVSCommandResult cvsUpdate(CVSConnexion connexion, File file) throws VCSException { + GlobalOptions globalOptions = connexion.getGlobalOptions(); + Client client = connexion.getClient(); if (!file.exists() || file.isFile()) { client.setLocalPath(file.getParent()); @@ -254,13 +172,14 @@ /** * Permet de recuperer les statuts depuis le serveur * - * @param file le fichier ou repertoire dont on souhaite le statut recursivement + * @param connexion connexion to be used + * @param file le fichier ou repertoire dont on souhaite le statut recursivement * @return the result of the command * @throws VCSException if any problem while updating */ - static public CVSCommandResult cvsStatus(File file) throws VCSException { - GlobalOptions globalOptions = getGlobalOptions(); - Client client = getClient(); + static public CVSCommandResult cvsStatus(CVSConnexion connexion, File file) throws VCSException { + GlobalOptions globalOptions = connexion.getGlobalOptions(); + Client client = connexion.getClient(); if (file.isFile()) { client.setLocalPath(file.getParent()); @@ -298,13 +217,14 @@ /** * Permet de recuperer les logs depuis le serveur * - * @param file le fichier ou repertoire dont on souhaite le log recursivement + * @param connexion connexion to be used + * @param file le fichier ou repertoire dont on souhaite le log recursivement * @return the result of the command * @throws VCSException if any problem while updating */ - static public CVSCommandResult cvsLog(File file) throws VCSException { - GlobalOptions globalOptions = getGlobalOptions(); - Client client = getClient(); + static public CVSCommandResult cvsLog(CVSConnexion connexion, File file) throws VCSException { + GlobalOptions globalOptions = connexion.getGlobalOptions(); + Client client = connexion.getClient(); if (file.isFile()) { client.setLocalPath(file.getParent()); @@ -345,12 +265,13 @@ * Tous les r�pertoires contenant des fichiers a ajouter doivent aussi * etre ajout� s'il ne sont pas deja dans le CVS. * - * @param files la listes des fichiers a ajouter, si les fichiers sont - * deja ajout�s cela ne produit pas d'erreur + * @param connexion connexion to be used + * @param files la listes des fichiers a ajouter, si les fichiers sont + * deja ajout�s cela ne produit pas d'erreur * @return the result of the command * @throws VCSException if any problem while updating */ - static public CVSCommandResult cvsAdd(List<File> files) throws VCSException { + static public CVSCommandResult cvsAdd(CVSConnexion connexion, List<File> files) throws VCSException { StandardAdminHandler adminHandler = new StandardAdminHandler(); File root = null; @@ -383,8 +304,8 @@ return new CVSCommandResult(); } else { log.debug(_("lutinvcs.message.add.cvs", root, fileToAdd)); - GlobalOptions globalOptions = getGlobalOptions(); - Client client = getClient(); + GlobalOptions globalOptions = connexion.getGlobalOptions(); + Client client = connexion.getClient(); client.setLocalPath(root.getPath()); @@ -415,12 +336,13 @@ /** * Permet de marquer des fichier a supprimer du CVS * - * @param files la listes des fichiers a supprimer, si les fichiers sont - * deja supprim�s cela ne produit pas d'erreur + * @param connexion connexion to be used + * @param files la listes des fichiers a supprimer, si les fichiers sont + * deja supprim�s cela ne produit pas d'erreur * @return the result of the command * @throws VCSException if any problem while updating */ - static public CVSCommandResult cvsRemove(List<File> files) throws VCSException { + static public CVSCommandResult cvsRemove(CVSConnexion connexion, List<File> files) throws VCSException { File root = null; File tmpRoot = null; List<File> fileToRemove = new ArrayList<File>(); @@ -442,8 +364,8 @@ return new CVSCommandResult(); } else { log.debug(_("lutinvcs.message.remove.files", fileToRemove)); - GlobalOptions globalOptions = getGlobalOptions(); - Client client = getClient(); + GlobalOptions globalOptions = connexion.getGlobalOptions(); + Client client = connexion.getClient(); client.setLocalPath(root.getPath()); @@ -476,13 +398,14 @@ /** * Permet d'envoyer des modifications au CVS * - * @param files le fichier ou repertoire a envoyer, si file represente un - * repertoire alors un commit recursif est fait - * @param msg message of the commit + * @param connexion connexion to be used + * @param files le fichier ou repertoire a envoyer, si file represente un + * repertoire alors un commit recursif est fait + * @param msg message of the commit * @return the result of the command * @throws VCSException if any problem while updating */ - static public CVSCommandResult cvsCommit(List<File> files, String msg) throws VCSException { + static public CVSCommandResult cvsCommit(CVSConnexion connexion, List<File> files, String msg) throws VCSException { File root = null; File tmpRoot = null; for (File file : files) { @@ -495,8 +418,8 @@ } } - GlobalOptions globalOptions = getGlobalOptions(); - Client client = getClient(); + GlobalOptions globalOptions = connexion.getGlobalOptions(); + Client client = connexion.getClient(); client.setLocalPath(root.getPath()); @@ -524,9 +447,6 @@ return listener.getResult(); } - public static void setConfig(VCSConfig config) { - CVSHelper.config = config; - } static protected class LogCVSListener implements CVSListener { protected CVSCommandResult result = new CVSCommandResult(); Modified: trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNConnexion.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNConnexion.java 2008-04-05 20:41:33 UTC (rev 369) +++ trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNConnexion.java 2008-04-05 20:43:32 UTC (rev 370) @@ -14,27 +14,163 @@ */ package org.codelutin.vcs.impl.svn; +import static org.codelutin.i18n.I18n._; +import org.codelutin.vcs.ConnectionState; +import org.codelutin.vcs.SVNProvider; +import org.codelutin.vcs.VCSConnexionConfig; +import org.codelutin.vcs.VCSConnexionMode; +import org.codelutin.vcs.VCSException; +import org.codelutin.vcs.VCSRuntimeException; import org.codelutin.vcs.util.AbstractVCSConnexion; -import org.codelutin.vcs.VCSConfig; -import org.codelutin.vcs.VCSHandler; +import org.codelutin.vcs.util.AbstractVCSHandler; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.io.SVNRepository; +import org.tmatesoft.svn.core.wc.ISVNOptions; +import org.tmatesoft.svn.core.wc.SVNClientManager; +import org.tmatesoft.svn.core.wc.SVNWCClient; +import org.tmatesoft.svn.core.wc.SVNWCUtil; +import java.io.File; +import java.util.Arrays; + /** @author chemit */ public class SVNConnexion extends AbstractVCSConnexion { - public void init(VCSConfig config, VCSHandler handler) { - state = null; + protected SVNURL repositoryURL; + + protected SVNRepository repository; + + protected SVNClientManager ourClientManager; + + protected SVNWCClient ourWcClient; + + public SVNConnexion(VCSConnexionMode mode, SVNProvider provider) { + super(mode, provider); } + public void init(VCSConnexionConfig config) { + state = ConnectionState.UNDEFINED; + this.config = config; + + try { + + // construct remote repository SVNURL + + repositoryURL = SVNURL.parseURIEncoded(getRemoteUrl()); + log.info("repositoryURL " + repositoryURL); + + // instanciate runtime default options + ISVNOptions options = SVNWCUtil.createDefaultOptions(true); + + // TODO Deal with authentication + + if (config.isUseSshConnexion()) { + // we use a ssh2 authentication mecanism (username /keyFile) + // just push in System properties that's we need for this... + System.setProperty("svnkit.ssh2.key", config.getKeyFile().getAbsolutePath()); + System.setProperty("svnkit.ssh2.username", config.getUserName()); + if (!config.isNoPassPhrase()) { + char[] pass = getConfig().getPassphrase().toCharArray(); + if (pass != null) { + System.setProperty("svnkit.ssh2.passphrase", Arrays.toString(pass)); + Arrays.fill(pass, '0'); + } + } + //System.setProperty("svnkit.ssh2.password", ""); + //System.setProperty("svnkit.ssh2.port", "22"); + + // instanciate svn client manager + ourClientManager = SVNClientManager.newInstance(options); + + } else { + // we use a simple authentication mecanism (username/password) + ourClientManager = SVNClientManager.newInstance(options, config.getUserName(), config.getUserName()); + } + // instanciate repo + repository = ourClientManager.createRepository(repositoryURL, true); + + // add our svn event logger TODO Remake this logger or use the + // DebugLog from svnkit ? + ourClientManager.setEventHandler(new SVNHelper.SVNEventLoggerHandler()); + } catch (SVNException e) { + // TODO I18N + throw new VCSRuntimeException("could not compute repository url ", e); + } + } + @Override public void close() throws IllegalStateException { checkInit(); if (!isOpen()) { return; } + //TODO to be done + log.info(this); } @Override public void open() throws IllegalStateException { checkInit(); + //TODO testConnexion ? } + + public String getRemoteUrl() { + StringBuilder sb = new StringBuilder(); + sb.append(config.isUseSshConnexion() ? "svn+ssh://" : "svn://"); + sb.append(config.getHostName()).append("/"); + sb.append(config.getRemotePath()).append("/"); + sb.append(config.getRemoteDatabase()); + return sb.toString(); + } + + public boolean hasProtocoleChanged(SVNHandler handler) throws VCSException { + File root = config.getLocalDatabasePath(); + if (!root.exists() || !AbstractVCSHandler.isFileInCheckedDir(root, handler)) { + // local database does not exists, so no switch + return false; + } + String oldProtocol = handler.getSVNStatus(this, root, false).getURL().getProtocol(); + String newProtocol = repositoryURL.getProtocol(); + return !oldProtocol.equals(newProtocol); + } + + public void testConnection() throws VCSException { + //TODO This is not the good place for this, this should be done in provider + if (getConfig().isUseSshConnexion()) { + // try to test the ssh connection + + File path = getConfig().getKeyFile(); + try { + String passphrase = getConfig().getPassphrase(); + SVNHelper.testSSHConnection(repositoryURL.toString(), getConfig().getUserName(), path == null ? null : path.getAbsolutePath(), passphrase == null ? new char[0] : passphrase.toCharArray()); + return; + } catch (VCSException e) { + log.warn(_("lutinvcs.error.vcs.no.ssh.connection", getConfig().getUserName(), path)); + } + } + // do not use ssh connection + getConfig().setUseSshConnexion(false); + // try to test with a anonymous connection + SVNHelper.testAnonymousConnection(repositoryURL.toString()); + } + + + public SVNWCClient getOurWcClient() { + if (ourWcClient == null) + ourWcClient = ourClientManager.getWCClient(); + return ourWcClient; + } + + public SVNClientManager getOurClientManager() { + return ourClientManager; + } + + public SVNRepository getRepository() { + return repository; + } + + public SVNURL getRepositoryURL() { + return repositoryURL; + } } Modified: trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHandler.java 2008-04-05 20:41:33 UTC (rev 369) +++ trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHandler.java 2008-04-05 20:43:32 UTC (rev 370) @@ -20,17 +20,15 @@ package org.codelutin.vcs.impl.svn; import static org.codelutin.i18n.I18n._; -import org.codelutin.vcs.util.AbstractVCSHandler; -import org.codelutin.vcs.VCSConfig; +import org.codelutin.vcs.VCSConnexionConfig; import org.codelutin.vcs.VCSException; -import org.codelutin.vcs.util.VCSHelper; -import static org.codelutin.vcs.util.VCSHelper.isFileInCheckedDir; import org.codelutin.vcs.VCSRuntimeException; import org.codelutin.vcs.VCSState; import static org.codelutin.vcs.VCSState.OUT_OF_DATE; import static org.codelutin.vcs.VCSState.OUT_OF_DATE_AND_MODIFIED; import static org.codelutin.vcs.VCSState.UP_TO_DATE; import org.codelutin.vcs.VCSStatus; +import org.codelutin.vcs.util.AbstractVCSHandler; import org.tmatesoft.svn.core.ISVNDirEntryHandler; import org.tmatesoft.svn.core.ISVNLogEntryHandler; import org.tmatesoft.svn.core.SVNCommitInfo; @@ -39,21 +37,15 @@ import org.tmatesoft.svn.core.SVNLogEntry; import org.tmatesoft.svn.core.SVNNodeKind; import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.io.SVNRepository; -import org.tmatesoft.svn.core.wc.ISVNOptions; -import org.tmatesoft.svn.core.wc.SVNClientManager; import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc.SVNStatus; import org.tmatesoft.svn.core.wc.SVNStatusType; import static org.tmatesoft.svn.core.wc.SVNStatusType.*; -import org.tmatesoft.svn.core.wc.SVNWCClient; -import org.tmatesoft.svn.core.wc.SVNWCUtil; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -65,83 +57,16 @@ * @author chemit */ -public final class SVNHandler extends AbstractVCSHandler { +public final class SVNHandler extends AbstractVCSHandler<SVNConnexion> { - protected SVNURL repositoryURL; - - protected SVNRepository repository; - - protected SVNClientManager ourClientManager; - - protected SVNWCClient ourWcClient; - - public SVNHandler(VCSConfig config) { - - super(config, ".svn", "entries"); - - SVNHelper.setupLibrary(); - - try { - - // construct remote repository SVNURL - - repositoryURL = SVNURL.parseURIEncoded(getRemoteUrl()); - log.info("repositoryURL " + repositoryURL); - - // instanciate runtime default options - ISVNOptions options = SVNWCUtil.createDefaultOptions(true); - - // TODO Deal with authentication - - if (config.isUseSshConnexion()) { - // we use a ssh2 authentication mecanism (username /keyFile) - // just push in System properties that's we need for this... - System.setProperty("svnkit.ssh2.key", config.getKeyFile().getAbsolutePath()); - System.setProperty("svnkit.ssh2.username", config.getUserName()); - if (!config.isNoPassPhrase()) { - char[] pass = getConfig().getPassphrase().toCharArray(); - if (pass != null) { - System.setProperty("svnkit.ssh2.passphrase", Arrays.toString(pass)); - Arrays.fill(pass, '0'); - } - } - //System.setProperty("svnkit.ssh2.password", ""); - //System.setProperty("svnkit.ssh2.port", "22"); - - // instanciate svn client manager - ourClientManager = SVNClientManager.newInstance(options); - - } else { - // we use a simple authentication mecanism (username/password) - ourClientManager = SVNClientManager.newInstance(options, config.getUserName(), config.getUserName()); - } - // instanciate repo - repository = ourClientManager.createRepository(repositoryURL, true); - - // add our svn event logger TODO Remake this logger or use the - // DebugLog from svnkit ? - ourClientManager.setEventHandler(new SVNHelper.SVNEventLoggerHandler()); - } catch (SVNException e) { - // TODO I18N - throw new VCSRuntimeException("could not compute repository url ", e); - } + public SVNHandler() { + super(".svn", "entries"); } - public boolean hasProtocoleChanged() throws VCSException { - File root = config.getLocalDatabasePath(); - if (!root.exists() || !isFileInCheckedDir(root, this)) { - // local database does not exists, so no switch - return false; - } - String oldProtocol = getSVNStatus(root, false).getURL().getProtocol(); - String newProtocol = repositoryURL.getProtocol(); - return !oldProtocol.equals(newProtocol); - } - - public void initWorkingCopy() throws VCSException { + public void initWorkingCopy(SVNConnexion connexion) throws VCSException { try { // test connection - repository.testConnection(); + connexion.getRepository().testConnection(); } catch (SVNException e1) { // connexion failed, what do we want to do ? display vcs @@ -150,47 +75,20 @@ throw new VCSException(e1); } + VCSConnexionConfig config = connexion.getConfig(); File root = config.getLocalDatabasePath(); if (!root.exists()) { - getLocalDatabasePath().mkdirs(); + config.getLocalDatabasePath().mkdirs(); } - long lastRevision = checkoutOnlyTheDirectory(root, SVNRevision.HEAD); + long lastRevision = checkoutOnlyTheDirectory(connexion, root, SVNRevision.HEAD); log.info(_("lutinvcs.message.copy.revision", null, lastRevision)); } - public void testConnection() throws VCSException { - if (getConfig().isUseSshConnexion()) { - // try to test the ssh connection - - File path = getConfig().getKeyFile(); - try { - String passphrase = getConfig().getPassphrase(); - SVNHelper.testSSHConnection(repositoryURL.toString(), getConfig().getUserName(), path == null ? null : path.getAbsolutePath(), passphrase == null ? new char[0] : passphrase.toCharArray()); - return; - } catch (VCSException e) { - log.warn(_("lutinvcs.error.vcs.no.ssh.connection", getConfig().getUserName(), path)); - } - } - // do not use ssh connection - getConfig().setUseSshConnexion(false); - // try to test with a anonymous connection - SVNHelper.testAnonymousConnection(repositoryURL.toString()); - } - - public String getRemoteUrl() { - StringBuilder sb = new StringBuilder(); - sb.append(config.isUseSshConnexion() ? "svn+ssh://" : "svn://"); - sb.append(config.getHostName()).append("/"); - sb.append(config.getRemotePath()).append("/"); - sb.append(config.getRemoteDatabase()); - return sb.toString(); - } - // TODO Delete VCSStatus and all links, use VCSState - public VCSStatus getStatus(File file) { + public VCSStatus getStatus(SVNConnexion connexion, File file) { SVNStatusType statusType; try { - statusType = getStatusType(file); + statusType = getStatusType(connexion, file); } catch (SVNException e) { return VCSStatus.NONE; } @@ -217,18 +115,18 @@ } // tmp is used to get back the revision - public VCSState getState(File file, Collection tmp) throws VCSException { - return getState(file, tmp, true); + public VCSState getState(SVNConnexion connexion, File file, Collection tmp) throws VCSException { + return getState(connexion, file, tmp, true); } @SuppressWarnings("unchecked") - public VCSState getState(File file, Collection tmp, boolean noremote) throws VCSException { + public VCSState getState(SVNConnexion connexion, File file, Collection tmp, boolean noremote) throws VCSException { VCSState result = VCSState.UNKNOWN; boolean exist = file.exists(); - VCSHelper.assertFileInWC(file, this); + assertFileInWC(file, this, connexion); // file is in a working copy @@ -242,7 +140,7 @@ // check if present on remote repository try { - stat = ourClientManager.getStatusClient().doStatus(file, true); + stat = connexion.getOurClientManager().getStatusClient().doStatus(file, true); if (stat != null) { @@ -272,7 +170,7 @@ // file is under VCS and exists try { - stat = ourClientManager.getStatusClient().doStatus(file, true); + stat = connexion.getOurClientManager().getStatusClient().doStatus(file, true); } catch (SVNException e) { log.warn(_("lutinvcs.error.not.find.status", file, e.getErrorMessage())); @@ -322,35 +220,35 @@ private int prefixPath = -1; - private int getPrefixPath() { + private int getPrefixPath(SVNConnexion connexion) { if (prefixPath == -1) - prefixPath = getLocalDatabasePath().getAbsolutePath().length() + 1; + prefixPath = connexion.getConfig().getLocalDatabasePath().getAbsolutePath().length() + 1; return prefixPath; } - private String getRelativePath(File f) { + private String getRelativePath(SVNConnexion connexion, File f) { final String path = f.getAbsolutePath(); - return path.length() <= getPrefixPath() ? path : path.substring(getPrefixPath()); + return path.length() <= getPrefixPath(connexion) ? path : path.substring(getPrefixPath(connexion)); } - public boolean isOnRemote(File file) { - VCSStatus fileStatus = getStatus(file); + public boolean isOnRemote(SVNConnexion connexion, File file) { + VCSStatus fileStatus = getStatus(connexion, file); return !(VCSStatus.UNVERSIONED == fileStatus || VCSStatus.NONE == fileStatus); } - public boolean isUpToDate(File file) throws VCSException { - SVNStatus status = getSVNStatus(file); + public boolean isUpToDate(SVNConnexion connexion, File file) throws VCSException { + SVNStatus status = getSVNStatus(connexion, file); return status.getContentsStatus() == STATUS_NORMAL && STATUS_NONE == status.getRemoteContentsStatus(); } - public long add(List<File> files, String msg) throws VCSException { + public long add(SVNConnexion connexion, List<File> files, String msg) throws VCSException { assertFilesExist(files, msg); try { ArrayList<File> filesTmp = new ArrayList<File>(files); for (Iterator<File> it = filesTmp.iterator(); it.hasNext();) { File file = it.next(); - VCSStatus status = getStatus(file); + VCSStatus status = getStatus(connexion, file); if (!file.exists() || status == VCSStatus.NORMAL) { // do not commit this file it.remove(); @@ -358,15 +256,15 @@ } // we must check first if file need really to be added ? if (status == VCSStatus.UNVERSIONED) { - getOurWcClient().doAdd(file, false, false, false, false, false); - log.debug("mark to add '" + getRelativePath(file) + "'"); + connexion.getOurWcClient().doAdd(file, false, false, false, false, false); + log.debug("mark to add '" + getRelativePath(connexion, file) + "'"); } } if (!filesTmp.isEmpty() && msg != null) { // we do commit - long rev = commit(filesTmp, msg); + long rev = commit(connexion, filesTmp, msg); for (File file : filesTmp) { - log.info("'" + getRelativePath(file) + "' at revison " + rev); + log.info("'" + getRelativePath(connexion, file) + "' at revison " + rev); } return rev; } @@ -376,23 +274,23 @@ return -1; } - public void delete(List<File> files, String msg) throws VCSException { + public void delete(SVNConnexion connexion, List<File> files, String msg) throws VCSException { assertFilesExist(files, "delete"); - files.remove(getLocalDatabasePath()); - files.remove(getLocalDatabasePath().getParentFile()); + files.remove(connexion.getConfig().getLocalDatabasePath()); + files.remove(connexion.getConfig().getLocalDatabasePath().getParentFile()); try { // when delete is true, after commit we have a none status for (File file : files) { - getOurWcClient().doDelete(file, true, msg != null, false); - log.debug("mark to delete '" + getRelativePath(file) + "'"); + connexion.getOurWcClient().doDelete(file, true, msg != null, false); + log.debug("mark to delete '" + getRelativePath(connexion, file) + "'"); } long revision; if (msg != null) { // we do commit - revision = commit(files, msg); + revision = commit(connexion, files, msg); for (File file : files) { - log.info("'" + getRelativePath(file) + "' at revison " + revision); + log.info("'" + getRelativePath(connexion, file) + "' at revison " + revision); } } } catch (SVNException e) { @@ -400,27 +298,27 @@ } } - public void revert(List<File> files) throws VCSException { + public void revert(SVNConnexion connexion, List<File> files) throws VCSException { assertFilesExist(files, "revert"); try { for (File file : files) { // we have nothing to do for with a normal status file - if (getStatus(file) == VCSStatus.NORMAL) { + if (getStatus(connexion, file) == VCSStatus.NORMAL) { continue; } - getOurWcClient().doRevert(file, true); - log.info("'" + getRelativePath(file) + "' at revison " + "TODO"); + connexion.getOurWcClient().doRevert(file, true); + log.info("'" + getRelativePath(connexion, file) + "' at revison " + "TODO"); } } catch (SVNException e) { throw new VCSException(e); } } - public long commit(List<File> files, String msg) throws VCSException { + public long commit(SVNConnexion connexion, List<File> files, String msg) throws VCSException { assertFilesExist(files, "commit"); try { - SVNCommitInfo commitInfo = ourClientManager.getCommitClient() + SVNCommitInfo commitInfo = connexion.getOurClientManager().getCommitClient() .doCommit(files.toArray(new File[files.size()]), false, msg, false, true); log.debug("to revision " + commitInfo.getNewRevision()); return commitInfo.getNewRevision(); @@ -429,8 +327,8 @@ } } - public void update(File file) throws VCSException { - update(file, SVNRevision.HEAD); + public void update(SVNConnexion connexion, File file) throws VCSException { + update(connexion, file, SVNRevision.HEAD); } /** @@ -439,45 +337,45 @@ * @throws VCSException if any exception while update operation (like update a * locally modified file or a unversionned file) */ - public void update(File file, Object revision) throws VCSException { + public void update(SVNConnexion connexion, File file, Object revision) throws VCSException { try { - VCSStatus status = getStatus(file); + VCSStatus status = getStatus(connexion, file); if (status == VCSStatus.MODIFIED) throw new VCSException("could not update a localy modified file " + file); if (status == VCSStatus.UNVERSIONED || status == VCSStatus.NONE) throw new VCSException("could not update a non versionned file " + file); - long newRev = ourClientManager.getUpdateClient().doUpdate(file, (SVNRevision) revision, true); - log.info("'" + getRelativePath(file) + "' to revision " + newRev); + long newRev = connexion.getOurClientManager().getUpdateClient().doUpdate(file, (SVNRevision) revision, true); + log.info("'" + getRelativePath(connexion, file) + "' to revision " + newRev); } catch (SVNException e) { throw new VCSException(e); } } - public void checkout(File destDir, String module, boolean recurse) + public void checkout(SVNConnexion connexion, File destDir, String module, boolean recurse) throws VCSException { try { - final SVNURL urlModule = repositoryURL.appendPath(module, true); + final SVNURL urlModule = connexion.getRepositoryURL().appendPath(module, true); String sep = File.separator; // TODO Why this ? final File modulePath = new File(destDir, module.replaceAll("/", "\\".equals(sep) ? sep + sep : sep)); - log.info(urlModule + " to path '" + getRelativePath(modulePath) + "' (module:" + module + ")"); - ourClientManager.getUpdateClient().doCheckout(urlModule, modulePath, null, SVNRevision.HEAD, recurse); + log.info(urlModule + " to path '" + getRelativePath(connexion, modulePath) + "' (module:" + module + ")"); + connexion.getOurClientManager().getUpdateClient().doCheckout(urlModule, modulePath, null, SVNRevision.HEAD, recurse); } catch (SVNException e) { throw new VCSException(e); } } - public void checkoutFile(File destDir, String module) throws VCSException { - update(new File(destDir, module)); + public void checkoutFile(SVNConnexion connexion, File destDir, String module) throws VCSException { + update(connexion, new File(destDir, module)); } - public long checkoutOnlyTheDirectory(File root, Object revision) + public long checkoutOnlyTheDirectory(SVNConnexion connexion, File root, Object revision) throws VCSException { long lastRevision; try { // obtain module - File repoRoot = getLocalDatabasePath(); + File repoRoot = connexion.getConfig().getLocalDatabasePath(); File tmp = root; StringBuilder sb = new StringBuilder(); while (!tmp.equals(repoRoot)) { @@ -488,16 +386,16 @@ if (module.length() > 0) module = module.substring(1); - SVNURL url = repositoryURL.appendPath(module, true); + SVNURL url = connexion.getRepositoryURL().appendPath(module, true); - lastRevision = ourClientManager.getUpdateClient().doCheckout( + lastRevision = connexion.getOurClientManager().getUpdateClient().doCheckout( url, root, null, (SVNRevision) (revision == null ? SVNRevision.HEAD : revision), false); - log.info(url + " to path '" + getRelativePath(root) + "' (module:" + module + ") to revision " + lastRevision); + log.info(url + " to path '" + getRelativePath(connexion, root) + "' (module:" + module + ") to revision " + lastRevision); // Suppress all files from root directory of working copy for (File file : root.listFiles()) if (file.isFile()) @@ -508,7 +406,7 @@ return lastRevision; } - public List<String> getRemoteStorageNames(File directory) + public List<String> getRemoteStorageNames(SVNConnexion connexion, File directory) throws VCSException { final List<String> result = new ArrayList<String>(); @@ -522,7 +420,7 @@ if (dirEntry.getKind() == SVNNodeKind.FILE) { String s = dirEntry.getRelativePath(); - // TODO Prefer use VCSHelper.XXX method to convert names + // TODO Prefer use XXX method to convert names if (s.indexOf("/") > -1) { s = s.replaceAll("/", sep.equals("\\") ? sep + sep : sep); } @@ -530,8 +428,7 @@ } } }; - ourClientManager.getLogClient().doList(directory, SVNRevision.BASE, - SVNRevision.HEAD, true, handler); + connexion.getOurClientManager().getLogClient().doList(directory, SVNRevision.BASE, SVNRevision.HEAD, true, handler); } catch (SVNException e) { throw new VCSException(e); } @@ -539,10 +436,10 @@ return result; } - public SVNRevision getRevision(File f) throws VCSException { + public SVNRevision getRevision(SVNConnexion connexion, File f) throws VCSException { SVNStatus status; try { - status = ourClientManager.getStatusClient().doStatus(f, false); + status = connexion.getOurClientManager().getStatusClient().doStatus(f, false); return status.getRevision(); } catch (SVNException e) { throw new VCSException(e); @@ -556,12 +453,12 @@ * @return la liste des r�visions en tre la startRevision et la endRevision * @throws VCSException if nay exception while operation */ - public List<SVNLogEntry> getLog(Object startRevision, Object endRevision, + public List<SVNLogEntry> getLog(SVNConnexion connexion, Object startRevision, Object endRevision, File file) throws VCSException { final List<SVNLogEntry> result = new ArrayList<SVNLogEntry>(); - final long workingRevision = getRevision(file).getNumber(); + final long workingRevision = getRevision(connexion, file).getNumber(); final long startRev = ((SVNRevision) startRevision).getNumber(); ISVNLogEntryHandler handler = new ISVNLogEntryHandler() { @@ -573,7 +470,7 @@ }; try { - ourClientManager.getLogClient().doLog(new File[]{file}, + connexion.getOurClientManager().getLogClient().doLog(new File[]{file}, (SVNRevision) startRevision, (SVNRevision) endRevision, false, false, 1024, handler); } catch (SVNException e) { @@ -591,13 +488,13 @@ * @return le log ou null si auncune r�vision n'a �t� fourni * @throws VCSException if nay exception while operation */ - public String getChangeLog(File file) throws VCSException { + public String getChangeLog(SVNConnexion connexion, File file) throws VCSException { SVNRevision startRevision = file.exists() ? SVNRevision.WORKING : SVNRevision.create(0); log.debug("file " + file + " init Rev " + startRevision); - List<SVNLogEntry> logInfo = getLog(startRevision, SVNRevision.HEAD, + List<SVNLogEntry> logInfo = getLog(connexion, startRevision, SVNRevision.HEAD, file); // List<SVNLogEntry> logInfo = getLog(file.exists()?SVNRevision.WORKING: // SVNRevision.BASE, SVNRevision.HEAD, file); @@ -625,20 +522,20 @@ return result.substring(1); } - public String getDiff(File file) throws VCSException, IOException { + public String getDiff(SVNConnexion connexion, File file) throws VCSException, IOException { // make diff against Head revision of file - return getDiff(file, SVNRevision.HEAD); + return getDiff(connexion, file, SVNRevision.HEAD); } - public String getDiff(File file, Object againstRevision) + public String getDiff(SVNConnexion connexion, File file, Object againstRevision) throws VCSException, IOException { assertFileExist(file, "getDiff"); SVNRevision remoteRevision = (SVNRevision) againstRevision; - SVNStatus status = getSVNStatus(file); + SVNStatus status = getSVNStatus(connexion, file); if (status == null) { throw new VCSException("could not found status for the file " + file); @@ -667,7 +564,7 @@ // we know there is something to diff ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { - ourClientManager.getDiffClient().doDiff(file, localRevision, file, remoteRevision, true, false, baos); + connexion.getOurClientManager().getDiffClient().doDiff(file, localRevision, file, remoteRevision, true, false, baos); return baos.toString(); } catch (Exception e) { throw new VCSException(e); @@ -676,16 +573,20 @@ } } - public String getFileContent(File file, Object revision) + public boolean hasProtocoleChanged(SVNConnexion connexion) throws VCSException { + return connexion.hasProtocoleChanged(this); + } + + public String getFileContent(SVNConnexion connexion, File file, Object revision) throws VCSException, IOException { if (file == null || file.isDirectory()) { throw new VCSRuntimeException("could not invoke getFileContent for a directory [" + file + "]"); } String path = file.getAbsolutePath(); - int prefixRoot = getLocalDatabasePath().getAbsolutePath().length(); + int prefixRoot = connexion.getConfig().getLocalDatabasePath().getAbsolutePath().length(); if (path.length() < prefixRoot) { - throw new VCSException("can't get the content file for file " + file + " since it is not under the root working copy (" + getLocalDatabasePath() + ")"); + throw new VCSException("can't get the content file for file " + file + " since it is not under the root working copy (" + connexion.getConfig().getLocalDatabasePath() + ")"); } String sep = File.separator; path = path.substring(prefixRoot).replaceAll("\\".equals(sep) ? "\\\\" : sep, "/"); @@ -693,9 +594,9 @@ ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { - repository.setLocation(repositoryURL, false); + connexion.getRepository().setLocation(connexion.getRepositoryURL(), false); - repository.getFile(path.substring(1), ((SVNRevision) revision).getNumber(), null, baos); + connexion.getRepository().getFile(path.substring(1), ((SVNRevision) revision).getNumber(), null, baos); return baos.toString(); } catch (SVNException e) { @@ -705,21 +606,21 @@ } } - public byte[] getBinaryFileContent(File file, Object revision) throws VCSException, IOException { + public byte[] getBinaryFileContent(SVNConnexion connexion, File file, Object revision) throws VCSException, IOException { if (file == null || file.isDirectory()) throw new VCSRuntimeException("could not invoke getFileContent for a directory [" + file + "]"); String path = file.getAbsolutePath(); - int prefixRoot = getLocalDatabasePath().getAbsolutePath().length(); + int prefixRoot = connexion.getConfig().getLocalDatabasePath().getAbsolutePath().length(); if (path.length() < prefixRoot) - throw new VCSException("can't get the content file for file " + file + " since it is not under the root working copy (" + getLocalDatabasePath() + ")"); + throw new VCSException("can't get the content file for file " + file + " since it is not under the root working copy (" + connexion.getConfig().getLocalDatabasePath() + ")"); String sep = File.separator; path = path.substring(prefixRoot).replaceAll("\\".equals(sep) ? "\\\\" : sep, "/"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { - repository.setLocation(repositoryURL, false); - repository.getFile(path.substring(1), ((SVNRevision) revision).getNumber(), null, baos); + connexion.getRepository().setLocation(connexion.getRepositoryURL(), false); + connexion.getRepository().getFile(path.substring(1), ((SVNRevision) revision).getNumber(), null, baos); return baos.toByteArray(); } catch (SVNException e) { throw new VCSException(e); @@ -728,32 +629,23 @@ } } - public SVNURL getRepositoryURL() { - return repositoryURL; + public SVNStatus getSVNStatus(SVNConnexion connexion, File file) throws VCSException { + return getSVNStatus(connexion, file, true); } - public SVNStatus getSVNStatus(File file) throws VCSException { - return getSVNStatus(file, true); - } - - protected SVNStatus getSVNStatus(File file, boolean remote) throws VCSException { + protected SVNStatus getSVNStatus(SVNConnexion connexion, File file, boolean remote) throws VCSException { try { - return ourClientManager.getStatusClient().doStatus(file, remote); + return connexion.getOurClientManager().getStatusClient().doStatus(file, remote); } catch (SVNException e) { throw new VCSException(e); } } - protected SVNStatusType getStatusType(File file) throws SVNException { - SVNStatus status = ourClientManager.getStatusClient().doStatus(file, false); + protected SVNStatusType getStatusType(SVNConnexion connexion, File file) throws SVNException { + SVNStatus status = connexion.getOurClientManager().getStatusClient().doStatus(file, false); return status == null ? UNKNOWN : status.getContentsStatus(); } - private SVNWCClient getOurWcClient() { - if (ourWcClient == null) - ourWcClient = ourClientManager.getWCClient(); - return ourWcClient; - } private void assertFilesExist(List<File> files, String command) throws VCSException { @@ -766,19 +658,19 @@ throw new VCSRuntimeException(getClass().getName() + "#" + command + "(File,...) first argument can not be null"); } - public void makeRemoteDir(String commitMessage, String... dirNames) + public void makeRemoteDir(SVNConnexion connexion, String commitMessage, String... dirNames) throws VCSException { try { SVNURL[] urls = new SVNURL[dirNames.length]; for (int i = 0; i < dirNames.length; i++) { - SVNURL url = repositoryURL; + SVNURL url = connexion.getRepositoryURL(); for (String path : dirNames[i].split("/")) url = url.appendPath(path, false); urls[i] = url; } - SVNCommitInfo commit = ourClientManager.getCommitClient().doMkDir( + SVNCommitInfo commit = connexion.getOurClientManager().getCommitClient().doMkDir( urls, commitMessage); long rev = commit.getNewRevision(); for (String dirName : dirNames) { @@ -789,18 +681,18 @@ } } - public void deleteRemoteDir(String commitMessage, String... dirNames) + public void deleteRemoteDir(SVNConnexion connexion, String commitMessage, String... dirNames) throws VCSException { try { SVNURL[] urls = new SVNURL[dirNames.length]; for (int i = 0; i < dirNames.length; i++) { - SVNURL url = repositoryURL; + SVNURL url = connexion.getRepositoryURL(); for (String path : dirNames[i].split("/")) url = url.appendPath(path, false); urls[i] = url; } - SVNCommitInfo commit = ourClientManager.getCommitClient().doDelete( + SVNCommitInfo commit = connexion.getOurClientManager().getCommitClient().doDelete( urls, commitMessage); long rev = commit.getNewRevision(); for (String dirName : dirNames) { Modified: trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHelper.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHelper.java 2008-04-05 20:41:33 UTC (rev 369) +++ trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHelper.java 2008-04-05 20:43:32 UTC (rev 370) @@ -22,7 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codelutin.vcs.VCSException; -import org.codelutin.vcs.util.VCSHelper; +import org.codelutin.vcs.util.AbstractVCSHandler; import org.codelutin.vcs.VCSRuntimeException; import org.codelutin.vcs.VCSTypeRepo; import org.tmatesoft.svn.core.SVNCancelException; @@ -183,8 +183,8 @@ VCSTypeRepo result; - String remotePath = VCSHelper.getRemotePath(typeRepo, uncleanRemotePath); - String remoteDatabase = VCSHelper.getRemoteDatabase(typeRepo, databaseVersion); + String remotePath = AbstractVCSHandler.getRemotePath(typeRepo, uncleanRemotePath); + String remoteDatabase = AbstractVCSHandler.getRemoteDatabase(typeRepo, databaseVersion); StringBuilder sb = new StringBuilder("svn://").append(hostName); sb.append("/").append(remotePath); String url = sb.toString();