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
InputFile
in 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.String
absolutePath()
Normalized absolute path.void
addIgnoreIssuesOnLineRanges(java.util.Collection<int[]> lineRanges)
java.nio.charset.Charset
charset()
Charset to be used to decode this specific file.void
checkMetadata()
java.lang.String
contents()
Fetches the entire contents of the file, decoding with theInputFile.charset()
.boolean
equals(java.lang.Object obj)
java.io.File
file()
The underlying absoluteFile
.java.lang.String
filename()
Filename for this file (inclusing extension).java.util.Optional<java.util.Set<java.lang.Integer>>
getExecutableLines()
java.lang.String
getModuleRelativePath()
java.lang.String
getProjectRelativePath()
java.lang.String
hash()
Digest hash of the file.int
hashCode()
boolean
hasNoSonarAt(int line)
java.io.InputStream
inputStream()
Creates a stream of the file's contents.boolean
isEmpty()
Check if the file content is empty (ignore potential BOM).boolean
isExcludedForCoverage()
boolean
isExcludedForDuplication()
boolean
isFile()
Is the component anInputFile
boolean
isIgnoreAllIssues()
boolean
isIgnoreAllIssuesOnLine(java.lang.Integer line)
boolean
isPublished()
java.lang.String
key()
Component key (without branch).java.lang.String
language()
Language, for example "java" or "php".int
lastValidOffset()
int
lines()
Number of physical lines.TextPointer
newPointer(int globalOffset)
TextPointer
newPointer(int line, int lineOffset)
Returns aTextPointer
in the given file.TextRange
newRange(int startOffset, int endOffset)
Create Range from global offsets.TextRange
newRange(int startLine, int startLineOffset, int endLine, int endLineOffset)
Returns aTextRange
in the given file.TextRange
newRange(TextPointer start, TextPointer end)
Returns aTextRange
in the given file.int
nonBlankLines()
void
noSonarAt(java.util.Set<java.lang.Integer> noSonarLines)
int[]
originalLineEndOffsets()
int[]
originalLineStartOffsets()
java.nio.file.Path
path()
The underlying absolutePath
.java.lang.String
relativePath()
Deprecated.since 6.6TextRange
selectLine(int line)
Returns aTextRange
in the given file that select the full line.DefaultInputFile
setCharset(java.nio.charset.Charset charset)
DefaultInputFile
setExcludedForCoverage(boolean excludedForCoverage)
DefaultInputFile
setExcludedForDuplication(boolean excludedForDuplication)
void
setExecutableLines(java.util.Set<java.lang.Integer> executableLines)
void
setIgnoreAllIssues(boolean ignoreAllIssues)
DefaultInputFile
setMetadata(Metadata metadata)
DefaultInputFile
setPublished(boolean published)
DefaultInputFile
setStatus(InputFile.Status status)
InputFile.Status
status()
java.lang.String
toString()
Return a string to identify this file (suitable for logs).InputFile.Type
type()
Does it contain main or test code ?java.net.URI
uri()
Identifier of the file.void
validate(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.IOException
Description copied from interface:InputFile
Creates 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:
inputStream
in interfaceIndexedFile
- Specified by:
inputStream
in interfaceInputFile
- Throws:
java.io.IOException
-
contents
public java.lang.String contents() throws java.io.IOException
Description copied from interface:InputFile
Fetches 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:InputFile
Relative path to module (for normal Sensors) or project (forglobal
Sensors) base directory. File separator is the forward slash ('/'), even on Microsoft Windows.
Returnssrc/main/java/com/Foo.java
if module base dir is/path/to/module
and 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:
relativePath
in interfaceIndexedFile
- Specified by:
relativePath
in interfaceInputFile
- Specified by:
relativePath
in 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:InputFile
Normalized 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:
absolutePath
in interfaceIndexedFile
- Specified by:
absolutePath
in interfaceInputFile
- Specified by:
absolutePath
in interfaceInputPath
- See Also:
InputFile.absolutePath()
,InputDir.absolutePath()
-
file
public java.io.File file()
Description copied from interface:InputFile
The underlying absoluteFile
. It should not be used to read the file in the filesystem.- Specified by:
file
in interfaceIndexedFile
- Specified by:
file
in interfaceInputFile
- Specified by:
file
in interfaceInputPath
- See Also:
InputFile.contents()
,InputFile.inputStream()
-
path
public java.nio.file.Path path()
Description copied from interface:InputFile
The underlying absolutePath
. It should not be used to read the file in the filesystem.- Specified by:
path
in interfaceIndexedFile
- Specified by:
path
in interfaceInputFile
- Specified by:
path
in interfaceInputPath
- See Also:
InputFile.contents()
,InputFile.inputStream()
-
language
@CheckForNull public java.lang.String language()
Description copied from interface:InputFile
Language, 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:
language
in interfaceIndexedFile
- Specified by:
language
in interfaceInputFile
-
type
public InputFile.Type type()
Description copied from interface:InputFile
Does it contain main or test code ?- Specified by:
type
in interfaceIndexedFile
- Specified by:
type
in interfaceInputFile
-
key
public java.lang.String key()
Component key (without branch).- Specified by:
key
in interfaceInputComponent
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classDefaultInputComponent
-
toString
public java.lang.String toString()
Description copied from interface:InputFile
Return a string to identify this file (suitable for logs).- Specified by:
toString
in interfaceInputFile
- Overrides:
toString
in classDefaultInputComponent
-
status
public InputFile.Status status()
-
lines
public int lines()
Description copied from interface:InputFile
Number 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:InputFile
Check if the file content is empty (ignore potential BOM).
-
charset
public java.nio.charset.Charset charset()
Description copied from interface:InputFile
Charset 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:InputFile
Returns aTextPointer
in the given file.- Specified by:
newPointer
in 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:InputFile
Returns aTextRange
in the given file.
-
newRange
public TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset)
Description copied from interface:InputFile
Returns aTextRange
in 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:InputFile
Returns aTextRange
in the given file that select the full line.- Specified by:
selectLine
in 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:
equals
in classDefaultInputComponent
-
isFile
public boolean isFile()
Description copied from interface:InputComponent
Is the component anInputFile
- Specified by:
isFile
in interfaceInputComponent
-
filename
public java.lang.String filename()
Description copied from interface:IndexedFile
Filename for this file (inclusing extension). For example: MyClass.java.- Specified by:
filename
in interfaceIndexedFile
-
uri
public java.net.URI uri()
Description copied from interface:IndexedFile
Identifier 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:
uri
in interfaceIndexedFile
- Specified by:
uri
in 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()
-
-