Search in sources :

Example 66 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class SymbolReferencesSensorTest method testNoExecutionIfNoSymbolFile.

@Test
public void testNoExecutionIfNoSymbolFile() {
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build();
    fileSystem.add(inputFile);
    sensor.execute(context);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 67 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class AbsolutePathPredicate method get.

@Override
public Iterable<InputFile> get(Index index) {
    String relative = PathUtils.sanitize(new PathResolver().relativePath(baseDir.toFile(), new File(path)));
    if (relative == null) {
        return Collections.emptyList();
    }
    InputFile f = index.inputFile(relative);
    return f != null ? Arrays.asList(f) : Collections.<InputFile>emptyList();
}
Also used : PathResolver(org.sonar.api.scan.filesystem.PathResolver) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile)

Example 68 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class DefaultFileSystem method inputFile.

@Override
public InputFile inputFile(FilePredicate predicate) {
    Iterable<InputFile> files = inputFiles(predicate);
    Iterator<InputFile> iterator = files.iterator();
    if (!iterator.hasNext()) {
        return null;
    }
    InputFile first = iterator.next();
    if (!iterator.hasNext()) {
        return first;
    }
    StringBuilder sb = new StringBuilder();
    sb.append("expected one element but was: <" + first);
    for (int i = 0; i < 4 && iterator.hasNext(); i++) {
        sb.append(", " + iterator.next());
    }
    if (iterator.hasNext()) {
        sb.append(", ...");
    }
    sb.append('>');
    throw new IllegalArgumentException(sb.toString());
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile)

Example 69 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class File method create.

/**
   * Internal use only.
   * @deprecated since 5.1 use {@link FileSystem#inputFile(org.sonar.api.batch.fs.FilePredicate)}
   */
@Deprecated
public static File create(String relativePathFromBasedir) {
    File file = new File();
    String normalizedPath = normalize(relativePathFromBasedir);
    file.setKey(normalizedPath);
    file.setPath(normalizedPath);
    String directoryPath;
    if (normalizedPath != null && normalizedPath.contains(Directory.SEPARATOR)) {
        directoryPath = StringUtils.substringBeforeLast(normalizedPath, Directory.SEPARATOR);
        file.filename = StringUtils.substringAfterLast(normalizedPath, Directory.SEPARATOR);
    } else {
        directoryPath = Directory.SEPARATOR;
        file.filename = normalizedPath;
    }
    file.parent = Directory.create(directoryPath);
    return file;
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile)

Example 70 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class File method create.

/**
   * Internal use only.
   * @deprecated since 5.1 use {@link FileSystem#inputFile(org.sonar.api.batch.fs.FilePredicate)}
   */
@Deprecated
public static File create(String relativePathFromBasedir, Language language, boolean unitTest) {
    File file = create(relativePathFromBasedir);
    file.setLanguage(language);
    if (unitTest) {
        file.setQualifier(Qualifiers.UNIT_TEST_FILE);
    }
    return file;
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile)

Aggregations

InputFile (org.sonar.api.batch.fs.InputFile)102 Test (org.junit.Test)61 File (java.io.File)45 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)39 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)20 TaskResult (org.sonar.scanner.mediumtest.TaskResult)19 IOException (java.io.IOException)10 FilePredicates (org.sonar.api.batch.fs.FilePredicates)8 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)7 List (java.util.List)6 FileSystem (org.sonar.api.batch.fs.FileSystem)6 BlameLine (org.sonar.api.batch.scm.BlameLine)6 ArrayList (java.util.ArrayList)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)4 DefaultBlameOutput (org.sonar.scanner.scm.DefaultBlameOutput)4 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)3 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)3 MutableTestPlan (org.sonar.api.test.MutableTestPlan)3 Block (org.sonar.duplications.block.Block)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2