You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2026/04/27 12:46:46 UTC

(camel) branch main updated: CAMEL-23353: Add missing doc, test and proper handle when download=false for extra.repos (#22784)

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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 122ed1a73400 CAMEL-23353: Add missing doc, test and proper handle when download=false for extra.repos (#22784)
122ed1a73400 is described below

commit 122ed1a73400ab63ecdd05b0ee84e47002b35298
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Mon Apr 27 14:46:40 2026 +0200

    CAMEL-23353: Add missing doc, test and proper handle when download=false for extra.repos (#22784)
---
 .../modules/ROOT/pages/camel-jbang.adoc            | 11 ++++
 .../dsl/jbang/core/commands/ExportQuarkus.java     | 10 +--
 .../tooling/maven/MavenDownloaderImplTest.java     | 73 ++++++++++++++++++++++
 3 files changed, 90 insertions(+), 4 deletions(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index fe567fc6db23..de578f12c467 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -869,6 +869,14 @@ with the key `camel.jbang.repos` as shown:
 camel.jbang.repos=https://packages.atlassian.com/maven-external
 ----
 
+Alternatively, you can configure default Maven repositories globally via a system property.
+This is useful for custom Camel distributions that require additional repositories without manual configuration on each command:
+
+[source,bash]
+----
+export JAVA_TOOL_OPTIONS="-Dcamel.extra.repos=repo1=https://repo1.example.com/maven2,repo2=https://repo2.example.com/releases"
+----
+
 When running Camel you need to include the properties file to use:
 
 [source,bash]
@@ -4065,6 +4073,9 @@ camel export --runtime=quarkus --gav=com.foo:acme:1.0-SNAPSHOT --directory=../my
 
 TIP: See the possible options by running: `camel export --help` for more details.
 
+NOTE: The Quarkus platform version is automatically resolved from the Quarkus platform registry based on the Camel version's compatible Quarkus stream.
+If the registry is unavailable or downloads are disabled, the build-time default version is used.
+
 NOTE: You cannot use `--profile` option when exporting to Camel Quarkus.
 
 === Exporting to Camel Main
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java
index c33ce84a6f19..49e40b0edb9f 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java
@@ -138,10 +138,12 @@ class ExportQuarkus extends Export {
             appJar = "target" + File.separator + ids[1] + "-" + ids[2] + ".jar";
         }
         copyReadme(BUILD_DIR, appJar);
-        // resolve Quarkus platform version from registry (if available)
-        String resolved = QuarkusHelper.resolveQuarkusPlatformVersion(quarkusVersion);
-        if (resolved != null) {
-            quarkusVersion = resolved;
+        // resolve Quarkus platform version from registry (when download is true)
+        if (download) {
+            String resolved = QuarkusHelper.resolveQuarkusPlatformVersion(quarkusVersion);
+            if (resolved != null) {
+                quarkusVersion = resolved;
+            }
         }
         // gather dependencies
         Set<String> deps = resolveDependencies(settings, profile);
diff --git a/tooling/camel-tooling-maven/src/test/java/org/apache/camel/tooling/maven/MavenDownloaderImplTest.java b/tooling/camel-tooling-maven/src/test/java/org/apache/camel/tooling/maven/MavenDownloaderImplTest.java
index 95d49d5184e4..6ccc9a13de6b 100644
--- a/tooling/camel-tooling-maven/src/test/java/org/apache/camel/tooling/maven/MavenDownloaderImplTest.java
+++ b/tooling/camel-tooling-maven/src/test/java/org/apache/camel/tooling/maven/MavenDownloaderImplTest.java
@@ -23,6 +23,7 @@ import java.security.MessageDigest;
 import java.util.Base64;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.util.FileUtil;
@@ -623,4 +624,76 @@ class MavenDownloaderImplTest {
             LOG.info("Authentication and mirror test passed - artifact resolved through authenticated mirror");
         }
     }
+
+    @Test
+    void testExtraDefaultRepositoriesFromSystemProperty() throws Exception {
+        // This test verifies that MIMA correctly loads extra default repositories from system properties.
+
+        // Use the local test server that requires authentication
+        String testRepoUrl = "http://localhost:" + localServer.getLocalPort() + "/maven/repository";
+        String extraReposValue = "test-server=" + testRepoUrl;
+
+        File customLocalRepo = new File(tempDir, "extra-repos-test-m2");
+        Files.createDirectories(customLocalRepo.toPath());
+
+        String artifactCoords = "org.apache.camel:camel-test:9.99.9-non-exist";
+
+        // Callable that captures local variables and performs artifact resolution
+        Callable<List<MavenArtifact>> resolve = () -> {
+            try (MavenDownloaderImpl downloader = new MavenDownloaderImpl()) {
+                downloader.setMavenCentralEnabled(false);
+                downloader.setMavenApacheSnapshotEnabled(false);
+                downloader.build();
+
+                MavenDownloader customDownloader = downloader.customize(
+                        customLocalRepo.getAbsolutePath(),
+                        5000,
+                        10000);
+
+                return customDownloader.resolveArtifacts(
+                        List.of(artifactCoords),
+                        null,
+                        false,
+                        false);
+            }
+        };
+
+        String originalValue = System.getProperty("camel.extra.repos");
+        try {
+            // NEGATIVE TEST: without the extra repo, the resolution fails because of no artifact can be resolved, definitely not authentication failure
+            System.clearProperty("camel.extra.repos");
+
+            try {
+                resolve.call();
+                fail("Should have failed without extra repos system property");
+            } catch (MavenResolutionException e) {
+                // Expected - no repositories configured
+                assertFalse(e.getMessage().contains("401") || e.getMessage().contains("Unauthorized")
+                        || e.getMessage().contains("status code"),
+                        "Should fail due to no repositories, not authentication, got: " + e.getMessage());
+            }
+
+            // POSITIVE TEST: with the extra repo configured, we have to receive authentication failure
+            System.setProperty("camel.extra.repos", extraReposValue);
+
+            try {
+                resolve.call();
+                fail("Should have failed with 401 Unauthorized (proves repo was loaded from system property)");
+            } catch (MavenResolutionException e) {
+                // Expected - repository loaded but download fails due to no authentication
+                // The 401 error proves the repository from the system property was actually used
+                assertTrue(e.getMessage().contains("401") || e.getMessage().contains("Unauthorized")
+                        || e.getMessage().contains("status code"),
+                        "Should fail with 401/authentication error (proves repository was used), got: " + e.getMessage());
+            }
+
+        } finally {
+            // Clean up system property
+            if (originalValue != null) {
+                System.setProperty("camel.extra.repos", originalValue);
+            } else {
+                System.clearProperty("camel.extra.repos");
+            }
+        }
+    }
 }