diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml
new file mode 100644
index 000000000..4bf6cde65
--- /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@v2.1.6
+ with:
+ path: ~/.sonar/cache
+ key: ${{ runner.os }}-sonar
+ restore-keys: ${{ runner.os }}-sonar
+ - name: Cache Gradle packages
+ uses: actions/cache@v2.1.6
+ 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..504846f20 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.2.0"
}
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
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..236c359b5 100644
--- a/readme.md
+++ b/readme.md
@@ -1,5 +1,7 @@
# Microsoft Graph Core SDK for Java
+[](https://search.maven.org/artifact/com.microsoft.graph/microsoft-graph-core) [](https://sonarcloud.io/dashboard?id=microsoftgraph_msgraph-sdk-java-core) [](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
@@ -20,7 +22,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 +37,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/http/CoreHttpProvider.java b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java
index 8be1022b7..4b53f5bbe 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.name())) {
scanner.useDelimiter(endOfFile);
if (scanner.hasNext()) {
return scanner.next();
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
*/
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));
+ }
}