use of org.apache.karaf.features.Feature in project karaf by apache.
the class FeaturesDumpProvider method writeDump.
/**
* {@inheritDoc}
*/
protected void writeDump(OutputStreamWriter outputStreamWriter) throws Exception {
// creates header
outputStreamWriter.write("Repositories:\n");
// list repositories
for (Repository repo : features.listRepositories()) {
outputStreamWriter.write(repo.getURI() + " (" + repo.getName() + ")\n");
}
// list features
outputStreamWriter.write("\nfeatures:\n");
for (Feature feature : features.listFeatures()) {
outputStreamWriter.write(feature.getName() + " " + feature.getVersion());
outputStreamWriter.write(" installed: " + features.isInstalled(feature));
outputStreamWriter.write("\nBundles:\n");
for (BundleInfo bundle : feature.getBundles()) {
outputStreamWriter.write("\t" + bundle.getLocation());
if (bundle.getStartLevel() != 0) {
outputStreamWriter.write(" start level " + bundle.getStartLevel());
}
outputStreamWriter.write("\n\n");
}
}
// flush & close stream
outputStreamWriter.close();
}
use of org.apache.karaf.features.Feature in project karaf by apache.
the class FeatureReq method getMatchingFeatures.
public Stream<Feature> getMatchingFeatures(Map<String, Map<String, Feature>> allFeatures) {
Pattern pattern = Pattern.compile(name);
Function<String, Optional<Feature>> func = featureName -> {
Feature matchingFeature = null;
if (pattern.matcher(featureName).matches()) {
Map<String, Feature> versions = allFeatures.get(featureName);
matchingFeature = getLatestFeature(versions, versionRange);
}
return Optional.ofNullable(matchingFeature);
};
return allFeatures.keySet().stream().map(func).filter(Optional::isPresent).map(Optional::get);
}
use of org.apache.karaf.features.Feature in project karaf by apache.
the class FeatureReq method getLatestFeature.
private static Feature getLatestFeature(Map<String, Feature> versions, VersionRange versionRange) {
Feature feature = null;
if (versions != null && !versions.isEmpty()) {
Version latest = Version.emptyVersion;
for (String available : versions.keySet()) {
Version availableVersion = VersionTable.getVersion(available);
if (availableVersion.compareTo(latest) >= 0 && versionRange.contains(availableVersion)) {
Feature possiblyBlacklisted = versions.get(available);
// return only if there are no more non-blaclisted features
if (feature == null || !possiblyBlacklisted.isBlacklisted()) {
feature = possiblyBlacklisted;
}
latest = availableVersion;
}
}
}
return feature;
}
use of org.apache.karaf.features.Feature in project karaf by apache.
the class FeaturesServiceImpl method getFeatureCache.
/**
* Should not be called while holding a lock.
* @return map from feature name to map from feature version to Feature
*/
protected Map<String, Map<String, Feature>> getFeatureCache() throws Exception {
Set<String> uris;
synchronized (lock) {
if (featureCache != null) {
return featureCache;
}
uris = new TreeSet<>(state.repositories);
}
// the outer map's key is feature name, the inner map's key is feature version
Map<String, Map<String, Feature>> map = new HashMap<>();
// Two phase load:
// * first load dependent repositories
Set<String> loaded = new HashSet<>();
Queue<String> toLoad = new ArrayDeque<>(uris);
while (!toLoad.isEmpty()) {
String uri = toLoad.remove();
Repository repo;
synchronized (lock) {
repo = repositories.getRepository(uri);
}
try {
if (repo == null) {
repo = repositories.create(URI.create(uri), false);
synchronized (lock) {
repositories.addRepository(repo);
}
}
if (loaded.add(uri)) {
for (URI u : repo.getRepositories()) {
toLoad.add(u.toString());
}
}
} catch (Exception e) {
LOGGER.warn("Can't load features repository {}", uri, e);
}
}
List<Repository> repos;
synchronized (lock) {
repos = Arrays.asList(repositories.listRepositories());
}
// * then load all features
for (Repository repo : repos) {
for (Feature f : repo.getFeatures()) {
Map<String, Feature> versionMap = map.computeIfAbsent(f.getName(), key -> new HashMap<>());
versionMap.put(f.getVersion(), f);
}
}
synchronized (lock) {
if (uris.equals(state.repositories)) {
featureCache = map;
}
}
return map;
}
use of org.apache.karaf.features.Feature in project karaf by apache.
the class FeaturesServiceImpl method addRepository.
@Override
public void addRepository(URI uri, boolean install) throws Exception {
Repository repository = repositories.create(uri, true);
synchronized (lock) {
repositories.addRepository(repository);
featureCache = null;
// Add repo
if (!state.repositories.add(uri.toString())) {
return;
}
saveState();
}
callListeners(new RepositoryEvent(repository, RepositoryEvent.EventType.RepositoryAdded, false));
// install the features in the repo
if (install) {
HashSet<String> features = new HashSet<>();
for (Feature feature : repository.getFeatures()) {
features.add(feature.getId());
}
installFeatures(features, EnumSet.noneOf(FeaturesService.Option.class));
}
}
Aggregations