Class TestInputFileBuilder


  • public class TestInputFileBuilder
    extends java.lang.Object
    Intended to be used in unit tests that need to create InputFiles. An InputFile is unambiguously identified by a module key and a relative path, so these parameters are mandatory.

    A module base directory is only needed to construct absolute paths.

    Examples of usage of the constructors:

     InputFile file1 = TestInputFileBuilder.create("module1", "myfile.java").build();
     InputFile file2 = TestInputFileBuilder.create("", fs.baseDir(), myfile).build();
     

    file1 will have the "module1" as both module key and module base directory. file2 has an empty string as module key, and a relative path which is the path from the filesystem base directory to myfile.

    Since:
    6.3
    • Constructor Detail

      • TestInputFileBuilder

        public TestInputFileBuilder​(java.lang.String projectKey,
                                    java.lang.String relativePath)
        Create a InputFile identified by the given project key and relative path.
      • TestInputFileBuilder

        public TestInputFileBuilder​(java.lang.String projectKey,
                                    java.io.File moduleBaseDir,
                                    java.io.File filePath)
        Create a InputFile with a given module key and module base directory. The relative path is generated comparing the file path to the module base directory. filePath must point to a file that is within the module base directory.
      • TestInputFileBuilder

        public TestInputFileBuilder​(java.lang.String projectKey,
                                    java.lang.String relativePath,
                                    int id)
    • Method Detail

      • create

        public static TestInputFileBuilder create​(java.lang.String moduleKey,
                                                  java.io.File moduleBaseDir,
                                                  java.io.File filePath)
      • create

        public static TestInputFileBuilder create​(java.lang.String moduleKey,
                                                  java.lang.String relativePath)
      • nextBatchId

        public static int nextBatchId()
      • setProjectBaseDir

        public TestInputFileBuilder setProjectBaseDir​(java.nio.file.Path projectBaseDir)
      • setModuleBaseDir

        public TestInputFileBuilder setModuleBaseDir​(java.nio.file.Path moduleBaseDir)
      • setStatus

        public TestInputFileBuilder setStatus​(org.sonar.api.batch.fs.InputFile.Status status)
      • setContents

        public TestInputFileBuilder setContents​(java.lang.String content)
        Set contents of the file and calculates metadata from it. The contents will be returned by InputFile.contents() and InputFile.inputStream() and can be inconsistent with the actual physical file pointed by InputFile.path(), InputFile.absolutePath(), etc.
      • setOriginalLineStartOffsets

        public TestInputFileBuilder setOriginalLineStartOffsets​(int[] originalLineStartOffsets)
      • setOriginalLineEndOffsets

        public TestInputFileBuilder setOriginalLineEndOffsets​(int[] originalLineEndOffsets)
      • newDefaultInputModule

        public static DefaultInputModule newDefaultInputModule​(java.lang.String moduleKey,
                                                               java.io.File baseDir)
      • newDefaultInputModule

        public static DefaultInputModule newDefaultInputModule​(org.sonar.api.batch.bootstrap.ProjectDefinition projectDefinition)
      • newDefaultInputProject

        public static DefaultInputProject newDefaultInputProject​(java.lang.String projectKey,
                                                                 java.io.File baseDir)
      • newDefaultInputProject

        public static DefaultInputProject newDefaultInputProject​(org.sonar.api.batch.bootstrap.ProjectDefinition projectDefinition)
      • newDefaultInputProject

        public static DefaultInputProject newDefaultInputProject​(java.lang.String key,
                                                                 java.nio.file.Path baseDir)
                                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • newDefaultInputDir

        public static DefaultInputDir newDefaultInputDir​(AbstractProjectOrModule module,
                                                         java.lang.String relativePath)
                                                  throws java.io.IOException
        Throws:
        java.io.IOException