Replace embedded and repackaged GSON library

Replace substituted GSON package names with those provided from the vendor.
Reduce OSGi-metadata declaration of core-module because the artificial package org.jclouds.json.gson.internal was removed.
Remove the Gson module its children Gson bundle, and Gson shaded.
Remove duplication conflict and check-style rules due to the removal of the internal Gson module.
Add maven repository where a custom version of the Gson library gets hosted, which exports all packages.

Remove particular repository

Remove the declaration of the repository that serves a custom build GSON version. The build uses GSON in its original form of the vendor, which gets distributed through the standard distribution channel. The identifiers for group, artifact, and version correspond to the latest stable release of GSON.

Integrate GSON library in Clouds Core Bundle

The change contained in the commit puts the GSON library into the classpath of the JClouds core module.
After several tests with Karaf and Karaf JClouds, especially if the Maven identifier matches the original GSON library, there are only a limited number of ways to keep the deployment effort low.

Specifically, Karaf has a set of predefined Maven repositories that can be easily customized. The order in which a particular repository is resolved into the customized GSON library is more difficult. In normal OSGi applications, which do not have such a management function, I imagine this configuration to be more complicated.  Sure, a unique identifier would help, but then we are back to step 1.

Although I honestly don't like to see this kind of approach in a codebase I'm working with, there are not many alternatives to the main aspect of deployment mentioned above.

Maybe the approach can still ease the problem in the short term. In a further mid-term step, however, this problem must be addressed in general.
This commit is contained in:
gurkerl83 2020-06-25 15:27:15 +02:00 committed by Andrew Gaul
parent 1cd28c93c4
commit d82868cc47
13 changed files with 24 additions and 240 deletions

View File

@ -37,7 +37,7 @@ import org.jclouds.crypto.Crypto;
import org.jclouds.crypto.Pems; import org.jclouds.crypto.Pems;
import org.jclouds.json.config.GsonModule.DateAdapter; import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.json.gson.internal.JsonReaderInternalAccess; import com.google.gson.internal.JsonReaderInternalAccess;
import org.jclouds.json.internal.NullFilteringTypeAdapterFactories; import org.jclouds.json.internal.NullFilteringTypeAdapterFactories;
import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.MapTypeAdapterFactory; import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.MapTypeAdapterFactory;
import org.jclouds.json.internal.NullHackJsonLiteralAdapter; import org.jclouds.json.internal.NullHackJsonLiteralAdapter;

View File

@ -41,9 +41,9 @@
<jclouds.osgi.import>*</jclouds.osgi.import> <jclouds.osgi.import>*</jclouds.osgi.import>
<!-- https://issues.apache.org/jira/browse/JCLOUDS-1529 --> <!-- https://issues.apache.org/jira/browse/JCLOUDS-1529 -->
<jclouds.osgi.export> <jclouds.osgi.export>
!org.jclouds.json.gson.internal*,
org.jclouds*;version=${project.version};-noimport:=true org.jclouds*;version=${project.version};-noimport:=true
</jclouds.osgi.export> </jclouds.osgi.export>
<jclouds.osgi.include>lib/gson-${gson.version}.jar=gson-${gson.version}.jar;lib:=true</jclouds.osgi.include>
<jclouds.osgi.activator>org.jclouds.osgi.Activator</jclouds.osgi.activator> <jclouds.osgi.activator>org.jclouds.osgi.Activator</jclouds.osgi.activator>
</properties> </properties>
@ -82,8 +82,8 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.jclouds</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>jclouds-gson</artifactId> <artifactId>gson</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>

View File

@ -37,9 +37,9 @@ import org.jclouds.domain.JsonBall;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.json.Json; import org.jclouds.json.Json;
import org.jclouds.json.SerializedNames; import org.jclouds.json.SerializedNames;
import org.jclouds.json.gson.internal.ConstructorConstructor; import com.google.gson.internal.ConstructorConstructor;
import org.jclouds.json.gson.internal.Excluder; import com.google.gson.internal.Excluder;
import org.jclouds.json.gson.internal.JsonReaderInternalAccess; import com.google.gson.internal.JsonReaderInternalAccess;
import org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory; import org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory;
import org.jclouds.json.internal.EnumTypeAdapterThatReturnsFromValue; import org.jclouds.json.internal.EnumTypeAdapterThatReturnsFromValue;
import org.jclouds.json.internal.GsonWrapper; import org.jclouds.json.internal.GsonWrapper;

