Skip to content

Commit e7ff35e

Browse files
authored
Merge pull request #221 from microsoftgraph/dev
2.0.4 release
2 parents a3745a3 + 891b7bf commit e7ff35e

File tree

8 files changed

+80
-16
lines changed

8 files changed

+80
-16
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Static analysis with SonarCloud
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- dev
7+
- feature/v2
8+
pull_request:
9+
types: [opened, synchronize, reopened]
10+
jobs:
11+
build:
12+
name: Build
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
18+
- name: Set up JDK 11
19+
uses: actions/setup-java@v1
20+
with:
21+
java-version: 11
22+
- name: Cache SonarCloud packages
23+
uses: actions/[email protected]
24+
with:
25+
path: ~/.sonar/cache
26+
key: ${{ runner.os }}-sonar
27+
restore-keys: ${{ runner.os }}-sonar
28+
- name: Cache Gradle packages
29+
uses: actions/[email protected]
30+
with:
31+
path: ~/.gradle/caches
32+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
33+
restore-keys: ${{ runner.os }}-gradle
34+
- name: Build and analyze
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
37+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
38+
run: ./gradlew build sonarqube --info

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ plugins {
1515
id 'signing'
1616
id 'jacoco'
1717
id 'com.github.spotbugs' version '4.7.1'
18+
id "org.sonarqube" version "3.2.0"
1819
}
1920

2021
java {
@@ -88,6 +89,14 @@ def pomConfig = {
8889
}
8990
}
9091

92+
sonarqube {
93+
properties {
94+
property "sonar.projectKey", "msgraph-sdk-java-core"
95+
property "sonar.organization", "microsoftgraph"
96+
property "sonar.host.url", "https://sonarcloud.io"
97+
}
98+
}
99+
91100
//Publishing tasks-
92101
//Maven Central Snapshot: publishSnapshotPublicationToMavenRepository
93102
//Maven Central Release: publishMavenCentralReleasePublicationToMaven2Repository

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mavenGroupId = com.microsoft.graph
2525
mavenArtifactId = microsoft-graph-core
2626
mavenMajorVersion = 2
2727
mavenMinorVersion = 0
28-
mavenPatchVersion = 3
28+
mavenPatchVersion = 4
2929
mavenArtifactSuffix =
3030

3131
#These values are used to run functional tests

readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Microsoft Graph Core SDK for Java
22

3+
[![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)
4+
35
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)
46

