Skip to content

Commit 0b2cba6

Browse files
committed
[CALCITE-6669] Httpcore/Httpclient not relocated in shaded Avatica jar
1 parent 38f7289 commit 0b2cba6

File tree

4 files changed

+147
-2
lines changed

4 files changed

+147
-2
lines changed

shaded/core/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ configurations {
4141

4242
dependencies {
4343
shaded(project(":core"))
44+
testImplementation("junit:junit")
4445
}
4546

4647
tasks {
@@ -69,7 +70,7 @@ tasks {
6970
listOf(
7071
"com.fasterxml.jackson",
7172
"com.google.protobuf",
72-
"org.apache.http",
73+
"org.apache.hc",
7374
"org.apache.commons"
7475
).forEach {
7576
relocate(it, "${project.group}.shaded.$it")
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.calcite.avatica.shadetest;
18+
19+
import org.junit.Test;
20+
21+
import java.io.File;
22+
import java.io.IOException;
23+
import java.nio.file.FileSystems;
24+
import java.nio.file.Files;
25+
import java.nio.file.Path;
26+
import java.nio.file.PathMatcher;
27+
import java.util.Optional;
28+
import java.util.jar.JarFile;
29+
import java.util.regex.Pattern;
30+
31+
import static org.junit.Assert.assertTrue;
32+
33+
public class ShadingTest {
34+
35+
// Note that many of these files could be excluded.
36+
// This is for regression testing, and not the minimum file set.
37+
String[] allowedPathPatterns = { "^META-INF", "^org/apache/calcite/", ".*\\.proto",
38+
"^org/slf4j/", "^org/publicsuffix/" };
39+
40+
@Test
41+
public void validateShadedJar() throws Exception {
42+
43+
String patternString = String.join("|", allowedPathPatterns);
44+
Pattern allowedNames = Pattern.compile(patternString);
45+
46+
try (JarFile jar = new JarFile(getShadedJarFile())) {
47+
jar.stream()
48+
.filter(c -> !c.isDirectory())
49+
.forEach(c -> {
50+
assertTrue(c.getName() + " does not match allowed names",
51+
allowedNames.matcher(c.getName()).find());
52+
});
53+
}
54+
}
55+
56+
private File getShadedJarFile() throws IOException {
57+
58+
Path libPath = FileSystems.getDefault().getPath("").resolve("build/libs/").toAbsolutePath();
59+
60+
PathMatcher matcher = FileSystems.getDefault()
61+
.getPathMatcher("glob:avatica-*-shadow.jar");
62+
63+
Optional<Path> found = Files.list(libPath).filter(c -> matcher.matches(c.getFileName()))
64+
.findFirst();
65+
assertTrue("Could not find jar in " + libPath, found.isPresent());
66+
67+
return found.get().toFile();
68+
}
69+
}

standalone-server/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ dependencies {
5050

5151
shaded("org.slf4j:slf4j-api")
5252
shaded("org.apache.logging.log4j:log4j-slf4j-impl")
53+
54+
testImplementation("junit:junit")
5355
}
5456

5557
tasks {
@@ -97,7 +99,7 @@ tasks {
9799
"com.google.common",
98100
"com.google.protobuf",
99101
"javax.servlet",
100-
"org.apache.http",
102+
"org.apache.hc",
101103
"org.apache.commons"
102104
).forEach {
103105
relocate(it, "${project.group}.standalone.shaded.$it")
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.calcite.avatica.shadetest;
18+
19+
import org.junit.Test;
20+
21+
import java.io.File;
22+
import java.io.IOException;
23+
import java.nio.file.FileSystems;
24+
import java.nio.file.Files;
25+
import java.nio.file.Path;
26+
import java.nio.file.PathMatcher;
27+
import java.util.Optional;
28+
import java.util.jar.JarFile;
29+
import java.util.regex.Pattern;
30+
31+
import static org.junit.Assert.assertTrue;
32+
33+
public class ShadingTest {
34+
35+
// Note that many of these files could be excluded.
36+
// This is for regression testing, and not the minimum file set.
37+
String[] allowedPathPatterns = { "^META-INF", "^org/apache/calcite/", "^log4j2.xml", ".*\\.proto",
38+
"^org/publicsuffix/", "^org/slf4j/", "^org/apache/logging/slf4j/", "^com/google/j2objc/",
39+
"^google/protobuf/", "^about.html$", "^org/eclipse/jetty/", "^jetty-dir.css",
40+
"^com/google/thirdparty/", "^org/checkerframework/", "^javax/annotation/",
41+
"^com/google/errorprone/", "^Log4j-.*\\.xsd$", "^Log4j-.*\\.dtd$", "^Log4j-.*\\.properties$",
42+
"^org/apache/logging/log4j/", "^org/codehaus/mojo/animal_sniffer/" };
43+
44+
@Test
45+
public void validateShadedJar() throws Exception {
46+
47+
String patternString = String.join("|", allowedPathPatterns);
48+
Pattern allowedNames = Pattern.compile(patternString);
49+
50+
try (JarFile jar = new JarFile(getShadedJarFile())) {
51+
jar.stream()
52+
.filter(c -> !c.isDirectory())
53+
.forEach(c -> {
54+
assertTrue(c.getName() + " does not match allowed names",
55+
allowedNames.matcher(c.getName()).find());
56+
});
57+
}
58+
}
59+
60+
private File getShadedJarFile() throws IOException {
61+
62+
Path libPath = FileSystems.getDefault().getPath("").resolve("build/libs/").toAbsolutePath();
63+
64+
PathMatcher matcher = FileSystems.getDefault()
65+
.getPathMatcher("glob:avatica-standalone-server-*-shadow.jar");
66+
67+
Optional<Path> found = Files.list(libPath).filter(c -> matcher.matches(c.getFileName()))
68+
.findFirst();
69+
assertTrue("Could not find jar in " + libPath, found.isPresent());
70+
71+
return found.get().toFile();
72+
}
73+
}

0 commit comments

Comments
 (0)