Author: tchemit Date: 2008-04-13 15:59:12 +0000 (Sun, 13 Apr 2008) New Revision: 510 Added: trunk/lutinvcs/provider/svn/src/main/java/org/codelutin/vcs/provider/SVNProvider.java Removed: trunk/lutinvcs/provider/svn/src/main/java/org/codelutin/vcs/SVNProvider.java Modified: trunk/lutinvcs/provider/svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider trunk/lutinvcs/provider/svn/src/test/java/org/codelutin/vcs/provider/svn/FindTypeRepoTest.java Log: package provider Deleted: trunk/lutinvcs/provider/svn/src/main/java/org/codelutin/vcs/SVNProvider.java =================================================================== --- trunk/lutinvcs/provider/svn/src/main/java/org/codelutin/vcs/SVNProvider.java 2008-04-13 15:58:23 UTC (rev 509) +++ trunk/lutinvcs/provider/svn/src/main/java/org/codelutin/vcs/SVNProvider.java 2008-04-13 15:59:12 UTC (rev 510) @@ -1,240 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * 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 2 - * 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, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.vcs; - -import org.codelutin.vcs.provider.svn.SVNConnexion; -import org.codelutin.vcs.provider.svn.SVNHandler; -import org.codelutin.vcs.type.VCSTypeRepo; -import org.codelutin.vcs.util.AbstractVCSHandler; -import org.codelutin.vcs.util.AbstractVCSProvider; -import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.SVNNodeKind; -import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; -import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory; -import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl; -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.SVNWCUtil; - -import java.util.Arrays; - -/** - * SVN Provider - * - * @author chemit - */ -public class SVNProvider extends AbstractVCSProvider<SVNConnexion, SVNHandler> { - - private static boolean libraryInit; - - public SVNProvider() { - - super("SVN", SVNHandler.class, SVNConnexion.class); - - setupLibrary(); - } - - /** - * Test if a anonymous svn connection can be openned. - * - * @param url the svn url to test - * @return <code>true</code> if connection is ok,<code>false</code> otherwise. - * @throws org.codelutin.vcs.VCSException if could not compute the SVNURL - */ - public static boolean testAnonymousConnection(String url) throws VCSException { - boolean result = true; - - SVNRepository repository = getAnonymousConnection(url); - try { - repository.testConnection(); - } catch (SVNException e) { - result = false; - } finally { - if (repository != null) { - try { - repository.closeSession(); - } catch (Exception e) { - log.warn(e); - } - } - } - return result; - } - - /** - * Test if a anonymous svn connection can be openned. - * - * @param url the svn url to test - * @param username user name - * @param privateKeyFilePath the file to used as protected key file - * @param passphrase passphrase to use - * @return <code>true</code> if connection is ok,<code>false</code> otherwise. - * @throws org.codelutin.vcs.VCSException if could not compute the SVNURL - */ - public static boolean testSSHConnection(String url, String username, String privateKeyFilePath, char[] passphrase) throws VCSException { - boolean result = true; - - SVNRepository repository = getSSHConnection(url, username, privateKeyFilePath, passphrase); - try { - repository.testConnection(); - } catch (SVNException e) { - result = false; - } finally { - if (repository != null) { - try { - repository.closeSession(); - } catch (Exception e) { - log.warn(e); - } - } - } - return result; - } - - public static SVNRepository getAnonymousConnection(String url) throws VCSException { - - setupLibrary(); - - SVNURL testRepositoryURL; - try { - testRepositoryURL = SVNURL.parseURIEncoded(url); - } catch (SVNException e) { - throw new VCSException(e); - } - SVNRepository repository; - try { - ISVNOptions options = SVNWCUtil.createDefaultOptions(true); - SVNClientManager manager = SVNClientManager.newInstance(options, "anonymous", "anonymous"); - repository = manager.createRepository(testRepositoryURL, false); - repository.testConnection(); - return repository; - } catch (SVNException e) { - throw new VCSException(e); - } - } - - public static SVNRepository getSSHConnection(String url, String username, String privateKeyFilePath, char[] passphrase) throws VCSException { - - setupLibrary(); - - SVNURL testRepositoryURL; - try { - testRepositoryURL = SVNURL.parseURIEncoded(url); - } catch (SVNException e) { - throw new VCSException(e); - } - SVNRepository repository; - try { - ISVNOptions options = SVNWCUtil.createDefaultOptions(true); - System.setProperty("svnkit.ssh2.key", privateKeyFilePath); - System.setProperty("svnkit.ssh2.username", username); - if (passphrase != null && passphrase.length > 0) { - System.setProperty("svnkit.ssh2.passphrase", Arrays.toString(passphrase)); - } - //System.setProperty("svnkit.ssh2.passphrase", ""); - //System.setProperty("svnkit.ssh2.password", ""); - //System.setProperty("svnkit.ssh2.port", "22"); - - // instanciate svn client manager - SVNClientManager manager = SVNClientManager.newInstance(options); - repository = manager.createRepository(testRepositoryURL, false); - repository.testConnection(); - return repository; - } catch (SVNException e) { - throw new VCSException(e); - } - } - - /** - * TODO This method is specifi to IsisFish, must be removed from here. - * TODO Implement a IsisSVNProvider ? - * - * @param typeRepo the type of repo we want to use if possible - * @param uncleanRemotePath remote path (could be unclean) - * @param databaseVersion the database version to use - * @param hostName the hostname to use - * @return the typeRepo to use - * @throws org.codelutin.vcs.VCSException if could not compute SVNURL to tests - */ - public static VCSTypeRepo findTypeRepo(VCSTypeRepo typeRepo, - String uncleanRemotePath, - String databaseVersion, - String hostName) throws VCSException { - - - VCSTypeRepo result; - - 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(); - log.info("try svn url " + url + " (" + remoteDatabase + ")"); - - SVNRepository repository; - try { - repository = getAnonymousConnection(url); - } catch (VCSException e) { - log.warn(e); - return null; - } - - try { - SVNNodeKind kind = repository.checkPath(remoteDatabase, SVNRevision.HEAD.getNumber()); - log.info("kind node found for " + remoteDatabase + " : " + kind); - // typeRepo type is ok, use it - if (kind == SVNNodeKind.NONE) { - // could not found the remote database - if (typeRepo == VCSTypeRepo.HEAD) { - // this is a fatal error since head always exists - throw new VCSRuntimeException("could not found svn trunk " + url + " (" + repository.getLocation() + ")"); - } else { - result = VCSTypeRepo.HEAD; - } - } else { - // was found, so keep it - result = typeRepo; - } - } catch (SVNException e) { - throw new VCSRuntimeException(e); - } - log.info("required:" + typeRepo + " available:" + result); - return result; - } - - static void setupLibrary() { - if (libraryInit) { - return; - } - libraryInit = true; - /* - * For using over http:// and https:// - */ - DAVRepositoryFactory.setup(); - - /* - * For using over svn:// and svn+xxx:// - */ - SVNRepositoryFactoryImpl.setup(); - - /* - * For using over file:/// - */ - FSRepositoryFactory.setup(); - } -} Copied: trunk/lutinvcs/provider/svn/src/main/java/org/codelutin/vcs/provider/SVNProvider.java (from rev 508, trunk/lutinvcs/provider/svn/src/main/java/org/codelutin/vcs/SVNProvider.java) =================================================================== --- trunk/lutinvcs/provider/svn/src/main/java/org/codelutin/vcs/provider/SVNProvider.java (rev 0) +++ trunk/lutinvcs/provider/svn/src/main/java/org/codelutin/vcs/provider/SVNProvider.java 2008-04-13 15:59:12 UTC (rev 510) @@ -0,0 +1,242 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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 2 + * 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, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.vcs.provider; + +import org.codelutin.vcs.provider.svn.SVNConnexion; +import org.codelutin.vcs.provider.svn.SVNHandler; +import org.codelutin.vcs.type.VCSTypeRepo; +import org.codelutin.vcs.util.AbstractVCSHandler; +import org.codelutin.vcs.util.AbstractVCSProvider; +import org.codelutin.vcs.VCSException; +import org.codelutin.vcs.VCSRuntimeException; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNNodeKind; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; +import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory; +import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl; +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.SVNWCUtil; + +import java.util.Arrays; + +/** + * SVN Provider + * + * @author chemit + */ +public class SVNProvider extends AbstractVCSProvider<SVNConnexion, SVNHandler> { + + private static boolean libraryInit; + + public SVNProvider() { + + super("SVN", SVNHandler.class, SVNConnexion.class); + + setupLibrary(); + } + + /** + * Test if a anonymous svn connection can be openned. + * + * @param url the svn url to test + * @return <code>true</code> if connection is ok,<code>false</code> otherwise. + * @throws org.codelutin.vcs.VCSException if could not compute the SVNURL + */ + public static boolean testAnonymousConnection(String url) throws VCSException { + boolean result = true; + + SVNRepository repository = getAnonymousConnection(url); + try { + repository.testConnection(); + } catch (SVNException e) { + result = false; + } finally { + if (repository != null) { + try { + repository.closeSession(); + } catch (Exception e) { + log.warn(e); + } + } + } + return result; + } + + /** + * Test if a anonymous svn connection can be openned. + * + * @param url the svn url to test + * @param username user name + * @param privateKeyFilePath the file to used as protected key file + * @param passphrase passphrase to use + * @return <code>true</code> if connection is ok,<code>false</code> otherwise. + * @throws org.codelutin.vcs.VCSException if could not compute the SVNURL + */ + public static boolean testSSHConnection(String url, String username, String privateKeyFilePath, char[] passphrase) throws VCSException { + boolean result = true; + + SVNRepository repository = getSSHConnection(url, username, privateKeyFilePath, passphrase); + try { + repository.testConnection(); + } catch (SVNException e) { + result = false; + } finally { + if (repository != null) { + try { + repository.closeSession(); + } catch (Exception e) { + log.warn(e); + } + } + } + return result; + } + + public static SVNRepository getAnonymousConnection(String url) throws VCSException { + + setupLibrary(); + + SVNURL testRepositoryURL; + try { + testRepositoryURL = SVNURL.parseURIEncoded(url); + } catch (SVNException e) { + throw new VCSException(e); + } + SVNRepository repository; + try { + ISVNOptions options = SVNWCUtil.createDefaultOptions(true); + SVNClientManager manager = SVNClientManager.newInstance(options, "anonymous", "anonymous"); + repository = manager.createRepository(testRepositoryURL, false); + repository.testConnection(); + return repository; + } catch (SVNException e) { + throw new VCSException(e); + } + } + + public static SVNRepository getSSHConnection(String url, String username, String privateKeyFilePath, char[] passphrase) throws VCSException { + + setupLibrary(); + + SVNURL testRepositoryURL; + try { + testRepositoryURL = SVNURL.parseURIEncoded(url); + } catch (SVNException e) { + throw new VCSException(e); + } + SVNRepository repository; + try { + ISVNOptions options = SVNWCUtil.createDefaultOptions(true); + System.setProperty("svnkit.ssh2.key", privateKeyFilePath); + System.setProperty("svnkit.ssh2.username", username); + if (passphrase != null && passphrase.length > 0) { + System.setProperty("svnkit.ssh2.passphrase", Arrays.toString(passphrase)); + } + //System.setProperty("svnkit.ssh2.passphrase", ""); + //System.setProperty("svnkit.ssh2.password", ""); + //System.setProperty("svnkit.ssh2.port", "22"); + + // instanciate svn client manager + SVNClientManager manager = SVNClientManager.newInstance(options); + repository = manager.createRepository(testRepositoryURL, false); + repository.testConnection(); + return repository; + } catch (SVNException e) { + throw new VCSException(e); + } + } + + /** + * TODO This method is specifi to IsisFish, must be removed from here. + * TODO Implement a IsisSVNProvider ? + * + * @param typeRepo the type of repo we want to use if possible + * @param uncleanRemotePath remote path (could be unclean) + * @param databaseVersion the database version to use + * @param hostName the hostname to use + * @return the typeRepo to use + * @throws org.codelutin.vcs.VCSException if could not compute SVNURL to tests + */ + public static VCSTypeRepo findTypeRepo(VCSTypeRepo typeRepo, + String uncleanRemotePath, + String databaseVersion, + String hostName) throws VCSException { + + + VCSTypeRepo result; + + 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(); + log.info("try svn url " + url + " (" + remoteDatabase + ")"); + + SVNRepository repository; + try { + repository = getAnonymousConnection(url); + } catch (VCSException e) { + log.warn(e); + return null; + } + + try { + SVNNodeKind kind = repository.checkPath(remoteDatabase, SVNRevision.HEAD.getNumber()); + log.info("kind node found for " + remoteDatabase + " : " + kind); + // typeRepo type is ok, use it + if (kind == SVNNodeKind.NONE) { + // could not found the remote database + if (typeRepo == VCSTypeRepo.HEAD) { + // this is a fatal error since head always exists + throw new VCSRuntimeException("could not found svn trunk " + url + " (" + repository.getLocation() + ")"); + } else { + result = VCSTypeRepo.HEAD; + } + } else { + // was found, so keep it + result = typeRepo; + } + } catch (SVNException e) { + throw new VCSRuntimeException(e); + } + log.info("required:" + typeRepo + " available:" + result); + return result; + } + + static void setupLibrary() { + if (libraryInit) { + return; + } + libraryInit = true; + /* + * For using over http:// and https:// + */ + DAVRepositoryFactory.setup(); + + /* + * For using over svn:// and svn+xxx:// + */ + SVNRepositoryFactoryImpl.setup(); + + /* + * For using over file:/// + */ + FSRepositoryFactory.setup(); + } +} Modified: trunk/lutinvcs/provider/svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider =================================================================== --- trunk/lutinvcs/provider/svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider 2008-04-13 15:58:23 UTC (rev 509) +++ trunk/lutinvcs/provider/svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider 2008-04-13 15:59:12 UTC (rev 510) @@ -1 +1 @@ -org.codelutin.vcs.SVNProvider \ No newline at end of file +org.codelutin.vcs.provider.SVNProvider \ No newline at end of file Modified: trunk/lutinvcs/provider/svn/src/test/java/org/codelutin/vcs/provider/svn/FindTypeRepoTest.java =================================================================== --- trunk/lutinvcs/provider/svn/src/test/java/org/codelutin/vcs/provider/svn/FindTypeRepoTest.java 2008-04-13 15:58:23 UTC (rev 509) +++ trunk/lutinvcs/provider/svn/src/test/java/org/codelutin/vcs/provider/svn/FindTypeRepoTest.java 2008-04-13 15:59:12 UTC (rev 510) @@ -2,7 +2,7 @@ import junit.framework.TestCase; import org.codelutin.vcs.VCSException; -import org.codelutin.vcs.SVNProvider; +import org.codelutin.vcs.provider.SVNProvider; import org.codelutin.vcs.type.VCSTypeRepo; /**