use of org.apache.karaf.features.Repository in project karaf by apache.
the class FeaturesServiceImpl method refreshFeatures.
@Override
public void refreshFeatures(EnumSet<Option> options) throws Exception {
Set<URI> uris = new LinkedHashSet<>();
for (Repository r : this.repositories.listRepositories()) {
uris.add(r.getURI());
}
this.refreshRepositories(uris);
this.featuresProcessor = new FeaturesProcessorImpl(cfg);
this.repositories = new RepositoryCacheImpl(featuresProcessor);
State state = copyState();
doProvisionInThread(state.requirements, emptyMap(), state, getFeaturesById(), options);
}
use of org.apache.karaf.features.Repository 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));
}
}
use of org.apache.karaf.features.Repository 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.Repository in project karaf by apache.
the class FeaturesValidationTest method testNs12Unmarshall.
@Test
public void testNs12Unmarshall() throws Exception {
Repository features = unmarshalAndValidate("f06.xml");
assertNotNull(features);
}
use of org.apache.karaf.features.Repository in project karaf by apache.
the class FeaturesValidationTest method testNs10NoName.
@Test
public void testNs10NoName() throws Exception {
Repository features = unmarshalAndValidate("f03.xml");
assertNotNull(features);
}
Aggregations