Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assemblies/features/framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
<groupId>org.apache.karaf.features</groupId>
<artifactId>org.apache.karaf.features.core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.karaf.maven</groupId>
<artifactId>org.apache.karaf.maven.resolver.paxurl</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

Expand Down
2 changes: 2 additions & 0 deletions assemblies/features/framework/src/main/feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<bundle start-level="11">mvn:org.apache.felix/org.apache.felix.configurator/${felix.configurator.version}</bundle>
<bundle start-level="11">mvn:org.apache.karaf.config/org.apache.karaf.config.core/${project.version}</bundle>
<!-- features service -->
<bundle start-level="14">mvn:org.apache.karaf.maven/org.apache.karaf.maven.resolver.paxurl/${project.version}</bundle>
<bundle start-level="15">mvn:org.apache.karaf.features/org.apache.karaf.features.core/${project.version}</bundle>
<bundle dependency="true" start-level="14">mvn:jakarta.xml.bind/jakarta.xml.bind-api/${spec.jaxb-api.version}</bundle>
<bundle dependency="true" start-level="14">mvn:org.glassfish.jaxb/jaxb-runtime/${spec.jaxb.version}</bundle>
Expand Down Expand Up @@ -76,6 +77,7 @@
<!-- file install -->
<bundle start-level="12">mvn:org.apache.felix/org.apache.felix.fileinstall/${felix.fileinstall.version}</bundle>
<!-- features service -->
<bundle start-level="14">mvn:org.apache.karaf.maven/org.apache.karaf.maven.resolver.paxurl/${project.version}</bundle>
<bundle start-level="15">mvn:org.apache.karaf.features/org.apache.karaf.features.core/${project.version}</bundle>
<bundle dependency="true" start-level="14">mvn:jakarta.xml.bind/jakarta.xml.bind-api/${spec.jaxb-api.version}</bundle>
<bundle dependency="true" start-level="14">mvn:org.glassfish.jaxb/jaxb-runtime/${spec.jaxb.version}</bundle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.api.action.lifecycle.Service;
import org.apache.karaf.shell.support.completers.FileCompleter;
import org.ops4j.pax.url.mvn.MavenResolver;
import org.apache.karaf.features.spi.MavenResolver;

