Repository navigation
feat(services): add native karaf.url service (mvn: and wrap:) and use it in karaf-light - #2333
Merged
Merged
Conversation
jbonofre
force-pushed
the
gh-2332
branch
3 times, most recently
from
November 19, 2026 09:27
1e1f014 to
91bb4a6
Compare
Add a new URL handler service under services/url that provides a native replacement for pax-url-mvn. The service registers a URLStreamHandlerService for the mvn: protocol and exposes a MavenResolver API for programmatic artifact resolution from local and remote Maven repositories.
Remove the redundant explicit Bundle-Activator instruction, which collided with the activator class already detected by karaf-services-maven-plugin and produced an invalid duplicate-type manifest header, failing the bundle build. Also embed org.apache.karaf.util.maven and org.apache.karaf.util.tracker(.annotation), which are provided-scope dependencies that were not packaged into the bundle, leaving Parser and BaseActivator unresolved at runtime.
Add a wrap: URL handler to the native Karaf URL service, equivalent to pax-url-wrap. The handler supports the same syntax (wrap:jar-url[,instructions-url][$instructions]), the overwrite modes (keep, merge, full) and the same defaults (optional Import-Package, Export-Package: *, symbolic name derived from the URL). The OSGi manifest is generated with bnd, embedded privately in the bundle (only the used packages, with the OSGi API not provided by the framework), so all bnd instructions are supported.
…rl service The features service now resolves mvn: URIs through the org.apache.karaf.features.spi contract, so the karaf.url service implements it instead of exposing its own MavenResolver API. MavenResolverImpl implements org.apache.karaf.features.spi.MavenResolver. A failed resolution is never retried by the features service, as the downloads from the remote repositories are already retried (connection.retryCount). The bundle registers a MavenResolverFactory, which the features service uses with the org.apache.karaf.url.mvn configuration, and a ready to use MavenResolver, used by the components that just resolve an artifact (feature:export-bundles). The factory is also declared for ServiceLoader, so it can be used outside the OSGi framework, where the configuration variables are resolved with the system properties. The org.apache.karaf.services.url package is removed: the bundle no longer exports any package.
…bution The karaf-light distribution now provides the mvn: and wrap: protocols with the native Karaf URL service instead of pax-url-aether and pax-url-wrap, and the features service resolves the Maven artifacts with it, through the Karaf Maven resolver SPI. - Add the url feature (Karaf URL service at start level 5 and its etc/org.apache.karaf.url.mvn.cfg configuration) to the standard features. - karaf-light uses url as startup feature and blacklists the pax-url-aether and pax-url-wrap bundles, and the org.apache.karaf.maven.resolver.paxurl provider of the framework feature (the wrap feature stays as marker for the wrap deployer and the wrap prerequisites). The unused Pax URL files are removed from the assembly. - The Karaf URL service declares its URL handler capabilities, supports the @multi repositories (KAR repositories), and waits for the ConfigAdmin configuration when org.apache.karaf.url.mvn.requireConfigAdminConfig is set (as in etc/config.properties). Until then, it provides neither the URL handlers nor the Maven resolver, so the features service uses the system repository. - Child instances get the Karaf URL service configuration and the features processing file of the root instance. - Document the Karaf URL service provider in the Maven resolver section of the manual.
The features service used the last registered MavenResolverFactory and, when it went away, no factory at all, even if another one was still registered. Installing the url feature in the standard distribution then silently replaced the Pax URL resolver, and uninstalling it left the features service resolving from the system repository only. The features service now uses the factory with the highest service.ranking and, for the same ranking, the first registered one (as BundleContext.getServiceReference() does), and switches to the best remaining one when the factory in use is unregistered.
…araf.url resolver - Parse the repositories as Pax URL does: only the known @ options (@id=, @snapshots, @noreleases, @multi, ...) are removed, any other @ is part of the URL. A distribution in /var/jenkins/workspace/job@2 or a repository URL with credentials were cut at the first @. - Authenticate on a remote repository with the credentials of its URL (https://user:password@host/...), given to that host only. - Download each artifact to a temporary file of its own and move it atomically, so concurrent downloads of the same artifact do not mix their content (as SimpleDownloadTask, apachegh-2808). - Resolve the file: repositories of the remote repositories list, which were skipped. - Use the repository of mvn:repository_url!groupId/artifactId URLs. - Accept hand written file: URIs (spaces, relative URIs) as Pax URL does, and ignore an invalid repository with a warning instead of failing every resolution. - Reject the artifact paths leading outside of the repositories (mvn:a/../.. for instance). - Fetch the checksums with the same connection settings as the artifact (certificateCheck, timeouts, credentials), and fail a download which can't be verified with the fail checksum policy, as Maven does.
…tances
A child instance got the etc/org.apache.karaf.features.xml file of the root
instance, but not etc/versions.properties, which provides the values of its
${...} placeholders.
bundle:watch only read the local repository of the org.ops4j.pax.url.mvn configuration, so in the karaf-light distribution it watched ~/.m2/repository instead of the configured local repository. Without Pax URL configuration, it now uses the org.apache.karaf.url.mvn one. The options of the local repository (@id=...) are now removed as for the repositories: the path was replaced by the part starting at its first @, which also broke the paths containing @ (/var/jenkins/workspace/job@2).
…tamped snapshot When a resolution failed, MavenDownloadTask resolved the artifact again without the snapshot timestamp, even when its URL had none, so each missing artifact was resolved twice with the same URL.
…gs in the karaf.url resolver - Resolve the snapshots from the maven-metadata.xml files of the remote repositories (Maven 3 snapshotVersions and Maven 2 timestamps), using the newest version, and keep the local copy when it is newer or when the repositories can't be reached. As Maven, the metadata of each repository is kept in the local repository, and checked again as the update policy (globalUpdatePolicy, daily by default) tells. - Enforce @snapshots and @noreleases on the remote repositories. - Read the Maven settings (settings property, else ~/.m2/settings.xml, ${maven.home}/conf/settings.xml, ${M2_HOME}/conf/settings.xml): local repository, repositories of the active profiles (when repositories is not set, or appended when it starts with +), credentials of the servers, mirrors and proxies. - Without configuration, use the default repositories of the Karaf instance and the remote repositories of etc/org.apache.karaf.url.mvn.cfg, and log it, instead of ~/.m2/repository only. - Only retry the downloads which may succeed (server errors, rate limit, connection reset, checksum mismatch), with an increasing delay, and not an unknown host, a refused connection, a timeout or a client error. The resolution error now gives the error of each repository, and the error responses are read so the connections can be reused. - Substitute the variables of the configuration once, with the Felix InterpolationHelper (default values, nested variables), embedded in the bundle. - Remove the resolve(groupId, artifactId, classifier, extension, version) override, which dropped an empty version: the SPI default method is used. - Document the settings, the defaults and the policies in the configuration.
…cies of the karaf.url resolver - Compare the version of a remote snapshot with the one of the local copy, as Maven does: its maven-metadata-local.xml when it was installed, else the version it was downloaded with (in karaf-url-status.properties, as long as the file is not replaced). The modification time of the local copy was used, so a snapshot deployed by a build started before the download, or any snapshot when the local repository was copied, was never resolved. - Without metadata in the repositories, don't download a snapshot the local repository already has: its version can't be compared, so it was downloaded again on each resolution, even over a newer local build. The maven-metadata-local.xml of a file: repository is read. - Use the http proxy of the Maven settings for the https repositories when there is no https proxy, as Maven does. - Apply the @update=, @snapshotsUpdate=, @Checksum=, @releasesChecksum= and @snapshotsChecksum= options of the repositories when the global policies are not set, as Pax URL does, and read the checksum policies case insensitively. - Don't use the repository id, which may come from the URL, as a path in the name of the metadata cache file.
…f a karaf-light instance A child of a root instance starting the Karaf URL service got etc/org.ops4j.pax.url.mvn.cfg, so bundle:watch used the local repository of the Pax URL configuration (~/.m2/repository by default) instead of the configured one. As the logging configuration, it now only gets it when the root instance starts Pax URL.
…af home directory As the Karaf URL service, bundle:watch resolves a relative local repository of the org.apache.karaf.url.mvn configuration in the Karaf home directory, not in the working directory.
… fallback and NOTICE in karaf.url - Strip repository options and support file: URIs on localRepository in MavenConfiguration/Repository - Split wrap: URLs without regex ambiguity and allow valid OSGi header value characters in WrapUrlParser - Fall back across snapshot repositories ordered by metadata timestamp and decode checksums as UTF-8 in MavenResolverImpl - Quote literal segments in MavenSettings nonProxyHosts wildcard matching - Add bnd notice to assemblies/apache-karaf-light NOTICE
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #2212, closes #2332.
Add a native Karaf URL service as an alternative to Pax URL, and use it in the
apache-karaf-lightdistribution.Rebased on #2928: the Karaf URL service is now a provider of the Karaf Maven resolver SPI (
org.apache.karaf.features.spi), so this PR no longer changesprofileortooling.Karaf URL service (
services/url)mvn:protocol handler, resolving artifacts from the default (local, file-based) repositories, the local repository and remote repositories, without Aether. Configuration PID:org.apache.karaf.url.mvn(property names compatible withorg.ops4j.pax.url.mvn).@options are removed, so paths and URLs containing@(/var/jenkins/workspace/job@2,https://user:password@host/...) work.@snapshotsand@noreleasesapply to the remote repositories,file:remote repositories are read in place, and the repository ofmvn:repository_url!groupId/artifactId/...URLs is used. An invalid repository is ignored with a warning. The@update=,@snapshotsUpdate=,@checksum=,@releasesChecksum=and@snapshotsChecksum=options of the repositories apply when the global policies are not set, as in Pax URL.maven-metadata.xmlfiles of the repositories (Maven 3 and Maven 2 metadata), using the newest version. As in Maven, the metadata of each repository is cached in the local repository and checked again according to the update policy (dailyby default). The local copy is kept when it is not older, or when the repositories can't be reached: its version is the one of itsmaven-metadata-local.xml(mvn install), or the one it was downloaded with, not its modification time. Without metadata in the repositories, a snapshot is only downloaded when the local repository doesn't have it.settings, else~/.m2/settings.xml,${maven.home}/conf/settings.xml,${M2_HOME}/conf/settings.xml): local repository, repositories of the active profiles (used whenrepositoriesis not set, appended when it starts with+), server credentials (by repository id), mirrors and proxies (as in Maven, thehttpproxy is also used for thehttpsrepositories when there is nohttpsone).failpolicy also rejects a download without a checksum. The repository ids are not used as paths in the metadata cache file names. Only the errors which may not happen again are retried, with an increasing delay, and the resolution error gives the error of each repository. Artifact paths leading outside the repositories are rejected.etc/org.apache.karaf.url.mvn.cfg.MavenResolverFactory, used by the features service with theorg.apache.karaf.url.mvnconfiguration, and a ready to useMavenResolver, used byfeature:export-bundles. The factory is also declared forServiceLoader, so it can be used outside the OSGi framework. A failed resolution is not retried by the features service, as the downloads from the remote repositories are already retried (connection.retryCount). The bundle doesn't export any package.wrap:protocol handler, equivalent to pax-url-wrap: same syntax (wrap:jar-url[,instructions-url][$instructions]), overwrite modes (keep,merge,full) and defaults. The manifest is generated with bnd (the buildbnd.version, 7.5.0), embedded privately in the bundle (only the used packages), so all bnd instructions are supported. The bundle is about 2.5 MB because of bnd.@multirepositories (KAR repositories), declares the URL handler capabilities, and waits for the ConfigAdmin configuration whenorg.apache.karaf.url.mvn.requireConfigAdminConfigis set. Until then, it provides neither the URL handlers nor the Maven resolver, so the features service uses the system repository.karaf-light distribution
urlfeature in the standard features (Karaf URL service at start level 5 with itsetc/org.apache.karaf.url.mvn.cfg), used as startup feature by karaf-light.org.apache.karaf.maven.resolver.paxurlprovider of theframework-lightfeature (thewrapfeature stays as marker for the wrap deployer and thewrapprerequisites). The unused Pax URL files are removed from the assembly.versions.properties.Changes for all distributions
MavenResolverFactorywith the highestservice.ranking(the first registered one for the same ranking), and falls back to the best remaining one when it is unregistered. Installing theurlfeature in the standard distribution therefore doesn't replace Pax URL.MavenDownloadTaskresolves a failed artifact again without the snapshot timestamp only when its URL has one.bundle:watchuses the local repository of theorg.apache.karaf.url.mvnconfiguration when there is no Pax URL configuration, resolves a relative one in the Karaf home directory as the Karaf URL service does, and no longer breaks local repository paths containing@.The default distribution still uses Pax URL, through
org.apache.karaf.maven.resolver.paxurl.Testing
ServiceLoaderand withoutBundleContext), the features service factory selection,bundle:watchand the instance alignment.services/url,features/core,bundle/coreandinstance.job@2directory: only the Karaf URL and logging services (no Pax URL or Pax Logging bundle),wrap:mvn:install with instructions, path traversal rejected, child instance create/start. Since Add lightweight karaf-logging service and use it in apache-karaf-light #2949,feature:install karaf-webfails on karaf-light (org.apache.juli.loggingis only exported by pax-logging-api), unrelated to this PR.bundle:update, and a newbundle:updatedoesn't download it again.file:remote repository,mvn:file:...!g/a/vrepository,karaf-webinstall.settings.xml: snapshot installed frommaven-metadata.xml, newer deployment picked bybundle:update,bundle:watchupdating from the configured local repository.feature:install url, and the features service falls back to the Karaf one when the Pax URL provider is stopped.wrap:mvn:installs, deploy folder wrapping,feature:installwithwrap:bundles,kar:install, child instance create/start.Known limitations
LATEST,RELEASEand version ranges are not resolved, and a timestamped snapshot version is resolved as the newest version of its snapshot.activeProfilesoractiveByDefault.maven:*commands still target theorg.ops4j.pax.url.mvnconfiguration.feature:export-bundlesresolves the bundle locations with theMavenResolverservice, so it doesn't exportwrap:locations.httptohttpsare not followed (HttpURLConnection), afile:mirror is used as a remote repository, read timeouts are not retried, andlocalRepositoryis a path (not afile:URL).feature:install urland after a restart).