3838import java .io .File ;
3939import java .io .FileOutputStream ;
4040import java .io .IOException ;
41+ import java .net .URI ;
4142import java .net .URL ;
4243import java .nio .charset .StandardCharsets ;
4344import java .nio .file .Files ;
@@ -91,6 +92,7 @@ class FileHistoryCacheTest {
9192 private boolean savedFetchHistoryWhenNotInCache ;
9293 private boolean savedIsHandleHistoryOfRenamedFiles ;
9394 private boolean savedIsTagsEnabled ;
95+ private boolean savedIsIndexer ;
9496
9597 @ BeforeAll
9698 static void setUpClass () throws Exception {
@@ -117,6 +119,9 @@ void setUp() throws Exception {
117119 savedFetchHistoryWhenNotInCache = env .isFetchHistoryWhenNotInCache ();
118120 savedIsHandleHistoryOfRenamedFiles = env .isHandleHistoryOfRenamedFiles ();
119121 savedIsTagsEnabled = env .isTagsEnabled ();
122+ savedIsIndexer = env .isIndexer ();
123+
124+ env .setIndexer (true );
120125 }
121126
122127 /**
@@ -134,6 +139,7 @@ void tearDown() {
134139 env .setIncludedNames (new Filter ());
135140 env .setHandleHistoryOfRenamedFiles (savedIsHandleHistoryOfRenamedFiles );
136141 env .setTagsEnabled (savedIsTagsEnabled );
142+ env .setIndexer (savedIsIndexer );
137143 }
138144
139145 /**
@@ -254,12 +260,13 @@ void testStoreAndGetIncrementalTags() throws Exception {
254260 File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
255261 assertTrue (reposRoot .exists ());
256262
263+ env .setTagsEnabled (true );
264+
265+ // It is necessary to call getRepository() only after tags were enabled
266+ // to produce list of tags.
257267 Repository repo = RepositoryFactory .getRepository (reposRoot );
258268 assertNotNull (repo );
259269
260- // Enable tagging of history entries.
261- repo .setTagsEnabled (true );
262-
263270 History historyToStore = repo .getHistory (reposRoot );
264271 assertNotNull (historyToStore );
265272
@@ -434,19 +441,22 @@ void testRenameFileThenDoIncrementalReindex() throws Exception {
434441 // The test expects support for renamed files.
435442 env .setHandleHistoryOfRenamedFiles (true );
436443
444+ // Use tags for better coverage.
445+ env .setTagsEnabled (true );
446+
447+ // It is necessary to call getRepository() only after tags were enabled
448+ // to produce list of tags.
437449 Repository repo = RepositoryFactory .getRepository (reposRoot );
438450 assertNotNull (repo );
439451
440- // Use tags for better coverage.
441- repo .setTagsEnabled (true );
442-
443452 // Generate history index.
444453 History historyToStore = repo .getHistory (reposRoot );
445454 cache .store (historyToStore , repo );
446455
447456 // Import changesets which rename one of the files in the repository.
448- MercurialRepositoryTest .runHgCommand (reposRoot , "import" ,
449- Paths .get (getClass ().getResource ("/history/hg-export-renamed.txt" ).toURI ()).toString ());
457+ URL url = getClass ().getResource ("/history/hg-export-renamed.txt" );
458+ assertNotNull (url );
459+ MercurialRepositoryTest .runHgCommand (reposRoot , "import" , Paths .get (url .toURI ()).toString ());
450460
451461 // Perform incremental reindex.
452462 repo .createCache (cache , cache .getLatestCachedRevision (repo ));
@@ -548,42 +558,46 @@ void testRenameFileThenDoIncrementalReindex() throws Exception {
548558 void testRenamedFilePlusChangesBranched () throws Exception {
549559 File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
550560 assertTrue (reposRoot .exists ());
551- History updatedHistory ;
552561
553562 // Branch the repo and add one changeset.
554- runHgCommand (reposRoot , "unbundle" ,
555- Paths .get (getClass ().getResource ("/history/hg-branch.bundle" ).toURI ()).toString ());
563+ URL url = getClass ().getResource ("/history/hg-branch.bundle" );
564+ assertNotNull (url );
565+ runHgCommand (reposRoot , "unbundle" , Paths .get (url .toURI ()).toString ());
556566
557567 // Import changesets which rename one of the files in the default branch.
558- runHgCommand (reposRoot , "import" ,
559- Paths .get (getClass ().getResource ("/history/hg-export-renamed.txt" ).toURI ()).toString ());
568+ url = getClass ().getResource ("/history/hg-export-renamed.txt" );
569+ assertNotNull (url );
570+ runHgCommand (reposRoot , "import" , Paths .get (url .toURI ()).toString ());
560571
561572 // Switch to the newly created branch.
562573 runHgCommand (reposRoot , "update" , "mybranch" );
563574
575+ // Use tags for better coverage.
576+ env .setTagsEnabled (true );
577+
578+ // It is necessary to call getRepository() only after tags were enabled
579+ // to produce list of tags.
564580 Repository repo = RepositoryFactory .getRepository (reposRoot );
565581 assertNotNull (repo );
566582
567583 // The test expects support for renamed files.
568584 repo .setHandleRenamedFiles (true );
569585
570- // Use tags for better coverage.
571- repo .setTagsEnabled (true );
572-
573586 // Generate history index.
574587 History historyToStore = repo .getHistory (reposRoot );
575588 cache .store (historyToStore , repo );
576589
577590 // Import changesets which rename the file in the new branch.
578- runHgCommand (reposRoot , "import" ,
579- Paths .get (getClass ().getResource ("/history/hg-export-renamed-branched.txt" ).toURI ()).toString ());
591+ url = getClass ().getResource ("/history/hg-export-renamed-branched.txt" );
592+ assertNotNull (url );
593+ runHgCommand (reposRoot , "import" , Paths .get (url .toURI ()).toString ());
580594
581595 // Perform incremental reindex.
582596 repo .createCache (cache , cache .getLatestCachedRevision (repo ));
583597
584598 // Check complete list of history entries for the renamed file.
585599 File testFile = new File (reposRoot .toString () + File .separatorChar + "blog.txt" );
586- updatedHistory = cache .get (testFile , repo , false );
600+ History updatedHistory = cache .get (testFile , repo , false );
587601
588602 HistoryEntry e0 = new HistoryEntry (
589603 "15:709c7a27f9fa" ,
@@ -978,7 +992,6 @@ void testNoHistoryFetch() throws Exception {
978992 env .setFetchHistoryWhenNotInCache (false );
979993
980994 // Pretend we are done with first phase of indexing.
981- env .setIndexer (true );
982995 HistoryGuru .getInstance ().setHistoryIndexDone ();
983996
984997 // First try repo with ability to fetch history for directories.
0 commit comments