39
39
import java .io .FileOutputStream ;
40
40
import java .io .IOException ;
41
41
import java .nio .charset .StandardCharsets ;
42
+ import java .nio .file .Files ;
43
+ import java .nio .file .Path ;
42
44
import java .nio .file .Paths ;
43
45
import java .util .Date ;
44
46
import java .util .Iterator ;
60
62
import org .opengrok .indexer .configuration .Filter ;
61
63
import org .opengrok .indexer .configuration .IgnoredNames ;
62
64
import org .opengrok .indexer .configuration .RuntimeEnvironment ;
65
+ import org .opengrok .indexer .util .IOUtils ;
63
66
import org .opengrok .indexer .util .TandemPath ;
64
67
import org .opengrok .indexer .util .TestRepository ;
65
68
68
71
*
69
72
* @author Vladimir Kotal
70
73
*/
71
- public class FileHistoryCacheTest {
74
+ class FileHistoryCacheTest {
72
75
73
76
private static final String SVN_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ;
74
77
@@ -159,7 +162,7 @@ private void assertSameEntry(HistoryEntry expected, HistoryEntry actual, boolean
159
162
*/
160
163
@ EnabledForRepository (MERCURIAL )
161
164
@ Test
162
- public void testStoreAndGetNotRenamed () throws Exception {
165
+ void testStoreAndGetNotRenamed () throws Exception {
163
166
File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
164
167
Repository repo = RepositoryFactory .getRepository (reposRoot );
165
168
History historyToStore = repo .getHistory (reposRoot );
@@ -185,7 +188,7 @@ public void testStoreAndGetNotRenamed() throws Exception {
185
188
*/
186
189
@ EnabledForRepository (MERCURIAL )
187
190
@ Test
188
- public void testStoreAndGetIncrementalTags () throws Exception {
191
+ void testStoreAndGetIncrementalTags () throws Exception {
189
192
// Enable tagging of history entries.
190
193
env .setTagsEnabled (true );
191
194
@@ -260,7 +263,7 @@ public void testStoreAndGetIncrementalTags() throws Exception {
260
263
@ Test
261
264
@ EnabledOnOs ({OS .LINUX , OS .MAC , OS .SOLARIS , OS .AIX , OS .OTHER })
262
265
@ EnabledForRepository (MERCURIAL )
263
- public void testStoreAndGet () throws Exception {
266
+ void testStoreAndGet () throws Exception {
264
267
File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
265
268
266
269
// The test expects support for renamed files.
@@ -382,7 +385,7 @@ public void testStoreAndGet() throws Exception {
382
385
@ EnabledOnOs ({OS .LINUX , OS .MAC , OS .SOLARIS , OS .AIX , OS .OTHER })
383
386
@ EnabledForRepository (MERCURIAL )
384
387
@ Test
385
- public void testRenameFileThenDoIncrementalReindex () throws Exception {
388
+ void testRenameFileThenDoIncrementalReindex () throws Exception {
386
389
File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
387
390
History updatedHistory ;
388
391
@@ -504,7 +507,7 @@ public void testRenameFileThenDoIncrementalReindex() throws Exception {
504
507
@ EnabledOnOs ({OS .LINUX , OS .MAC , OS .SOLARIS , OS .AIX , OS .OTHER })
505
508
@ EnabledForRepository (MERCURIAL )
506
509
@ Test
507
- public void testRenamedFilePlusChangesBranched () throws Exception {
510
+ void testRenamedFilePlusChangesBranched () throws Exception {
508
511
File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
509
512
History updatedHistory ;
510
513
@@ -620,7 +623,9 @@ public void testRenamedFilePlusChangesBranched() throws Exception {
620
623
*/
621
624
@ EnabledForRepository (SUBVERSION )
622
625
@ Test
623
- public void testMultipleRenamedFiles () throws Exception {
626
+ void testMultipleRenamedFiles () throws Exception {
627
+ createSvnRepository ();
628
+
624
629
File reposRoot = new File (repositories .getSourceRoot (), "subversion" );
625
630
History updatedHistory ;
626
631
@@ -669,6 +674,31 @@ public void testMultipleRenamedFiles() throws Exception {
669
674
assertSameEntries (histConstruct .getHistoryEntries (), updatedHistory .getHistoryEntries (), false );
670
675
}
671
676
677
+ private void createSvnRepository () throws Exception {
678
+ var svnLog = FileHistoryCacheTest .class .getResource ("/history/svnlog.dump" );
679
+ Path tempDir = Files .createTempDirectory ("opengrok" );
680
+ Runtime .getRuntime ().addShutdownHook (new Thread (() -> {
681
+ try {
682
+ IOUtils .removeRecursive (tempDir );
683
+ } catch (IOException e ) {
684
+ // ignore
685
+ }
686
+ }));
687
+ String repo = tempDir .resolve ("svn-repo" ).toString ();
688
+ var svnCreateRepoProcess = new ProcessBuilder ("svnadmin" , "create" , repo ).start ();
689
+ assertEquals (0 , svnCreateRepoProcess .waitFor ());
690
+
691
+ var svnLoadRepoFromDumpProcess = new ProcessBuilder ("svnadmin" , "load" , repo )
692
+ .redirectInput (Paths .get (svnLog .toURI ()).toFile ())
693
+ .start ();
694
+ assertEquals (0 , svnLoadRepoFromDumpProcess .waitFor ());
695
+
696
+ var svnCheckoutProcess = new ProcessBuilder ("svn" , "checkout" , Path .of (repo ).toUri ().toString (),
697
+ Path .of (repositories .getSourceRoot ()).resolve ("subversion" ).toString ())
698
+ .start ();
699
+ assertEquals (0 , svnCheckoutProcess .waitFor ());
700
+ }
701
+
672
702
private void changeFileAndCommit (Git git , File file , String comment ) throws Exception {
673
703
String authorName = "Foo Bar" ;
674
704
String authorEmail =
"[email protected] " ;
@@ -748,7 +778,9 @@ void testRenamedFileHistoryWithPerPartes(int maxCount) throws Exception {
748
778
*/
749
779
@ EnabledForRepository (SUBVERSION )
750
780
@ Test
751
- public void testRenamedFile () throws Exception {
781
+ void testRenamedFile () throws Exception {
782
+ createSvnRepository ();
783
+
752
784
File reposRoot = new File (repositories .getSourceRoot (), "subversion" );
753
785
History updatedHistory ;
754
786
@@ -835,7 +867,7 @@ private void checkNoHistoryFetchRepo(String reponame, String filename,
835
867
*/
836
868
@ EnabledForRepository ({MERCURIAL , SCCS })
837
869
@ Test
838
- public void testNoHistoryFetch () throws Exception {
870
+ void testNoHistoryFetch () throws Exception {
839
871
// Do not create history cache for files which do not have it cached.
840
872
env .setFetchHistoryWhenNotInCache (false );
841
873
@@ -860,7 +892,7 @@ public void testNoHistoryFetch() throws Exception {
860
892
@ EnabledOnOs ({OS .LINUX , OS .MAC , OS .SOLARIS , OS .AIX , OS .OTHER })
861
893
@ EnabledForRepository (MERCURIAL )
862
894
@ Test
863
- public void testStoreAndTryToGetIgnored () throws Exception {
895
+ void testStoreAndTryToGetIgnored () throws Exception {
864
896
env .getIgnoredNames ().add ("f:Make*" );
865
897
866
898
File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
0 commit comments