forked from apache/camel-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
456 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
...src/main/java/org/apache/camel/quarkus/component/xchange/deployment/XchangeProcessor.java
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
...ion-test/src/main/java/org/apache/camel/quarkus/component/xchange/it/XchangeResource.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...src/main/java/org/apache/camel/quarkus/component/xchange/deployment/XchangeProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* 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.component.xchange.deployment; | ||
|
||
import java.lang.reflect.Modifier; | ||
import java.util.List; | ||
|
||
import io.quarkus.bootstrap.model.AppArtifact; | ||
import io.quarkus.bootstrap.model.AppDependency; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.CombinedIndexBuildItem; | ||
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.deployment.builditem.IndexDependencyBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; | ||
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; | ||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.AnnotationTarget; | ||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.IndexView; | ||
import org.knowm.xchange.BaseExchange; | ||
|
||
class XchangeProcessor { | ||
|
||
private static final String FEATURE = "camel-xchange"; | ||
|
||
@BuildStep | ||
FeatureBuildItem feature() { | ||
return new FeatureBuildItem(FEATURE); | ||
} | ||
|
||
@BuildStep | ||
ExtensionSslNativeSupportBuildItem activateSslNativeSupport() { | ||
return new ExtensionSslNativeSupportBuildItem(FEATURE); | ||
} | ||
|
||
@BuildStep | ||
void indexDependenciesAndResources( | ||
BuildProducer<IndexDependencyBuildItem> indexedDependency, | ||
BuildProducer<NativeImageResourceBuildItem> nativeImageResource, | ||
CurateOutcomeBuildItem curateOutcome) { | ||
|
||
List<AppDependency> userDependencies = curateOutcome.getEffectiveModel().getUserDependencies(); | ||
for (AppDependency dependency : userDependencies) { | ||
AppArtifact artifact = dependency.getArtifact(); | ||
|
||
if (artifact.getGroupId().equals("org.knowm.xchange")) { | ||
// Index any org.knowm.xchange dependencies present on the classpath as they contain the APIs for interacting with each crypto exchange | ||
String artifactId = artifact.getArtifactId(); | ||
indexedDependency.produce(new IndexDependencyBuildItem(artifact.getGroupId(), artifactId)); | ||
|
||
// Include crypto exchange metadata resources | ||
String[] split = artifactId.split("-"); | ||
if (split.length > 1) { | ||
String cryptoExchange = split[split.length - 1]; | ||
nativeImageResource.produce(new NativeImageResourceBuildItem(cryptoExchange + ".json")); | ||
} | ||
} | ||
} | ||
|
||
indexedDependency.produce(new IndexDependencyBuildItem("org.jboss.spec.javax.ws.rs", "jboss-jaxrs-api_2.1_spec")); | ||
} | ||
|
||
@BuildStep | ||
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, CombinedIndexBuildItem combinedIndex) { | ||
// The xchange component dynamically instantiates Exchange classes so they must be registered for reflection | ||
IndexView index = combinedIndex.getIndex(); | ||
String[] xchangeClasses = index.getAllKnownSubclasses(DotName.createSimple(BaseExchange.class.getName())) | ||
.stream() | ||
.map(classInfo -> classInfo.name().toString()) | ||
.toArray(String[]::new); | ||
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, xchangeClasses)); | ||
|
||
// DTO classes need to be serialized / deserialized | ||
String[] dtoClasses = index.getKnownClasses() | ||
.stream() | ||
.map(classInfo -> classInfo.name().toString()) | ||
.filter(className -> className.startsWith("org.knowm.xchange.dto")) | ||
.toArray(String[]::new); | ||
reflectiveClass.produce(new ReflectiveClassBuildItem(false, true, dtoClasses)); | ||
|
||
// rescu REST framework needs reflective access to the value method on some JAX-RS annotations | ||
String[] jaxrsAnnotations = index.getKnownClasses() | ||
.stream() | ||
.filter(ClassInfo::isAnnotation) | ||
.filter(classInfo -> classInfo.firstMethod("value") != null) | ||
.map(classInfo -> classInfo.name().toString()) | ||
.filter(className -> className.startsWith("javax.ws.rs")) | ||
.toArray(String[]::new); | ||
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, jaxrsAnnotations)); | ||
|
||
} | ||
|
||
@BuildStep | ||
void registerProxyClasses(BuildProducer<NativeImageProxyDefinitionBuildItem> nativeImageProxy, | ||
CombinedIndexBuildItem combinedIndexBuildItem) { | ||
// Some xchange libraries use JAX-RS proxies to interact with the exchange APIs so we need to register them | ||
IndexView index = combinedIndexBuildItem.getIndex(); | ||
index.getAnnotations(DotName.createSimple("javax.ws.rs.Path")) | ||
.stream() | ||
.map(AnnotationInstance::target) | ||
.filter(target -> target.kind().equals(AnnotationTarget.Kind.CLASS)) | ||
.map(AnnotationTarget::asClass) | ||
.filter(classInfo -> Modifier.isInterface(classInfo.flags())) | ||
.map(classInfo -> classInfo.name().toString()) | ||
.filter(className -> className.startsWith("org.knowm.xchange")) | ||
.map(NativeImageProxyDefinitionBuildItem::new) | ||
.forEach(nativeImageProxy::produce); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.