You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/12/17 14:38:31 UTC

[camel-quarkus] 05/06: Create substitutions for jsch

This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 5d79801e1af51ebf16b62f3a5c8857e9598b18e1
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Wed Dec 11 16:32:40 2019 +0100

    Create substitutions for jsch
---
 .../component/ftp/deployment/FtpProcessor.java     | 21 ++++++++++---
 extensions/ftp/runtime/pom.xml                     |  4 +++
 .../component/ftp/graal/AnyLocalAddress.java       | 31 +++++++++++++++++++
 .../ftp/graal/AnyLocalAddressAccessor.java         | 25 +++++++++++++++
 .../camel/quarkus/component/ftp/graal/Flags.java   | 36 ++++++++++++++++++++++
 .../ftp/graal/PortWatcherSubstitution.java         | 35 +++++++++++++++++++++
 6 files changed, 147 insertions(+), 5 deletions(-)

diff --git a/extensions/ftp/deployment/src/main/java/org/apache/camel/quarkus/component/ftp/deployment/FtpProcessor.java b/extensions/ftp/deployment/src/main/java/org/apache/camel/quarkus/component/ftp/deployment/FtpProcessor.java
index 3b48f61..27d781c 100644
--- a/extensions/ftp/deployment/src/main/java/org/apache/camel/quarkus/component/ftp/deployment/FtpProcessor.java
+++ b/extensions/ftp/deployment/src/main/java/org/apache/camel/quarkus/component/ftp/deployment/FtpProcessor.java
@@ -16,16 +16,21 @@
  */
 package org.apache.camel.quarkus.component.ftp.deployment;
 
-import io.quarkus.deployment.annotations.BuildProducer;
-import io.quarkus.deployment.annotations.BuildStep;
-import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
-import io.quarkus.deployment.builditem.FeatureBuildItem;
-import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.camel.component.file.remote.FtpConfiguration;
 import org.apache.camel.component.file.remote.FtpsConfiguration;
 import org.apache.camel.component.file.remote.RemoteFileConfiguration;
 import org.apache.camel.component.file.remote.SftpConfiguration;
+import org.apache.camel.quarkus.component.ftp.graal.AnyLocalAddress;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
 
 class FtpProcessor {
 
@@ -100,4 +105,10 @@ class FtpProcessor {
     ExtensionSslNativeSupportBuildItem activateSslNativeSupport() {
         return new ExtensionSslNativeSupportBuildItem(FEATURE);
     }
+
+    @BuildStep
+    List<RuntimeInitializedClassBuildItem> runtimeInitializedClasses() {
+        return Arrays.asList(
+                new RuntimeInitializedClassBuildItem(AnyLocalAddress.class.getName()));
+    }
 }
diff --git a/extensions/ftp/runtime/pom.xml b/extensions/ftp/runtime/pom.xml
index 91858a1..00ee45a 100644
--- a/extensions/ftp/runtime/pom.xml
+++ b/extensions/ftp/runtime/pom.xml
@@ -54,6 +54,10 @@
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.oracle.substratevm</groupId>
+            <artifactId>svm</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/AnyLocalAddress.java b/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/AnyLocalAddress.java
new file mode 100644
index 0000000..cc631c5
--- /dev/null
+++ b/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/AnyLocalAddress.java
@@ -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.component.ftp.graal;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class AnyLocalAddress {
+    public static InetAddress address;
+
+    static {
+        try {
+            address = InetAddress.getByName("0.0.0.0");
+        } catch (UnknownHostException e) {
+        }
+    }
+}
diff --git a/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/AnyLocalAddressAccessor.java b/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/AnyLocalAddressAccessor.java
new file mode 100644
index 0000000..dbf03c5
--- /dev/null
+++ b/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/AnyLocalAddressAccessor.java
@@ -0,0 +1,25 @@
+/*
+ * 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.ftp.graal;
+
+import java.net.InetAddress;
+
+final class AnyLocalAddressAccessor {
+    static InetAddress get() {
+        return AnyLocalAddress.address;
+    }
+}
diff --git a/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/Flags.java b/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/Flags.java
new file mode 100644
index 0000000..94139a6
--- /dev/null
+++ b/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/Flags.java
@@ -0,0 +1,36 @@
+/*
+ * 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.ftp.graal;
+
+import java.util.function.BooleanSupplier;
+
+public final class Flags {
+    private Flags() {
+    }
+
+    public static final class JGitIsNotOnClasspath implements BooleanSupplier {
+        @Override
+        public boolean getAsBoolean() {
+            try {
+                Class.forName("io.quarkus.jgit.runtime.Target_com_jcraft_jsch_PortWatcher");
+                return false;
+            } catch (ClassNotFoundException e) {
+                return true;
+            }
+        }
+    }
+}
diff --git a/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/PortWatcherSubstitution.java b/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/PortWatcherSubstitution.java
new file mode 100644
index 0000000..1c436a2
--- /dev/null
+++ b/extensions/ftp/runtime/src/main/java/org/apache/camel/quarkus/component/ftp/graal/PortWatcherSubstitution.java
@@ -0,0 +1,35 @@
+/*
+ * 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.ftp.graal;
+
+import java.net.InetAddress;
+
+import com.oracle.svm.core.annotate.Alias;
+import com.oracle.svm.core.annotate.InjectAccessors;
+import com.oracle.svm.core.annotate.TargetClass;
+
+/*
+ * We need to exclude this substitution if JGit is present as substitutions will collide
+ * 
+ *     https://github.com/quarkusio/quarkus/blob/0be78a6813db0d3be7d8e43ac76ace2b808433ef/extensions/jgit/runtime/src/main/java/io/quarkus/jgit/runtime/PortWatcherSubstitutions.java#L14-L20
+ */
+@TargetClass(className = "com.jcraft.jsch.PortWatcher", onlyWith = Flags.JGitIsNotOnClasspath.class)
+final class PortWatcherSubstitution {
+    @Alias
+    @InjectAccessors(AnyLocalAddressAccessor.class)
+    private static InetAddress anyLocalAddress;
+}