Skip to content

Commit 42bc56c

Browse files
committed
Merge branch 'master' into release/4
2 parents 247d622 + 681d299 commit 42bc56c

File tree

3 files changed

+72
-73
lines changed

3 files changed

+72
-73
lines changed

build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ dependencies {
4848
add(configuration ?: name.contains('test') ? 'testCompile' : 'compile', "$group:$name:${version?:''}${classifier?:''}${ext?:''}")
4949
}
5050

51-
//compile 'com.github.scm4j:scm4j-vcs-api:master-SNAPSHOT'
5251
compile 'org.tmatesoft.svnkit:svnkit:1.8.14'
5352
compile 'org.apache.commons:commons-lang3:3.5'
5453

5554
testCompile 'junit:junit:4.12'
56-
//testCompile 'com.github.scm4j:scm4j-vcs-test:master-SNAPSHOT'
5755
testCompile 'org.mockito:mockito-core:2.0.62-beta'
5856
}
5957

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

Lines changed: 37 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,30 @@
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.List;
13-
import java.util.Set;
14-
153
import org.apache.commons.io.FileUtils;
164
import org.apache.commons.lang3.StringUtils;
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;
5+
import org.scm4j.vcs.api.*;
246
import org.scm4j.vcs.api.exceptions.EVCSBranchExists;
257
import org.scm4j.vcs.api.exceptions.EVCSException;
268
import org.scm4j.vcs.api.exceptions.EVCSFileNotFound;
279
import org.scm4j.vcs.api.exceptions.EVCSTagExists;
2810
import org.scm4j.vcs.api.workingcopy.IVCSLockedWorkingCopy;
2911
import org.scm4j.vcs.api.workingcopy.IVCSRepositoryWorkspace;
3012
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;
13+
import org.tmatesoft.svn.core.*;
4114
import org.tmatesoft.svn.core.auth.BasicAuthenticationManager;
4215
import org.tmatesoft.svn.core.auth.SVNAuthentication;
4316
import org.tmatesoft.svn.core.auth.SVNPasswordAuthentication;
4417
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
4518
import org.tmatesoft.svn.core.io.SVNRepository;
4619
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;
20+
import org.tmatesoft.svn.core.wc.*;
21+
import org.tmatesoft.svn.core.wc2.*;
22+
23+
import java.io.ByteArrayOutputStream;
24+
import java.io.File;
25+
import java.io.FileWriter;
26+
import java.nio.charset.StandardCharsets;
27+
import java.util.*;
6828