57
## Samples and usage guide
@@ -20,7 +22,7 @@ repositories {
2022
2123
dependencies {
2224
// Include the sdk as a dependency
23-
implementation 'com.microsoft.graph:microsoft-graph-core:2.0.3'
25+
implementation 'com.microsoft.graph:microsoft-graph-core:2.0.4'
2426
// This dependency is only needed if you are using the TokenCrendentialAuthProvider
2527
implementation 'com.azure:azure-identity:1.2.5'
2628
}
@@ -35,7 +37,7 @@ Add the dependency in `dependencies` in pom.xml
3537
<!-- Include the sdk as a dependency -->
3638
<groupId>com.microsoft.graph</groupId>
3739
<artifactId>microsoft-graph-core</artifactId>
38-
<version>2.0.3</version>
40+
<version>2.0.4</version>
3941
<!-- This dependency is only needed if you are using the TokenCrendentialAuthProvider -->
4042
<groupId>com.azure</groupId>
4143
<artifactId>azure-identity</artifactId>

src/main/java/com/microsoft/graph/http/CoreHttpProvider.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import java.io.OutputStream;
4141
import java.io.UnsupportedEncodingException;
4242
import java.net.URL;
43+
import java.nio.charset.Charset;
44+
import java.nio.charset.StandardCharsets;
4345
import java.util.List;
4446
import java.util.Locale;
4547
import java.util.Map;
@@ -74,7 +76,7 @@ public class CoreHttpProvider implements IHttpProvider<Request> {
7476
/**
7577
* The encoding type for getBytes
7678
*/
77-
private static final String JSON_ENCODING = "UTF-8";
79+
private static final Charset JSON_ENCODING = StandardCharsets.UTF_8;
7880
/**
7981
* The content type for JSON responses
8082
*/
@@ -295,14 +297,10 @@ public <Result, Body> Request getHttpRequest(@Nonnull final IHttpRequest request
295297
} else {
296298
logger.logDebug("Sending " + serializable.getClass().getName() + " as request body");
297299
final String serializeObject = serializer.serializeObject(serializable);
298-
try {
299-
bytesToWrite = serializeObject.getBytes(JSON_ENCODING);
300-
} catch (final UnsupportedEncodingException ex) {
301-
final ClientException clientException = new ClientException("Unsupported encoding problem: ",
302-
ex);
303-
logger.logError("Unsupported encoding problem: " + ex.getMessage(), ex);
304-
throw clientException;
305-
}
300+
if(serializeObject == null) {
301+
throw new ClientException("Error during serialization of request body, the result was null", null);
302+
}
303+
bytesToWrite = serializeObject.getBytes(JSON_ENCODING);
306304

307305
// If the user hasn't specified a Content-Type for the request
308306
if (!hasHeader(requestHeaders, CONTENT_TYPE_HEADER_NAME)) {
@@ -593,9 +591,8 @@ private Request convertIHttpRequestToOkHttpRequest(IHttpRequest request) {
593591
@Nullable
594592
public static String streamToString(@Nonnull final InputStream input) {
595593
Objects.requireNonNull(input, "parameter input cannot be null");
596-
final String httpStreamEncoding = "UTF-8";
597594
final String endOfFile = "\\A";
598-
try (final Scanner scanner = new Scanner(input, httpStreamEncoding)) {
595+
try (final Scanner scanner = new Scanner(input, JSON_ENCODING.name())) {
599596
scanner.useDelimiter(endOfFile);
600597
if (scanner.hasNext()) {
601598
return scanner.next();

src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class TelemetryHandler implements Interceptor{
2525
/**
2626
* Current SDK version
2727
*/
28-
public static final String VERSION = "v2.0.3";
28+
public static final String VERSION = "v2.0.4";
2929
/**
3030
* Verion prefix
3131
*/

src/main/java/com/microsoft/graph/serializer/GsonFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,15 @@ public TimeOfDay deserialize(final JsonElement json,
256256
}
257257
};
258258

259+
final JsonSerializer<TimeOfDay> timeOfDayJsonSerializer = new JsonSerializer<TimeOfDay>() {
260+
@Override
261+
public JsonElement serialize(final TimeOfDay src,
262+
final Type typeOfSrc,
263+
final JsonSerializationContext context) {
264+
return new JsonPrimitive(src.toString());
265+
}
266+
};
267+
259268
final JsonDeserializer<Boolean> booleanJsonDeserializer = new JsonDeserializer<Boolean>() {
260269
@Override
261270
public Boolean deserialize(final JsonElement json,
@@ -344,6 +353,7 @@ public Float deserialize(final JsonElement json,
344353
.registerTypeHierarchyAdapter(BaseCollectionPage.class, collectionPageDeserializer)
345354
.registerTypeHierarchyAdapter(BaseCollectionResponse.class, collectionResponseDeserializer)
346355
.registerTypeAdapter(TimeOfDay.class, timeOfDayJsonDeserializer)
356+
.registerTypeAdapter(TimeOfDay.class, timeOfDayJsonSerializer)
347357
.registerTypeAdapterFactory(new FallbackTypeAdapterFactory(logger))
348358
.create();
349359
}

src/test/java/com/microsoft/graph/serializer/TimeOfDayTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.microsoft.graph.serializer;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.mockito.Mockito.mock;
45

56
import org.junit.jupiter.api.Test;
67

78
import com.microsoft.graph.core.TimeOfDay;
9+
import com.microsoft.graph.logger.ILogger;
810

911
public class TimeOfDayTests {
1012

@@ -43,5 +45,11 @@ public void testTimeOfDayDeserializerWithFraction() throws Exception{
4345
assertEquals(30, time.getMinute());
4446
assertEquals(44, time.getSecond());
4547
}
46-
48+
@Test
49+
public void testTimeOfDaySerialization() throws Exception {
50+
final TimeOfDay time = new TimeOfDay(12, 30, 44);
51+
final ILogger logger = mock(ILogger.class);
52+
final ISerializer serializer = new DefaultSerializer(logger);
53+
assertEquals("\"12:30:44\"", serializer.serializeObject(time));
54+
}
4755
}

0 commit comments

Comments
 (0)