Skip to content

Patch jackson-core with locally modified class #92984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 18, 2023
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
2 changes: 1 addition & 1 deletion libs/x-content/impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ String jacksonVersion = "2.14.1"
dependencies {
compileOnly project(':libs:elasticsearch-core')
compileOnly project(':libs:elasticsearch-x-content')
implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
implementation project(path: ':libs:x-content:impl:es-jackson-core', configuration: 'shadow')
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-smile:${jacksonVersion}"
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:${jacksonVersion}"
Expand Down
32 changes: 32 additions & 0 deletions libs/x-content/impl/es-jackson-core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

apply plugin: 'elasticsearch.build'
apply plugin: 'com.github.johnrengelman.shadow'

String jacksonVersion = "2.14.1"

dependencies {
implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
}

['jarHell', 'thirdPartyAudit', 'forbiddenApisMain', 'splitPackagesAudit', 'checkstyleMain', 'licenseHeaders', 'spotlessJavaCheck'].each {
tasks.named(it).configure {
enabled = false
}
}

tasks.named("dependencyLicenses").configure {
mapping from: /jackson-.*/, to: 'jackson'
}

shadowJar {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this needs to exclude the original FilterDelegateParser class file, otherwise there will be two copies, the original and the one added by this project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resulting jar only have one FilteringParserDelegate (new).
I think it wouldn't work when excluding with this snippet (similar to the hadoop approach)

tasks.named('shadowJar').configure {
   exclude 'com/fasterxml/jackson/core/filter/FilteringParserDelegate.class'
}

This results in a jar without FilteringParserDelegate class at all. This is because in the docs https://imperceptiblethoughts.com/shadow/configuration/filtering/
it says:

When using exclude/include with a ShadowJar task, the resulting copy specs are applied to the final JAR contents. This means that, the configuration is applied to the individual files from both the project source set or any of the dependencies to be merged.

In hadoop api is removing the original inner classes and replacing the public class.

jar -tf hadoop-client-api-3.3.3.jar | grep ShutdownHookManager
org/apache/hadoop/util/ShutdownHookManager.class
org/apache/hadoop/util/ShutdownHookManager$HookEntry.class
org/apache/hadoop/util/ShutdownHookManager$1.class
org/apache/hadoop/util/ShutdownHookManager$2.class

The snippet has a $ in it

tasks.named('shadowJar').configure {
  exclude 'org/apache/hadoop/util/ShutdownHookManager$*.class'
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah lets filter out the jar version of FilteringParserDelegate explicitly. Otherwise which version will be picked is a gradle implementation detail and could change anytime when gradle or the shadow jar plugin is updated.

We can differ between the jar version and our patched version by using the following api:

shadowJar {
  exclude { element ->
    element.file == null && element.path.endsWith("FilteringParserDelegate.class")
  }
  manifest {
    attributes 'Multi-Release' : 'true'
  }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I remember now why we have that filter. It's specifically for the anonymous inner classes. So I think it's ok to just overwrite. However, please double check the jar manually to confirm there are not eg 2 entries in the zip manifest.

manifest {
attributes 'Multi-Release' : 'true'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This copy of Jackson JSON processor streaming parser/generator is licensed under the
Apache (Software) License, version 2.0 ("the License").
See the License for details about distribution rights, and the
specific rights regarding derivate works.

You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0
20 changes: 20 additions & 0 deletions libs/x-content/impl/es-jackson-core/licenses/jackson-NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Jackson JSON processor

Jackson is a high-performance, Free/Open Source JSON processing library.
It was originally written by Tatu Saloranta ([email protected]), and has
been in development since 2007.
It is currently developed by a community of developers, as well as supported
commercially by FasterXML.com.

## Licensing

Jackson core and extension components may licensed under different licenses.
To find the details that apply to this artifact see the accompanying LICENSE file.
For more information, including possible other licensing options, contact
FasterXML.com (http://fasterxml.com).

## Credits

A list of contributors may be found from CREDITS file, which is included
in some artifacts (usually source distributions); but is always available
from the source code management (SCM) system project uses.
Loading