87
87
import org .opengrok .indexer .analysis .Definitions ;
88
88
import org .opengrok .indexer .analysis .FileAnalyzer ;
89
89
import org .opengrok .indexer .analysis .FileAnalyzer .Genre ;
90
+ import org .opengrok .indexer .analysis .FileAnalyzerFactory ;
90
91
import org .opengrok .indexer .configuration .Project ;
91
92
import org .opengrok .indexer .configuration .RuntimeEnvironment ;
92
93
import org .opengrok .indexer .history .HistoryException ;
@@ -313,9 +314,7 @@ private void initialize() throws IOException {
313
314
ignoredNames = env .getIgnoredNames ();
314
315
includedNames = env .getIncludedNames ();
315
316
analyzerGuru = new AnalyzerGuru ();
316
- if (env .isGenerateHtml ()) {
317
- xrefDir = new File (env .getDataRootFile (), XREF_DIR );
318
- }
317
+ xrefDir = new File (env .getDataRootFile (), XREF_DIR );
319
318
listeners = new CopyOnWriteArrayList <>();
320
319
dirtyFile = new File (indexDir , "dirty" );
321
320
dirty = dirtyFile .exists ();
@@ -677,17 +676,17 @@ private void setDirty() {
677
676
}
678
677
}
679
678
679
+ private File whatXrefFile (String path , boolean compress ) {
680
+ return new File (xrefDir , path + (compress ? ".gz" : "" ));
681
+ }
682
+
680
683
/**
681
684
* Queue the removal of xref file for given path
682
685
* @param path path to file under source root
683
686
*/
684
687
private void removeXrefFile (String path ) {
685
- File xrefFile ;
686
- if (RuntimeEnvironment .getInstance ().isCompressXref ()) {
687
- xrefFile = new File (xrefDir , path + ".gz" );
688
- } else {
689
- xrefFile = new File (xrefDir , path );
690
- }
688
+ RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
689
+ File xrefFile = whatXrefFile (path , env .isCompressXref ());
691
690
PendingFileDeletion pending = new PendingFileDeletion (
692
691
xrefFile .getAbsolutePath ());
693
692
completer .add (pending );
@@ -750,7 +749,7 @@ private void addFile(File file, String path, Ctags ctags)
750
749
fa .setFoldingEnabled (RuntimeEnvironment .getInstance ().isFoldingEnabled ());
751
750
752
751
Document doc = new Document ();
753
- try (Writer xrefOut = getXrefWriter (fa , path )) {
752
+ try (Writer xrefOut = newXrefWriter (fa , path )) {
754
753
analyzerGuru .populateDocument (doc , file , path , fa , xrefOut );
755
754
} catch (InterruptedException e ) {
756
755
LOGGER .log (Level .WARNING , "File ''{0}'' interrupted--{1}" ,
@@ -1076,6 +1075,8 @@ private void indexDown(File dir, String parent, IndexDownArgs args)
1076
1075
}
1077
1076
Arrays .sort (files , FILENAME_COMPARATOR );
1078
1077
1078
+ final boolean [] outIsXrefWriter = new boolean [1 ];
1079
+
1079
1080
for (File file : files ) {
1080
1081
String path = parent + File .separator + file .getName ();
1081
1082
if (!accept (dir , file , outLocalRelPath )) {
@@ -1127,7 +1128,9 @@ private void indexDown(File dir, String parent, IndexDownArgs args)
1127
1128
*/
1128
1129
if (uidIter != null && uidIter .term () != null
1129
1130
&& uidIter .term ().bytesEquals (buid )) {
1130
- boolean chkres = chkSettings (file , path );
1131
+ boolean chkres = chkSettings (outIsXrefWriter , file ,
1132
+ path ) && (!outIsXrefWriter [0 ] ||
1133
+ checkXrefExistence (path ));
1131
1134
if (!chkres ) {
1132
1135
removeFile (false );
1133
1136
}
@@ -1579,16 +1582,21 @@ public int hashCode() {
1579
1582
return hash ;
1580
1583
}
1581
1584
1585
+ private boolean isXrefWriter (FileAnalyzer fa ) {
1586
+ Genre g = fa .getFactory ().getGenre ();
1587
+ return (g == Genre .PLAIN || g == Genre .XREFABLE );
1588
+ }
1589
+
1582
1590
/**
1583
1591
* Get a writer to which the xref can be written, or null if no xref
1584
1592
* should be produced for files of this type.
1585
1593
*/
1586
- private Writer getXrefWriter (FileAnalyzer fa , String path ) throws IOException {
1587
- Genre g = fa . getFactory (). getGenre ();
1588
- if ( xrefDir != null && ( g == Genre . PLAIN || g == Genre . XREFABLE )) {
1589
- RuntimeEnvironment env = RuntimeEnvironment . getInstance ();
1594
+ private Writer newXrefWriter (FileAnalyzer fa , String path )
1595
+ throws IOException {
1596
+ RuntimeEnvironment env = RuntimeEnvironment . getInstance ();
1597
+ if ( env . isGenerateHtml () && isXrefWriter ( fa )) {
1590
1598
boolean compressed = env .isCompressXref ();
1591
- File xrefFile = new File ( xrefDir , path + ( compressed ? ".gz" : "" ) );
1599
+ File xrefFile = whatXrefFile ( path , compressed );
1592
1600
File parentFile = xrefFile .getParentFile ();
1593
1601
1594
1602
// If mkdirs() returns false, the failure is most likely
@@ -1662,7 +1670,9 @@ private void finishWriting() throws IOException {
1662
1670
* @param path the source file path
1663
1671
* @return {@code false} if a mismatch is detected
1664
1672
*/
1665
- private boolean chkSettings (File file , String path ) throws IOException {
1673
+ private boolean chkSettings (boolean [] outIsXrefWriter , File file ,
1674
+ String path ) throws IOException {
1675
+
1666
1676
int reqTabSize = project != null && project .hasTabSizeSetting () ?
1667
1677
project .getTabSize () : 0 ;
1668
1678
Integer actTabSize = settings .getTabSize ();
@@ -1693,6 +1703,7 @@ private boolean chkSettings(File file, String path) throws IOException {
1693
1703
break ;
1694
1704
}
1695
1705
1706
+ FileAnalyzer fa = null ;
1696
1707
String fileTypeName ;
1697
1708
if (actGuruVersion .equals (reqGuruVersion )) {
1698
1709
fileTypeName = doc .get (QueryBuilder .TYPE );
@@ -1701,6 +1712,12 @@ private boolean chkSettings(File file, String path) throws IOException {
1701
1712
LOGGER .log (Level .FINEST , "Missing TYPE field: {0}" , path );
1702
1713
break ;
1703
1714
}
1715
+
1716
+ FileAnalyzerFactory fac =
1717
+ AnalyzerGuru .findByFileTypeName (fileTypeName );
1718
+ if (fac != null ) {
1719
+ fa = fac .getAnalyzer ();
1720
+ }
1704
1721
} else {
1705
1722
/**
1706
1723
* If the stored guru version does not match, re-verify the
@@ -1709,7 +1726,7 @@ private boolean chkSettings(File file, String path) throws IOException {
1709
1726
*/
1710
1727
LOGGER .log (Level .FINER , "Guru version mismatch: {0}" , path );
1711
1728
1712
- FileAnalyzer fa = getAnalyzerFor (file , path );
1729
+ fa = getAnalyzerFor (file , path );
1713
1730
fileTypeName = fa .getFileTypeName ();
1714
1731
String oldTypeName = doc .get (QueryBuilder .TYPE );
1715
1732
if (!fileTypeName .equals (oldTypeName )) {
@@ -1732,6 +1749,10 @@ private boolean chkSettings(File file, String path) throws IOException {
1732
1749
return false ;
1733
1750
}
1734
1751
1752
+ if (fa != null ) {
1753
+ outIsXrefWriter [0 ] = isXrefWriter (fa );
1754
+ }
1755
+
1735
1756
// The versions checks have passed.
1736
1757
break ;
1737
1758
}
@@ -1761,6 +1782,24 @@ private IndexAnalysisSettings2 readAnalysisSettings() throws IOException {
1761
1782
return dao .read (reader );
1762
1783
}
1763
1784
1785
+ private boolean checkXrefExistence (String path ) {
1786
+ RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
1787
+ boolean chkres = whatXrefFile (path , env .isCompressXref ()).exists ();
1788
+
1789
+ if (!env .isGenerateHtml ()) {
1790
+ if (chkres ) {
1791
+ LOGGER .log (Level .FINEST , "Extraneous {0}" , path );
1792
+ removeXrefFile (path );
1793
+ }
1794
+ return true ;
1795
+ }
1796
+
1797
+ if (!chkres ) {
1798
+ LOGGER .log (Level .FINEST , "Missing {0}" , path );
1799
+ }
1800
+ return chkres ;
1801
+ }
1802
+
1764
1803
private class IndexDownArgs {
1765
1804
boolean count_only ;
1766
1805
int cur_count ;
0 commit comments