This is an automated email from the git hooks/post-receive script. New commit to branch feature/3879 in repository scmwebeditor. See http://git.nuiton.org/scmwebeditor.git commit 33603cba14c5a237d8c5aca379b2770c76669b0e Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Feb 14 19:28:49 2016 +0100 Application dans le module svn --- .../org/nuiton/scmwebeditor/svn/SvnConnection.java | 214 ++++++++++++--------- .../nuiton/scmwebeditor/svn/SvnFileManager.java | 76 +++----- .../org/nuiton/scmwebeditor/svn/SvnProvider.java | 29 ++- .../java/org/nuiton/scmwebeditor/svn/SvnUtil.java | 18 ++ 4 files changed, 173 insertions(+), 164 deletions(-) diff --git a/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnConnection.java b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnConnection.java index b2a8451..252e59c 100644 --- a/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnConnection.java +++ b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnConnection.java @@ -24,6 +24,7 @@ package org.nuiton.scmwebeditor.svn; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.scmwebeditor.api.ScmAuthentication; import org.nuiton.scmwebeditor.api.ScmConnection; import org.nuiton.scmwebeditor.api.ScmRevision; import org.nuiton.scmwebeditor.api.dto.BrowseDto; @@ -31,7 +32,15 @@ import org.nuiton.scmwebeditor.api.dto.CommitDto; import org.nuiton.scmwebeditor.api.dto.result.BrowseResultDto; import org.nuiton.scmwebeditor.api.dto.result.CommitResultDto; import org.nuiton.util.FileUtil; -import org.tmatesoft.svn.core.*; +import org.tmatesoft.svn.core.SVNAuthenticationException; +import org.tmatesoft.svn.core.SVNDepth; +import org.tmatesoft.svn.core.SVNDirEntry; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNNodeKind; +import org.tmatesoft.svn.core.SVNProperties; +import org.tmatesoft.svn.core.SVNProperty; +import org.tmatesoft.svn.core.SVNRevisionProperty; +import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; import org.tmatesoft.svn.core.internal.util.SVNEncodingUtil; @@ -39,16 +48,30 @@ import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions; import org.tmatesoft.svn.core.io.SVNFileRevision; import org.tmatesoft.svn.core.io.SVNRepository; import org.tmatesoft.svn.core.io.SVNRepositoryFactory; -import org.tmatesoft.svn.core.wc.*; +import org.tmatesoft.svn.core.wc.SVNClientManager; +import org.tmatesoft.svn.core.wc.SVNCommitClient; +import org.tmatesoft.svn.core.wc.SVNDiffClient; +import org.tmatesoft.svn.core.wc.SVNInfo; +import org.tmatesoft.svn.core.wc.SVNRevision; +import org.tmatesoft.svn.core.wc.SVNUpdateClient; +import org.tmatesoft.svn.core.wc.SVNWCClient; +import org.tmatesoft.svn.core.wc.SVNWCUtil; import javax.naming.AuthenticationException; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; import java.util.Map; +import java.util.Optional; import java.util.TreeMap; /** @@ -87,24 +110,34 @@ public class SvnConnection implements ScmConnection { protected SVNClientManager manager; - public String getSvnPath() { return svnPath; } + public String getSvnPath() { + return svnPath; + } - public DefaultSVNOptions getSvnOption() { return svnOption; } + public DefaultSVNOptions getSvnOption() { + return svnOption; + } - public String getPathToLocalRepos() { return pathToLocalRepos; } + public String getPathToLocalRepos() { + return pathToLocalRepos; + } - public void setPathToLocalRepos(String pathToLocalRepos) { this.pathToLocalRepos = pathToLocalRepos; } + public void setPathToLocalRepos(String pathToLocalRepos) { + this.pathToLocalRepos = pathToLocalRepos; + } - public SVNClientManager getManager() { return manager; } + public SVNClientManager getManager() { + return manager; + } public SvnConnection(String address, String pathToLocalRepos) throws SVNException { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("SVN repository"); } - if (address.lastIndexOf('/') != -1){ + if (address.lastIndexOf('/') != -1) { svnPath = address.substring(0, address.lastIndexOf('/')); fileName = address.substring(address.lastIndexOf('/') + 1); @@ -134,44 +167,44 @@ public class SvnConnection implements ScmConnection { SVNRepository repository; ISVNAuthenticationManager svnAuthManager; - String name = dto.getUsername(); - String password = dto.getPassword(); + switch (dto.getId()) { + case "": - if (dto.getId().equals("")) { - - try { - if (log.isDebugEnabled()) { - log.debug("Address svn : " + dto.getAddress()); - } + try { + if (log.isDebugEnabled()) { + log.debug("Address svn : " + dto.getAddress()); + } - String encodedUrl = SVNEncodingUtil.autoURIEncode(addressSvn); - repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(encodedUrl)); - svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(name, password); - repository.setAuthenticationManager(svnAuthManager); + String encodedUrl = SVNEncodingUtil.autoURIEncode(addressSvn); + repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(encodedUrl)); + svnAuthManager = SvnUtil.createAuthenticationManager(dto.getScmAuthentication()); + repository.setAuthenticationManager(svnAuthManager); - repository.testConnection(); + repository.testConnection(); - } catch (SVNAuthenticationException e) { - if (log.isErrorEnabled()) { - log.error("Can't access to the repository : Auth Problem", e); - } - resultDto.setError(BrowseResultDto.AUTH_ERROR); - return resultDto; - } catch (SVNException e) { - if (log.isErrorEnabled()) { - log.error("Can't access to the repository", e); + } catch (SVNAuthenticationException e) { + if (log.isErrorEnabled()) { + log.error("Can't access to the repository : Auth Problem", e); + } + resultDto.setError(BrowseResultDto.AUTH_ERROR); + return resultDto; + } catch (SVNException e) { + if (log.isErrorEnabled()) { + log.error("Can't access to the repository", e); + } + resultDto.setError(BrowseResultDto.ERROR); + return resultDto; } - resultDto.setError(BrowseResultDto.ERROR); - return resultDto; - } - resultDto.setError(BrowseResultDto.ROOT); - return resultDto; - } else if (dto.getId().equals("0")) { - url = dto.getAddress(); - } else { - url = dto.getId(); - dto.setAddress(dto.getId()); + resultDto.setError(BrowseResultDto.ROOT); + return resultDto; + case "0": + url = dto.getAddress(); + break; + default: + url = dto.getId(); + dto.setAddress(dto.getId()); + break; } @@ -179,7 +212,7 @@ public class SvnConnection implements ScmConnection { String encodedUrl = SVNEncodingUtil.autoURIEncode(url); repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(encodedUrl)); - svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(name, password); + svnAuthManager = SvnUtil.createAuthenticationManager(dto.getScmAuthentication()); repository.setAuthenticationManager(svnAuthManager); if (log.isDebugEnabled()) { @@ -243,7 +276,7 @@ public class SvnConnection implements ScmConnection { CommitResultDto resultDto = new CommitResultDto(); - updateAuthentication(dto.getUsername(), dto.getPassword()); + updateAuthentication(dto.getScmAuthentication()); if (log.isDebugEnabled()) { log.debug("Entering SVN commit"); @@ -329,7 +362,7 @@ public class SvnConnection implements ScmConnection { resultDto.setDiff(diff.substring(diff.indexOf("@@"))); delTempDirectory(checkoutdir); try { - resultDto.setHeadCommiter(getHeadcommiter(dto.getAddress(), dto.getUsername(), dto.getPassword())); + resultDto.setHeadCommiter(getHeadcommiter(dto.getAddress(), Optional.of(dto.getScmAuthentication()))); } catch (SVNException e) { log.error("Can't get head commiter", e); } @@ -377,7 +410,7 @@ public class SvnConnection implements ScmConnection { log.debug("Try to commit"); } commitClient.doCommit(tabFile, false, "From scmwebeditor -- " + dto.getCommitMessage(), null, null, false, - false, SVNDepth.FILES); + false, SVNDepth.FILES); } catch (SVNAuthenticationException authexep) { if (log.isErrorEnabled()) { log.error("AUTH FAIL", authexep); @@ -389,8 +422,7 @@ public class SvnConnection implements ScmConnection { // deleting temporary directory delTempDirectory(checkoutdir); - dto.setUsername(null); - dto.setPassword(null); + dto.setScmAuthentication(null); resultDto.setError(CommitResultDto.AUTH_ERROR); return resultDto; @@ -418,12 +450,11 @@ public class SvnConnection implements ScmConnection { delTempDirectory(checkoutdir); if (log.isInfoEnabled()) { - log.info(dto.getUsername() + " commit the file " + dto.getAddress() + " with message : " - + dto.getCommitMessage()); + log.info(dto.getScmAuthentication() + " commit the file " + dto.getAddress() + " with message : " + dto.getCommitMessage()); } try { - resultDto.setNumRevision(getHeadRevisionNumber(dto.getAddress(), dto.getUsername(), dto.getPassword())); + resultDto.setNumRevision(getHeadRevisionNumber(dto.getAddress(), Optional.of(dto.getScmAuthentication()))); } catch (AuthenticationException e) { if (log.isErrorEnabled()) { log.error("Auth fail", e); @@ -435,22 +466,20 @@ public class SvnConnection implements ScmConnection { @Override - public File getFileContent(String path, String username, String password) throws AuthenticationException { - - File fileContent = getFileContentAtRevision(path, username, password, "-1"); + public File getFileContent(String path, Optional<ScmAuthentication> optionalScmAuthentication) throws AuthenticationException { - return fileContent; + return getFileContentAtRevision(path, optionalScmAuthentication, "-1"); } @Override - public String getHeadRevisionNumber(String path, String username, String password) throws AuthenticationException { + public String getHeadRevisionNumber(String path, Optional<ScmAuthentication> optionalScmAuthentication) throws AuthenticationException { if (log.isDebugEnabled()) { log.debug("headRevisionNumber expected " + addressSvn + " ; got " + path); } - ISVNAuthenticationManager svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); + ISVNAuthenticationManager svnAuthManager = SvnUtil.createAuthenticationManager(optionalScmAuthentication.orElse(ScmAuthentication.ANONYMOUS)); DefaultSVNOptions svnOptions = new DefaultSVNOptions(); svnOptions.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); @@ -506,7 +535,7 @@ public class SvnConnection implements ScmConnection { } @Override - public String getFilePath(String address, String repositoryRoot, String username, String password) { + public String getFilePath(String address, String repositoryRoot, Optional<ScmAuthentication> optionalScmAuthentication) { String path = address; @@ -515,7 +544,7 @@ public class SvnConnection implements ScmConnection { File svgFile = null; try { - svgFile = getFileContent(address, username, password); + svgFile = getFileContent(address, optionalScmAuthentication); } catch (AuthenticationException e) { if (log.isErrorEnabled()) { log.error("Can not get file content for address " + address); @@ -531,16 +560,16 @@ public class SvnConnection implements ScmConnection { } @Override - public Map<ScmRevision, String> getRevisions(String address, String username, String password) throws AuthenticationException { + public Map<ScmRevision, String> getRevisions(String address, Optional<ScmAuthentication> optionalScmAuthentication) throws AuthenticationException { final int MAX_MESSAGE_LENGTH = 64; String url = address.substring(0, address.lastIndexOf('/')); String file = address.substring(address.lastIndexOf('/') + 1); - Map<ScmRevision, String> revisions = new TreeMap<ScmRevision, String>(); + Map<ScmRevision, String> revisions = new TreeMap<>(); - updateAuthentication(username, password); + updateAuthentication(optionalScmAuthentication.orElse(ScmAuthentication.ANONYMOUS)); SVNRepository repository; @@ -548,7 +577,7 @@ public class SvnConnection implements ScmConnection { // getting the revisions repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url)); - ISVNAuthenticationManager svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); + ISVNAuthenticationManager svnAuthManager = SvnUtil.createAuthenticationManager(optionalScmAuthentication.orElse(ScmAuthentication.ANONYMOUS)); repository.setAuthenticationManager(svnAuthManager); SVNNodeKind nodeKind = repository.checkPath(file, -1); @@ -617,8 +646,7 @@ public class SvnConnection implements ScmConnection { } @Override - public File getFileContentAtRevision(String path, String username, String password, - String revision) throws AuthenticationException { + public File getFileContentAtRevision(String path, Optional<ScmAuthentication> optionalScmAuthentication, String revision) throws AuthenticationException { String url = path.substring(0, path.lastIndexOf('/')); String file = path.substring(path.lastIndexOf('/') + 1); @@ -645,14 +673,14 @@ public class SvnConnection implements ScmConnection { } } - updateAuthentication(username, password); + updateAuthentication(optionalScmAuthentication.orElse(ScmAuthentication.ANONYMOUS)); SVNRepository repository; try { repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url)); - ISVNAuthenticationManager svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); + ISVNAuthenticationManager svnAuthManager = SvnUtil.createAuthenticationManager(optionalScmAuthentication.orElse(ScmAuthentication.ANONYMOUS)); repository.setAuthenticationManager(svnAuthManager); SVNNodeKind nodeKind = repository.checkPath(file, rev); @@ -709,8 +737,7 @@ public class SvnConnection implements ScmConnection { @Override - public File getDiffs(String path, String username, String password, - String revision1, String revision2) throws AuthenticationException { + public File getDiffs(String path, Optional<ScmAuthentication> optionalScmAuthentication, String revision1, String revision2) throws AuthenticationException { String url = path.substring(0, path.lastIndexOf('/')); String file = path.substring(path.lastIndexOf('/') + 1); @@ -738,14 +765,14 @@ public class SvnConnection implements ScmConnection { } } - updateAuthentication(username, password); + updateAuthentication(optionalScmAuthentication.orElse(ScmAuthentication.ANONYMOUS)); SVNRepository repository; try { repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url)); - ISVNAuthenticationManager svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); + ISVNAuthenticationManager svnAuthManager = SvnUtil.createAuthenticationManager(optionalScmAuthentication.orElse(ScmAuthentication.ANONYMOUS)); repository.setAuthenticationManager(svnAuthManager); SVNNodeKind nodeKind1 = repository.checkPath(file, rev1); @@ -810,12 +837,12 @@ public class SvnConnection implements ScmConnection { } - public String getSvnRoot(String username, String password) { + public String getSvnRoot(ScmAuthentication scmAuthentication) { String repositoryRoot; try { String encodedUrl = SVNEncodingUtil.autoURIEncode(addressSvn); SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(encodedUrl)); - ISVNAuthenticationManager svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); + ISVNAuthenticationManager svnAuthManager = SvnUtil.createAuthenticationManager(scmAuthentication); repository.setAuthenticationManager(svnAuthManager); repositoryRoot = repository.getRepositoryRoot(true).toString(); @@ -830,8 +857,8 @@ public class SvnConnection implements ScmConnection { } - public void updateAuthentication(String login, String password) { - authManager = SVNWCUtil.createDefaultAuthenticationManager(login, password); + public void updateAuthentication(ScmAuthentication scmAuthentication) { + authManager = SvnUtil.createAuthenticationManager(scmAuthentication); manager = SVNClientManager.newInstance(svnOption, authManager); } @@ -850,9 +877,7 @@ public class SvnConnection implements ScmConnection { ByteArrayOutputStream diff = getDiff(text); - boolean positiveSize = (diff.size() > 0); - - return positiveSize; + return diff.size() > 0; } public ByteArrayOutputStream getDiff(String text) throws IOException { @@ -866,7 +891,7 @@ public class SvnConnection implements ScmConnection { try { diffClient.doDiff(pathToFile, SVNRevision.UNDEFINED, SVNRevision.WORKING, SVNRevision.HEAD, - SVNDepth.INFINITY, true, diff, null); + SVNDepth.INFINITY, true, diff, null); } catch (SVNException e) { log.error("Diff fail", e); } @@ -888,7 +913,7 @@ public class SvnConnection implements ScmConnection { } upclient.doCheckout(remoteUrl, checkoutdir, - SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); + SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); } @@ -907,7 +932,7 @@ public class SvnConnection implements ScmConnection { /** - * Use to delete the checkout temp directory + * Use to delete the checkout temp directory. * * @param checkoutdir The dir temp directory */ @@ -926,16 +951,16 @@ public class SvnConnection implements ScmConnection { /** - * Gives the name of the person who made the last commit - * @param address the repository's address - * @param login the username to use to connect to the repository - * @param password the password to use to connect to the repository + * Gives the name of the person who made the last commit. + * + * @param address the repository's address + * @param optionalScmAuthentication the username to use to connect to the repository * @return the name of the person who made the last commit * @throws SVNException if there is a problem while accessing the repository */ - public String getHeadcommiter(String address, String login, String password) throws SVNException { + public String getHeadcommiter(String address, Optional<ScmAuthentication> optionalScmAuthentication) throws SVNException { - ISVNAuthenticationManager svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(login, password); + ISVNAuthenticationManager svnAuthManager = SvnUtil.createAuthenticationManager(optionalScmAuthentication.orElse(ScmAuthentication.ANONYMOUS)); DefaultSVNOptions svnOptions = new DefaultSVNOptions(); svnOptions.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); @@ -944,19 +969,17 @@ public class SvnConnection implements ScmConnection { SVNInfo info = wcClient.doInfo(SVNURL.parseURIEncoded(address), SVNRevision.HEAD, SVNRevision.HEAD); - String headAuthor = info.getAuthor(); - - - return headAuthor; + return info.getAuthor(); } /** - * Makes a list of the files and directories in the repository + * Makes a list of the files and directories in the repository. + * * @param repository the repository to use to fetch information - * @param path the path to the directory (in the repository) to make the list from - * @param address the repository's address - * @param resultDto the DTO which will contain the files and directories found + * @param path the path to the directory (in the repository) to make the list from + * @param address the repository's address + * @param resultDto the DTO which will contain the files and directories found */ public void listEntries(SVNRepository repository, String path, String address, BrowseResultDto resultDto) { @@ -992,6 +1015,7 @@ public class SvnConnection implements ScmConnection { /** * Gives a unique address for the given file name + * * @param fileName the name of the file * @return a unique address for the file name */ diff --git a/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnFileManager.java b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnFileManager.java index a4fc1d3..ccf7e89 100644 --- a/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnFileManager.java +++ b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnFileManager.java @@ -24,8 +24,16 @@ package org.nuiton.scmwebeditor.svn; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.scmwebeditor.api.ScmFileManager; -import org.nuiton.scmwebeditor.api.dto.*; -import org.nuiton.scmwebeditor.api.dto.result.*; +import org.nuiton.scmwebeditor.api.dto.CreateDirectoryDto; +import org.nuiton.scmwebeditor.api.dto.MoveFileDto; +import org.nuiton.scmwebeditor.api.dto.RemoveDirectoryDto; +import org.nuiton.scmwebeditor.api.dto.RemoveFileDto; +import org.nuiton.scmwebeditor.api.dto.UploadFileDto; +import org.nuiton.scmwebeditor.api.dto.result.CreateDirectoryResultDto; +import org.nuiton.scmwebeditor.api.dto.result.MoveFileResultDto; +import org.nuiton.scmwebeditor.api.dto.result.RemoveDirectoryResultDto; +import org.nuiton.scmwebeditor.api.dto.result.RemoveFileResultDto; +import org.nuiton.scmwebeditor.api.dto.result.UploadFileResultDto; import org.tmatesoft.svn.core.SVNAuthenticationException; import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNException; @@ -49,7 +57,7 @@ public class SvnFileManager implements ScmFileManager { public SvnFileManager(SvnConnection connection) throws SVNException { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("SVN repository"); } @@ -62,15 +70,7 @@ public class SvnFileManager implements ScmFileManager { UploadFileResultDto resultDto = new UploadFileResultDto(); - if (dto.getUsername() == null) { - dto.setUsername("anonymous"); - } - - if (dto.getPassword() == null) { - dto.setPassword("anonymous"); - } - - resultDto.setScmRoot(connection.getSvnRoot(dto.getUsername(), dto.getPassword())); + resultDto.setScmRoot(connection.getSvnRoot(dto.getScmAuthentication())); if (resultDto.getScmRoot() == null) { resultDto.setScmRoot(connection.getSvnPath()); @@ -82,7 +82,7 @@ public class SvnFileManager implements ScmFileManager { resultDto.setFileRoot(connection.getSvnPath()); } - connection.updateAuthentication(dto.getUsername(), dto.getPassword()); + connection.updateAuthentication(dto.getScmAuthentication()); try { connection.testConnection(); @@ -112,7 +112,7 @@ public class SvnFileManager implements ScmFileManager { try { commitClient.doImport(dto.getUpload(), SVNURL.parseURIEncoded(dto.getScmPath() + "/" + dto.getUploadFileName()), - "From scmwebeditor -- add the file : " + dto.getUploadFileName(), null, false, false, SVNDepth.EMPTY); + "From scmwebeditor -- add the file : " + dto.getUploadFileName(), null, false, false, SVNDepth.EMPTY); } catch (SVNAuthenticationException authexep) { if (log.isErrorEnabled()) { @@ -141,15 +141,7 @@ public class SvnFileManager implements ScmFileManager { RemoveFileResultDto resultDto = new RemoveFileResultDto(); - if (dto.getUsername() == null) { - dto.setUsername("anonymous"); - } - - if (dto.getPassword() == null) { - dto.setPassword("anonymous"); - } - - resultDto.setScmRoot(connection.getSvnRoot(dto.getUsername(), dto.getPassword())); + resultDto.setScmRoot(connection.getSvnRoot(dto.getScmAuthentication())); if (resultDto.getScmRoot() == null) { resultDto.setScmRoot(connection.getSvnPath()); @@ -161,7 +153,7 @@ public class SvnFileManager implements ScmFileManager { resultDto.setFileRoot(connection.getSvnPath()); } - connection.updateAuthentication(dto.getUsername(), dto.getPassword()); + connection.updateAuthentication(dto.getScmAuthentication()); try { connection.testConnection(); @@ -216,15 +208,7 @@ public class SvnFileManager implements ScmFileManager { CreateDirectoryResultDto resultDto = new CreateDirectoryResultDto(); - if (dto.getUsername() == null) { - dto.setUsername("anonymous"); - } - - if (dto.getPassword() == null) { - dto.setPassword("anonymous"); - } - - resultDto.setScmRoot(connection.getSvnRoot(dto.getUsername(), dto.getPassword())); + resultDto.setScmRoot(connection.getSvnRoot(dto.getScmAuthentication())); if (resultDto.getScmRoot() == null) { resultDto.setScmRoot(connection.getSvnPath()); @@ -236,7 +220,7 @@ public class SvnFileManager implements ScmFileManager { resultDto.setFileRoot(connection.getSvnPath()); } - connection.updateAuthentication(dto.getUsername(), dto.getPassword()); + connection.updateAuthentication(dto.getScmAuthentication()); try { connection.testConnection(); @@ -298,15 +282,7 @@ public class SvnFileManager implements ScmFileManager { RemoveDirectoryResultDto resultDto = new RemoveDirectoryResultDto(); - if (dto.getUsername() == null) { - dto.setUsername("anonymous"); - } - - if (dto.getPassword() == null) { - dto.setPassword("anonymous"); - } - - resultDto.setScmRoot(connection.getSvnRoot(dto.getUsername(), dto.getPassword())); + resultDto.setScmRoot(connection.getSvnRoot(dto.getScmAuthentication())); if (resultDto.getScmRoot() == null) { resultDto.setScmRoot(connection.getSvnPath()); @@ -318,7 +294,7 @@ public class SvnFileManager implements ScmFileManager { resultDto.setFileRoot(connection.getSvnPath()); } - connection.updateAuthentication(dto.getUsername(), dto.getPassword()); + connection.updateAuthentication(dto.getScmAuthentication()); try { connection.testConnection(); @@ -380,15 +356,7 @@ public class SvnFileManager implements ScmFileManager { MoveFileResultDto resultDto = new MoveFileResultDto(); - if (dto.getUsername() == null) { - dto.setUsername("anonymous"); - } - - if (dto.getPassword() == null) { - dto.setPassword("anonymous"); - } - - resultDto.setScmRoot(connection.getSvnRoot(dto.getUsername(), dto.getPassword())); + resultDto.setScmRoot(connection.getSvnRoot(dto.getScmAuthentication())); if (resultDto.getScmRoot() == null) { resultDto.setScmRoot(connection.getSvnPath()); @@ -400,7 +368,7 @@ public class SvnFileManager implements ScmFileManager { resultDto.setFileRoot(connection.getSvnPath()); } - connection.updateAuthentication(dto.getUsername(), dto.getPassword()); + connection.updateAuthentication(dto.getScmAuthentication()); try { connection.testConnection(); diff --git a/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnProvider.java b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnProvider.java index 2b2ac79..ac3a070 100644 --- a/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnProvider.java +++ b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnProvider.java @@ -24,7 +24,12 @@ package org.nuiton.scmwebeditor.svn; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.scmwebeditor.api.*; +import org.nuiton.scmwebeditor.api.OperationNotSupportedException; +import org.nuiton.scmwebeditor.api.RepositoryNotFoundException; +import org.nuiton.scmwebeditor.api.ScmAuthentication; +import org.nuiton.scmwebeditor.api.ScmConnection; +import org.nuiton.scmwebeditor.api.ScmProvider; +import org.nuiton.scmwebeditor.api.SweInternalException; import org.nuiton.scmwebeditor.api.dto.CreateBranchDto; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; @@ -32,6 +37,7 @@ import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl; import javax.naming.AuthenticationException; import java.util.List; +import java.util.Optional; /** * Implementation of the SVN's specific features @@ -56,19 +62,17 @@ public class SvnProvider implements ScmProvider { } @Override - public List<String> listBranches(String address, String username, String password) throws OperationNotSupportedException { + public List<String> listBranches(String address, Optional<ScmAuthentication> optionalScmAuthentication) throws OperationNotSupportedException { throw new OperationNotSupportedException("The 'list branches' operation is not available for SVN repositories"); } @Override - public String createBranch(CreateBranchDto dto) throws OperationNotSupportedException, - AuthenticationException, RepositoryNotFoundException { + public String createBranch(CreateBranchDto dto) throws OperationNotSupportedException, AuthenticationException, RepositoryNotFoundException { throw new OperationNotSupportedException("The 'create a branch' operation is not available for SVN repositories"); } @Override - public String changeBranch(String branchName, String pathToLocalRepos, String username, String password) - throws OperationNotSupportedException { + public String changeBranch(String branchName, String pathToLocalRepos, Optional<ScmAuthentication> optionalScmAuthentication) throws OperationNotSupportedException { throw new OperationNotSupportedException("The 'change branch' operation is not available for SVN repositories"); } @@ -83,7 +87,7 @@ public class SvnProvider implements ScmProvider { } @Override - public ScmConnection getConnection(String address, String pathToLocalRepos) { + public SvnConnection getConnection(String address, String pathToLocalRepos) { SvnConnection svnConn = null; @@ -99,7 +103,7 @@ public class SvnProvider implements ScmProvider { } @Override - public ScmFileManager getFileManager(ScmConnection connection) { + public SvnFileManager getFileManager(ScmConnection connection) { SvnFileManager fileManager = null; @@ -121,16 +125,11 @@ public class SvnProvider implements ScmProvider { @Override public boolean addressSeemsCompatible(String address) { - if (address.startsWith("svn://") || address.contains("svn.") || address.contains("subversion.")) { - return true; - } else { - return false; - } + return address.startsWith("svn://") || address.contains("svn.") || address.contains("subversion."); } @Override public String getDefaultBranchName() throws OperationNotSupportedException { - throw new OperationNotSupportedException("The 'get default branch name' operation is not available for " + - "SVN repositories"); + throw new OperationNotSupportedException("The 'get default branch name' operation is not available for SVN repositories"); } } diff --git a/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnUtil.java b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnUtil.java new file mode 100644 index 0000000..908a73b --- /dev/null +++ b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnUtil.java @@ -0,0 +1,18 @@ +package org.nuiton.scmwebeditor.svn; + +import org.nuiton.scmwebeditor.api.ScmAuthentication; +import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; +import org.tmatesoft.svn.core.wc.SVNWCUtil; + +/** + * Created on 14/02/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class SvnUtil { + + public static ISVNAuthenticationManager createAuthenticationManager(ScmAuthentication scmAuthentication) { + return SVNWCUtil.createDefaultAuthenticationManager(scmAuthentication.getUsername(), scmAuthentication.getPassword()); + } + +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.