6929
public class SVNVCS implements IVCS {
7030
private static final int SVN_PATH_IS_NOT_WORKING_COPY_ERROR_CODE = 155007;
@@ -150,10 +110,8 @@ public void createBranch(String srcBranchName, String dstBranchName, String comm
150110
}
151111

152112
public void createBranch(SVNURL fromUrl, SVNURL toUrl, String commitMessage) {
153-
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy()) {
154-
113+
try {
155114
getBranchUrl("test"); // for exceptions rethrowing test only
156-
157115
SVNCopyClient copyClient = clientManager.getCopyClient();
158116
SVNCopySource copySource = new SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, fromUrl);
159117
copySource.setCopyContents(false);
@@ -451,7 +409,7 @@ public List<VCSDiffEntry> getBranchesDiff(final String srcBranchName, final Stri
451409
@Override
452410
public Set<String> getBranches(String path) {
453411
try {
454-
List<String> entries = listEntries(SVNVCS.BRANCHES_PATH, path == null ? "" : path);
412+
List<String> entries = listEntries(SVNVCS.BRANCHES_PATH + (path == null ? "" : path));
455413
Set<String> tempRes = new HashSet<>(entries);
456414
if (repository.checkPath(MASTER_PATH, -1) == SVNNodeKind.DIR) {
457415
if (path == null || MASTER_PATH.startsWith(path) ) {
@@ -470,15 +428,15 @@ public Set<String> getBranches(String path) {
470428
}
471429
}
472430

473-
protected List<String> listEntries(String path, String subdirStartsWith) throws Exception {
431+
protected List<String> listEntries(String path) throws Exception {
474432
List<String> res = new ArrayList<>();
475-
if (repository.checkPath(path , -1) == SVNNodeKind.NONE) {
433+
if (repository.checkPath(path , -1) == SVNNodeKind.NONE) {
476434
return res;
477435
}
478436
@SuppressWarnings("unchecked")
479-
Collection<SVNDirEntry> subEntries = repository.getDir(path, -1, null, (Collection<SVNDirEntry>) null);
480-
List<SVNDirEntry> list = new ArrayList<>(subEntries);
481-
Collections.sort(list, new Comparator<SVNDirEntry>() {
437+
Collection<SVNDirEntry> entries = repository.getDir(path, -1 , null , (Collection<SVNDirEntry>) null);
438+
List<SVNDirEntry> entriesList = new ArrayList<>(entries);
439+
Collections.sort(entriesList, new Comparator<SVNDirEntry>() {
482440
@Override
483441
public int compare(SVNDirEntry o1, SVNDirEntry o2) {
484442
if (o1.getRevision() < o2.getRevision()) {
@@ -490,11 +448,13 @@ public int compare(SVNDirEntry o1, SVNDirEntry o2) {
490448
return 0;
491449
}
492450
});
493-
for (SVNDirEntry entry : list) {
494-
if (entry.getKind() == SVNNodeKind.DIR && entry.getName().startsWith(subdirStartsWith)) {
495-
res.add(path + entry.getName());
451+
for (SVNDirEntry entry : entriesList) {
452+
if (entry.getKind() == SVNNodeKind.DIR) {
453+
res.add((path.isEmpty() ? "" : StringUtils.appendIfMissing(path, "/")) + entry.getName());
454+
res.addAll(listEntries((path.equals("")) ? entry.getName() : path + entry.getName()));
496455
}
497456
}
457+
498458
return res;
499459
}
500460

@@ -638,8 +598,8 @@ public Boolean fileExists(String branchName, String filePath) {
638598

639599
@Override
640600
public VCSTag createTag(String branchName, String tagName, String tagMessage, String revisionToTag) throws EVCSTagExists {
641-
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy()) {
642-
SVNURL srcURL = getBranchUrl(branchName);
601+
try {
602+
SVNURL srcURL = getBranchUrl(branchName);
643603
SVNURL dstURL = SVNURL.parseURIEncoded(repoUrl + TAGS_PATH + tagName);
644604
SVNLogEntry copyFromEntry = revToSVNEntry(getBranchName(branchName),
645605
revisionToTag == null ? SVNRevision.HEAD.getNumber() : Long.parseLong(revisionToTag));
@@ -693,7 +653,7 @@ public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
693653
@Override
694654
public List<VCSTag> getTags() {
695655
try {
696-
List<String> entries = listEntries(TAGS_PATH, "");
656+
List<String> entries = listEntries(TAGS_PATH);
697657

698658
List<VCSTag> res = new ArrayList<>();
699659
SVNTagBaseCommit handler;
@@ -748,8 +708,19 @@ public void checkout(String branchName, String targetPath, String revision) {
748708
@Override
749709
public List<VCSTag> getTagsOnRevision(String revision) {
750710
try {
751-
List<String> tagEntries = listEntries(TAGS_PATH, "");
752711
List<VCSTag> res = new ArrayList<>();
712+
if (repository.checkPath(TAGS_PATH , -1) == SVNNodeKind.NONE) {
713+
return res;
714+
}
715+
List<String> tagEntries = new ArrayList<>();
716+
@SuppressWarnings("unchecked")
717+
Collection<SVNDirEntry> entries = repository.getDir(TAGS_PATH, -1 , null , (Collection<SVNDirEntry>) null);
718+
for (SVNDirEntry entry : entries) {
719+
if (entry.getKind() == SVNNodeKind.DIR) {
720+
tagEntries.add(TAGS_PATH + entry.getName());
721+
}
722+
}
723+
753724
SVNTagBaseCommit handler;
754725
for (String tagEntryStr : tagEntries) {
755726

src/test/java/org/scm4j/vcs/svn/SVNVCSTest.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private void testExceptionThrowing(Exception testException, Method m, Object[] p
175175
reset(svn);
176176
doThrow(testException).when(svn).checkout(any(SVNURL.class), any(File.class), (String) isNull());
177177
doThrow(testException).when(svn).getBranchUrl(null);
178-
doThrow(testException).when(svn).listEntries(anyString(), anyString());
178+
doThrow(testException).when(svn).listEntries(anyString());
179179
doThrow(testException).when(svn).getBranchFirstCommit(null);
180180
doThrow(testException).when(svn).revToSVNEntry(anyString(), any(Long.class));
181181
try {
@@ -207,7 +207,7 @@ private boolean wasMockedMethodInvoked() throws Exception {
207207
} catch (WantedButNotInvoked e1) {
208208
}
209209
try {
210-
verify(svn).listEntries(anyString(), anyString());
210+
verify(svn).listEntries(anyString());
211211
return true;
212212
} catch (WantedButNotInvoked e1) {
213213
}
@@ -401,12 +401,12 @@ public void testListEntriesSorting() throws Exception {
401401
doReturn(Arrays.asList(entry1, entry2)).when(mockedRepo).getDir(anyString(), anyLong(), any(SVNProperties.class),
402402
Matchers.<Collection<SVNDirEntry>>any());
403403

404-
List<String> entries = svn.listEntries("", "");
404+
List<String> entries = svn.listEntries("");
405405
assertEquals(entries.get(0), entry1.getName());
406406
assertEquals(entries.get(1), entry2.getName());
407407
doReturn(Arrays.asList(entry1, entry1)).when(mockedRepo).getDir(anyString(), anyLong(), any(SVNProperties.class),
408408
Matchers.<Collection<SVNDirEntry>>any());
409-
entries = svn.listEntries("", "");
409+
entries = svn.listEntries("");
410410
assertEquals(entries.get(0), entry1.getName());
411411
assertEquals(entries.get(1), entry1.getName());
412412
}
@@ -436,6 +436,36 @@ public void testListEntriesNone() throws Exception {
436436
SVNRepository mockedRepo = spy(svn.getSVNRepository());
437437
svn.setSVNRepository(mockedRepo);
438438
doReturn(SVNNodeKind.NONE).when(mockedRepo).checkPath((String) isNull(), anyLong());
439-
svn.listEntries(null, null); // expecting no NPE
439+
svn.listEntries(null); // expecting no NPE
440+
}
441+
442+
@Test
443+
public void testGetTagsOnRevisionNoTagsDir() throws SVNException {
444+
svn.getClientManager()
445+
.getCommitClient()
446+
.doDelete(new SVNURL[] { SVNURL.parseURIEncoded(svn.getRepoUrl() + "/" + SVNVCS.TAGS_PATH)}, "tags/ deleted");
447+
assertTrue(vcs.getTagsOnRevision("0").isEmpty());
448+
}
449+
450+
@Test
451+
public void testGetTagsOnRevisionExceptions() throws Exception {
452+
SVNRepository mockedRepo = spy(svn.getSVNRepository());
453+
svn.setSVNRepository(mockedRepo);
454+
vcs.createTag(null, TAG_NAME_1, TAG_MESSAGE_1, null);
455+
doThrow(testCommonException).when(svn).revToSVNEntry(anyString(), anyLong());
456+
try {
457+
vcs.getTagsOnRevision("");
458+
fail();
459+
} catch (RuntimeException e) {
460+
checkCommonException(e);
461+
}
462+
463+
doThrow(testSVNException).when(mockedRepo).checkPath(anyString(), anyLong());
464+
try {
465+
vcs.getTagsOnRevision("");
466+
fail();
467+
} catch (EVCSException e) {
468+
checkEVCSException(e);
469+
}
440470
}
441471
}

0 commit comments

Comments
 (0)