/**
* Simple {@link FeaturesCommandSupport} implementation that allows a user in
Expand Down
28 changes: 1 addition & 27 deletions features/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.url</groupId>
<artifactId>pax-url-aether</artifactId>
</dependency>

<dependency>
<groupId>org.ops4j.base</groupId>
<artifactId>ops4j-base-util-property</artifactId>
</dependency>
<dependency>
<groupId>org.ops4j.base</groupId>
<artifactId>ops4j-base-util-collections</artifactId>
</dependency>
<dependency>
<groupId>org.ops4j.pax.swissbox</groupId>
<artifactId>pax-swissbox-property</artifactId>
</dependency>

<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
Expand All @@ -158,12 +140,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.tinybundles</groupId>
<artifactId>tinybundles</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand Down Expand Up @@ -214,6 +190,7 @@
<instructions>
<Export-Package>
org.apache.karaf.features,
org.apache.karaf.features.spi,
org.apache.karaf.features.management,
org.apache.karaf.features.management.codec;-noimport:=true,
org.osgi.service.repository,
Expand Down Expand Up @@ -248,9 +225,6 @@
org.apache.karaf.util.xml,
org.eclipse.equinox.internal.region.*;-split-package:=merge-first,
org.apache.felix.resolver.*,
org.ops4j.pax.swissbox.*,
org.ops4j.util.*,
org.ops4j.lang.*,
com.fasterxml.jackson*
</Private-Package>
<Embed-Dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.concurrent.ScheduledExecutorService;

import org.apache.karaf.features.internal.download.impl.MavenDownloadManager;
import org.ops4j.pax.url.mvn.MavenResolver;
import org.apache.karaf.features.spi.MavenResolver;

public final class DownloadManagers {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.karaf.features.internal.download.Downloader;
import org.apache.karaf.features.internal.download.StreamProvider;
import org.apache.karaf.features.internal.util.MultiException;
import org.ops4j.pax.url.mvn.MavenResolver;
import org.apache.karaf.features.spi.MavenResolver;

public class MavenDownloadManager implements DownloadManager {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Objects;

import org.apache.karaf.util.maven.Parser;
import org.ops4j.pax.url.mvn.MavenResolver;
import org.apache.karaf.features.spi.MavenResolver;

public class MavenDownloadTask extends AbstractRetryableDownloadTask {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.apache.karaf.features.internal.service.StateStorage;
import org.apache.karaf.features.internal.util.SystemExitManager;
import org.apache.karaf.util.ThreadUtils;
import org.apache.karaf.features.spi.MavenResolverFactory;
import org.apache.karaf.util.tracker.BaseActivator;
import org.apache.karaf.util.tracker.annotation.ProvideService;
import org.apache.karaf.util.tracker.annotation.RequireService;
Expand Down Expand Up @@ -84,6 +85,7 @@
@Services(
requires = {
@RequireService(ConfigurationAdmin.class),
@RequireService(MavenResolverFactory.class),
@RequireService(value = URLStreamHandlerService.class, filter = "(url.handler.protocol=mvn)")
},
provides = {
Expand Down Expand Up @@ -200,6 +202,7 @@ protected void doStart() throws Exception {
configurationAdmin,
installSupport,
cfg);
simpleFeaturesService.setMavenResolverFactory(getTrackedService(MavenResolverFactory.class));
try {
EventAdminListener eventAdminListener = new EventAdminListener(bundleContext);
simpleFeaturesService.registerListener(eventAdminListener);
Expand All @@ -216,6 +219,7 @@ protected void doStart() throws Exception {
installSupport,
globalRepository,
cfg);
featuresService.setMavenResolverFactory(getTrackedService(MavenResolverFactory.class));
try {
EventAdminListener eventAdminListener = new EventAdminListener(bundleContext);
featuresService.registerListener(eventAdminListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@
import org.apache.karaf.features.internal.model.processing.FeaturesProcessing;
import org.apache.karaf.features.internal.model.processing.ObjectFactory;
import org.apache.karaf.util.xml.IndentingXMLEventWriter;
import org.ops4j.pax.swissbox.property.BundleContextPropertyResolver;
import org.ops4j.util.property.DictionaryPropertyResolver;
import org.ops4j.util.property.PropertyResolver;
import org.apache.karaf.features.internal.util.PropertyResolver;
import org.apache.karaf.features.internal.util.PropertySubstitutor;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
Expand Down Expand Up @@ -106,9 +105,9 @@ public FeaturesProcessing read(InputStream stream, Properties versions) throws E
Unmarshaller unmarshaller = FEATURES_PROCESSING_CONTEXT.createUnmarshaller();
UnmarshallerHandler handler = unmarshaller.getUnmarshallerHandler();

// BundleContextPropertyResolver gives access to e.g., ${karaf.base}
final PropertyResolver resolver = bundleContext == null ? new DictionaryPropertyResolver(versions)
: new DictionaryPropertyResolver(versions, new BundleContextPropertyResolver(bundleContext));
// the bundle context resolver gives access to e.g., ${karaf.base}
final PropertyResolver resolver = bundleContext == null ? PropertyResolver.forDictionary(versions)
: PropertyResolver.forDictionary(versions, PropertyResolver.forBundleContext(bundleContext));

// indirect unmarshaling with property resolution inside XML attribute values and CDATA
SAXParserFactory spf = SAXParserFactory.newInstance();
Expand Down Expand Up @@ -314,7 +313,7 @@ private void flushBuffer(boolean resolve) throws SAXException {
}

private String resolve(String value) {
String resolved = org.ops4j.util.collections.PropertyResolver.resolve(properties, value);
String resolved = PropertySubstitutor.substitute(properties, value);
if (resolved.contains("${")) {
// there are still unresolved properties - just log warning
LOG.warn("Value {} has unresolved properties, please check configuration.", value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@
import org.apache.karaf.util.json.JsonWriter;
import org.apache.karaf.util.collections.CopyOnWriteArrayIdentityList;
import org.eclipse.equinox.region.RegionDigraph;
import org.ops4j.pax.url.mvn.MavenResolver;
import org.ops4j.pax.url.mvn.MavenResolvers;
import org.apache.karaf.features.spi.MavenResolver;
import org.apache.karaf.features.spi.MavenResolverFactory;
import org.apache.karaf.features.spi.MavenResolvers;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.InvalidSyntaxException;
Expand Down Expand Up @@ -112,6 +113,8 @@ public class FeaturesServiceImpl implements FeaturesService, BootManaged, Deploy
private final FeatureRepoFinder featureFinder;
private final ConfigurationAdmin configurationAdmin;
private final Resolver resolver;

private volatile MavenResolverFactory mavenResolverFactory;
private final BundleInstallSupport installSupport;
private final FeaturesServiceConfig cfg;
private RepositoryCache repositories;
Expand Down Expand Up @@ -1086,18 +1089,29 @@ private void doProvision(Map<String, Set<String>> requirements, /
}
}

/**
* Set the {@link MavenResolverFactory} to use. When left unset, the factory is looked up with
* {@link MavenResolvers#factory()}, which is how non-OSGi embedders get one.
*
* @param mavenResolverFactory the factory to use.
*/
public void setMavenResolverFactory(MavenResolverFactory mavenResolverFactory) {
this.mavenResolverFactory = mavenResolverFactory;
}

