Skip to content

Commit fad4c93

Browse files
committed
test coverage 100%
getLastTag() implemented
1 parent 513a2be commit fad4c93

File tree

3 files changed

+152
-165
lines changed

3 files changed

+152
-165
lines changed

src/main/java/org/scm4j/vcs/svn/SVNVCS.java

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,23 @@
11
package org.scm4j.vcs.svn;
22

3-
import java.io.ByteArrayOutputStream;
4-
import java.io.File;
5-
import java.io.FileWriter;
6-
import java.nio.charset.StandardCharsets;
7-
import java.util.ArrayList;
8-
import java.util.Collection;
9-
import java.util.Collections;
10-
import java.util.Comparator;
11-
import java.util.HashSet;
12-
import java.util.Iterator;
13-
import java.util.List;
14-
import java.util.Set;
15-
163
import org.apache.commons.io.FileUtils;
17-
import org.scm4j.vcs.api.IVCS;
18-
import org.scm4j.vcs.api.VCSChangeType;
19-
import org.scm4j.vcs.api.VCSCommit;
20-
import org.scm4j.vcs.api.VCSDiffEntry;
21-
import org.scm4j.vcs.api.VCSMergeResult;
22-
import org.scm4j.vcs.api.VCSTag;
23-
import org.scm4j.vcs.api.WalkDirection;
4+
import org.scm4j.vcs.api.*;
245
import org.scm4j.vcs.api.exceptions.EVCSBranchExists;
256
import org.scm4j.vcs.api.exceptions.EVCSException;
267
import org.scm4j.vcs.api.exceptions.EVCSFileNotFound;
278
import org.scm4j.vcs.api.exceptions.EVCSTagExists;
289
import org.scm4j.vcs.api.workingcopy.IVCSLockedWorkingCopy;
2910
import org.scm4j.vcs.api.workingcopy.IVCSRepositoryWorkspace;
3011
import org.scm4j.vcs.api.workingcopy.IVCSWorkspace;
31-
import org.tmatesoft.svn.core.ISVNLogEntryHandler;
32-
import org.tmatesoft.svn.core.SVNCommitInfo;
33-
import org.tmatesoft.svn.core.SVNDepth;
34-
import org.tmatesoft.svn.core.SVNDirEntry;
35-
import org.tmatesoft.svn.core.SVNException;
36-
import org.tmatesoft.svn.core.SVNLogEntry;
37-
import org.tmatesoft.svn.core.SVNLogEntryPath;
38-
import org.tmatesoft.svn.core.SVNNodeKind;
39-
import org.tmatesoft.svn.core.SVNProperties;
40-
import org.tmatesoft.svn.core.SVNURL;
12+
import org.tmatesoft.svn.core.*;
4113
import org.tmatesoft.svn.core.auth.BasicAuthenticationManager;
4214
import org.tmatesoft.svn.core.auth.SVNAuthentication;
4315
import org.tmatesoft.svn.core.auth.SVNPasswordAuthentication;
4416
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
4517
import org.tmatesoft.svn.core.io.SVNRepository;
4618
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
47-
import org.tmatesoft.svn.core.wc.ISVNConflictHandler;
48-
import org.tmatesoft.svn.core.wc.ISVNOptions;
49-
import org.tmatesoft.svn.core.wc.SVNClientManager;
50-
import org.tmatesoft.svn.core.wc.SVNConflictChoice;
51-
import org.tmatesoft.svn.core.wc.SVNConflictDescription;
52-
import org.tmatesoft.svn.core.wc.SVNConflictResult;
53-
import org.tmatesoft.svn.core.wc.SVNCopyClient;
54-
import org.tmatesoft.svn.core.wc.SVNCopySource;
55-
import org.tmatesoft.svn.core.wc.SVNDiffClient;
56-
import org.tmatesoft.svn.core.wc.SVNRevision;
57-
import org.tmatesoft.svn.core.wc.SVNRevisionRange;
58-
import org.tmatesoft.svn.core.wc.SVNStatusType;
59-
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
60-
import org.tmatesoft.svn.core.wc.SVNWCClient;
61-
import org.tmatesoft.svn.core.wc.SVNWCUtil;
62-
import org.tmatesoft.svn.core.wc2.ISvnObjectReceiver;
63-
import org.tmatesoft.svn.core.wc2.SvnDiff;
64-
import org.tmatesoft.svn.core.wc2.SvnDiffStatus;
65-
import org.tmatesoft.svn.core.wc2.SvnDiffSummarize;
66-
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
67-
import org.tmatesoft.svn.core.wc2.SvnTarget;
19+
import org.tmatesoft.svn.core.wc.*;
20+
import org.tmatesoft.svn.core.wc2.*;
6821