View File

@ -26,10 +26,10 @@ import java.lang.reflect.Modifier;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jclouds.json.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory; import com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory;
import org.jclouds.json.gson.internal.ConstructorConstructor; import com.google.gson.internal.ConstructorConstructor;
import org.jclouds.json.gson.internal.Excluder; import com.google.gson.internal.Excluder;
import org.jclouds.json.gson.internal.bind.ReflectiveTypeAdapterFactory; import com.google.gson.internal.bind.ReflectiveTypeAdapterFactory;
import org.jclouds.json.internal.NamingStrategies.AnnotationConstructorNamingStrategy; import org.jclouds.json.internal.NamingStrategies.AnnotationConstructorNamingStrategy;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;

View File

@ -28,7 +28,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.jclouds.json.gson.internal.JsonReaderInternalAccess; import com.google.gson.internal.JsonReaderInternalAccess;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
@ -56,7 +56,7 @@ public class NullFilteringTypeAdapterFactories {
} }
static <T> TypeToken<?> resolve(TypeToken<T> ownerType, Type param) { static <T> TypeToken<?> resolve(TypeToken<T> ownerType, Type param) {
return TypeToken.get(org.jclouds.json.gson.internal.$Gson$Types.resolve(ownerType.getType(), ownerType.getRawType(), return TypeToken.get(com.google.gson.internal.$Gson$Types.resolve(ownerType.getType(), ownerType.getRawType(),
param)); param));
} }

View File

@ -20,7 +20,7 @@ import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import org.jclouds.json.gson.internal.bind.TypeAdapters; import com.google.gson.internal.bind.TypeAdapters;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapter;

View File

@ -31,8 +31,8 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import org.jclouds.json.SerializedNames; import org.jclouds.json.SerializedNames;
import org.jclouds.json.gson.internal.ConstructorConstructor; import com.google.gson.internal.ConstructorConstructor;
import org.jclouds.json.gson.internal.Excluder; import com.google.gson.internal.Excluder;
import org.jclouds.json.internal.NamingStrategies.AnnotationConstructorNamingStrategy; import org.jclouds.json.internal.NamingStrategies.AnnotationConstructorNamingStrategy;
import org.jclouds.json.internal.NamingStrategies.AnnotationOrNameFieldNamingStrategy; import org.jclouds.json.internal.NamingStrategies.AnnotationOrNameFieldNamingStrategy;
import org.jclouds.json.internal.NamingStrategies.ExtractNamed; import org.jclouds.json.internal.NamingStrategies.ExtractNamed;

View File

@ -1,51 +0,0 @@
<?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.3.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<artifactId>jclouds-gson</artifactId>
<name>jclouds-gson OSGi bundle</name>
<description>jclouds-gson OSGi bundle with gson internal packages relocated</description>
<packaging>bundle</packaging>
<properties>
<jclouds.osgi.export>
org.jclouds.json.gson.internal*;version=${project.version};-noimport:=true,
!com.google.gson.internal*,
com.google.gson*;version=${project.version};-noimport:=true,
</jclouds.osgi.export>
<jclouds.osgi.import>*</jclouds.osgi.import>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-gson-shaded</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -1,82 +0,0 @@
<?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.3.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-shaded</artifactId>
<name>jclouds-gson shaded library</name>
<description>jclouds-gson library with gson internal packages relocated</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.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>

View File

