Package org.sonar.api.batch.fs.internal
Class DefaultInputFile
- java.lang.Object
-
- org.sonar.api.batch.fs.internal.DefaultInputComponent
-
- org.sonar.api.batch.fs.internal.DefaultInputFile
-
- All Implemented Interfaces:
IndexedFile,InputComponent,InputFile,InputPath
public class DefaultInputFile extends DefaultInputComponent implements InputFile
- Since:
- 4.2
To create
InputFilein tests, useTestInputFileBuilder.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.sonar.api.batch.fs.InputFile
InputFile.Status, InputFile.Type
-
-
Constructor Summary
Constructors Constructor Description DefaultInputFile(DefaultIndexedFile indexedFile, java.util.function.Consumer<DefaultInputFile> metadataGenerator)DefaultInputFile(DefaultIndexedFile indexedFile, java.util.function.Consumer<DefaultInputFile> metadataGenerator, java.lang.String contents)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.StringabsolutePath()Normalized absolute path.voidaddIgnoreIssuesOnLineRanges(java.util.Collection<int[]> lineRanges)java.nio.charset.Charsetcharset()Charset to be used to decode this specific file.voidcheckMetadata()java.lang.Stringcontents()Fetches the entire contents of the file, decoding with theInputFile.charset().booleanequals(java.lang.Object obj)java.io.Filefile()The underlying absoluteFile.java.lang.Stringfilename()Filename for this file (inclusing extension).java.util.Optional<java.util.Set<java.lang.Integer>>getExecutableLines()java.lang.StringgetModuleRelativePath()java.lang.StringgetProjectRelativePath()java.lang.Stringhash()Digest hash of the file.inthashCode()booleanhasNoSonarAt(int line)java.io.InputStreaminputStream()Creates a stream of the file's contents.booleanisEmpty()Check if the file content is empty (ignore potential BOM).booleanisExcludedForCoverage()booleanisExcludedForDuplication()booleanisFile()Is the component anInputFilebooleanisIgnoreAllIssues()booleanisIgnoreAllIssuesOnLine(java.lang.Integer line)booleanisPublished()java.lang.Stringkey()Component key (without branch).java.lang.Stringlanguage()Language, for example "java" or "php".intlastValidOffset()intlines()Number of physical lines.TextPointernewPointer(int globalOffset)TextPointernewPointer(int line, int lineOffset)Returns aTextPointerin the given file.TextRangenewRange(int startOffset, int endOffset)Create Range from global offsets.TextRangenewRange(int startLine, int startLineOffset, int endLine, int endLineOffset)Returns aTextRangein the given file.TextRangenewRange(TextPointer start, TextPointer end)Returns aTextRangein the given file.intnonBlankLines()voidnoSonarAt(java.util.Set<java.lang.Integer> noSonarLines)int[]originalLineEndOffsets()int[]originalLineStartOffsets()java.nio.file.Pathpath()The underlying absolutePath.java.lang.StringrelativePath()Deprecated.since 6.6TextRangeselectLine(int line)Returns aTextRangein the given file that select the full line.DefaultInputFilesetCharset(java.nio.charset.Charset charset)DefaultInputFilesetExcludedForCoverage(boolean excludedForCoverage)DefaultInputFilesetExcludedForDuplication(boolean excludedForDuplication)voidsetExecutableLines(java.util.Set<java.lang.Integer> executableLines)voidsetIgnoreAllIssues(boolean ignoreAllIssues)DefaultInputFilesetMetadata(Metadata metadata)DefaultInputFilesetPublished(boolean published)DefaultInputFilesetStatus(InputFile.Status status)InputFile.Statusstatus()java.lang.StringtoString()Return a string to identify this file (suitable for logs).InputFile.Typetype()Does it contain main or test code ?java.net.URIuri()Identifier of the file.voidvalidate(TextRange range)-
Methods inherited from class org.sonar.api.batch.fs.internal.DefaultInputComponent
hasMeasureFor, scannerId, setHasMeasureFor
-
-
-
-
Constructor Detail
-
DefaultInputFile
public DefaultInputFile(DefaultIndexedFile indexedFile, java.util.function.Consumer<DefaultInputFile> metadataGenerator)
-
DefaultInputFile
public DefaultInputFile(DefaultIndexedFile indexedFile, java.util.function.Consumer<DefaultInputFile> metadataGenerator, @Nullable java.lang.String contents)
-
-
Method Detail
-
checkMetadata
public void checkMetadata()
-
inputStream
public java.io.InputStream inputStream() throws java.io.IOExceptionDescription copied from interface:InputFileCreates a stream of the file's contents. Depending on the runtime context, the source might be a file in a physical or virtual filesystem. Typically, it won't be buffered. The stream must be closed by the caller. Since 6.4 BOM is automatically filtered out.- Specified by:
inputStreamin interfaceIndexedFile- Specified by:
inputStreamin interfaceInputFile- Throws:
java.io.IOException
-
contents
public java.lang.String contents() throws java.io.IOExceptionDescription copied from interface:InputFileFetches the entire contents of the file, decoding with theInputFile.charset(). Since 6.4 BOM is automatically filtered out.
-
setPublished
public DefaultInputFile setPublished(boolean published)
-
isPublished
public boolean isPublished()
-
setExcludedForCoverage
public DefaultInputFile setExcludedForCoverage(boolean excludedForCoverage)
-
isExcludedForCoverage
public boolean isExcludedForCoverage()
-
setExcludedForDuplication
public DefaultInputFile setExcludedForDuplication(boolean excludedForDuplication)
-
isExcludedForDuplication
public boolean isExcludedForDuplication()
-
relativePath
@Deprecated public java.lang.String relativePath()
Deprecated.since 6.6Description copied from interface:InputFileRelative path to module (for normal Sensors) or project (forglobalSensors) base directory. File separator is the forward slash ('/'), even on Microsoft Windows.
Returnssrc/main/java/com/Foo.javaif module base dir is/path/to/moduleand if file is/path/to/module/src/main/java/com/Foo.java.
Relative path is not null and is normalized ('foo/../foo' is replaced by 'foo').- Specified by:
relativePathin interfaceIndexedFile- Specified by:
relativePathin interfaceInputFile- Specified by:
relativePathin interfaceInputPath- See Also:
InputFile.relativePath(),InputDir.relativePath()
-
getModuleRelativePath
public java.lang.String getModuleRelativePath()
-
getProjectRelativePath
public java.lang.String getProjectRelativePath()
-
absolutePath
public java.lang.String absolutePath()
Description copied from interface:InputFileNormalized absolute path. File separator is forward slash ('/'), even on Microsoft Windows.
This is not canonical path. Symbolic links are not resolved. For example if /project/src links to /tmp/src and basedir is /project, then this method returns /project/src/index.php. Usefile().getCanonicalPath()to resolve symbolic link.- Specified by:
absolutePathin interfaceIndexedFile- Specified by:
absolutePathin interfaceInputFile- Specified by:
absolutePathin interfaceInputPath- See Also:
InputFile.absolutePath(),InputDir.absolutePath()
-
file
public java.io.File file()
Description copied from interface:InputFileThe underlying absoluteFile. It should not be used to read the file in the filesystem.- Specified by:
filein interfaceIndexedFile- Specified by:
filein interfaceInputFile- Specified by:
filein interfaceInputPath- See Also:
InputFile.contents(),InputFile.inputStream()
-
path
public java.nio.file.Path path()
Description copied from interface:InputFileThe underlying absolutePath. It should not be used to read the file in the filesystem.- Specified by:
pathin interfaceIndexedFile- Specified by:
pathin interfaceInputFile- Specified by:
pathin interfaceInputPath- See Also:
InputFile.contents(),InputFile.inputStream()
-
language
@CheckForNull public java.lang.String language()
Description copied from interface:InputFileLanguage, for example "java" or "php". Can be null if indexation of all files is enabled and no language claims to support the file.- Specified by:
languagein interfaceIndexedFile- Specified by:
languagein interfaceInputFile
-
type
public InputFile.Type type()
Description copied from interface:InputFileDoes it contain main or test code ?- Specified by:
typein interfaceIndexedFile- Specified by:
typein interfaceInputFile
-
key
public java.lang.String key()
Component key (without branch).- Specified by:
keyin interfaceInputComponent
-
hashCode
public int hashCode()
- Overrides:
hashCodein classDefaultInputComponent
-
toString
public java.lang.String toString()
Description copied from interface:InputFileReturn a string to identify this file (suitable for logs).- Specified by:
toStringin interfaceInputFile- Overrides:
toStringin classDefaultInputComponent
-
status
public InputFile.Status status()
-
lines
public int lines()
Description copied from interface:InputFileNumber of physical lines. This method supports all end-of-line characters. Formula is (number of line break + 1).Returns 1 if the file is empty.
Returns 2 for foo\nbar.
Returns 3 for foo\nbar\n.
-
isEmpty
public boolean isEmpty()
Description copied from interface:InputFileCheck if the file content is empty (ignore potential BOM).
-
charset
public java.nio.charset.Charset charset()
Description copied from interface:InputFileCharset to be used to decode this specific file.
-
lastValidOffset
public int lastValidOffset()
-
hash
public java.lang.String hash()
Digest hash of the file.
-
nonBlankLines
public int nonBlankLines()
-
originalLineStartOffsets
public int[] originalLineStartOffsets()
-
originalLineEndOffsets
public int[] originalLineEndOffsets()
-
newPointer
public TextPointer newPointer(int line, int lineOffset)
Description copied from interface:InputFileReturns aTextPointerin the given file.- Specified by:
newPointerin interfaceInputFile- Parameters:
line- Line of the pointer. Start at 1.lineOffset- Offset in the line. Start at 0.
-
newRange
public TextRange newRange(TextPointer start, TextPointer end)
Description copied from interface:InputFileReturns aTextRangein the given file.
-
newRange
public TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset)
Description copied from interface:InputFileReturns aTextRangein the given file.newRange(1, 0, 1, 1)selects the first character at line 1newRange(1, 0, 1, 10)selects the 10 first characters at line 1
-
selectLine
public TextRange selectLine(int line)
Description copied from interface:InputFileReturns aTextRangein the given file that select the full line.- Specified by:
selectLinein interfaceInputFile- Parameters:
line- Start at 1.
-
validate
public void validate(TextRange range)
-
newRange
public TextRange newRange(int startOffset, int endOffset)
Create Range from global offsets. Used for backward compatibility with older API.
-
newPointer
public TextPointer newPointer(int globalOffset)
-
setStatus
public DefaultInputFile setStatus(InputFile.Status status)
-
setCharset
public DefaultInputFile setCharset(java.nio.charset.Charset charset)
-
setMetadata
public DefaultInputFile setMetadata(Metadata metadata)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classDefaultInputComponent
-
isFile
public boolean isFile()
Description copied from interface:InputComponentIs the component anInputFile- Specified by:
isFilein interfaceInputComponent
-
filename
public java.lang.String filename()
Description copied from interface:IndexedFileFilename for this file (inclusing extension). For example: MyClass.java.- Specified by:
filenamein interfaceIndexedFile
-
uri
public java.net.URI uri()
Description copied from interface:IndexedFileIdentifier of the file. The only guarantee is that it is unique in the project. You should not assume it is a file:// URI.- Specified by:
uriin interfaceIndexedFile- Specified by:
uriin interfaceInputPath
-
noSonarAt
public void noSonarAt(java.util.Set<java.lang.Integer> noSonarLines)
-
hasNoSonarAt
public boolean hasNoSonarAt(int line)
-
isIgnoreAllIssues
public boolean isIgnoreAllIssues()
-
setIgnoreAllIssues
public void setIgnoreAllIssues(boolean ignoreAllIssues)
-
addIgnoreIssuesOnLineRanges
public void addIgnoreIssuesOnLineRanges(java.util.Collection<int[]> lineRanges)
-
isIgnoreAllIssuesOnLine
public boolean isIgnoreAllIssuesOnLine(@Nullable java.lang.Integer line)
-
setExecutableLines
public void setExecutableLines(java.util.Set<java.lang.Integer> executableLines)
-
getExecutableLines
public java.util.Optional<java.util.Set<java.lang.Integer>> getExecutableLines()
-
-