2121import java .io .ByteArrayOutputStream ;
2222import java .io .File ;
2323import java .io .FileWriter ;
24- import java .io .UnsupportedEncodingException ;
2524import java .nio .charset .StandardCharsets ;
2625import java .util .*;
2726
@@ -40,7 +39,11 @@ public class SVNVCS implements IVCS {
4039
4140 public static final String MASTER_PATH = "trunk/" ;
4241 public static final String BRANCHES_PATH = "branches/" ;
43- private static final String SVN_VCS_TYPE_STRING = "svn" ;
42+ public static final String SVN_VCS_TYPE_STRING = "svn" ;
43+
44+ public void setClientManager (SVNClientManager clientManager ) {
45+ this .clientManager = clientManager ;
46+ }
4447
4548 public SVNClientManager getClientManager () {
4649 return clientManager ;
@@ -49,6 +52,18 @@ public SVNClientManager getClientManager() {
4952 public ISVNOptions getOptions () {
5053 return options ;
5154 }
55+
56+ public SVNURL getTrunkSVNUrl () {
57+ return trunkSVNUrl ;
58+ }
59+
60+ public SVNRepository getSVNRepository () {
61+ return repository ;
62+ }
63+
64+ public void setSVNRepository (SVNRepository repository ) {
65+ this .repository = repository ;
66+ }
5267
5368 public SVNVCS (IVCSRepositoryWorkspace repo , String user , String password ) {
5469 this .repo = repo ;
@@ -73,23 +88,23 @@ public SVNVCS(IVCSRepositoryWorkspace repo, String user, String password) {
7388 options , repository .getAuthenticationManager ());
7489 }
7590
76- public SVNRepository getRepository () {
77- return repository ;
78- }
79-
80- private SVNURL getBranchUrl (String branchPath ) throws SVNException {
91+ public SVNURL getBranchUrl (String branchPath ) throws Exception {
8192 return SVNURL .parseURIEncoded (repoUrl + getBranchName (branchPath ));
8293 }
94+
95+
8396
8497 @ Override
85- public void createBranch (String srcBranchName , String dstBranchName , String commitMessage ) {
98+ public void createBranch (String srcBranchName , String dstBranchName , String commitMessage ) throws EVCSBranchExists {
99+ SVNURL fromUrl ;
100+ SVNURL toUrl ;
86101 try {
87- SVNURL fromUrl = getBranchUrl (srcBranchName );
88- SVNURL toUrl = getBranchUrl (dstBranchName );
89- createBranch ( fromUrl , toUrl , commitMessage );
90- } catch ( SVNException e ) {
91- throw new EVCSException ( e );
92- }
102+ fromUrl = getBranchUrl (srcBranchName );
103+ toUrl = getBranchUrl (dstBranchName );
104+ } catch ( Exception e ) {
105+ throw new RuntimeException ( e );
106+ }
107+ createBranch ( fromUrl , toUrl , commitMessage );
93108 }
94109
95110 public void createBranch (SVNURL fromUrl , SVNURL toUrl , String commitMessage ) {
@@ -127,6 +142,8 @@ public void deleteBranch(String branchName, String commitMessage) {
127142 .doDelete (new SVNURL [] { getBranchUrl (branchName ) }, commitMessage );
128143 } catch (SVNException e ) {
129144 throw new EVCSException (e );
145+ } catch (Exception e ) {
146+ throw new RuntimeException (e );
130147 }
131148 }
132149
@@ -188,7 +205,7 @@ public SVNWCClient getRevertClient(DefaultSVNOptions options) {
188205 return new SVNWCClient (authManager , options );
189206 }
190207
191- public void checkout (SVNURL sourceUrl , File destPath ) throws SVNException {
208+ public void checkout (SVNURL sourceUrl , File destPath ) throws Exception {
192209 SVNUpdateClient updateClient = clientManager .getUpdateClient ();
193210 updateClient .setIgnoreExternals (false );
194211 if (isWorkingCopyInited (destPath )) {
@@ -199,7 +216,7 @@ public void checkout(SVNURL sourceUrl, File destPath) throws SVNException {
199216 }
200217 }
201218
202- private boolean isWorkingCopyInited (File destPath ) {
219+ public boolean isWorkingCopyInited (File destPath ) {
203220 try {
204221 clientManager .getStatusClient ().doStatus (destPath , false );
205222 return true ;
@@ -214,7 +231,7 @@ private boolean isWorkingCopyInited(File destPath) {
214231
215232 @ Override
216233 public void setCredentials (String user , String password ) {
217- userPassAuth = SVNPasswordAuthentication .newInstance (user , password .toCharArray (), true , trunkSVNUrl , false );
234+ userPassAuth = SVNPasswordAuthentication .newInstance (user , password == null ? null : password .toCharArray (), true , trunkSVNUrl , false );
218235 authManager .setAuthentications (new SVNAuthentication [] {userPassAuth });
219236 }
220237
@@ -226,17 +243,17 @@ public void setProxy(String host, int port, String proxyUser, String proxyPasswo
226243
227244 @ Override
228245 public String getFileContent (String branchName , String filePath , String encoding ) {
229- ByteArrayOutputStream baos = new ByteArrayOutputStream ( );
246+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
230247 try {
231- repository .getFile (new File (getBranchName (branchName ), filePath ).getPath ().replace ("\\ " , "/" ),
248+ repository .getFile (new File (getBranchName (branchName ), filePath ).getPath ().replace ("\\ " , "/" ),
232249 -1 , new SVNProperties (), baos );
233250 return baos .toString (encoding );
234251 } catch (SVNException e ) {
235252 if (e .getErrorMessage ().getErrorCode ().getCode () == SVN_FILE_NOT_FOUND_ERROR_CODE ) {
236253 throw new EVCSFileNotFound (e );
237254 }
238255 throw new EVCSException (e );
239- } catch (UnsupportedEncodingException e ) {
256+ } catch (Exception e ) {
240257 throw new RuntimeException (e );
241258 }
242259
@@ -299,8 +316,9 @@ public String getRepoUrl() {
299316 return repo .getRepoUrl ();
300317 }
301318
302- private void fillUnifiedDiffs (final String srcBranchName , final String dstBranchName , List <VCSDiffEntry > entries )
303- throws SVNException {
319+ private List <VCSDiffEntry > fillUnifiedDiffs (final String srcBranchName , final String dstBranchName , List <VCSDiffEntry > entries )
320+ throws Exception {
321+ List <VCSDiffEntry > res = new ArrayList <>();
304322 for (VCSDiffEntry entry : entries ) {
305323 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
306324
@@ -325,15 +343,12 @@ private void fillUnifiedDiffs(final String srcBranchName, final String dstBranch
325343 diff .setOutput (baos );
326344 diff .run ();
327345
328- try {
329- entry .setUnifiedDiff (baos .toString ("UTF-8" ));
330- } catch (UnsupportedEncodingException e ) {
331- throw new RuntimeException (e );
332- }
346+ res .add (new VCSDiffEntry (entry .getFilePath (), entry .getChangeType (), baos .toString ("UTF-8" )));
333347 }
348+ return res ;
334349 }
335350
336- private SVNLogEntry getBranchFirstCommit (final String branchPath ) throws SVNException {
351+ protected SVNLogEntry getBranchFirstCommit (final String branchPath ) throws Exception {
337352 final List <SVNLogEntry > logEntries = new ArrayList <>();
338353 repository .log (new String [] { getBranchName (branchPath ) }, -1 /* start from head descending */ ,
339354 0 , true , true , -1 , new ISVNLogEntryHandler () {
@@ -347,7 +362,7 @@ public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
347362
348363
349364 private List <VCSDiffEntry > getDiffEntries (final String srcBranchName , final String dstBranchName )
350- throws SVNException {
365+ throws Exception {
351366 final SvnOperationFactory svnOperationFactory = new SvnOperationFactory ();
352367 final SvnDiffSummarize summarizeDiff = svnOperationFactory .createDiffSummarize ();
353368 final List <VCSDiffEntry > res = new ArrayList <>();
@@ -362,34 +377,36 @@ public void receive(SvnTarget target, SvnDiffStatus diffStatus) throws SVNExcept
362377 return ;
363378 }
364379 VCSDiffEntry entry = new VCSDiffEntry (diffStatus .getPath (),
365- SVNChangeTypeToVCSChangeType (diffStatus .getModificationType ()));
380+ SVNChangeTypeToVCSChangeType (diffStatus .getModificationType ()), null );
366381 res .add (entry );
367382 }
368383
369- private VCSChangeType SVNChangeTypeToVCSChangeType (SVNStatusType modificationType ) {
370- if (SVNStatusType .STATUS_ADDED .equals (modificationType )) {
371- return VCSChangeType .ADD ;
372- } else if (SVNStatusType .STATUS_DELETED .equals (modificationType )) {
373- return VCSChangeType .DELETE ;
374- } else if (SVNStatusType .STATUS_MODIFIED .equals (modificationType )) {
375- return VCSChangeType .MODIFY ;
376- } else {
377- return VCSChangeType .UNKNOWN ;
378- }
379- }
384+
380385 });
381386 summarizeDiff .run ();
382387
383388 return res ;
384389 }
385390
391+ public VCSChangeType SVNChangeTypeToVCSChangeType (SVNStatusType modificationType ) {
392+ if (SVNStatusType .STATUS_ADDED .equals (modificationType )) {
393+ return VCSChangeType .ADD ;
394+ } else if (SVNStatusType .STATUS_DELETED .equals (modificationType )) {
395+ return VCSChangeType .DELETE ;
396+ } else if (SVNStatusType .STATUS_MODIFIED .equals (modificationType )) {
397+ return VCSChangeType .MODIFY ;
398+ } else {
399+ return VCSChangeType .UNKNOWN ;
400+ }
401+ }
402+
386403 @ Override
387404 public List <VCSDiffEntry > getBranchesDiff (final String srcBranchName , final String dstBranchName ) {
388405 try {
389406 try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ()) {
390407 checkout (getBranchUrl (dstBranchName ), wc .getFolder ());
391408 List <VCSDiffEntry > entries = getDiffEntries (srcBranchName , dstBranchName );
392- fillUnifiedDiffs (srcBranchName , dstBranchName , entries );
409+ entries = fillUnifiedDiffs (srcBranchName , dstBranchName , entries );
393410 return entries ;
394411 }
395412 } catch (SVNException e ) {
@@ -413,7 +430,7 @@ public Set<String> getBranches() {
413430 }
414431 }
415432
416- private void addTrunkIfExists (Set <String > res ) {
433+ protected void addTrunkIfExists (Set <String > res ) {
417434 try {
418435 if (repository .checkPath (MASTER_PATH , -1 ) == SVNNodeKind .DIR ) {
419436 res .add (MASTER_PATH .replace ("/" , "" ));
@@ -424,7 +441,7 @@ private void addTrunkIfExists(Set<String> res) {
424441
425442 }
426443
427- private void listEntries (Set <String > entries , String path ) throws SVNException {
444+ public void listEntries (Set <String > entries , String path ) throws Exception {
428445 @ SuppressWarnings ("unchecked" )
429446 Collection <SVNDirEntry > subEntries = repository .getDir (path , -1 , null , (Collection <SVNDirEntry >) null );
430447 for (SVNDirEntry entry : subEntries ) {
@@ -462,13 +479,11 @@ public String getVCSTypeString() {
462479
463480 @ Override
464481 public VCSCommit removeFile (String branchName , String filePath , String commitMessage ) {
465- try {
466- try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ()) {
467- SVNCommitInfo res = clientManager
468- .getCommitClient ()
469- .doDelete (new SVNURL [] {getBranchUrl (branchName ).appendPath (filePath , true )}, commitMessage );
470- return new VCSCommit (Long .toString (res .getNewRevision ()), commitMessage , res .getAuthor ());
471- }
482+ try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ()) {
483+ SVNCommitInfo res = clientManager
484+ .getCommitClient ()
485+ .doDelete (new SVNURL [] {getBranchUrl (branchName ).appendPath (filePath , true )}, commitMessage );
486+ return new VCSCommit (Long .toString (res .getNewRevision ()), commitMessage , res .getAuthor ());
472487 } catch (SVNException e ) {
473488 throw new EVCSException (e );
474489 } catch (Exception e ) {
0 commit comments