diff --git a/.gitignore b/.gitignore index ee34c3f..3ed2c28 100644 --- a/.gitignore +++ b/.gitignore @@ -218,3 +218,6 @@ test.bat # Examples rosette_apiExamples/*.exe rosette_apiExamples/*.dll + +# Sonar +.sonarqube/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d1cf990..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: csharp -install: -- nuget restore rosette_api.sln -script: -- xbuild /p:Configuration=Release rosette_api.sln -- mono ./packages/NUnit.Console.3.0.1/tools/nunit3-console.exe ./rosette_apiUnitTests/bin/Release/rosette_apiUnitTests.dll -notifications: - slack: - secure: i8q0FGroh4HVOLtMHPvPSupJ9s7LQ7WDbI5VNBBH6C+wpmk3H1kmlAy7ZjlLXtc99QBKDu69gphQksZSzjvmvHUXiwt23faBsVKqOSb+QfdEajSNEEl8Ujkw38osd/tJdwPbABfM/RKKUx9E3NhK9WfsNUWZEDMnIdC4WoR9WvB8WltwKGwCpruQePp3MO8IltIfkajUTsabu5ezodjD1X6qojfD777g8ivLwJP/x9koIGIdfm2d1SKA+ywdgaZOZeAfCSe6ETLCfU6Wa4DHxe3COBwOM5fJ6C/aHPQn3tpbsfLGG5rsb+fNuyeMuhJUZi0/XOX3w4O3rQ502bvG1cSrfotbhldkeQKqIPW1vqpsF82/UFliKpGVAC0Y1h2DQ3YZWHEUqfsqPlZ3QuFrekesic3qUgO8TVTSLyzmhYbc8QHOQs8iXbbm3qoT+yTdkDvILubhXemZC8RXohsjbBPkRAMc8zcyR+gLN8mUrR6/gUzJ7JtMD9hoM+HLS7Vj0+iFJYwLNzrEFMebe54+fDcv/cKRwYQSI+UdABG2Dm31TK94NT6uCvY6rFC3PSU1at+ci23PgF41BzFLDK+9AWgsTgSspPUiyoMtI25BwBd0ryUUhqepKF9WJvX9jsJBopMd9Z60wVuIbUeRnOL4NMalNfu1FpcMH/s0K9c3+3M= diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile new file mode 100644 index 0000000..797d437 --- /dev/null +++ b/CI.Jenkinsfile @@ -0,0 +1,60 @@ +node ("docker-light") { + def sourceDir = pwd() + try { + stage("Clean up") { + step([$class: 'WsCleanup']) + } + stage("Checkout Code") { + checkout scm + } + stage("Build & Test") { + withSonarQubeEnv { + // TODO: Remove if we branch references work, otherwise, pass these to the exe somehow. + //if ("${env.CHANGE_BRANCH}" != "null") { + // mySonarOpts="$mySonarOpts -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}" + //} + //echo("Sonar Options are: $mySonarOpts") + // https://github.com/KSP-CKAN/CKAN/wiki/SSL-certificate-errors#removing-expired-lets-encrypt-certificates + // Reference for sed command and cert sync steps. + sh "docker run --rm \ + --pull always \ + --volume ${sourceDir}:/source \ + mono:6 \ + bash -c \"apt-get update && \ + apt-get install unzip default-jre-headless -y && \ + sed -i 's,^mozilla/DST_Root_CA_X3.crt\$,!mozilla/DST_Root_CA_X3.crt,' /etc/ca-certificates.conf && \ + update-ca-certificates && \ + cert-sync /etc/ssl/certs/ca-certificates.crt && \ + mkdir -p /opt/sonar-scanner && \ + pushd /opt/sonar-scanner && \ + curl --silent --output sonar-scanner.zip --location https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/5.9.2.58699/sonar-scanner-msbuild-5.9.2.58699-net46.zip && \ + unzip sonar-scanner.zip && \ + chmod a+x /opt/sonar-scanner/sonar-scanner-*/bin/* && \ + pushd /source && \ + mono /opt/sonar-scanner/SonarScanner.MSBuild.exe begin /k:\"rosette-api-csharp-binding\" /d:sonar.login=\"${env.SONAR_AUTH_TOKEN}\" /d:sonar.host.url=\"${env.SONAR_HOST_URL}\" && \ + nuget restore rosette_api.sln && \ + msbuild /p:Configuration=Release rosette_api.sln /t:Rebuild && \ + mono /opt/sonar-scanner/SonarScanner.MSBuild.exe end /d:sonar.login=\"${env.SONAR_AUTH_TOKEN}\" && \ + mono ./packages/NUnit.Console.3.0.1/tools/nunit3-console.exe ./rosette_apiUnitTests/bin/Release/rosette_apiUnitTests.dll\"" + // TODO: Finish coverage data gathering for Sonar. + ///opt/maven-basis/bin/mvn --batch-mode clean install sonar:sonar $mySonarOpts\"" + //pushd /tmp + //dotcover_version=2022.3.1 + //curl --silent --location --output dotcover.tar.gz https://download.jetbrains.com/resharper/dotUltimate.2022.3.1/JetBrains.dotCover.CommandLineTools.linux-x64.2022.3.1.tar.gz + //tar xzf dotcover.tar.gz + } + } + slack(true) + } catch (e) { + currentBuild.result = "FAILED" + slack(false) + throw e + } +} + +def slack(boolean success) { + def color = success ? "#00FF00" : "#FF0000" + def status = success ? "SUCCESSFUL" : "FAILED" + def message = status + ": Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})" + slackSend(color: color, channel: "#p-n-c_jenkins", message: message) +} \ No newline at end of file diff --git a/rosette_api/EntityID.cs b/rosette_api/EntityID.cs index 37d1cce..91f790c 100644 --- a/rosette_api/EntityID.cs +++ b/rosette_api/EntityID.cs @@ -34,12 +34,12 @@ public EntityID(string id) /// Creates a link to the Wikipedia article for this EntityID's ID if it is a QID. If the ID is not a QID, this method returns null. /// /// The valid Wikipedia link or null. - public string GetWikipedaURL() + public string GetWikipediaURL() { string siteLink = ("https://www.wikidata.org/w/api.php?action=wbgetentities&ids=" + ID + "&sitefilter=enwiki&props=sitelinks&format=json"); try { - string jsonStr = MakeRequest(siteLink).Result; + string jsonStr = MakeRequest(siteLink).Result; int lengthOfTitle = jsonStr.IndexOf("\"badges\":") - jsonStr.IndexOf("\"title\":") - 11; string title = jsonStr.Substring(jsonStr.IndexOf("\"title\":") + 9, lengthOfTitle); title = title.Replace(" ", "_"); @@ -53,6 +53,16 @@ public string GetWikipedaURL() } } + /// + /// Creates a link to the Wikipedia article for this EntityID's ID if it is a QID. If the ID is not a QID, this method returns null. + /// + /// The valid Wikipedia link or null. + [Obsolete("GetWikipedaURL is deprecated, please use GetWikipediaURL instead.")] + public string GetWikipedaURL() + { + return GetWikipediaURL(); + } + private async Task MakeRequest(string requestUrl) { try diff --git a/rosette_api/packages.config b/rosette_api/packages.config old mode 100755 new mode 100644 index 078edfa..9892ead --- a/rosette_api/packages.config +++ b/rosette_api/packages.config @@ -1,5 +1,5 @@ - - - - + + + + \ No newline at end of file diff --git a/rosette_api/rosette_api.csproj b/rosette_api/rosette_api.csproj index 6e8bb5a..6509ee5 100644 --- a/rosette_api/rosette_api.csproj +++ b/rosette_api/rosette_api.csproj @@ -41,9 +41,6 @@ - - ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll - @@ -51,6 +48,9 @@ + + ..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll + diff --git a/rosette_apiExamples/README.md b/rosette_apiExamples/README.md index 64966f5..073d633 100644 --- a/rosette_apiExamples/README.md +++ b/rosette_apiExamples/README.md @@ -53,12 +53,20 @@ Here are some methods for running the examples. ``` cd /csharp nuget restore rosette_api.sln - xbuild /p:Configuration=Release rosette_api.sln + msbuild /p:Configuration=Release rosette_api.sln ``` - _Optional:_ Run the Unit Tests. - ``` - mono ./packages/NUnit.Console.3.0.1/tools/nunit3-console.exe ./rosette_apiUnitTests/bin/Release/rosette_apiUnitTests.dll - ``` + - First, fix the certificate store so we can download wikidata. + Per: https://github.com/KSP-CKAN/CKAN/wiki/SSL-certificate-errors#removing-expired-lets-encrypt-certificates + ``` + sed -i 's/^mozilla\/DST_Root_CA_X3.crt$/!mozilla\/DST_Root_CA_X3.crt/' /etc/ca-certificates.conf + update-ca-certificates + cert-sync /etc/ssl/certs/ca-certificates.crt + ``` + - Then run the tests. + ``` + mono ./packages/NUnit.Console.3.0.1/tools/nunit3-console.exe ./rosette_apiUnitTests/bin/Release/rosette_apiUnitTests.dll + ``` - Copy the runtime binaries to the examples directory. ``` cp packages/Newtonsoft.Json.10.0.3/lib/net45/Newtonsoft.Json.dll rosette_apiExamples/. diff --git a/rosette_apiUnitTests/packages.config b/rosette_apiUnitTests/packages.config index 29b7832..efb64b1 100644 --- a/rosette_apiUnitTests/packages.config +++ b/rosette_apiUnitTests/packages.config @@ -1,14 +1,14 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/rosette_apiUnitTests/rosette_apiUnitTests.cs b/rosette_apiUnitTests/rosette_apiUnitTests.cs index 6467db5..9a595ff 100755 --- a/rosette_apiUnitTests/rosette_apiUnitTests.cs +++ b/rosette_apiUnitTests/rosette_apiUnitTests.cs @@ -787,22 +787,22 @@ public void EntityIDTestPassOnCreate() EntityID pass = new EntityID("Q1") { ID = "Q1" }; - Assert.AreEqual("https://en.wikipedia.org/wiki/Universe", pass.GetWikipedaURL()); + Assert.AreEqual("https://en.wikipedia.org/wiki/Universe", pass.GetWikipediaURL()); } [Test] public void EntityIDTestLinkValidOnSet() { EntityID tidAtFirst = new EntityID("T423"); - Assert.AreEqual(null, tidAtFirst.GetWikipedaURL()); + Assert.AreEqual(null, tidAtFirst.GetWikipediaURL()); tidAtFirst.ID = "Q2"; - Assert.AreEqual("https://en.wikipedia.org/wiki/Earth", tidAtFirst.GetWikipedaURL()); + Assert.AreEqual("https://en.wikipedia.org/wiki/Earth", tidAtFirst.GetWikipediaURL()); } [Test] public void EntityIDLinkNullOnSetToNull() { EntityID eid = new EntityID(null); - Assert.AreEqual(null, eid.GetWikipedaURL()); + Assert.AreEqual(null, eid.GetWikipediaURL()); } //------------------------- Language ---------------------------------------- diff --git a/rosette_apiUnitTests/rosette_apiUnitTests.csproj b/rosette_apiUnitTests/rosette_apiUnitTests.csproj index d3c8bd7..fb615ee 100644 --- a/rosette_apiUnitTests/rosette_apiUnitTests.csproj +++ b/rosette_apiUnitTests/rosette_apiUnitTests.csproj @@ -1,6 +1,8 @@  - + + + Debug AnyCPU @@ -9,10 +11,8 @@ Properties rosette_apiUnitTests rosette_apiUnitTests - v4.5.2 + v4.5 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages False @@ -48,15 +48,6 @@ ..\packages\LinqToExcel.1.11.0\lib\LinqToExcel.dll - - ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll - - - ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll - - - ..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll - ..\packages\LinqToExcel.1.11.0\lib\Remotion.dll @@ -66,12 +57,8 @@ ..\packages\LinqToExcel.1.11.0\lib\Remotion.Interfaces.dll - - ..\packages\RichardSzalay.MockHttp.3.2.1\lib\net45\RichardSzalay.MockHttp.dll - - 3.5 @@ -83,6 +70,19 @@ + + ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + + + ..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll + + + ..\packages\NUnit.3.13.3\lib\net45\nunit.framework.dll + + + ..\packages\RichardSzalay.MockHttp.6.0.0\lib\net45\RichardSzalay.MockHttp.dll + @@ -138,7 +138,6 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. -