From 4b19470949d817a7b54321c908ca730c0fcc3777 Mon Sep 17 00:00:00 2001 From: Jiri Ondrusek Date: Mon, 27 Apr 2026 11:47:02 +0200 Subject: [PATCH] CAMEL-23353: Add missing doc, test and proper handle when download=false for extra.repos --- .../modules/ROOT/pages/camel-jbang.adoc | 11 +++ .../jbang/core/commands/ExportQuarkus.java | 10 ++- .../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 fe567fc6db23e..de578f12c467a 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 8490fe454833c..d62da17bce804 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 @@ public Integer export() throws Exception { 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 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 95d49d5184e4c..6ccc9a13de6be 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.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 @@ void testAuthenticationAndMirrors() throws Exception { 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> 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"); + } + } + } }