protected DownloadManager createDownloadManager() throws IOException {
Dictionary<String, String> props = getMavenConfig();
MavenResolver resolver = MavenResolvers.createMavenResolver(props, "org.ops4j.pax.url.mvn");
MavenResolverFactory factory = mavenResolverFactory != null ? mavenResolverFactory : MavenResolvers.factory();
Dictionary<String, String> props = getMavenConfig(factory.getConfigurationPid());
MavenResolver resolver = factory.create(props);
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(cfg.downloadThreads, ThreadUtils.namedThreadFactory("downloader"));
executor.setMaximumPoolSize(cfg.downloadThreads);
return DownloadManagers.createDownloadManager(resolver, executor, cfg.scheduleDelay, cfg.scheduleMaxRun);
}

private Dictionary<String, String> getMavenConfig() throws IOException {
private Dictionary<String, String> getMavenConfig(String pid) throws IOException {
Hashtable<String, String> props = new Hashtable<>();
if (configurationAdmin != null) {
Configuration config = configurationAdmin.getConfiguration("org.ops4j.pax.url.mvn", null);
Configuration config = configurationAdmin.getConfiguration(pid, null);
if (config != null) {
Dictionary<String, Object> cfg = config.getProcessedProperties(null);
if (cfg != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
import org.apache.karaf.features.internal.model.JaxbUtil;
import org.apache.karaf.util.ThreadUtils;
import org.apache.karaf.util.collections.CopyOnWriteArrayIdentityList;
import org.ops4j.pax.url.mvn.MavenResolver;
import org.ops4j.pax.url.mvn.MavenResolvers;
import org.apache.karaf.features.spi.MavenResolver;
import org.apache.karaf.features.spi.MavenResolverFactory;
import org.apache.karaf.features.spi.MavenResolvers;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.InvalidSyntaxException;
Expand Down Expand Up @@ -108,6 +109,8 @@ public class SimpleFeaturesServiceImpl implements FeaturesService, BootManaged,
private final ConfigurationAdmin configurationAdmin;
private final BundleInstallSupport installSupport;
private final FeaturesServiceConfig cfg;

private volatile MavenResolverFactory mavenResolverFactory;
private RepositoryCache repositories;
private FeaturesProcessor featuresProcessor;

Expand Down Expand Up @@ -842,18 +845,29 @@ private void doProvision(Map<String, Set<String>> requirements,
}
}

/**
* Set the {@link MavenResolverFactory} to use. When left unset, the factory is looked up with
* {@link MavenResolvers#factory()}, which is how non-OSGi embedders get one.
*
* @param mavenResolverFactory the factory to use.
*/
public void setMavenResolverFactory(MavenResolverFactory mavenResolverFactory) {
this.mavenResolverFactory = mavenResolverFactory;
}

protected DownloadManager createDownloadManager() throws IOException {
Dictionary<String, String> props = getMavenConfig();
MavenResolver resolver = MavenResolvers.createMavenResolver(props, "org.ops4j.pax.url.mvn");
MavenResolverFactory factory = mavenResolverFactory != null ? mavenResolverFactory : MavenResolvers.factory();
Dictionary<String, String> props = getMavenConfig(factory.getConfigurationPid());
MavenResolver resolver = factory.create(props);
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(cfg.downloadThreads, ThreadUtils.namedThreadFactory("downloader"));
executor.setMaximumPoolSize(cfg.downloadThreads);
return DownloadManagers.createDownloadManager(resolver, executor, cfg.scheduleDelay, cfg.scheduleMaxRun);
}

private Dictionary<String, String> getMavenConfig() throws IOException {
private Dictionary<String, String> getMavenConfig(String pid) throws IOException {
Hashtable<String, String> props = new Hashtable<>();
if (configurationAdmin != null) {
Configuration config = configurationAdmin.getConfiguration("org.ops4j.pax.url.mvn", null);
Configuration config = configurationAdmin.getConfiguration(pid, null);
if (config != null) {
Dictionary<String, Object> cfg = config.getProcessedProperties(null);
if (cfg != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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.karaf.features.internal.util;

import java.util.Dictionary;

import org.osgi.framework.BundleContext;

/**
* Resolves a property by name, optionally delegating to a fallback resolver.
*
* <p>A blank value is treated as no value, so resolution falls through to the fallback.</p>
*/
@FunctionalInterface
public interface PropertyResolver {

/**
* Resolve a property.
*
* @param key the property name.
* @return the property value, or <code>null</code> if unknown.
*/
String get(String key);

/**
* A resolver backed by a dictionary.
*
* @param properties the properties to read, may be <code>null</code>.
* @return the resolver.
*/
static PropertyResolver forDictionary(Dictionary<?, ?> properties) {
return forDictionary(properties, null);
}

/**
* A resolver backed by a dictionary, falling back to another resolver.
*
* @param properties the properties to read, may be <code>null</code>.
* @param fallback the resolver to consult when the dictionary has no value, may be <code>null</code>.
* @return the resolver.
*/
static PropertyResolver forDictionary(Dictionary<?, ?> properties, PropertyResolver fallback) {
return key -> {
String value = null;
if (properties != null) {
Object raw = properties.get(key);
if (raw instanceof String) {
value = (String) raw;
}
}
if (value != null && value.trim().isEmpty()) {
value = null;
}
if (value == null && fallback != null) {
value = fallback.get(key);
}
return value;
};
}

/**
* A resolver backed by the framework properties, which themselves fall back to system properties.
* It gives access to e.g. <code>${karaf.base}</code>.
*
* @param bundleContext the bundle context to read, may be <code>null</code>.
* @return the resolver.
*/
static PropertyResolver forBundleContext(BundleContext bundleContext) {
return key -> {
String value = bundleContext == null ? null : bundleContext.getProperty(key);
return value != null && value.trim().isEmpty() ? null : value;
};
}

}
Loading
Loading