6922
import java.io.ByteArrayOutputStream;
7023
import java.io.File;
@@ -502,13 +455,12 @@ public void listEntries(List<String> entries, String path) throws Exception {
502455
public int compare(SVNDirEntry o1, SVNDirEntry o2) {
503456
if (o1.getRevision() < o2.getRevision()) {
504457
return -1;
505-
}
458+
}
506459
if (o1.getRevision() > o2.getRevision()) {
507460
return 1;
508461
}
509462
return 0;
510463
}
511-
512464
});
513465
for (SVNDirEntry entry : list) {
514466
if (entry.getKind() == SVNNodeKind.DIR) {
@@ -626,7 +578,7 @@ public VCSCommit getHeadCommit(String branchName) {
626578
try {
627579
SVNLogEntry entry = revToSVNEntry(getBranchName(branchName), -1L);
628580
if (entry != null) {
629-
return new VCSCommit(Long.toString(entry.getRevision()), entry.getMessage(),
581+
return new VCSCommit(Long.toString(entry.getRevision()), entry.getMessage(),
630582
entry.getAuthor());
631583
}
632584
return null;
@@ -680,7 +632,7 @@ public VCSTag createTag(String branchName, String tagName, String tagMessage) th
680632
}
681633
}
682634

683-
private SVNLogEntry revToSVNEntry(String branchName, Long rev) throws Exception {
635+
protected SVNLogEntry revToSVNEntry(String branchName, Long rev) throws Exception {
684636
SVNDirEntry info = repository.info(branchName, rev);
685637
@SuppressWarnings("unchecked")
686638
Collection<SVNLogEntry> entries = repository.log(new String[] {branchName}, null, info.getRevision(), info.getRevision(), true, true);
@@ -706,8 +658,8 @@ class SVNTagBaseCommit implements ISVNLogEntryHandler {
706658

707659
@Override
708660
public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
709-
for (Iterator<?> changedPaths = logEntry.getChangedPaths().keySet().iterator(); changedPaths.hasNext();) {
710-
SVNLogEntryPath entryPath = (SVNLogEntryPath) logEntry.getChangedPaths().get(changedPaths.next());
661+
for (String s : logEntry.getChangedPaths().keySet()) {
662+
SVNLogEntryPath entryPath = logEntry.getChangedPaths().get(s);
711663
copyFromRevision = entryPath.getCopyRevision();
712664
}
713665
}
@@ -730,4 +682,31 @@ public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
730682
throw new RuntimeException(e);
731683
}
732684
}
685+
686+
687+
@Override
688+
public VCSTag getLastTag() {
689+
try {
690+
SVNLogEntry entry = revToSVNEntry(TAGS_PATH, -1L);
691+
692+
Long copyFromRevision = -1L;
693+
for (String s : entry.getChangedPaths().keySet()) {
694+
SVNLogEntryPath entryPath = entry.getChangedPaths().get(s);
695+
copyFromRevision = entryPath.getCopyRevision();
696+
}
697+
698+
SVNLogEntry copyFromEntry = revToSVNEntry("", copyFromRevision);
699+
String tagName = "";
700+
for (String name : revToSVNEntry(TAGS_PATH, -1L).getChangedPaths().keySet()) {
701+
tagName = name.replace("/" + TAGS_PATH, "") ;
702+
}
703+
704+
return new VCSTag(tagName, entry.getMessage(), entry.getAuthor(), new VCSCommit(Long.toString(copyFromEntry.getRevision()),
705+
copyFromEntry.getMessage(), copyFromEntry.getAuthor()));
706+
} catch (SVNException e) {
707+
throw new EVCSException(e);
708+
} catch (Exception e) {
709+
throw new RuntimeException(e);
710+
}
711+
}
733712
}
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
package org.scm4j.vcs.svn;
22

3-
import org.scm4j.vcs.api.exceptions.EVCSException;
3+
import org.apache.commons.lang3.StringUtils;
44
import org.tmatesoft.svn.core.SVNException;
55
import org.tmatesoft.svn.core.SVNURL;
66
import org.tmatesoft.svn.core.io.SVNRepository;
77
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
8-
import org.apache.commons.lang3.StringUtils;
98

109
import java.io.File;
1110

1211
public class SVNVCSUtils {
13-
public static SVNRepository createRepository(File repoDir) {
14-
try {
15-
SVNURL localRepoUrl = SVNRepositoryFactory.createLocalRepository(repoDir, true, true);
16-
return SVNRepositoryFactory.create(localRepoUrl);
17-
} catch (SVNException e) {
18-
throw new EVCSException(e);
19-
}
12+
public static SVNRepository createRepository(File repoDir) throws SVNException {
13+
SVNURL localRepoUrl = SVNRepositoryFactory.createLocalRepository(repoDir, true, true);
14+
return SVNRepositoryFactory.create(localRepoUrl);
2015
}
2116

22-
public static void createFolderStructure(SVNVCS svn, String commitMessage) {
23-
try {
24-
svn
25-
.getClientManager()
26-
.getCommitClient()
27-
.doMkDir(new SVNURL[] {
28-
SVNURL.parseURIEncoded(StringUtils.appendIfMissing(svn.getRepoUrl(), "/") + SVNVCS.MASTER_PATH),
29-
SVNURL.parseURIEncoded(StringUtils.appendIfMissing(svn.getRepoUrl(), "/") + SVNVCS.BRANCHES_PATH),
30-
SVNURL.parseURIEncoded(StringUtils.appendIfMissing(svn.getRepoUrl(), "/") + SVNVCS.TAGS_PATH)},
31-
commitMessage);
32-
} catch (SVNException e) {
33-
throw new EVCSException(e);
34-
}
17+
public static void createFolderStructure(SVNVCS svn, String commitMessage) throws SVNException {
18+
svn
19+
.getClientManager()
20+
.getCommitClient()
21+
.doMkDir(new SVNURL[] {
22+
SVNURL.parseURIEncoded(StringUtils.appendIfMissing(svn.getRepoUrl(), "/") + SVNVCS.MASTER_PATH),
23+
SVNURL.parseURIEncoded(StringUtils.appendIfMissing(svn.getRepoUrl(), "/") + SVNVCS.BRANCHES_PATH),
24+
SVNURL.parseURIEncoded(StringUtils.appendIfMissing(svn.getRepoUrl(), "/") + SVNVCS.TAGS_PATH)},
25+
commitMessage);
3526
}
3627
}

0 commit comments

Comments
 (0)