Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'
}
Expand All @@ -35,7 +37,7 @@ Add the dependency in `dependencies` in pom.xml
<!-- Include the sdk as a dependency -->
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-core</artifactId>
<version>2.0.3</version>
<version>2.0.4</version>
<!-- This dependency is only needed if you are using the TokenCrendentialAuthProvider -->
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/com/microsoft/graph/http/CoreHttpProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,7 +76,7 @@ public class CoreHttpProvider implements IHttpProvider<Request> {
/**
* 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
*/
Expand Down Expand Up @@ -295,14 +297,10 @@ public <Result, Body> 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)) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/microsoft/graph/serializer/GsonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ public TimeOfDay deserialize(final JsonElement json,
}
};

final JsonSerializer<TimeOfDay> timeOfDayJsonSerializer = new JsonSerializer<TimeOfDay>() {
@Override
public JsonElement serialize(final TimeOfDay src,
final Type typeOfSrc,
final JsonSerializationContext context) {
return new JsonPrimitive(src.toString());
}
};

final JsonDeserializer<Boolean> booleanJsonDeserializer = new JsonDeserializer<Boolean>() {
@Override
public Boolean deserialize(final JsonElement json,
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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));
}
}