@ -1,46 +0,0 @@
<?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.3.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath>
</parent>
<artifactId>jclouds-gson-modules</artifactId>
<name>jclouds gson modules</name>
<packaging>pom</packaging>
<!--
The maven-bundle-plugin computes the manifest based on the classes that actually exist in
the classpath, but the maven-shade-plugin, runs after the bundle plugin. This results in the generated
manifest file not having the exports for the packages that have been relocated.
There are several threads on stackoverflow and others trying to make both plugins work together nicely but
none of the combinations work in our use case.
To overcome this, we generate both separately; first the shaded jar, then the bundle based on that jar.
-->
<modules>
<module>gson-shaded</module>
<module>gson-bundle</module>
</modules>
</project>

View File

@ -31,7 +31,6 @@
<modules> <modules>
<module>project</module> <module>project</module>
<module>resources</module> <module>resources</module>
<module>gson</module>
<module>core</module> <module>core</module>
<module>common</module> <module>common</module>
<module>compute</module> <module>compute</module>

View File

@ -225,6 +225,8 @@
<guava.version>22.0</guava.version> <guava.version>22.0</guava.version>
<guava.osgi.import>com.google.common.*;version="[22.0,30.0.0)"</guava.osgi.import> <guava.osgi.import>com.google.common.*;version="[22.0,30.0.0)"</guava.osgi.import>
<guice.version>4.2.3</guice.version> <guice.version>4.2.3</guice.version>
<gson.version>2.8.6</gson.version>
<guice.version>3.0</guice.version>
<okhttp.version>2.2.0</okhttp.version> <okhttp.version>2.2.0</okhttp.version>
<okio.osgi.import>okio;version="[1.2.0,1.3)"</okio.osgi.import> <okio.osgi.import>okio;version="[1.2.0,1.3)"</okio.osgi.import>
<surefire.version>2.17</surefire.version> <surefire.version>2.17</surefire.version>
@ -255,25 +257,10 @@
<version>${guava.version}</version> <version>${guava.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.jclouds</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>jclouds-gson</artifactId> <artifactId>gson</artifactId>
<version>${project.version}</version> <version>${gson.version}</version>
<exclusions> <scope>provided</scope>
<!--
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>org.apache.jclouds</groupId>
<artifactId>jclouds-gson-shaded</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.code.findbugs</groupId> <groupId>com.google.code.findbugs</groupId>
@ -641,6 +628,7 @@
<Import-Package>${guava.osgi.import},${jclouds.osgi.import}</Import-Package> <Import-Package>${guava.osgi.import},${jclouds.osgi.import}</Import-Package>
<DynamicImport-Package>${jclouds.osgi.dynamic}</DynamicImport-Package> <DynamicImport-Package>${jclouds.osgi.dynamic}</DynamicImport-Package>
<Fragment-Host>${jclouds.osgi.fragment}</Fragment-Host> <Fragment-Host>${jclouds.osgi.fragment}</Fragment-Host>
<Include-Resource>${jclouds.osgi.include}</Include-Resource>
</instructions> </instructions>
</configuration> </configuration>
</plugin> </plugin>
@ -1140,30 +1128,6 @@
<package>com.jcraft.jsch.agentproxy</package> <package>com.jcraft.jsch.agentproxy</package>
</packages> </packages>
</exception> </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>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-gson</artifactId>
</dependency>
</conflictingDependencies>
<packages>
<package>org.jclouds.json.gson.internal</package>
</packages>
</exception>
</exceptions> </exceptions>
<ignoredResourcePatterns> <ignoredResourcePatterns>
<!-- For all the jetty packages --> <!-- For all the jetty packages -->

View File

@ -57,7 +57,7 @@
</module> </module>
<module name="IllegalImport"> <module name="IllegalImport">
<!-- Avoid importing AutoValue shaded packages such as Guava --> <!-- Avoid importing AutoValue shaded packages such as Guava -->
<property name="illegalPkgs" value="sun,autovalue,org.testng.internal,com.google.gson.internal"/> <property name="illegalPkgs" value="sun,autovalue,org.testng.internal"/>
</module> </module>
<module name="WhitespaceAfter"> <module name="WhitespaceAfter">
<!-- TYPECAST disabled --> <!-- TYPECAST disabled -->