|
| 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.camel.quarkus.component.activemq6.deployment; |
| 18 | + |
| 19 | +import java.io.IOException; |
| 20 | +import java.io.InputStream; |
| 21 | +import java.util.Collection; |
| 22 | +import java.util.Properties; |
| 23 | +import java.util.stream.Stream; |
| 24 | + |
| 25 | +import io.quarkus.deployment.annotations.BuildProducer; |
| 26 | +import io.quarkus.deployment.annotations.BuildStep; |
| 27 | +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; |
| 28 | +import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem; |
| 29 | +import io.quarkus.deployment.builditem.FeatureBuildItem; |
| 30 | +import io.quarkus.deployment.builditem.IndexDependencyBuildItem; |
| 31 | +import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; |
| 32 | +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; |
| 33 | +import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem; |
| 34 | +import org.apache.activemq.transport.Transport; |
| 35 | +import org.apache.activemq.transport.discovery.DiscoveryAgent; |
| 36 | +import org.apache.activemq.util.IdGenerator; |
| 37 | +import org.apache.activemq.wireformat.WireFormatFactory; |
| 38 | +import org.jboss.jandex.ClassInfo; |
| 39 | +import org.jboss.jandex.DotName; |
| 40 | +import org.jboss.jandex.IndexView; |
| 41 | + |
| 42 | +class ActiveMQ6Processor { |
| 43 | + |
| 44 | + private static final String ACTIVEMQ_SERVICE_BASE = "META-INF/services/org/apache/activemq/"; |
| 45 | + private static final String FEATURE = "camel-activemq6"; |
| 46 | + |
| 47 | + @BuildStep |
| 48 | + FeatureBuildItem feature() { |
| 49 | + return new FeatureBuildItem(FEATURE); |
| 50 | + } |
| 51 | + |
| 52 | + @BuildStep |
| 53 | + ExtensionSslNativeSupportBuildItem activateSslNativeSupport() { |
| 54 | + return new ExtensionSslNativeSupportBuildItem(FEATURE); |
| 55 | + } |
| 56 | + |
| 57 | + @BuildStep |
| 58 | + void reflectiveClasses( |
| 59 | + CombinedIndexBuildItem combinedIndex, |
| 60 | + BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) { |
| 61 | + |
| 62 | + reflectiveClasses.produce( |
| 63 | + ReflectiveClassBuildItem.builder( |
| 64 | + java.net.Socket.class.getName(), |
| 65 | + "sun.security.ssl.SSLSocketImpl", |
| 66 | + org.apache.activemq.ActiveMQConnectionFactory.class.getName(), |
| 67 | + org.apache.activemq.ActiveMQPrefetchPolicy.class.getName(), |
| 68 | + org.apache.activemq.RedeliveryPolicy.class.getName(), |
| 69 | + org.apache.activemq.blob.BlobTransferPolicy.class.getName(), |
| 70 | + org.apache.activemq.command.ConsumerInfo.class.getName(), |
| 71 | + org.apache.activemq.openwire.v9.MarshallerFactory.class.getName(), |
| 72 | + org.apache.activemq.openwire.v10.MarshallerFactory.class.getName(), |
| 73 | + org.apache.activemq.openwire.v11.MarshallerFactory.class.getName(), |
| 74 | + org.apache.activemq.openwire.v12.MarshallerFactory.class.getName()) |
| 75 | + .methods() |
| 76 | + .build()); |
| 77 | + |
| 78 | + final IndexView index = combinedIndex.getIndex(); |
| 79 | + |
| 80 | + reflectiveClasses.produce( |
| 81 | + ReflectiveClassBuildItem.builder( |
| 82 | + Stream.of(Transport.class, WireFormatFactory.class, DiscoveryAgent.class) |
| 83 | + .map(DotName::createSimple) |
| 84 | + .map(index::getAllKnownImplementations) |
| 85 | + .flatMap(Collection::stream) |
| 86 | + .map(ClassInfo::name) |
| 87 | + .map(DotName::toString) |
| 88 | + .toArray(String[]::new)) |
| 89 | + .methods() |
| 90 | + .build()); |
| 91 | + } |
| 92 | + |
| 93 | + @BuildStep |
| 94 | + void addDependencies(BuildProducer<IndexDependencyBuildItem> indexDependency) { |
| 95 | + indexDependency.produce(new IndexDependencyBuildItem("org.apache.activemq", "activemq-client")); |
| 96 | + } |
| 97 | + |
| 98 | + @BuildStep |
| 99 | + void registerServiceProviders(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, |
| 100 | + BuildProducer<NativeImageResourceBuildItem> nativeImage) { |
| 101 | + |
| 102 | + String[] servicePaths = new String[] { |
| 103 | + ACTIVEMQ_SERVICE_BASE + "transport/discoveryagent/masterslave", |
| 104 | + ACTIVEMQ_SERVICE_BASE + "transport/discoveryagent/multicast", |
| 105 | + ACTIVEMQ_SERVICE_BASE + "transport/discoveryagent/simple", |
| 106 | + ACTIVEMQ_SERVICE_BASE + "transport/discoveryagent/static", |
| 107 | + ACTIVEMQ_SERVICE_BASE + "transport/failover", |
| 108 | + ACTIVEMQ_SERVICE_BASE + "transport/fanout", |
| 109 | + ACTIVEMQ_SERVICE_BASE + "transport/mock", |
| 110 | + ACTIVEMQ_SERVICE_BASE + "transport/multicast", |
| 111 | + ACTIVEMQ_SERVICE_BASE + "transport/nio", |
| 112 | + ACTIVEMQ_SERVICE_BASE + "transport/nio+ssl", |
| 113 | + ACTIVEMQ_SERVICE_BASE + "transport/ssl", |
| 114 | + ACTIVEMQ_SERVICE_BASE + "transport/tcp", |
| 115 | + ACTIVEMQ_SERVICE_BASE + "transport/udp", |
| 116 | + ACTIVEMQ_SERVICE_BASE + "wireformat/default", |
| 117 | + }; |
| 118 | + |
| 119 | + for (String path : servicePaths) { |
| 120 | + reflectiveClass.produce(ReflectiveClassBuildItem.builder(getServiceClass(path)).methods().build()); |
| 121 | + } |
| 122 | + |
| 123 | + nativeImage.produce(new NativeImageResourceBuildItem(servicePaths)); |
| 124 | + } |
| 125 | + |
| 126 | + @BuildStep |
| 127 | + void runtimeInitializedClasses(BuildProducer<RuntimeInitializedClassBuildItem> runtimeInitializedClass) { |
| 128 | + runtimeInitializedClass.produce(new RuntimeInitializedClassBuildItem(IdGenerator.class.getName())); |
| 129 | + } |
| 130 | + |
| 131 | + private String getServiceClass(String servicePath) { |
| 132 | + try (InputStream resource = ActiveMQ6Processor.class.getClassLoader().getResourceAsStream(servicePath)) { |
| 133 | + Properties properties = new Properties(); |
| 134 | + properties.load(resource); |
| 135 | + return properties.getProperty("class"); |
| 136 | + } catch (IOException e) { |
| 137 | + throw new IllegalStateException(e); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | +} |
0 commit comments