From 8fb77c4d8b55aca828ad88306abcfedacf5a24e1 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 1 Jun 2021 14:13:09 -0400 Subject: [PATCH 1/8] - switches to the charset constant instead of a string --- .../graph/http/CoreHttpProvider.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java index 8be1022b7..430491f12 100644 --- a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java +++ b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java @@ -40,6 +40,8 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URL; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Locale; import java.util.Map; @@ -74,7 +76,7 @@ public class CoreHttpProvider implements IHttpProvider { /** * The encoding type for getBytes */ - private static final String JSON_ENCODING = "UTF-8"; + private static final Charset JSON_ENCODING = StandardCharsets.UTF_8; /** * The content type for JSON responses */ @@ -295,14 +297,10 @@ public Request getHttpRequest(@Nonnull final IHttpRequest request } else { logger.logDebug("Sending " + serializable.getClass().getName() + " as request body"); final String serializeObject = serializer.serializeObject(serializable); - try { - bytesToWrite = serializeObject.getBytes(JSON_ENCODING); - } catch (final UnsupportedEncodingException ex) { - final ClientException clientException = new ClientException("Unsupported encoding problem: ", - ex); - logger.logError("Unsupported encoding problem: " + ex.getMessage(), ex); - throw clientException; - } + if(serializeObject == null) { + throw new ClientException("Error during serialization of request body, the result was null", null); + } + bytesToWrite = serializeObject.getBytes(JSON_ENCODING); // If the user hasn't specified a Content-Type for the request if (!hasHeader(requestHeaders, CONTENT_TYPE_HEADER_NAME)) { @@ -593,9 +591,8 @@ private Request convertIHttpRequestToOkHttpRequest(IHttpRequest request) { @Nullable public static String streamToString(@Nonnull final InputStream input) { Objects.requireNonNull(input, "parameter input cannot be null"); - final String httpStreamEncoding = "UTF-8"; final String endOfFile = "\\A"; - try (final Scanner scanner = new Scanner(input, httpStreamEncoding)) { + try (final Scanner scanner = new Scanner(input, JSON_ENCODING)) { scanner.useDelimiter(endOfFile); if (scanner.hasNext()) { return scanner.next(); From 456d57c62f853a534364f8a0557ce992d81d0a9e Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 1 Jun 2021 14:21:26 -0400 Subject: [PATCH 2/8] - fixes a bug where the scanner class doesn't have a charset CTOR on android --- src/main/java/com/microsoft/graph/http/CoreHttpProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java index 430491f12..4b53f5bbe 100644 --- a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java +++ b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java @@ -592,7 +592,7 @@ private Request convertIHttpRequestToOkHttpRequest(IHttpRequest request) { public static String streamToString(@Nonnull final InputStream input) { Objects.requireNonNull(input, "parameter input cannot be null"); final String endOfFile = "\\A"; - try (final Scanner scanner = new Scanner(input, JSON_ENCODING)) { + try (final Scanner scanner = new Scanner(input, JSON_ENCODING.name())) { scanner.useDelimiter(endOfFile); if (scanner.hasNext()) { return scanner.next(); From 3925b79a683dfc45af225cb6fe7176db552fdcdd Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 1 Jun 2021 14:46:46 -0400 Subject: [PATCH 3/8] - fixes #217 a bug where timeofday would not be serialized properly --- .../com/microsoft/graph/serializer/GsonFactory.java | 10 ++++++++++ .../com/microsoft/graph/serializer/TimeOfDayTests.java | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/graph/serializer/GsonFactory.java b/src/main/java/com/microsoft/graph/serializer/GsonFactory.java index d4da62625..4a040cc99 100644 --- a/src/main/java/com/microsoft/graph/serializer/GsonFactory.java +++ b/src/main/java/com/microsoft/graph/serializer/GsonFactory.java @@ -256,6 +256,15 @@ public TimeOfDay deserialize(final JsonElement json, } }; + final JsonSerializer timeOfDayJsonSerializer = new JsonSerializer() { + @Override + public JsonElement serialize(final TimeOfDay src, + final Type typeOfSrc, + final JsonSerializationContext context) { + return new JsonPrimitive(src.toString()); + } + }; + final JsonDeserializer booleanJsonDeserializer = new JsonDeserializer() { @Override public Boolean deserialize(final JsonElement json, @@ -344,6 +353,7 @@ public Float deserialize(final JsonElement json, .registerTypeHierarchyAdapter(BaseCollectionPage.class, collectionPageDeserializer) .registerTypeHierarchyAdapter(BaseCollectionResponse.class, collectionResponseDeserializer) .registerTypeAdapter(TimeOfDay.class, timeOfDayJsonDeserializer) + .registerTypeAdapter(TimeOfDay.class, timeOfDayJsonSerializer) .registerTypeAdapterFactory(new FallbackTypeAdapterFactory(logger)) .create(); } diff --git a/src/test/java/com/microsoft/graph/serializer/TimeOfDayTests.java b/src/test/java/com/microsoft/graph/serializer/TimeOfDayTests.java index 8a3f6234e..288c2953c 100644 --- a/src/test/java/com/microsoft/graph/serializer/TimeOfDayTests.java +++ b/src/test/java/com/microsoft/graph/serializer/TimeOfDayTests.java @@ -1,10 +1,12 @@ package com.microsoft.graph.serializer; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; import org.junit.jupiter.api.Test; import com.microsoft.graph.core.TimeOfDay; +import com.microsoft.graph.logger.ILogger; public class TimeOfDayTests { @@ -43,5 +45,11 @@ public void testTimeOfDayDeserializerWithFraction() throws Exception{ assertEquals(30, time.getMinute()); assertEquals(44, time.getSecond()); } - + @Test + public void testTimeOfDaySerialization() throws Exception { + final TimeOfDay time = new TimeOfDay(12, 30, 44); + final ILogger logger = mock(ILogger.class); + final ISerializer serializer = new DefaultSerializer(logger); + assertEquals("\"12:30:44\"", serializer.serializeObject(time)); + } } From aea1f2739aa2a8ba1dd5e53fd083c52b0b45bbae Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 1 Jun 2021 14:53:36 -0400 Subject: [PATCH 4/8] - bumps patch version --- gradle.properties | 2 +- readme.md | 4 ++-- .../java/com/microsoft/graph/httpcore/TelemetryHandler.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index f3c38535b..2e7cee095 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ mavenGroupId = com.microsoft.graph mavenArtifactId = microsoft-graph-core mavenMajorVersion = 2 mavenMinorVersion = 0 -mavenPatchVersion = 3 +mavenPatchVersion = 4 mavenArtifactSuffix = #These values are used to run functional tests diff --git a/readme.md b/readme.md index 815a9d2af..ac26cbe1d 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:2.0.3' + implementation 'com.microsoft.graph:microsoft-graph-core:2.0.4' // This dependency is only needed if you are using the TokenCrendentialAuthProvider implementation 'com.azure:azure-identity:1.2.5' } @@ -35,7 +35,7 @@ Add the dependency in `dependencies` in pom.xml com.microsoft.graph microsoft-graph-core - 2.0.3 + 2.0.4 com.azure azure-identity diff --git a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java index a8f18be66..ddc7ccdcf 100644 --- a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java @@ -25,7 +25,7 @@ public class TelemetryHandler implements Interceptor{ /** * Current SDK version */ - public static final String VERSION = "v2.0.3"; + public static final String VERSION = "v2.0.4"; /** * Verion prefix */ From f2b8199041bd5c1ec44208be9a649b52d6909065 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 12 Feb 2021 13:22:07 -0500 Subject: [PATCH 5/8] - adds sonarcloud configuration --- .github/workflows/sonarcloud.yml | 38 ++++++++++++++++++++++++++++++++ build.gradle | 9 ++++++++ 2 files changed, 47 insertions(+) create mode 100644 .github/workflows/sonarcloud.yml diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml new file mode 100644 index 000000000..038def4a6 --- /dev/null +++ b/.github/workflows/sonarcloud.yml @@ -0,0 +1,38 @@ +name: Static analysis with SonarCloud +on: + push: + branches: + - master + - dev + - feature/v2 + pull_request: + types: [opened, synchronize, reopened] +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Cache SonarCloud packages + uses: actions/cache@v1 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages + uses: actions/cache@v1 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew build sonarqube --info \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7d4be0145..756a0dd56 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,7 @@ plugins { id 'signing' id 'jacoco' id 'com.github.spotbugs' version '4.7.1' + id "org.sonarqube" version "3.1.1" } java { @@ -88,6 +89,14 @@ def pomConfig = { } } +sonarqube { + properties { + property "sonar.projectKey", "msgraph-sdk-java-core" + property "sonar.organization", "microsoftgraph" + property "sonar.host.url", "https://sonarcloud.io" + } +} + //Publishing tasks- //Maven Central Snapshot: publishSnapshotPublicationToMavenRepository //Maven Central Release: publishMavenCentralReleasePublicationToMaven2Repository From b4a7d3b511102c9802454fa9a218c08a151440bc Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 1 Jun 2021 15:05:16 -0400 Subject: [PATCH 6/8] - adds badges for download and sonarcloud to readme --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 815a9d2af..8a4b26bfb 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,7 @@ # Microsoft Graph Core SDK for Java +[![Download](https://img.shields.io/maven-central/v/com.microsoft.graph/microsoft-graph-core.svg)](https://search.maven.org/artifact/com.microsoft.graph/microsoft-graph-core) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=microsoftgraph_msgraph-sdk-java-core&metric=coverage)](https://sonarcloud.io/dashboard?id=microsoftgraph_msgraph-sdk-java-core) [![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=microsoftgraph_msgraph-sdk-java-core&metric=alert_status)](https://sonarcloud.io/dashboard?id=microsoftgraph_msgraph-sdk-java-core) + 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 64bf6b06b01c4b54494a4e39752c187fdcd2a9ea Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Jun 2021 05:15:26 +0000 Subject: [PATCH 7/8] Bump org.sonarqube from 3.1.1 to 3.2.0 Bumps org.sonarqube from 3.1.1 to 3.2.0. --- updated-dependencies: - dependency-name: org.sonarqube dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 756a0dd56..504846f20 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ plugins { id 'signing' id 'jacoco' id 'com.github.spotbugs' version '4.7.1' - id "org.sonarqube" version "3.1.1" + id "org.sonarqube" version "3.2.0" } java { From 869f22a077fb3fed15f326195cc386fee0bdc967 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Jun 2021 05:25:39 +0000 Subject: [PATCH 8/8] Bump actions/cache from 1 to 2.1.6 Bumps [actions/cache](https://github.com/actions/cache) from 1 to 2.1.6. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v1...v2.1.6) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sonarcloud.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 038def4a6..4bf6cde65 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -20,13 +20,13 @@ jobs: with: java-version: 11 - name: Cache SonarCloud packages - uses: actions/cache@v1 + uses: actions/cache@v2.1.6 with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - name: Cache Gradle packages - uses: actions/cache@v1 + uses: actions/cache@v2.1.6 with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}