Idean / sonar-swift

Open source Swift plugin for SonarQube (also supports Objective-C)
Other
890 stars 277 forks source link

WARN: file not included in sonar #81

Open zeusent opened 7 years ago

zeusent commented 7 years ago

Whenever I scan my Swift project I keep getting a lot of warnings like the one bellow and none of my files' issues are actually uploaded to the server:

11:04:44.445 INFO: Processing SwiftLint report sonar-reports/MYPROJECT-swiftlint.txt
11:04:44.445 DEBUG: record issue /Users/jenkins/Jenkins/jobs/MYPROJECT_iOS_Dev/workspace/MYPROJECT/Source/Extensions/UIFont+HV.swift:16:9: warning: Statement Position Violation: Else and catch should be on the same line, one space after the previous declaration. (statement_position)
11:04:44.446 WARN: file not included in sonar /Users/jenkins/Jenkins/jobs/MYPROJECT_iOS_Dev/workspace/MYPROJECT/Source/Extensions/UIFont+HV.swift
11:04:44.446 DEBUG: record issue /Users/jenkins/Jenkins/jobs/MYPROJECT_iOS_Dev/workspace/MYPROJECT/Source/Extensions/UIFont+HV.swift:28:9: warning: Statement Position Violation: Else and catch should be on the same line, one space after the previous declaration. (statement_position)
11:04:44.446 WARN: file not included in sonar 
...

I see this problem happening to some users as well (see #72) but there seems to be no activity. Some help might be really appreciated.

snod commented 7 years ago

I see the same issue but only when I run the scan with sonar.analysis.mode=preview (for use with the github-plugin).

snod commented 7 years ago

After some debugging I found this in SwiftLintReportParser:

    Pattern pattern = Pattern.compile("(.*.swift):(\\w+):?(\\w+)?: (warning|error): (.*) \\((\\w+)");
        Matcher matcher = pattern.matcher(line);
        while (matcher.find()) {
            String filePath = matcher.group(1);
            int lineNum = Integer.parseInt(matcher.group(2));
            String message = matcher.group(5);
            String ruleId = matcher.group(6);

            InputFile inputFile = fileSystem.inputFile(fileSystem.predicates().hasAbsolutePath(filePath));

            if (inputFile == null) {
                LOGGER.warn("file not included in sonar {}", filePath);
                continue;
            }

The inputFile is null when running the scanner in preview mode. it seems as if cannot create the file reference even though the path in filePath is correct.

MattCarr147 commented 6 years ago

Spent the last day or so battling with this issue, as it was preventing us from uploading swiftlint issues correctly. It turned out in our case that it was a case-sensitivity issue when searching for the file.

The file was located within:

/Users/username/Documents/Development/Project/(etc.)

Whereas Sonar had it included as:

/Users/username/documents/development/Project/(etc.)

I believe this was due to me navigating to the folder within terminal using cd documents/development (note lowercase) before running the shell command.

singh88 commented 6 years ago

@snod you are right. From the code, it looks like that might be the cause of the issue. But this functionality worked for me in one of my projects out of two, I don't understand why. The only difference between my projects is directory structure depth. I mean in one of my projects it looks like this

PathofJenkinsWorksapce/FolderA/Common/Manager/FileName.swift --Example A

and in other

PathofJenkinsWorksapce/FolderB/Sight/Content/Cell/FileName.swift -- Example B

I was able to get the reports on my open PR in GitHub in Example A not in B.

Well, above described solution or scenario is not relevant. Since this problem exists in GitHub preview mode.

stonehouse commented 6 years ago

Has there been any progress on this issue? I'm seeing the same error, again only in preview mode. The server is a Mac, so I don't see how the issue can be with case sensitivity. The path listed in the warning is exactly the same as the path to the actual file. Could it have something to do with the length of path?

Output for SwiftLint

[17:18:48]: ▸ INFO: Processing SwiftLint report reports/swiftlint.txt
[17:18:48]: ▸ WARN: file not included in sonar /usr/local/var/buildkite-agent/builds/Build-Server/account/repo/Project/Source/SourceFile.swift
[17:18:48]: ▸ WARN: file not included in sonar /usr/local/var/buildkite-agent/builds/Build-Server/account/repo/Project/Source/SourceFile2.swift

Output for Tailor

[17:18:48]: ▸ INFO: Processing Tailor report reports/tailor.txt
[17:18:48]: ▸ WARN: file not included in sonar /usr/local/var/buildkite-agent/builds/Build-Server/account/repo/Project/Source/SourceFile.swift
stonehouse commented 6 years ago

I've tried moving everything to a folder closer to root and I end up with the same errors, so I don't see how it's related to length. I also don't understand why this only happens in preview mode?

AyaAkl25 commented 5 years ago

Hey, is there any update on this issue please? because I am having the same error

dhruvsbhatt commented 5 years ago

Guys, any update on above issue ?

genert commented 5 years ago

Bump

gaelfoppolo commented 4 years ago

Can you provide a project sample to reproduce the issue?

davidy4ng commented 4 years ago

Is the given file available in one of your sonar.sources path from your sonar-project.properties?

kmarcell commented 4 years ago

I have run into the same issue with SwiftLint, Tailor and OCLint reports not showing up on SonarQube.

Anybody would be able to help?

Processing OCLint report
WARN: file not included in sonar
INFO: Processing SwiftLint report
WARN: file not included in sonar
INFO: Processing Tailor report
WARN: file not included in sonar

I have added all source folders to sonar.sources as comma separated values: sonar.sources=Foo/bar, Foo2/bar2, ... etc

INFO: SonarQube Scanner 4.2.0.1873 INFO: Java 11.0.5 AdoptOpenJDK (64-bit) INFO: Mac OS X 10.15.3 x86_64 INFO: SonarQube server 8.3.1 Plugin version backelite-sonar-swift-plugin-0.4.6

gbfansheng commented 2 years ago

!!!Solved!!! This problem happen to me and i finally found that i cant open the files reported by using "cd" command in Terminal. It was because i have two machine, one is for swiftlint, another is for Sonar. And the directory in swiftlint machine is not match in sonar machine. Hope it helps!