-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLI-1556 In Rider, all solution's files should be analyzed
- Loading branch information
1 parent
27ae7fd
commit 9efa53b
Showing
17 changed files
with
274 additions
and
124 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
common/src/main/java/org/sonarlint/intellij/common/analysis/FilesContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* SonarLint for IntelliJ IDEA | ||
* Copyright (C) 2015-2024 SonarSource | ||
* [email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | ||
*/ | ||
package org.sonarlint.intellij.common.analysis; | ||
|
||
import com.intellij.openapi.extensions.ExtensionPointName; | ||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import java.util.Set; | ||
|
||
public interface FilesContributor { | ||
// Name is constructed from plugin-id.extension-point-name | ||
ExtensionPointName<FilesContributor> EP_NAME = ExtensionPointName.create("org.sonarlint.idea.filesContributor"); | ||
|
||
Set<VirtualFile> listFiles(Module module); | ||
} |
50 changes: 50 additions & 0 deletions
50
common/src/main/java/org/sonarlint/intellij/common/util/FileUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* SonarLint for IntelliJ IDEA | ||
* Copyright (C) 2015-2024 SonarSource | ||
* [email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | ||
*/ | ||
package org.sonarlint.intellij.common.util | ||
|
||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.roots.GeneratedSourcesFilter.isGeneratedSourceByAnyFilter | ||
import com.intellij.openapi.roots.ProjectFileIndex | ||
import com.intellij.openapi.util.io.FileUtilRt | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import org.sonarlint.intellij.common.ui.ReadActionUtils.Companion.computeReadActionSafely | ||
import org.sonarlint.intellij.common.ui.SonarLintConsole | ||
|
||
class FileUtils { | ||
|
||
companion object { | ||
fun isFileValidForSonarLint(file: VirtualFile, project: Project): Boolean { | ||
try { | ||
val toSkip = computeReadActionSafely(project) { | ||
isGeneratedSourceByAnyFilter(file, project) | ||
|| ProjectFileIndex.getInstance(project).isExcluded(file) | ||
|| ProjectFileIndex.getInstance(project).isInLibrary(file) | ||
|| (!ApplicationManager.getApplication().isUnitTestMode && FileUtilRt.isTooLarge(file.length)) | ||
} | ||
return false == toSkip | ||
} catch (e: Exception) { | ||
SonarLintConsole.get(project).error("Error while visiting a file, reason: " + e.message) | ||
return false | ||
} | ||
} | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
its/projects/sample-complex-rider/mainFolder/folder1/file1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace NewCADServer | ||
{ | ||
public class file1 | ||
{ | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
its/projects/sample-complex-rider/mainFolder/folder1/folder1.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
</Project> |
21 changes: 21 additions & 0 deletions
21
its/projects/sample-complex-rider/mainFolder/sample-complex-rider.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "folder1", "folder1\folder1.csproj", "{88EC1BA3-5635-4166-AC4A-9FB6F9B5DB0D}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "folder2", "..\mainFolder2\folder2\folder2.csproj", "{244D7F07-F814-4F2E-A54C-8229B8E9ECA9}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{88EC1BA3-5635-4166-AC4A-9FB6F9B5DB0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{88EC1BA3-5635-4166-AC4A-9FB6F9B5DB0D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{88EC1BA3-5635-4166-AC4A-9FB6F9B5DB0D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{88EC1BA3-5635-4166-AC4A-9FB6F9B5DB0D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{244D7F07-F814-4F2E-A54C-8229B8E9ECA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{244D7F07-F814-4F2E-A54C-8229B8E9ECA9}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{244D7F07-F814-4F2E-A54C-8229B8E9ECA9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{244D7F07-F814-4F2E-A54C-8229B8E9ECA9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
6 changes: 6 additions & 0 deletions
6
its/projects/sample-complex-rider/mainFolder2/folder2/file2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace ClassLibraryFromExternalDirectory | ||
{ | ||
public class file2 | ||
{ | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
its/projects/sample-complex-rider/mainFolder2/folder2/folder2.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
rider/src/main/java/org/sonarlint/intellij/rider/RiderFilesContributor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* SonarLint for IntelliJ IDEA | ||
* Copyright (C) 2015-2024 SonarSource | ||
* [email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | ||
*/ | ||
package org.sonarlint.intellij.rider | ||
|
||
import com.intellij.openapi.module.Module | ||
import com.intellij.openapi.project.guessProjectDir | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.jetbrains.rider.projectView.workspace.ProjectModelEntity | ||
import com.jetbrains.rider.projectView.workspace.ProjectModelEntityVisitor | ||
import com.jetbrains.rider.projectView.workspace.getVirtualFileAsContentRoot | ||
import com.jetbrains.rider.projectView.workspace.isProjectFile | ||
import org.sonarlint.intellij.common.analysis.FilesContributor | ||
import org.sonarlint.intellij.common.util.FileUtils.Companion.isFileValidForSonarLint | ||
|
||
class RiderFilesContributor : FilesContributor { | ||
|
||
override fun listFiles(module: Module): MutableSet<VirtualFile> { | ||
val filesInContentRoots = mutableSetOf<VirtualFile>() | ||
|
||
// List files in Solution | ||
filesInContentRoots.addAll(listFilesInSolution(module)) | ||
|
||
// List files in project dir, sometimes not all files are found via the previous method | ||
filesInContentRoots.addAll( | ||
module.project.guessProjectDir()?.children?.filter { !it.isDirectory && it.isValid }?.toSet() ?: emptySet() | ||
) | ||
|
||
return filesInContentRoots | ||
} | ||
|
||
private fun listFilesInSolution(module: Module): Set<VirtualFile> { | ||
val filesInSolution = mutableSetOf<VirtualFile>() | ||
val visitor = object : ProjectModelEntityVisitor() { | ||
override fun visitProjectFile(entity: ProjectModelEntity): Result { | ||
if (module.isDisposed) { | ||
return Result.Stop | ||
} | ||
|
||
if (entity.isProjectFile()) { | ||
entity.getVirtualFileAsContentRoot()?.let { | ||
if (!it.isDirectory && it.isValid && isFileValidForSonarLint(it, module.project)) { | ||
filesInSolution.add(it) | ||
} | ||
} | ||
} | ||
|
||
return Result.Continue | ||
} | ||
} | ||
visitor.visit(module.project) | ||
return filesInSolution | ||
} | ||
|
||
} |
Oops, something went wrong.