diff --git a/build.gradle b/build.gradle index 1154f45..9f3cb1e 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ sourceCompatibility = 11 targetCompatibility = 11 version = '1.0' compileJava.options.encoding = 'UTF-8' -compileTestJava.options.encoding = "UTF-8" +compileTestJava.options.encoding = 'UTF-8' repositories { mavenLocal() @@ -18,22 +18,23 @@ repositories { } dependencies { - implementation 'mysql:mysql-connector-java:8.0.30' - implementation 'org.apache.httpcomponents:httpclient:4.5.13' + implementation 'mysql:mysql-connector-java:8.0.32' + implementation 'org.apache.httpcomponents:httpclient:4.5.14' implementation 'com.googlecode.json-simple:json-simple:1.1.1' - implementation 'com.google.code.gson:gson:2.10' - implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.896') - implementation 'com.amazonaws:aws-java-sdk-s3:1.12.332' - implementation 'com.google.api-client:google-api-client:2.0.0' - implementation 'com.google.oauth-client:google-oauth-client-jetty:1.34.1' + implementation 'com.google.code.gson:gson:2.10.1' + implementation platform('com.amazonaws:aws-java-sdk-bom:1.12.429') + implementation 'com.amazonaws:aws-java-sdk-s3:1.12.429' + implementation 'com.google.auth:google-auth-library-oauth2-http:1.16.0' + implementation 'com.google.api-client:google-api-client:2.2.0' implementation 'com.google.apis:google-api-services-calendar:v3-rev20220715-2.0.0' + implementation 'com.google.guava:guava:31.1-jre' + implementation 'commons-cli:commons-cli:1.5.0' + implementation 'net.sourceforge.argparse4j:argparse4j:0.9.0' + implementation 'org.apache.logging.log4j:log4j-api:2.20.0' + implementation 'org.apache.logging.log4j:log4j-core:2.20.0' + implementation 'javax.xml.bind:jaxb-api:2.3.1' testImplementation 'junit:junit:4.13.2' - compile 'com.google.guava:guava:31.1-jre' - compile group: 'commons-cli', name: 'commons-cli', version: '1.3.1' - compile group: 'net.sourceforge.argparse4j', name: 'argparse4j', version: '0.8.1' - compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.14.1' - compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.14.1' - compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.4' + testImplementation 'org.testng:testng:7.7.0' } jar { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index af1a2e9..2092c33 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Tue May 26 17:58:07 CEST 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/src/main/java/de/jeyp91/googlecalendar/GoogleCalendarConnector.java b/src/main/java/de/jeyp91/googlecalendar/GoogleCalendarConnector.java index 095234e..47852fa 100644 --- a/src/main/java/de/jeyp91/googlecalendar/GoogleCalendarConnector.java +++ b/src/main/java/de/jeyp91/googlecalendar/GoogleCalendarConnector.java @@ -1,12 +1,13 @@ package de.jeyp91.googlecalendar; -import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.JsonFactory; import com.google.api.client.json.gson.GsonFactory; -import com.google.api.services.calendar.CalendarScopes; import com.google.api.services.calendar.Calendar; +import com.google.api.services.calendar.CalendarScopes; +import com.google.auth.http.HttpCredentialsAdapter; +import com.google.auth.oauth2.GoogleCredentials; import java.io.*; import java.util.Collections; @@ -27,20 +28,23 @@ public class GoogleCalendarConnector { * @return An authorized Credential object. * @throws IOException If the Google_Credentials.json file cannot be found. */ - private static GoogleCredential getCredentials() throws IOException { + private static GoogleCredentials getGoogleCredentials() throws IOException { InputStream in = GoogleCalendarConnector.class.getResourceAsStream(SERVICE_CREDENTIALS_FILE_PATH); - return GoogleCredential.fromStream(in) + GoogleCredentials credentials = GoogleCredentials.fromStream(in) .createScoped(Collections.singleton(CalendarScopes.CALENDAR)); + credentials.refreshIfExpired(); + return credentials; } public static com.google.api.services.calendar.Calendar getSerivce() { - - com.google.api.services.calendar.Calendar service = null; + Calendar service = null; final NetHttpTransport HTTP_TRANSPORT; try { + // Build a new authorized API client service. HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); - service = new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials()) + service = new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, null) + .setHttpRequestInitializer(new HttpCredentialsAdapter(getGoogleCredentials())) .setApplicationName(APPLICATION_NAME) .build();