diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d51f6df --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.sonarqube/ +bin/ +.vs/ +.DS_Store +obj/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2da2006 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright 2017 Joshua Quek + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..df59cf3 --- /dev/null +++ b/Program.cs @@ -0,0 +1,64 @@ +// See https://aka.ms/new-console-template for more information +// Console.WriteLine("Hello, World!"); + +using System; +using System.Linq; +using System.IO; +using System.Text; +using System.Collections; +using System.Collections.Generic; + +/** + * Auto-generated code below aims at helping you parse + * the standard input according to the problem statement. + **/ +class Solution +{ + static void Main(string[] args) + { + int N = int.Parse(Console.ReadLine()); // Number of elements which make up the association table. + int Q = int.Parse(Console.ReadLine()); // Number Q of file names to be analyzed. + //This will use the file Ext as the Key and the MIME type as the value. + Dictionary fileExtention = new Dictionary(); + List fileName = new List(); + for (int i = 0; i < N; i++) + { + string[] inputs = Console.ReadLine().Split(' '); + string EXT = inputs[0].ToLower(); // file extension + string MT = inputs[1]; // MIME type. + fileExtention.Add(EXT, MT); + } + for (int i = 0; i < Q; i++) + { + string FNAME = Console.ReadLine();// One file name per line. + FNAME = FNAME.ToLower(); + if (FNAME.Contains('.')) + { + FNAME = FNAME.Substring(FNAME.LastIndexOf('.')+1); + } + else + { + FNAME = "N/A"; + } + fileName.Add(FNAME); + } + + foreach(string extention in fileName) + { + if(extention == "N/A") + { + Console.WriteLine("UNKNOWN"); + } + else if (fileExtention.ContainsKey(extention)) + { + string MIMETypeToReturn = string.Empty; + fileExtention.TryGetValue(extention, out MIMETypeToReturn); + Console.WriteLine(MIMETypeToReturn); + } + else + { + Console.WriteLine("UNKNOWN"); + } + } + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b13b26c --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Dotnetcore App +A sample dotnetcore app to showcase SonarQube scanning. + +## Description + +Please refer to the `scanner-csharp.sh` file for the cli commands to scan this project. + +Alternatively, you can also use Azure DevOps pipelines to do the scan - refer to the `azure-pipelines.yml` file for this. + +## License +MIT \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..b984dce --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,32 @@ +trigger: +- main + +pool: + vmImage: 'windows-latest' + +variables: + solution: '**/*.sln' + buildPlatform: 'Any CPU' + buildConfiguration: 'Release' + +steps: + +# Prepare Analysis Configuration task +- task: SonarQubePrepare@5 + inputs: + SonarQube: 'joshua-sonarqube' # SonarQube service connection id (found in Azure DevOps) + scannerMode: 'MSBuild' + projectKey: 'dotnetcore-azuredevops_dotnetcore-azuredevops_AYbAf9qWAu8T8ZieRlfh' + projectName: 'dotnetcore-sonar-azuredevops' + +# Dotnet build task +- task: DotNetCoreCLI@2 + displayName: 'dotnet build' + +# Run Code Analysis task +- task: SonarQubeAnalyze@5 + +# Publish Quality Gate Result task +- task: SonarQubePublish@5 + inputs: + pollingTimeoutSec: '300' \ No newline at end of file diff --git a/dotnetcore-sonar.csproj b/dotnetcore-sonar.csproj new file mode 100644 index 0000000..27cca26 --- /dev/null +++ b/dotnetcore-sonar.csproj @@ -0,0 +1,11 @@ + + + + Exe + net7.0 + dotnetcore_sonar + enable + enable + + + diff --git a/dotnetcore-sonar.sln b/dotnetcore-sonar.sln new file mode 100644 index 0000000..f2e35dd --- /dev/null +++ b/dotnetcore-sonar.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 25.0.1705.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnetcore-sonar", "dotnetcore-sonar.csproj", "{08FF83ED-E3E2-45AE-BB7B-5A9E4673EFBE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {08FF83ED-E3E2-45AE-BB7B-5A9E4673EFBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {08FF83ED-E3E2-45AE-BB7B-5A9E4673EFBE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {08FF83ED-E3E2-45AE-BB7B-5A9E4673EFBE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {08FF83ED-E3E2-45AE-BB7B-5A9E4673EFBE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {09EF56C3-9F1A-48BD-8FA0-5ED3401123EF} + EndGlobalSection +EndGlobal diff --git a/scanner-csharp.sh b/scanner-csharp.sh new file mode 100644 index 0000000..2a1dbf2 --- /dev/null +++ b/scanner-csharp.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +dotnet restore +dotnet sonarscanner begin /k:"csharp-dotnetcore-sonar" /n:"csharp-dotnetcore-sonar" /d:sonar.verbose=true /d:sonar.login="input your token here" +dotnet build +dotnet sonarscanner end /d:sonar.login="input your token here"