You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2019/06/17 15:47:41 UTC
[jclouds] branch master updated: JCLOUDS-1166: Relocate the gson
internal packge to be able to keep using it (#35)
This is an automated email from the ASF dual-hosted git repository.
nacx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jclouds.git
The following commit(s) were added to refs/heads/master by this push:
new b8606a1 JCLOUDS-1166: Relocate the gson internal packge to be able to keep using it (#35)
b8606a1 is described below
commit b8606a10ddb0f22628935b317267e1378b8fba3d
Author: Ignasi Barrera <na...@apache.org>
AuthorDate: Mon Jun 17 17:43:29 2019 +0200
JCLOUDS-1166: Relocate the gson internal packge to be able to keep using it (#35)
* JCLOUDS-1166: Relocate the gson internal packge to be able to keep using it
* Fixes
* Fix import order and shaded jar
* More fixes
* Proper dependency configuration
* Fix typos
* Bring back duplicate exclusions
---
.gitignore | 3 +
.../org/jclouds/chef/config/ChefParserModule.java | 2 +-
core/pom.xml | 5 +-
.../java/org/jclouds/json/config/GsonModule.java | 6 +-
...ConstructorAndReflectiveTypeAdapterFactory.java | 6 +-
.../NullFilteringTypeAdapterFactories.java | 29 ++++----
.../json/internal/NullHackJsonLiteralAdapter.java | 3 +-
...tructorAndReflectiveTypeAdapterFactoryTest.java | 4 +-
gson/pom.xml | 81 ++++++++++++++++++++++
pom.xml | 1 +
project/pom.xml | 49 +++++++++++++
resources/checkstyle.xml | 2 +-
12 files changed, 163 insertions(+), 28 deletions(-)
diff --git a/.gitignore b/.gitignore
index 92c0e88..2b1207e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,7 +19,10 @@ atlassian-ide-plugin.xml
.java-version
.factorypath
.apt_generated
+.apt_generated_tests
.checkstyle
nb-configuration.xml
nbactions.xml
/.nb-gradle/
+dependency-reduced-pom.xml
+.vscode
diff --git a/apis/chef/src/main/java/org/jclouds/chef/config/ChefParserModule.java b/apis/chef/src/main/java/org/jclouds/chef/config/ChefParserModule.java
index da4084d..fac073b 100644
--- a/apis/chef/src/main/java/org/jclouds/chef/config/ChefParserModule.java
+++ b/apis/chef/src/main/java/org/jclouds/chef/config/ChefParserModule.java
@@ -37,6 +37,7 @@ import org.jclouds.crypto.Crypto;
import org.jclouds.crypto.Pems;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
+import org.jclouds.json.gson.internal.JsonReaderInternalAccess;
import org.jclouds.json.internal.NullFilteringTypeAdapterFactories;
import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.MapTypeAdapterFactory;
import org.jclouds.json.internal.NullHackJsonLiteralAdapter;
@@ -53,7 +54,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapter;
-import com.google.gson.internal.JsonReaderInternalAccess;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.inject.AbstractModule;
diff --git a/core/pom.xml b/core/pom.xml
index cfa23c6..674b93a 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -78,9 +78,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>2.5</version>
+ <groupId>org.apache.jclouds</groupId>
+ <artifactId>jclouds-gson</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
diff --git a/core/src/main/java/org/jclouds/json/config/GsonModule.java b/core/src/main/java/org/jclouds/json/config/GsonModule.java
index 7b8bd0c..ebe8cf1 100644
--- a/core/src/main/java/org/jclouds/json/config/GsonModule.java
+++ b/core/src/main/java/org/jclouds/json/config/GsonModule.java
@@ -37,6 +37,9 @@ import org.jclouds.domain.JsonBall;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.json.Json;
import org.jclouds.json.SerializedNames;
+import org.jclouds.json.gson.internal.ConstructorConstructor;
+import org.jclouds.json.gson.internal.Excluder;
+import org.jclouds.json.gson.internal.JsonReaderInternalAccess;
import org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory;
import org.jclouds.json.internal.EnumTypeAdapterThatReturnsFromValue;
import org.jclouds.json.internal.GsonWrapper;
@@ -71,9 +74,6 @@ import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
-import com.google.gson.internal.ConstructorConstructor;
-import com.google.gson.internal.Excluder;
-import com.google.gson.internal.JsonReaderInternalAccess;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
diff --git a/core/src/main/java/org/jclouds/json/internal/DeserializationConstructorAndReflectiveTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/DeserializationConstructorAndReflectiveTypeAdapterFactory.java
index ae07809..1df3f5a 100644
--- a/core/src/main/java/org/jclouds/json/internal/DeserializationConstructorAndReflectiveTypeAdapterFactory.java
+++ b/core/src/main/java/org/jclouds/json/internal/DeserializationConstructorAndReflectiveTypeAdapterFactory.java
@@ -26,6 +26,9 @@ import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;
+import org.jclouds.json.gson.internal.ConstructorConstructor;
+import org.jclouds.json.gson.internal.Excluder;
+import org.jclouds.json.gson.internal.bind.ReflectiveTypeAdapterFactory;
import org.jclouds.json.internal.NamingStrategies.AnnotationConstructorNamingStrategy;
import com.google.common.base.MoreObjects;
@@ -40,9 +43,6 @@ import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
-import com.google.gson.internal.ConstructorConstructor;
-import com.google.gson.internal.Excluder;
-import com.google.gson.internal.bind.ReflectiveTypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
diff --git a/core/src/main/java/org/jclouds/json/internal/NullFilteringTypeAdapterFactories.java b/core/src/main/java/org/jclouds/json/internal/NullFilteringTypeAdapterFactories.java
index 85dd545..cdef883 100644
--- a/core/src/main/java/org/jclouds/json/internal/NullFilteringTypeAdapterFactories.java
+++ b/core/src/main/java/org/jclouds/json/internal/NullFilteringTypeAdapterFactories.java
@@ -16,6 +16,20 @@
*/
package org.jclouds.json.internal;
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Objects.equal;
+
+import java.io.IOException;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.jclouds.json.gson.internal.JsonReaderInternalAccess;
+
import com.google.common.base.Objects;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableCollection;
@@ -27,24 +41,11 @@ import com.google.common.collect.Multimap;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
-import com.google.gson.internal.JsonReaderInternalAccess;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
-import java.io.IOException;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import static com.google.common.base.Objects.equal;
-import static com.google.common.base.MoreObjects.toStringHelper;
-
/**
* Eliminates null values when deserializing Collections, Maps, and Multimaps
* <p/>
@@ -55,7 +56,7 @@ public class NullFilteringTypeAdapterFactories {
}
static <T> TypeToken<?> resolve(TypeToken<T> ownerType, Type param) {
- return TypeToken.get(com.google.gson.internal.$Gson$Types.resolve(ownerType.getType(), ownerType.getRawType(),
+ return TypeToken.get(org.jclouds.json.gson.internal.$Gson$Types.resolve(ownerType.getType(), ownerType.getRawType(),
param));
}
diff --git a/core/src/main/java/org/jclouds/json/internal/NullHackJsonLiteralAdapter.java b/core/src/main/java/org/jclouds/json/internal/NullHackJsonLiteralAdapter.java
index 1566176..e1f8909 100644
--- a/core/src/main/java/org/jclouds/json/internal/NullHackJsonLiteralAdapter.java
+++ b/core/src/main/java/org/jclouds/json/internal/NullHackJsonLiteralAdapter.java
@@ -20,9 +20,10 @@ import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Field;
+import org.jclouds.json.gson.internal.bind.TypeAdapters;
+
import com.google.common.base.Throwables;
import com.google.gson.TypeAdapter;
-import com.google.gson.internal.bind.TypeAdapters;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
diff --git a/core/src/test/java/org/jclouds/json/internal/DeserializationConstructorAndReflectiveTypeAdapterFactoryTest.java b/core/src/test/java/org/jclouds/json/internal/DeserializationConstructorAndReflectiveTypeAdapterFactoryTest.java
index 1d54d09..8b6ce9c 100644
--- a/core/src/test/java/org/jclouds/json/internal/DeserializationConstructorAndReflectiveTypeAdapterFactoryTest.java
+++ b/core/src/test/java/org/jclouds/json/internal/DeserializationConstructorAndReflectiveTypeAdapterFactoryTest.java
@@ -31,6 +31,8 @@ import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.json.SerializedNames;
+import org.jclouds.json.gson.internal.ConstructorConstructor;
+import org.jclouds.json.gson.internal.Excluder;
import org.jclouds.json.internal.NamingStrategies.AnnotationConstructorNamingStrategy;
import org.jclouds.json.internal.NamingStrategies.AnnotationOrNameFieldNamingStrategy;
import org.jclouds.json.internal.NamingStrategies.ExtractNamed;
@@ -48,8 +50,6 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import com.google.gson.TypeAdapter;
-import com.google.gson.internal.ConstructorConstructor;
-import com.google.gson.internal.Excluder;
import com.google.gson.reflect.TypeToken;
@Test(testName = "DeserializationConstructorTypeAdapterFactoryTest")
diff --git a/gson/pom.xml b/gson/pom.xml
new file mode 100644
index 0000000..949fb15
--- /dev/null
+++ b/gson/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>jclouds-project</artifactId>
+ <groupId>org.apache.jclouds</groupId>
+ <version>2.2.0-SNAPSHOT</version>
+ <relativePath>../project/pom.xml</relativePath>
+ </parent>
+
+ <!--
+ JCLOUDS-1166: This project relocates the 'com.google.gson.internal' package
+ so we can keep using its contents in OSGi environments.
+ This is a temporal solution and we should try to remove the usages of the classes in
+ there and remove this once that is done.
+ -->
+ <artifactId>jclouds-gson</artifactId>
+ <name>jclouds gson copy without internal packages</name>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.5</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>2.2</version>
+ <executions>
+ <execution>
+ <id>shade</id>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <artifactSet>
+ <includes>
+ <include>com.google.code.gson:gson</include>
+ </includes>
+ </artifactSet>
+ <relocations>
+ <relocation>
+ <pattern>com.google.gson.internal</pattern>
+ <shadedPattern>org.jclouds.json.gson.internal</shadedPattern>
+ </relocation>
+ </relocations>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
+ </transformers>
+ <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/pom.xml b/pom.xml
index fb4bf27..c16d829 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,6 +31,7 @@
<modules>
<module>project</module>
<module>resources</module>
+ <module>gson</module>
<module>core</module>
<module>common</module>
<module>compute</module>
diff --git a/project/pom.xml b/project/pom.xml
index 9fe9136..ec91ce1 100644
--- a/project/pom.xml
+++ b/project/pom.xml
@@ -255,6 +255,27 @@
<version>${guava.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.jclouds</groupId>
+ <artifactId>jclouds-gson</artifactId>
+ <version>${project.version}</version>
+ <exclusions>
+ <!--
+ Due to the following issues:
+ https://issues.apache.org/jira/browse/MSHADE-206
+ https://issues.apache.org/jira/browse/MNG-5899
+ The Maven reactor ignores the reduced pom.xml generated by the shade plugin, and all
+ the dependencies that are shaded are included as normal dependencies too, causing
+ duplicate class issues.
+ This exclusion makes sure projects including the shaded version don't get the original
+ gson dependency as well.
+ -->
+ <exclusion>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
@@ -517,9 +538,11 @@
<exclude>**/modernizer_exclusions.txt</exclude>
<exclude>**/.factorypath</exclude>
<exclude>**/.apt_generated/**</exclude>
+ <exclude>**/.apt_generated_tests/**</exclude>
<exclude>**/.checkstyle</exclude>
<exclude>nb-configuration.xml</exclude>
<exclude>nbactions.xml</exclude>
+ <exclude>dependency-reduced-pom.xml</exclude>
<!-- Temporary files generated on CloudBees slaves -->
<exclude>.repository/**</exclude>
@@ -592,6 +615,32 @@
<package>com.jcraft.jsch.agentproxy</package>
</packages>
</exception>
+ <!--
+ TODO: Remove this when the issues are fixed or we have completely moved away from
+ gson.internal
+ Due to the following issues:
+ https://issues.apache.org/jira/browse/MSHADE-206
+ https://issues.apache.org/jira/browse/MNG-5899
+ The contents of the shaded gson jar are directly included as part of jclouds-core.
+ The classes are exactly the same, so it is safe to exclude them here.
+ -->
+ <exception>
+ <conflictingDependencies>
+ <dependency>
+ <groupId>org.apache.jclouds</groupId>
+ <artifactId>jclouds-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jclouds</groupId>
+ <artifactId>jclouds-gson</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </conflictingDependencies>
+ <packages>
+ <package>org.jclouds.json.gson.internal</package>
+ </packages>
+ </exception>
</exceptions>
<ignoredResourcePatterns>
<!-- For all the jetty packages -->
diff --git a/resources/checkstyle.xml b/resources/checkstyle.xml
index 395ba67..d686ac7 100644
--- a/resources/checkstyle.xml
+++ b/resources/checkstyle.xml
@@ -57,7 +57,7 @@
</module>
<module name="IllegalImport">
<!-- Avoid importing AutoValue shaded packages such as Guava -->
- <property name="illegalPkgs" value="sun,autovalue,org.testng.internal"/>
+ <property name="illegalPkgs" value="sun,autovalue,org.testng.internal,com.google.gson.internal"/>
</module>
<module name="WhitespaceAfter">
<!-- TYPECAST disabled -->