From 945da794b59fc0c2cd74e4e79a265ecf0c0553e5 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 1 Oct 2020 09:52:17 -0400 Subject: [PATCH 01/17] - adds pom placeholder so dependency graph shows up --- .gitignore | 1 - build.gradle | 8 ++++++++ pom.xml | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore index f121de793..e34a1d606 100644 --- a/.gitignore +++ b/.gitignore @@ -31,5 +31,4 @@ hs_err_pid* # Maven /target/ -/pom.xml local.properties \ No newline at end of file diff --git a/build.gradle b/build.gradle index 5cfd7cbd4..165122096 100644 --- a/build.gradle +++ b/build.gradle @@ -20,6 +20,14 @@ java { modularity.inferModulePath = true } +sourceSets { + main { + java { + exclude 'pom.xml' + } + } +} + // In this section you declare where to find the dependencies of your project repositories { // Use jcenter for resolving your dependencies. diff --git a/pom.xml b/pom.xml new file mode 100644 index 000000000..b86d28dbe --- /dev/null +++ b/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + com.microsoft.graph + microsoft-graph-core + 1.0.5 + pom + + + + com.google.code.gson + gson + 2.8.6 + + + com.squareup.okhttp3 + gson + 3.12.1 + + + \ No newline at end of file From ca02f8edd9c3d15ae87fe53cbd6bcb6f5422f858 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 5 Oct 2020 12:17:15 -0400 Subject: [PATCH 02/17] - removes dependabot configuration for maven --- .github/dependabot.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 767270516..34477c7e2 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,8 +5,3 @@ updates: schedule: interval: daily open-pull-requests-limit: 10 -- package-ecosystem: maven - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 From 55052b205831ef20d9a5e3c0667a7c9a8b125697 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 7 Oct 2020 14:08:45 -0400 Subject: [PATCH 03/17] - adds dependabot for actions --- .github/dependabot.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 34477c7e2..75c8395a5 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,3 +5,8 @@ updates: schedule: interval: daily open-pull-requests-limit: 10 +- package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 From d874ba0dc9cae26e8f09a0c29c7139cd89afc8c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 06:44:18 +0000 Subject: [PATCH 04/17] Bump junit from 4.13 to 4.13.1 Bumps [junit](https://github.com/junit-team/junit4) from 4.13 to 4.13.1. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.13.1.md) - [Commits](https://github.com/junit-team/junit4/compare/r4.13...r4.13.1) Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 165122096..9991b2fa3 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ repositories { dependencies { // Use JUnit test framework - testImplementation 'junit:junit:4.13' + testImplementation 'junit:junit:4.13.1' api 'com.squareup.okhttp3:okhttp:3.12.1' From 028e2cc434d30fd88cdd74003149a45022708de1 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 25 Nov 2020 15:04:00 -0500 Subject: [PATCH 05/17] - adds a script to automatically increment minor version --- .azure-pipelines/buildAndPackage.yml | 1 - .azure-pipelines/prValidate.yml | 7 --- Scripts/getLatestVersion.ps1 | 31 ------------ Scripts/incrementMinorVersion.ps1 | 76 ++++++++++++++++++++++++++++ Scripts/validateMavenVersion.ps1 | 67 ------------------------ 5 files changed, 76 insertions(+), 106 deletions(-) delete mode 100644 Scripts/getLatestVersion.ps1 create mode 100644 Scripts/incrementMinorVersion.ps1 delete mode 100644 Scripts/validateMavenVersion.ps1 diff --git a/.azure-pipelines/buildAndPackage.yml b/.azure-pipelines/buildAndPackage.yml index 417ca04dd..5ff4edf8e 100644 --- a/.azure-pipelines/buildAndPackage.yml +++ b/.azure-pipelines/buildAndPackage.yml @@ -85,7 +85,6 @@ steps: settings.gradle gradle.properties **/gradle/wrapper/* - Scripts/getLatestVersion.ps1 TargetFolder: '$(Build.ArtifactStagingDirectory)/' - task: PublishBuildArtifacts@1 diff --git a/.azure-pipelines/prValidate.yml b/.azure-pipelines/prValidate.yml index 64bbf4c0b..cf2bd540d 100644 --- a/.azure-pipelines/prValidate.yml +++ b/.azure-pipelines/prValidate.yml @@ -43,13 +43,6 @@ steps: inputs: debugMode: false -- task: PowerShell@2 - condition: and(failed(), eq(variables['Build.SourceBranchName'], 'dev')) - inputs: - filePath: '$(System.DefaultWorkingDirectory)\Scripts\validateMavenVersion.ps1' - pwsh: true - arguments: '-packageName "$(PACKAGE_NAME)" -propertiesPath "$(PROPERTIES_PATH)"' - - task: Gradle@2 inputs: gradleWrapperFile: 'gradlew' diff --git a/Scripts/getLatestVersion.ps1 b/Scripts/getLatestVersion.ps1 deleted file mode 100644 index 4e935336b..000000000 --- a/Scripts/getLatestVersion.ps1 +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -<# -.Synopsis - Retrieve the latest version of the library -.Description - Retrieves the latest version specified in the Gradle.Properties file - Uses the retrieved values to update the enviornment variable VERSION_STRING -.Parameter propertiesPath -#> -Param( - [string]$propertiesPath -) - -#Retrieve the current version from the Gradle.Properties file given the specified path -if($propertiesPath -eq "" -or $null -eq $propertiesPath) { - $propertiesPath = Join-Path -Path $PSScriptRoot -ChildPath "../gradle.properties" -} -$file = get-item $propertiesPath -$findVersions = $file | Select-String -Pattern "mavenMajorVersion" -Context 0,2 -$findVersions = $findVersions -split "`r`n" - -$majorVersion = $findVersions[0].Substring($findVersions[0].Length-1) -$minorVersion = $findVersions[1].Substring($findVersions[1].Length-1) -$patchVersion = $findVersions[2].Substring($findVersions[2].Length-1) -$version = "$majorVersion.$minorVersion.$patchVersion" - -#Update the VERSION_STRING env variable and inform the user -Write-Host "##vso[task.setVariable variable=VERSION_STRING]$($version)"; -Write-Host "Updated the VERSION_STRING enviornment variable with the current Gradle.Properties, $version" \ No newline at end of file diff --git a/Scripts/incrementMinorVersion.ps1 b/Scripts/incrementMinorVersion.ps1 new file mode 100644 index 000000000..7de19349a --- /dev/null +++ b/Scripts/incrementMinorVersion.ps1 @@ -0,0 +1,76 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Increment the minor version string in the csproj if the major, + minor, or patch version hasn't been manually updated. +.Description + Assumptions: + Targets Microsoft.Graph.csproj + This script assumes it is run from the repo root. + VersionPrefix is set in the first property group in the csproj. + Major or patch update versions are manually set by dev. + Minor version is typically auto-incremented. + +#> + +function Update-ReadmeVersion([string]$readmeFilePath, [string]$version) { + $readmeFileContent = Get-Content -Path $readmeFilePath -Raw + $readmeFileContent = $readmeFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version + Set-Content -Path $readmeFilePath $readmeFileContent +} + +function Update-TelemetryVersion([string]$telemetryFilePath, [string]$version) { + $telemetryFileContent = Get-Content -Path $telemetryFilePath -Raw + $telemetryFileContent = $telemetryFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version + Set-Content -Path $telemetryFilePath $telemetryFileContent +} + +function Update-PackageVersion([string]$propertiesFilePath, [string]$version) { + $propertiesFileContent = Get-Content -Path $propertiesFilePath -Raw + if($version -match "(\d{1,})\.(\d{1,})\.(\d{1,})") { + $patch = $Matches[3] + $minor = $Matches[2] + $major = $Matches[1] + $propertiesFileContent = $propertiesFileContent -replace "mavenMajorVersion\s+=\s+\d{1,}", "mavenMajorVersion = $major" + $propertiesFileContent = $propertiesFileContent -replace "mavenMinorVersion\s+=\s+\d{1,}", "mavenMinorVersion = $minor" + $propertiesFileContent = $propertiesFileContent -replace "mavenPatchVersion\s+=\s+\d{1,}", "mavenPatchVersion = $patch" + Set-Content -Path $propertiesFilePath $propertiesFileContent + } else { + Write-Error "Invalid version number format $version" + } +} +function Get-CurrentTelemetryVersion([string]$telemetryFilePath) { + $telemetryFileContent = Get-Content -Path $telemetryFilePath -Raw + if($telemetryFileContent -match "(\d{1,}\.\d{1,}\.\d{1,})") { + return $Matches[1] + } else { + Write-Error "Invalid version number format" + return "" + } +} + +function Update-MinorVersionNumber([string]$currentVersion) { + if($currentVersion -match "(\d{1,})\.(\d{1,})\.(\d{1,})") { + [int]$minor = [convert]::ToInt32($Matches[2]) + $minor++; + $major = $Matches[1] + return "$major.$minor.0" + } else { + Write-Error "Invalid version number format $currentVersion" + return "" + } +} + +function Update-MinorVersion() { + $readmeFilePath = Join-Path -Path $PWD.ToString() -ChildPath "../readme.md" + $propertiesFilePath = Join-Path -Path $PWD.ToString() -ChildPath "../gradle.properties" + $telemetryFilePath = Join-Path -Path $PWD.ToString() -ChildPath "../src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java" + $currentVersion = Get-CurrentTelemetryVersion -telemetryFilePath $telemetryFilePath + $nextVersion = Update-MinorVersionNumber -currentVersion $currentVersion + Update-ReadmeVersion -version $nextVersion -readmeFilePath $readmeFilePath + Update-TelemetryVersion -version $nextVersion -telemetryFilePath $telemetryFilePath + Update-PackageVersion -version $nextVersion -propertiesFilePath $propertiesFilePath +} +Update-MinorVersion \ No newline at end of file diff --git a/Scripts/validateMavenVersion.ps1 b/Scripts/validateMavenVersion.ps1 deleted file mode 100644 index da1742bd2..000000000 --- a/Scripts/validateMavenVersion.ps1 +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -<# -.Synopsis - Ensure the maven version is updated in the case that the pull request is - to the main/master branch of the repo. -.Description - Retrieves the local, Maven, and Bintray versions of the Java-Core build. - Checks that the Maven and Bintray versions are aligned, trigger warning if not. - Checks that the current local version is greater than those currently deployed. -.Parameter propertiesPath -#> - - -Param( - [string]$propertiesPath -) - -#Find the local version from the Gradle.Properties file -if($propertiesPath -eq "" -or $null -eq $propertiesPath) { - $propertiesPath = Join-Path -Path $PSScriptRoot -ChildPath "../gradle.properties" -} -$file = get-item $propertiesPath -$findLocalVersions = $file | Select-String -Pattern "mavenMajorVersion" -Context 0,2 -$findLocalVersions = $findLocalVersions -split "`r`n" -$packageName = ($file | Select-String -Pattern "mavenArtifactId").Line.Split("=")[1].Trim() - -$localMajor = $findLocalVersions[0].Substring($findLocalVersions[0].Length-1) -$localMinor = $findLocalVersions[1].Substring($findLocalVersions[1].Length-1) -$localPatch = $findLocalVersions[2].Substring($findLocalVersions[2].Length-1) -$localVersion = [version]"$localMajor.$localMinor.$localPatch" - -#Set Web Client and retrieve Maven and Bintray versions from their respective repos. -$web_client = New-Object System.Net.WebClient - -$mavenAPIurl = "https://search.maven.org/solrsearch/select?q=$packageName&rows=20&wt=json" -$jsonResult = $web_client.DownloadString($mavenAPIurl) | ConvertFrom-Json -$mavenVersion = [version]$jsonResult.response.docs.latestVersion - -$bintrayAPIurl = "https://api.bintray.com/search/packages?name=$packageName" -$jsonResult = $web_client.DownloadString($bintrayAPIurl) | ConvertFrom-Json -$bintrayVersion = [version]$jsonResult.latest_version - -#If the api calls return empty then this library cannot be compared to the online versions -#may proceed with the pull request -if(($mavenVersion -eq $null) -and ($bintrayVersion -eq $null)) -{ - Write-Information "This package does not exist yet in the online repository, therefore there are no versions to compare." - return -} - -#Inform host of current Maven and Bintray versions -Write-Host 'The current version in the Maven central repository is:' $mavenVersion -Write-Host 'The current version in the Bintray central repository is:' $bintrayVersion - -#Warn in case Maven and Bintray versions are not the same. -if($mavenVersion -ne $bintrayVersion){ - Write-Warning "The current Maven and Bintray versions are not the same" -} -#Success if Local version has been updated, Error otherwise. -if($localVersion -gt $bintrayVersion -and $localVersion -gt $mavenVersion){ - Write-Host "The current pull request is of a greater version" -} -else{ - Write-Error "The current local version is not updated. Please update the local version in the Gradle.Properties file." -} From 44a3458092c092027dca95c5ef35c0120b25f7c4 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 25 Nov 2020 15:08:40 -0500 Subject: [PATCH 06/17] - updates synopsis to reflect script effects --- Scripts/incrementMinorVersion.ps1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Scripts/incrementMinorVersion.ps1 b/Scripts/incrementMinorVersion.ps1 index 7de19349a..75c2a28ad 100644 --- a/Scripts/incrementMinorVersion.ps1 +++ b/Scripts/incrementMinorVersion.ps1 @@ -3,14 +3,12 @@ <# .Synopsis - Increment the minor version string in the csproj if the major, + Increment the minor version string in the gradle.properties if the major, minor, or patch version hasn't been manually updated. .Description Assumptions: - Targets Microsoft.Graph.csproj + Targets Gradle.properties This script assumes it is run from the repo root. - VersionPrefix is set in the first property group in the csproj. - Major or patch update versions are manually set by dev. Minor version is typically auto-incremented. #> From 72df8dac87dc797109f6417426e1904d1b3b1b55 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 25 Nov 2020 15:36:26 -0500 Subject: [PATCH 07/17] - improves batches replacement by using regex saving compute --- .../com/microsoft/graph/content/MSBatchRequestContent.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java b/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java index 64eed6c23..d6f756ee8 100644 --- a/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java +++ b/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java @@ -118,8 +118,7 @@ private JsonObject getBatchRequestObjectFromRequestStep(final MSBatchRequestStep contentmap.add("id", new JsonPrimitive(batchRequestStep.getRequestId())); final String url = batchRequestStep.getRequest().url().toString() - .replaceAll("https://graph.microsoft.com/v1.0/", "").replaceAll("http://graph.microsoft.com/v1.0/", "") - .replaceAll("https://graph.microsoft.com/beta/", "").replaceAll("http://graph.microsoft.com/beta/", ""); + .replaceAll("(?i)^http[s]?:\\/\\/graph\\.microsoft\\.com\\/(?>v1\\.0|beta)\\/?", ""); // (?i) case insensitive contentmap.add("url", new JsonPrimitive(url)); contentmap.add("method", new JsonPrimitive(batchRequestStep.getRequest().method().toString())); From 6f582683f3064fbf4ccbfcde0d169ea3d46c1b6c Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 26 Nov 2020 13:40:28 -0500 Subject: [PATCH 08/17] - restores wrongly deleted script --- .azure-pipelines/buildAndPackage.yml | 1 + Scripts/getLatestVersion.ps1 | 31 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Scripts/getLatestVersion.ps1 diff --git a/.azure-pipelines/buildAndPackage.yml b/.azure-pipelines/buildAndPackage.yml index 5ff4edf8e..6eaed042f 100644 --- a/.azure-pipelines/buildAndPackage.yml +++ b/.azure-pipelines/buildAndPackage.yml @@ -85,6 +85,7 @@ steps: settings.gradle gradle.properties **/gradle/wrapper/* + Scripts/** TargetFolder: '$(Build.ArtifactStagingDirectory)/' - task: PublishBuildArtifacts@1 diff --git a/Scripts/getLatestVersion.ps1 b/Scripts/getLatestVersion.ps1 new file mode 100644 index 000000000..4e935336b --- /dev/null +++ b/Scripts/getLatestVersion.ps1 @@ -0,0 +1,31 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Retrieve the latest version of the library +.Description + Retrieves the latest version specified in the Gradle.Properties file + Uses the retrieved values to update the enviornment variable VERSION_STRING +.Parameter propertiesPath +#> +Param( + [string]$propertiesPath +) + +#Retrieve the current version from the Gradle.Properties file given the specified path +if($propertiesPath -eq "" -or $null -eq $propertiesPath) { + $propertiesPath = Join-Path -Path $PSScriptRoot -ChildPath "../gradle.properties" +} +$file = get-item $propertiesPath +$findVersions = $file | Select-String -Pattern "mavenMajorVersion" -Context 0,2 +$findVersions = $findVersions -split "`r`n" + +$majorVersion = $findVersions[0].Substring($findVersions[0].Length-1) +$minorVersion = $findVersions[1].Substring($findVersions[1].Length-1) +$patchVersion = $findVersions[2].Substring($findVersions[2].Length-1) +$version = "$majorVersion.$minorVersion.$patchVersion" + +#Update the VERSION_STRING env variable and inform the user +Write-Host "##vso[task.setVariable variable=VERSION_STRING]$($version)"; +Write-Host "Updated the VERSION_STRING enviornment variable with the current Gradle.Properties, $version" \ No newline at end of file From 8b523e70560ac6a94d0c77ed2c96dae10e7fd72a Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 1 Dec 2020 10:54:31 -0500 Subject: [PATCH 09/17] - improves performance by precompiling regex --- .../graph/content/MSBatchRequestContent.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java b/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java index d6f756ee8..85ae6347a 100644 --- a/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java +++ b/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ThreadLocalRandom; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -113,12 +115,19 @@ public String getBatchRequestContent() { return content; } + private static final Pattern protocolAndHostReplacementPattern = Pattern.compile("(?i)^http[s]?:\\/\\/graph\\.microsoft\\.com\\/(?>v1\\.0|beta)\\/?"); // (?i) case insensitive + private Matcher protocolAndHostReplacementMatcher; // not static to avoid multithreading issues as the object is mutable private JsonObject getBatchRequestObjectFromRequestStep(final MSBatchRequestStep batchRequestStep) { final JsonObject contentmap = new JsonObject(); contentmap.add("id", new JsonPrimitive(batchRequestStep.getRequestId())); - final String url = batchRequestStep.getRequest().url().toString() - .replaceAll("(?i)^http[s]?:\\/\\/graph\\.microsoft\\.com\\/(?>v1\\.0|beta)\\/?", ""); // (?i) case insensitive + if(protocolAndHostReplacementMatcher == null) { + protocolAndHostReplacementMatcher = protocolAndHostReplacementPattern.matcher(batchRequestStep.getRequest().url().toString()); + } else { + protocolAndHostReplacementMatcher = protocolAndHostReplacementMatcher.reset(batchRequestStep.getRequest().url().toString()); + } + + final String url = protocolAndHostReplacementMatcher.replaceAll(""); contentmap.add("url", new JsonPrimitive(url)); contentmap.add("method", new JsonPrimitive(batchRequestStep.getRequest().method().toString())); From 0cef256b4c0332ff00c7c41c349afc7b7e423218 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 1 Dec 2020 11:26:40 -0500 Subject: [PATCH 10/17] - replaces regex parsing by the version class --- Scripts/incrementMinorVersion.ps1 | 41 ++++++++++--------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/Scripts/incrementMinorVersion.ps1 b/Scripts/incrementMinorVersion.ps1 index 75c2a28ad..3d5758f1e 100644 --- a/Scripts/incrementMinorVersion.ps1 +++ b/Scripts/incrementMinorVersion.ps1 @@ -13,52 +13,37 @@ #> -function Update-ReadmeVersion([string]$readmeFilePath, [string]$version) { +function Update-ReadmeVersion([string]$readmeFilePath, [version]$version) { $readmeFileContent = Get-Content -Path $readmeFilePath -Raw - $readmeFileContent = $readmeFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version + $readmeFileContent = $readmeFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version.ToString() Set-Content -Path $readmeFilePath $readmeFileContent } -function Update-TelemetryVersion([string]$telemetryFilePath, [string]$version) { +function Update-TelemetryVersion([string]$telemetryFilePath, [version]$version) { $telemetryFileContent = Get-Content -Path $telemetryFilePath -Raw - $telemetryFileContent = $telemetryFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version + $telemetryFileContent = $telemetryFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version.ToString() Set-Content -Path $telemetryFilePath $telemetryFileContent } -function Update-PackageVersion([string]$propertiesFilePath, [string]$version) { +function Update-PackageVersion([string]$propertiesFilePath, [version]$version) { $propertiesFileContent = Get-Content -Path $propertiesFilePath -Raw - if($version -match "(\d{1,})\.(\d{1,})\.(\d{1,})") { - $patch = $Matches[3] - $minor = $Matches[2] - $major = $Matches[1] - $propertiesFileContent = $propertiesFileContent -replace "mavenMajorVersion\s+=\s+\d{1,}", "mavenMajorVersion = $major" - $propertiesFileContent = $propertiesFileContent -replace "mavenMinorVersion\s+=\s+\d{1,}", "mavenMinorVersion = $minor" - $propertiesFileContent = $propertiesFileContent -replace "mavenPatchVersion\s+=\s+\d{1,}", "mavenPatchVersion = $patch" - Set-Content -Path $propertiesFilePath $propertiesFileContent - } else { - Write-Error "Invalid version number format $version" - } + $propertiesFileContent = $propertiesFileContent -replace "mavenMajorVersion\s+=\s+\d{1,}", "mavenMajorVersion = $($version.Major)" + $propertiesFileContent = $propertiesFileContent -replace "mavenMinorVersion\s+=\s+\d{1,}", "mavenMinorVersion = $($version.Minor)" + $propertiesFileContent = $propertiesFileContent -replace "mavenPatchVersion\s+=\s+\d{1,}", "mavenPatchVersion = $($version.Build)" + Set-Content -Path $propertiesFilePath $propertiesFileContent } function Get-CurrentTelemetryVersion([string]$telemetryFilePath) { $telemetryFileContent = Get-Content -Path $telemetryFilePath -Raw if($telemetryFileContent -match "(\d{1,}\.\d{1,}\.\d{1,})") { - return $Matches[1] + return [version]::Parse($Matches[1]) } else { Write-Error "Invalid version number format" - return "" + return $null; } } -function Update-MinorVersionNumber([string]$currentVersion) { - if($currentVersion -match "(\d{1,})\.(\d{1,})\.(\d{1,})") { - [int]$minor = [convert]::ToInt32($Matches[2]) - $minor++; - $major = $Matches[1] - return "$major.$minor.0" - } else { - Write-Error "Invalid version number format $currentVersion" - return "" - } +function Update-MinorVersionNumber([version]$currentVersion) { + return [version]::new($currentVersion.Major, $currentVersion.Minor + 1, 0); } function Update-MinorVersion() { From 726f88edf407efebb9c6a6acd7e2ede3b01500dc Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 1 Dec 2020 16:06:52 -0500 Subject: [PATCH 11/17] - adds editor config --- .editorconfig | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..3bf6f4f2b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +[*.java] +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true \ No newline at end of file From 2b047ffdc750fd3b0726317153f69656c9fbbac7 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 2 Dec 2020 09:07:54 -0500 Subject: [PATCH 12/17] - fixes a bug where regex replacement on multithreading could cross wires --- .../graph/content/MSBatchRequestContent.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java b/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java index 85ae6347a..4b9fc0a9e 100644 --- a/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java +++ b/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java @@ -29,7 +29,7 @@ public class MSBatchRequestContent { /* * Creates Batch request content using list provided - * + * * @param batchRequestStepsArray List of batch steps for batching */ public MSBatchRequestContent(final List batchRequestStepsArray) { @@ -50,7 +50,7 @@ public MSBatchRequestContent() { /* * @param batchRequestStep Batch request step adding to batch content - * + * * @return true or false based on addition or no addition of batch request step * given */ @@ -81,7 +81,7 @@ public String addBatchRequestStep(final Request request, final String... arrayOf /* * @param requestId Id of Batch request step to be removed - * + * * @return true or false based on removal or no removal of batch request step * with given id */ @@ -116,18 +116,13 @@ public String getBatchRequestContent() { } private static final Pattern protocolAndHostReplacementPattern = Pattern.compile("(?i)^http[s]?:\\/\\/graph\\.microsoft\\.com\\/(?>v1\\.0|beta)\\/?"); // (?i) case insensitive - private Matcher protocolAndHostReplacementMatcher; // not static to avoid multithreading issues as the object is mutable private JsonObject getBatchRequestObjectFromRequestStep(final MSBatchRequestStep batchRequestStep) { final JsonObject contentmap = new JsonObject(); contentmap.add("id", new JsonPrimitive(batchRequestStep.getRequestId())); - if(protocolAndHostReplacementMatcher == null) { - protocolAndHostReplacementMatcher = protocolAndHostReplacementPattern.matcher(batchRequestStep.getRequest().url().toString()); - } else { - protocolAndHostReplacementMatcher = protocolAndHostReplacementMatcher.reset(batchRequestStep.getRequest().url().toString()); - } + final Matcher protocolAndHostReplacementMatcher = protocolAndHostReplacementPattern.matcher(batchRequestStep.getRequest().url().toString()); - final String url = protocolAndHostReplacementMatcher.replaceAll(""); + final String url = protocolAndHostReplacementMatcher.replaceAll(""); contentmap.add("url", new JsonPrimitive(url)); contentmap.add("method", new JsonPrimitive(batchRequestStep.getRequest().method().toString())); @@ -186,5 +181,5 @@ private JsonObject requestBodyToJSONObject(final Request request) throws IOExcep else return requestBodyElement.getAsJsonObject(); } - + } From 88eaadf95d38f2f77bda7fed30c6c112a7b2ad77 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 3 Dec 2020 09:19:35 -0500 Subject: [PATCH 13/17] - updates link to getting started and adds link to javadoc --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 53619c747..a706ea649 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # Microsoft Graph Core SDK for Java -Get started with the Microsoft Graph Core SDK for Java by integrating the [Microsoft Graph API](https://graph.microsoft.io/en-us/getting-started) into your Java and Android application! +Get started with the Microsoft Graph Core SDK for Java by integrating the [Microsoft Graph API](https://developer.microsoft.com/en-us/graph/get-started/java) into your Java and Android application! You can also have a look at the [Javadoc](https://docs.microsoft.com/en-us/java/api/com.microsoft.graph.httpcore?view=graph-core-java) ## Samples and usage guide From 89a6d3bb63d52d1408d74cd9b4cc7e199503f6ca Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 9 Dec 2020 08:32:32 -0500 Subject: [PATCH 14/17] - adds codeowners for the repository --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 000000000..10a1e9e17 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @baywet @ddyett @MichaelMainer @nikithauc @zengin \ No newline at end of file From 790a976957b73152db8e3e4ada9ebef36dcec4d2 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 10 Dec 2020 12:41:08 -0500 Subject: [PATCH 15/17] - adds android api version in telemetry handler --- .../graph/httpcore/TelemetryHandler.java | 42 ++++++++++++--- .../graph/httpcore/TelemetryHandlerTest.java | 54 +++++++++---------- 2 files changed, 63 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java index 51d3569c5..889b91f68 100644 --- a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java @@ -1,6 +1,7 @@ package com.microsoft.graph.httpcore; import java.io.IOException; +import java.lang.reflect.Field; import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions; @@ -13,21 +14,23 @@ public class TelemetryHandler implements Interceptor{ public static final String SDK_VERSION = "SdkVersion"; public static final String VERSION = "v1.0.5"; public static final String GRAPH_VERSION_PREFIX = "graph-java-core"; - public static final String JAVA_VERSION_PREFIX = "java"; + public static final String JAVA_VERSION_PREFIX = "java"; + public static final String ANDROID_VERSION_PREFIX = "android"; public static final String CLIENT_REQUEST_ID = "client-request-id"; @Override public Response intercept(Chain chain) throws IOException { - Request request = chain.request(); - Request.Builder telemetryAddedBuilder = request.newBuilder(); + final Request request = chain.request(); + final Request.Builder telemetryAddedBuilder = request.newBuilder(); TelemetryOptions telemetryOptions = request.tag(TelemetryOptions.class); if(telemetryOptions == null) telemetryOptions = new TelemetryOptions(); - String featureUsage = "(featureUsage=" + telemetryOptions.getFeatureUsage() + ")"; - String javaVersion = System.getProperty("java.version"); - String sdkversion_value = GRAPH_VERSION_PREFIX + "/" + VERSION + " " + featureUsage + " " + JAVA_VERSION_PREFIX + "/" + javaVersion; + final String featureUsage = "(featureUsage=" + telemetryOptions.getFeatureUsage() + ")"; + final String javaVersion = System.getProperty("java.version"); + final String androidVersion = getAndroidAPILevel(); + final String sdkversion_value = GRAPH_VERSION_PREFIX + "/" + VERSION + " " + featureUsage + " " + JAVA_VERSION_PREFIX + "/" + javaVersion + " " + ANDROID_VERSION_PREFIX + "/" + androidVersion; telemetryAddedBuilder.addHeader(SDK_VERSION, sdkversion_value); if(request.header(CLIENT_REQUEST_ID) == null) { @@ -37,4 +40,31 @@ public Response intercept(Chain chain) throws IOException { return chain.proceed(telemetryAddedBuilder.build()); } + private String androidAPILevel; + private String getAndroidAPILevel() { + if(androidAPILevel == null) { + androidAPILevel = getAndroidAPILevelInternal(); + } + return androidAPILevel; + } + private String getAndroidAPILevelInternal() { + try { + final Class buildClass = Class.forName("android.os.Build"); + final Class[] subclasses = buildClass.getDeclaredClasses(); + Class versionClass = null; + for(final Class subclass : subclasses) { + if(subclass.getName().endsWith("VERSION")) { + versionClass = subclass; + break; + } + } + final Field sdkVersionField = versionClass.getField("SDK_INT"); + final Object value = sdkVersionField.get(null); + final String valueStr = String.valueOf(value); + return valueStr == null || valueStr == "" ? "0" : valueStr; + } catch (IllegalAccessException | ClassNotFoundException | NoSuchFieldException ex) { + // we're not on android and return "0" to align with java version which returns "0" when running on android + return "0"; + } + } } diff --git a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java index deab260a4..036cc18e4 100644 --- a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java @@ -5,7 +5,6 @@ import java.io.IOException; -import org.junit.Ignore; import org.junit.Test; import okhttp3.Interceptor; @@ -13,60 +12,61 @@ import okhttp3.Request; import okhttp3.Response; -@Ignore public class TelemetryHandlerTest { @Test public void telemetryInitTest() { - TelemetryHandler telemetryHandler = new TelemetryHandler(); + final TelemetryHandler telemetryHandler = new TelemetryHandler(); assertNotNull(telemetryHandler); } - + @Test public void interceptTest() throws IOException { - String expectedHeader = TelemetryHandler.SDK_VERSION + TelemetryHandler.GRAPH_VERSION_PREFIX +"/" + final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" +TelemetryHandler.VERSION; - OkHttpClient client = HttpClients.createDefault(new ICoreAuthenticationProvider() { + final OkHttpClient client = HttpClients.createDefault(new ICoreAuthenticationProvider() { @Override public Request authenticateRequest(Request request) { return request; } }); - Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); - Response response = client.newCall(request).execute(); + final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); + final Response response = client.newCall(request).execute(); assertNotNull(response); - assertTrue(response.request().header("SdkVersion").contains(expectedHeader)); + assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); + assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(TelemetryHandler.ANDROID_VERSION_PREFIX)); + assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(TelemetryHandler.JAVA_VERSION_PREFIX)); } - + @Test public void arrayInterceptorsTest() throws IOException { - - AuthenticationHandler authenticationHandler = new AuthenticationHandler(new ICoreAuthenticationProvider() { - + + final AuthenticationHandler authenticationHandler = new AuthenticationHandler(new ICoreAuthenticationProvider() { + @Override public Request authenticateRequest(Request request) { return request; } }); - Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler(), authenticationHandler}; - OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - String expectedHeader = TelemetryHandler.SDK_VERSION + TelemetryHandler.GRAPH_VERSION_PREFIX +"/" + final Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler(), authenticationHandler}; + final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); + final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" +TelemetryHandler.VERSION; - Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); - Response response = client.newCall(request).execute(); + final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); + final Response response = client.newCall(request).execute(); assertNotNull(response); - assertTrue(response.request().header("SdkVersion").contains(expectedHeader)); + assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); } - + @Test public void arrayInterceptorEmptyTest() throws IOException { - Interceptor[] interceptors = null; - OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - String expectedHeader = TelemetryHandler.SDK_VERSION + TelemetryHandler.GRAPH_VERSION_PREFIX +"/" + final Interceptor[] interceptors = null; + final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); + final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" +TelemetryHandler.VERSION; - Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); - Response response = client.newCall(request).execute(); + final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); + final Response response = client.newCall(request).execute(); assertNotNull(response); - assertTrue(response.request().header("SdkVersion").contains(expectedHeader)); + assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); } - + } From 61ae79b2c1add59ac6980f660b0e52a8527a134e Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 10 Dec 2020 12:43:20 -0500 Subject: [PATCH 16/17] - bumps patch --- gradle.properties | 2 +- pom.xml | 2 +- readme.md | 4 ++-- .../java/com/microsoft/graph/httpcore/TelemetryHandler.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index 74406c825..17a8f7ac8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ mavenGroupId = com.microsoft.graph mavenArtifactId = microsoft-graph-core mavenMajorVersion = 1 mavenMinorVersion = 0 -mavenPatchVersion = 5 +mavenPatchVersion = 6 mavenArtifactSuffix = nightliesUrl = http://dl.bintray.com/MicrosoftGraph/Maven diff --git a/pom.xml b/pom.xml index b86d28dbe..dc77c1858 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ com.microsoft.graph microsoft-graph-core - 1.0.5 + 1.0.6 pom diff --git a/readme.md b/readme.md index a706ea649..b280482d9 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,7 @@ repositories { dependencies { // Include the sdk as a dependency - implementation 'com.microsoft.graph:microsoft-graph-core:1.0.5' + implementation 'com.microsoft.graph:microsoft-graph-core:1.0.6' } ``` @@ -32,7 +32,7 @@ Add the dependency in `dependencies` in pom.xml com.microsoft.graph microsoft-graph-core - 1.0.5 + 1.0.6 ``` diff --git a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java index 889b91f68..3729b5256 100644 --- a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java @@ -12,7 +12,7 @@ public class TelemetryHandler implements Interceptor{ public static final String SDK_VERSION = "SdkVersion"; - public static final String VERSION = "v1.0.5"; + public static final String VERSION = "v1.0.6"; public static final String GRAPH_VERSION_PREFIX = "graph-java-core"; public static final String JAVA_VERSION_PREFIX = "java"; public static final String ANDROID_VERSION_PREFIX = "android"; From 49a107bc78922f8b05723dd18cf75bf80f4ae248 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 14 Dec 2020 10:31:26 -0500 Subject: [PATCH 17/17] - space/tabs fix to make @zengin happy :) --- .../graph/httpcore/TelemetryHandler.java | 42 ++++---- .../graph/httpcore/TelemetryHandlerTest.java | 100 +++++++++--------- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java index 3729b5256..b5da60c3f 100644 --- a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java @@ -11,34 +11,34 @@ public class TelemetryHandler implements Interceptor{ - public static final String SDK_VERSION = "SdkVersion"; - public static final String VERSION = "v1.0.6"; - public static final String GRAPH_VERSION_PREFIX = "graph-java-core"; + public static final String SDK_VERSION = "SdkVersion"; + public static final String VERSION = "v1.0.6"; + public static final String GRAPH_VERSION_PREFIX = "graph-java-core"; public static final String JAVA_VERSION_PREFIX = "java"; public static final String ANDROID_VERSION_PREFIX = "android"; - public static final String CLIENT_REQUEST_ID = "client-request-id"; + public static final String CLIENT_REQUEST_ID = "client-request-id"; - @Override - public Response intercept(Chain chain) throws IOException { - final Request request = chain.request(); - final Request.Builder telemetryAddedBuilder = request.newBuilder(); + @Override + public Response intercept(Chain chain) throws IOException { + final Request request = chain.request(); + final Request.Builder telemetryAddedBuilder = request.newBuilder(); - TelemetryOptions telemetryOptions = request.tag(TelemetryOptions.class); - if(telemetryOptions == null) - telemetryOptions = new TelemetryOptions(); + TelemetryOptions telemetryOptions = request.tag(TelemetryOptions.class); + if(telemetryOptions == null) + telemetryOptions = new TelemetryOptions(); - final String featureUsage = "(featureUsage=" + telemetryOptions.getFeatureUsage() + ")"; - final String javaVersion = System.getProperty("java.version"); - final String androidVersion = getAndroidAPILevel(); - final String sdkversion_value = GRAPH_VERSION_PREFIX + "/" + VERSION + " " + featureUsage + " " + JAVA_VERSION_PREFIX + "/" + javaVersion + " " + ANDROID_VERSION_PREFIX + "/" + androidVersion; - telemetryAddedBuilder.addHeader(SDK_VERSION, sdkversion_value); + final String featureUsage = "(featureUsage=" + telemetryOptions.getFeatureUsage() + ")"; + final String javaVersion = System.getProperty("java.version"); + final String androidVersion = getAndroidAPILevel(); + final String sdkversion_value = GRAPH_VERSION_PREFIX + "/" + VERSION + " " + featureUsage + " " + JAVA_VERSION_PREFIX + "/" + javaVersion + " " + ANDROID_VERSION_PREFIX + "/" + androidVersion; + telemetryAddedBuilder.addHeader(SDK_VERSION, sdkversion_value); - if(request.header(CLIENT_REQUEST_ID) == null) { - telemetryAddedBuilder.addHeader(CLIENT_REQUEST_ID, telemetryOptions.getClientRequestId()); - } + if(request.header(CLIENT_REQUEST_ID) == null) { + telemetryAddedBuilder.addHeader(CLIENT_REQUEST_ID, telemetryOptions.getClientRequestId()); + } - return chain.proceed(telemetryAddedBuilder.build()); - } + return chain.proceed(telemetryAddedBuilder.build()); + } private String androidAPILevel; private String getAndroidAPILevel() { diff --git a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java index 036cc18e4..8fcffc3df 100644 --- a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java @@ -13,60 +13,60 @@ import okhttp3.Response; public class TelemetryHandlerTest { - @Test - public void telemetryInitTest() { - final TelemetryHandler telemetryHandler = new TelemetryHandler(); - assertNotNull(telemetryHandler); - } + @Test + public void telemetryInitTest() { + final TelemetryHandler telemetryHandler = new TelemetryHandler(); + assertNotNull(telemetryHandler); + } - @Test - public void interceptTest() throws IOException { - final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" - +TelemetryHandler.VERSION; - final OkHttpClient client = HttpClients.createDefault(new ICoreAuthenticationProvider() { - @Override - public Request authenticateRequest(Request request) { - return request; - } - }); - final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); - final Response response = client.newCall(request).execute(); - assertNotNull(response); - assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); - assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(TelemetryHandler.ANDROID_VERSION_PREFIX)); - assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(TelemetryHandler.JAVA_VERSION_PREFIX)); - } + @Test + public void interceptTest() throws IOException { + final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" + +TelemetryHandler.VERSION; + final OkHttpClient client = HttpClients.createDefault(new ICoreAuthenticationProvider() { + @Override + public Request authenticateRequest(Request request) { + return request; + } + }); + final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); + final Response response = client.newCall(request).execute(); + assertNotNull(response); + assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); + assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(TelemetryHandler.ANDROID_VERSION_PREFIX)); + assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(TelemetryHandler.JAVA_VERSION_PREFIX)); + } - @Test - public void arrayInterceptorsTest() throws IOException { + @Test + public void arrayInterceptorsTest() throws IOException { - final AuthenticationHandler authenticationHandler = new AuthenticationHandler(new ICoreAuthenticationProvider() { + final AuthenticationHandler authenticationHandler = new AuthenticationHandler(new ICoreAuthenticationProvider() { - @Override - public Request authenticateRequest(Request request) { - return request; - } - }); - final Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler(), authenticationHandler}; - final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" - +TelemetryHandler.VERSION; - final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); - final Response response = client.newCall(request).execute(); - assertNotNull(response); - assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); - } + @Override + public Request authenticateRequest(Request request) { + return request; + } + }); + final Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler(), authenticationHandler}; + final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); + final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" + +TelemetryHandler.VERSION; + final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); + final Response response = client.newCall(request).execute(); + assertNotNull(response); + assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); + } - @Test - public void arrayInterceptorEmptyTest() throws IOException { - final Interceptor[] interceptors = null; - final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" - +TelemetryHandler.VERSION; - final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); - final Response response = client.newCall(request).execute(); - assertNotNull(response); - assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); - } + @Test + public void arrayInterceptorEmptyTest() throws IOException { + final Interceptor[] interceptors = null; + final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); + final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" + +TelemetryHandler.VERSION; + final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); + final Response response = client.newCall(request).execute(); + assertNotNull(response); + assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); + } }