3939import java .io .FileOutputStream ;
4040import java .io .IOException ;
4141import java .nio .charset .StandardCharsets ;
42+ import java .nio .file .Files ;
43+ import java .nio .file .Path ;
4244import java .nio .file .Paths ;
4345import java .util .Date ;
4446import java .util .Iterator ;
6062import org .opengrok .indexer .configuration .Filter ;
6163import org .opengrok .indexer .configuration .IgnoredNames ;
6264import org .opengrok .indexer .configuration .RuntimeEnvironment ;
65+ import org .opengrok .indexer .util .IOUtils ;
6366import org .opengrok .indexer .util .TandemPath ;
6467import org .opengrok .indexer .util .TestRepository ;
6568
6871 *
6972 * @author Vladimir Kotal
7073 */
71- public class FileHistoryCacheTest {
74+ class FileHistoryCacheTest {
7275
7376 private static final String SVN_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ;
7477
@@ -159,7 +162,7 @@ private void assertSameEntry(HistoryEntry expected, HistoryEntry actual, boolean
159162 */
160163 @ EnabledForRepository (MERCURIAL )
161164 @ Test
162- public void testStoreAndGetNotRenamed () throws Exception {
165+ void testStoreAndGetNotRenamed () throws Exception {
163166 File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
164167 Repository repo = RepositoryFactory .getRepository (reposRoot );
165168 History historyToStore = repo .getHistory (reposRoot );
@@ -185,7 +188,7 @@ public void testStoreAndGetNotRenamed() throws Exception {
185188 */
186189 @ EnabledForRepository (MERCURIAL )
187190 @ Test
188- public void testStoreAndGetIncrementalTags () throws Exception {
191+ void testStoreAndGetIncrementalTags () throws Exception {
189192 // Enable tagging of history entries.
190193 env .setTagsEnabled (true );
191194
@@ -260,7 +263,7 @@ public void testStoreAndGetIncrementalTags() throws Exception {
260263 @ Test
261264 @ EnabledOnOs ({OS .LINUX , OS .MAC , OS .SOLARIS , OS .AIX , OS .OTHER })
262265 @ EnabledForRepository (MERCURIAL )
263- public void testStoreAndGet () throws Exception {
266+ void testStoreAndGet () throws Exception {
264267 File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
265268
266269 // The test expects support for renamed files.
@@ -382,7 +385,7 @@ public void testStoreAndGet() throws Exception {
382385 @ EnabledOnOs ({OS .LINUX , OS .MAC , OS .SOLARIS , OS .AIX , OS .OTHER })
383386 @ EnabledForRepository (MERCURIAL )
384387 @ Test
385- public void testRenameFileThenDoIncrementalReindex () throws Exception {
388+ void testRenameFileThenDoIncrementalReindex () throws Exception {
386389 File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
387390 History updatedHistory ;
388391
@@ -504,7 +507,7 @@ public void testRenameFileThenDoIncrementalReindex() throws Exception {
504507 @ EnabledOnOs ({OS .LINUX , OS .MAC , OS .SOLARIS , OS .AIX , OS .OTHER })
505508 @ EnabledForRepository (MERCURIAL )
506509 @ Test
507- public void testRenamedFilePlusChangesBranched () throws Exception {
510+ void testRenamedFilePlusChangesBranched () throws Exception {
508511 File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
509512 History updatedHistory ;
510513
@@ -620,7 +623,9 @@ public void testRenamedFilePlusChangesBranched() throws Exception {
620623 */
621624 @ EnabledForRepository (SUBVERSION )
622625 @ Test
623- public void testMultipleRenamedFiles () throws Exception {
626+ void testMultipleRenamedFiles () throws Exception {
627+ createSvnRepository ();
628+
624629 File reposRoot = new File (repositories .getSourceRoot (), "subversion" );
625630 History updatedHistory ;
626631
@@ -669,6 +674,31 @@ public void testMultipleRenamedFiles() throws Exception {
669674 assertSameEntries (histConstruct .getHistoryEntries (), updatedHistory .getHistoryEntries (), false );
670675 }
671676
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+
672702 private void changeFileAndCommit (Git git , File file , String comment ) throws Exception {
673703 String authorName = "Foo Bar" ;
674704 String authorEmail = "foo@bar.com" ;
@@ -748,7 +778,9 @@ void testRenamedFileHistoryWithPerPartes(int maxCount) throws Exception {
748778 */
749779 @ EnabledForRepository (SUBVERSION )
750780 @ Test
751- public void testRenamedFile () throws Exception {
781+ void testRenamedFile () throws Exception {
782+ createSvnRepository ();
783+
752784 File reposRoot = new File (repositories .getSourceRoot (), "subversion" );
753785 History updatedHistory ;
754786
@@ -835,7 +867,7 @@ private void checkNoHistoryFetchRepo(String reponame, String filename,
835867 */
836868 @ EnabledForRepository ({MERCURIAL , SCCS })
837869 @ Test
838- public void testNoHistoryFetch () throws Exception {
870+ void testNoHistoryFetch () throws Exception {
839871 // Do not create history cache for files which do not have it cached.
840872 env .setFetchHistoryWhenNotInCache (false );
841873
@@ -860,7 +892,7 @@ public void testNoHistoryFetch() throws Exception {
860892 @ EnabledOnOs ({OS .LINUX , OS .MAC , OS .SOLARIS , OS .AIX , OS .OTHER })
861893 @ EnabledForRepository (MERCURIAL )
862894 @ Test
863- public void testStoreAndTryToGetIgnored () throws Exception {
895+ void testStoreAndTryToGetIgnored () throws Exception {
864896 env .getIgnoredNames ().add ("f:Make*" );
865897
866898 File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
0 commit comments