Skip to content
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

Remove dependency on optional dependency org.brotli:dec #6778

Merged
merged 1 commit into from
Nov 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,24 @@
*/
package org.apache.camel.quarkus.support.httpclient5.deployment;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Modifier;

import io.quarkus.deployment.GeneratedClassGizmoAdaptor;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.GeneratedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.gizmo.ClassCreator;
import io.quarkus.gizmo.MethodCreator;
import io.quarkus.gizmo.MethodDescriptor;
import org.apache.camel.quarkus.support.httpclient5.graal.BrotliAbsentBooleanSupplier;

class HttpClient5Processor {
private static final String BROTLI_INPUT_STREAM_CLASS_NAME = "org.brotli.dec.BrotliInputStream";
private static final String NTLM_ENGINE_IMPL = "org.apache.hc.client5.http.impl.auth.NTLMEngineImpl";

@BuildStep
Expand All @@ -34,4 +46,54 @@ NativeImageResourceBuildItem suffixListResource() {
void runtimeInitializedClasses(BuildProducer<RuntimeInitializedClassBuildItem> runtimeInitializedClasses) {
runtimeInitializedClasses.produce(new RuntimeInitializedClassBuildItem(NTLM_ENGINE_IMPL));
}

@BuildStep(onlyIf = { NativeOrNativeSourcesBuild.class, BrotliAbsentBooleanSupplier.class })
void generateBrotliInputStreamClass(BuildProducer<GeneratedClassBuildItem> generatedClass) {
zhfeng marked this conversation as resolved.
Show resolved Hide resolved
try (ClassCreator classCreator = ClassCreator.builder()
.className(BROTLI_INPUT_STREAM_CLASS_NAME)
.superClass(InputStream.class)
.classOutput(new GeneratedClassGizmoAdaptor(generatedClass, false))
.build()) {

aldettinger marked this conversation as resolved.
Show resolved Hide resolved
/*
* Creates a simplified impl of BrotliInputStream to satisfy the native compiler:
*
* public class BrotliInputStream extends InputStream {
* public BrotliInputStream() {
* }
*
* public BrotliInputStream(InputStream stream) {
* }
*
* public int read() {
* throw new UnsupportedOperationException();
* }
* }
*/

try (MethodCreator defaultConstructor = classCreator.getMethodCreator("<init>", void.class)) {
defaultConstructor.setModifiers(Modifier.PUBLIC);
defaultConstructor.invokeSpecialMethod(
MethodDescriptor.ofMethod(BROTLI_INPUT_STREAM_CLASS_NAME, "<init>", void.class),
defaultConstructor.getThis());
defaultConstructor.returnValue(null);
}

try (MethodCreator constructorWithInputStreamArg = classCreator.getMethodCreator("<init>", void.class,
InputStream.class)) {
constructorWithInputStreamArg.setModifiers(Modifier.PUBLIC);
constructorWithInputStreamArg.invokeSpecialMethod(
MethodDescriptor.ofMethod(BROTLI_INPUT_STREAM_CLASS_NAME, "<init>", void.class),
constructorWithInputStreamArg.getThis());
constructorWithInputStreamArg.returnValue(null);
}

try (MethodCreator readMethod = classCreator.getMethodCreator("read", int.class)) {
readMethod.setModifiers(Modifier.PUBLIC);
readMethod.addException(IOException.class);
readMethod.throwException(UnsupportedOperationException.class,
"Cannot read from BrotliInputStream. Add org.brotli:dec to the application classpath");
}
}
}
}
5 changes: 3 additions & 2 deletions extensions-support/httpclient5/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
<artifactId>httpclient5</artifactId>
</dependency>
<dependency>
<groupId>org.brotli</groupId>
<artifactId>dec</artifactId>
<groupId>org.graalvm.sdk</groupId>
<artifactId>nativeimage</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/
package org.apache.camel.quarkus.support.httpclient5.graal;

import java.util.function.BooleanSupplier;

public class BrotliAbsentBooleanSupplier implements BooleanSupplier {
@Override
public boolean getAsBoolean() {
try {
Thread.currentThread().getContextClassLoader().loadClass("org.brotli.dec.BrotliInputStream");
return false;
} catch (ClassNotFoundException e) {
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.
*/
package org.apache.camel.quarkus.support.httpclient5.graal;

import java.io.IOException;
import java.io.InputStream;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import org.apache.hc.client5.http.entity.BrotliDecompressingEntity;
import org.apache.hc.client5.http.entity.BrotliInputStreamFactory;

/**
* Remove references to optional brotli:dec dependency.
*/
final class BrotliSubstitutions {
}

@TargetClass(value = BrotliInputStreamFactory.class, onlyWith = { BrotliAbsentBooleanSupplier.class })
final class SubstituteBrotliInputStreamFactory {
@Substitute
public InputStream create(InputStream inputStream) throws IOException {
throw new UnsupportedOperationException(
"Cannot create BrotliInputStream. Add org.brotli:dec to the application classpath.");
}
}

@TargetClass(value = BrotliDecompressingEntity.class, onlyWith = { BrotliAbsentBooleanSupplier.class })
final class SubstituteBrotliDecompressingEntity {
@Substitute
public static boolean isAvailable() {
return false;
}
}
4 changes: 4 additions & 0 deletions extensions/saxon/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-httpclient5-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-saxon</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions extensions/saxon/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
<artifactId>camel-quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-saxon</artifactId>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-httpclient5</artifactId>
</dependency>
<dependency>
<groupId>org.brotli</groupId>
<artifactId>dec</artifactId>
<groupId>org.apache.camel</groupId>
<artifactId>camel-saxon</artifactId>
</dependency>
</dependencies>

Expand Down
4 changes: 4 additions & 0 deletions extensions/xslt-saxon/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-xslt-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-httpclient5-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-xslt-saxon</artifactId>
Expand Down
13 changes: 4 additions & 9 deletions extensions/xslt-saxon/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,12 @@
<artifactId>camel-quarkus-xslt</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xslt-saxon</artifactId>
</dependency>
<dependency>
<groupId>org.brotli</groupId>
<artifactId>dec</artifactId>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-httpclient5</artifactId>
</dependency>
<!-- Required for the native build of the simple app with this extension only -->
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xslt-saxon</artifactId>
</dependency>
</dependencies>

Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
<azure-core-http-vertx.version>1.0.0-beta.21</azure-core-http-vertx.version> <!-- TODO: https://github.com/apache/camel-quarkus/issues/4181 -->
<cassandra-driver-test.version>3.7.1</cassandra-driver-test.version><!-- Keep in sync with testcontainers instead of Debezium bom -->
<bouncycastle.version>1.79</bouncycastle.version><!-- @sync io.quarkus:quarkus-bom:${quarkus.version} dep:org.bouncycastle:bcprov-jdk18on -->
<brotli.version>0.1.2</brotli.version><!-- @sync org.apache.httpcomponents.client5:httpclient5-parent:${httpclient5.version} prop:brotli.version -->
<caffeine.version>3.1.8</caffeine.version><!-- @sync io.quarkus:quarkus-bom:${quarkus.version} dep:com.github.ben-manes.caffeine:caffeine -->
<commons-beanutils.version>${commons-beanutils-version}</commons-beanutils.version>
<commons-cli.version>1.8.0</commons-cli.version><!-- keep in sync with Quarkus, via quarkus-bootstrap-core -->
Expand Down
5 changes: 0 additions & 5 deletions poms/bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7237,11 +7237,6 @@
<artifactId>bcutil-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>org.brotli</groupId>
<artifactId>dec</artifactId>
<version>${brotli.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-mail</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions poms/bom/src/main/generated/flattened-full-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7159,11 +7159,6 @@
<artifactId>bcutil-jdk18on</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>1.79</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>org.brotli</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>dec</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>0.1.2</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>angus-mail</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
Expand Down
5 changes: 0 additions & 5 deletions poms/bom/src/main/generated/flattened-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7109,11 +7109,6 @@
<artifactId>bcutil-jdk18on</artifactId>
<version>1.79</version>
</dependency>
<dependency>
<groupId>org.brotli</groupId>
<artifactId>dec</artifactId>
<version>0.1.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-mail</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7109,11 +7109,6 @@
<artifactId>bcutil-jdk18on</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>1.79</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>org.brotli</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>dec</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>0.1.2</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>angus-mail</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
Expand Down