Skip to content

Commit 83b80cd

Browse files
committed
differentiate by hdfs version
1 parent fd17d22 commit 83b80cd

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/PatcherInfo.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public static PatcherInfo classPatcher(String jarEntryName, String classSha256,
2929
}
3030

3131
boolean matches(byte[] otherClassSha256) {
32-
if (this.classSha256 == null) {
33-
return true;
34-
}
3532
return Arrays.equals(this.classSha256, otherClassSha256);
3633
}
3734
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/Utils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ public static void patchJar(File inputFile, File outputFile, Collection<PatcherI
7171
throw new IllegalArgumentException(
7272
String.format(
7373
Locale.ROOT,
74-
"error patching JAR [%s]: SHA256 digest mismatch for class [%s] (expected: [%s], found: [%s]). "
75-
+ "This JAR was updated to a version that contains a different class, for which this patcher was not "
76-
+ "designed for. Please check if the patcher still applies correctly to this class, and update its "
77-
+ "SHA256 digest.",
74+
"""
75+
Error patching JAR [%s]: SHA256 digest mismatch for class [%s] (expected: [%s], \
76+
found: [%s]). This JAR was updated to a version that contains a different class, \
77+
for which this patcher was not designed for. Please check if the patcher still \
78+
applies correctly to this class, and update its SHA256 digest.""",
7879
inputFile.getName(),
7980
classPatcher.jarEntryName(),
8081
HexFormat.of().formatHex(classPatcher.classSha256()),

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/hdfs/HdfsClassPatcher.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,43 @@ record JarPatchers(String artifactTag, Pattern artifactPattern, List<PatcherInfo
3636

3737
static final List<JarPatchers> allPatchers = List.of(
3838
new JarPatchers(
39-
"hadoop-common",
40-
Pattern.compile("hadoop-common-(?!.*tests)"),
39+
"hadoop2-common",
40+
Pattern.compile("hadoop-common-2(?!.*tests)"),
4141
List.of(
4242
classPatcher(
4343
"org/apache/hadoop/util/ShutdownHookManager.class",
44-
"90641e0726fc9372479728ef9b7ae2be20fb7ab4cddd4938e55ffecadddd4d94",
44+
"3912451f02da9199dae7dba3f1420e0d951067addabbb235e7551de52234a0ef",
4545
ShutdownHookManagerPatcher::new
4646
),
4747
classPatcher(
4848
"org/apache/hadoop/util/Shell.class",
49-
"8837c7f3eeda3f658fc3d6595f18e77a4558220ff0becdf3e175fa4397a6fd0c",
49+
"60400dc800e7c3e1a5fc499793033d877f5319bbd7633fee05d5a1d96b947bbd",
5050
ShellPatcher::new
5151
),
5252
classPatcher(
5353
"org/apache/hadoop/security/UserGroupInformation.class",
54-
"3c34bbc2716a6c8f4e356e78550599b0a4f01882712b4f7787d032fb10527212",
54+
"218078b8c77838f93d015c843775985a71f3c7a8128e2a9394410f0cd1da5f53",
55+
SubjectGetSubjectPatcher::new
56+
)
57+
)
58+
),
59+
new JarPatchers(
60+
"hadoop3-common",
61+
Pattern.compile("hadoop-common-3(?!.*tests)"),
62+
List.of(
63+
classPatcher(
64+
"org/apache/hadoop/util/ShutdownHookManager.class",
65+
"7720e8545a02de6fd03f4170f0e471d1301ef73d7d6a09097bad361f9e31f819",
66+
ShutdownHookManagerPatcher::new
67+
),
68+
classPatcher(
69+
"org/apache/hadoop/util/Shell.class",
70+
"856d0b829cf550df826387af15fa1c772bc7d26d6461535b17b9d5114d308dc4",
71+
ShellPatcher::new
72+
),
73+
classPatcher(
74+
"org/apache/hadoop/security/UserGroupInformation.class",
75+
"52f5973f35a282908d48a573a03c04f240a22c9f6007d7c5e7852aff1c641420",
5576
SubjectGetSubjectPatcher::new
5677
)
5778
)

test/fixtures/hdfs-fixture/build.gradle

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,44 @@ apply plugin: 'com.gradleup.shadow'
1313

1414
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
1515

16-
def patched = Attribute.of('patched', Boolean)
16+
def hdfs2patched = Attribute.of('hdfs2-patched', Boolean)
17+
def hdfs3patched = Attribute.of('hdfs3-patched', Boolean)
1718
configurations {
1819
hdfs2 {
1920
attributes {
20-
attribute(patched, true)
21+
attribute(hdfs2patched, true)
2122
}
2223
}
2324
hdfs3 {
2425
attributes {
25-
attribute(patched, true)
26+
attribute(hdfs3patched, true)
2627
}
2728
}
2829
consumable("shadowedHdfs2")
2930
}
3031

3132
dependencies {
3233
attributesSchema {
33-
attribute(patched)
34+
attribute(hdfs2patched)
35+
attribute(hdfs3patched)
3436
}
3537
artifactTypes.getByName("jar") {
36-
attributes.attribute(patched, false)
38+
attributes.attribute(hdfs2patched, false)
39+
attributes.attribute(hdfs3patched, false)
3740
}
3841
registerTransform(org.elasticsearch.gradle.internal.dependencies.patches.hdfs.HdfsClassPatcher) {
39-
from.attribute(patched, false)
40-
to.attribute(patched, true)
42+
from.attribute(hdfs2patched, false)
43+
to.attribute(hdfs2patched, true)
4144
parameters {
42-
matchingArtifacts = ["hadoop-common"]
45+
matchingArtifacts = ["hadoop2-common"]
46+
}
47+
}
48+
49+
registerTransform(org.elasticsearch.gradle.internal.dependencies.patches.hdfs.HdfsClassPatcher) {
50+
from.attribute(hdfs3patched, false)
51+
to.attribute(hdfs3patched, true)
52+
parameters {
53+
matchingArtifacts = ["hadoop3-common"]
4354
}
4455
}
4556

0 commit comments

Comments
 (0)