use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationImplTest method testMissingVersionInName.
@Test
public void testMissingVersionInName() throws Exception {
String expectedName = "test-dependencies";
Repository repo = mock(Repository.class);
when(repo.getName()).thenReturn(expectedName);
when(repo.getFeatures()).thenReturn(new Feature[0]);
ApplicationImpl application = new ApplicationImpl(repo);
assertThat("Application name is wrong", application.getName(), equalTo(expectedName));
assertThat("Version number is wrong", application.getVersion(), equalTo("0.0.0"));
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationImplTest method testComplexApplicationName.
@Test
public void testComplexApplicationName() throws Exception {
String name = "test-dependencies-1.2.3-1a";
Repository repo = mock(Repository.class);
when(repo.getName()).thenReturn(name);
when(repo.getFeatures()).thenReturn(new Feature[0]);
ApplicationImpl application = new ApplicationImpl(repo);
assertThat("Application name is wrong", application.getName(), equalTo("test-dependencies"));
assertThat("Version number is wrong", application.getVersion(), equalTo("1.2.3-1a"));
}
use of org.apache.karaf.features.Repository in project karaf by apache.
the class FeaturesServiceImpl method registerListener.
//
// Listeners support
//
@Override
public void registerListener(FeaturesListener listener) {
listeners.add(listener);
try {
Set<String> repositoriesList = new TreeSet<>();
Map<String, Set<String>> installedFeatures = new TreeMap<>();
synchronized (lock) {
repositoriesList.addAll(state.repositories);
installedFeatures.putAll(copy(state.installedFeatures));
}
for (String uri : repositoriesList) {
Repository repository = repositories.create(URI.create(uri), false);
listener.repositoryEvent(new RepositoryEvent(repository, RepositoryEvent.EventType.RepositoryAdded, true));
}
for (Map.Entry<String, Set<String>> entry : installedFeatures.entrySet()) {
for (String id : entry.getValue()) {
Feature feature = org.apache.karaf.features.internal.model.Feature.valueOf(id);
listener.featureEvent(new FeatureEvent(FeatureEvent.EventType.FeatureInstalled, feature, entry.getKey(), true));
}
}
} catch (Exception e) {
LOGGER.error("Error notifying listener about the current state", e);
}
}
use of org.apache.karaf.features.Repository in project karaf by apache.
the class FeaturesServiceImpl method removeRepository.
@Override
public void removeRepository(URI uri, boolean uninstall) throws Exception {
// This will also ensure the cache is loaded
Repository repo = getRepository(uri);
if (repo == null) {
return;
}
Map<String, Set<String>> reqsToRemove;
Set<String> features;
synchronized (lock) {
getFeatureCache();
features = new HashSet<>();
for (Set<String> reqs : state.requirements.values()) {
features.addAll(reqs);
}
Set<Repository> repos = new HashSet<>();
for (String r : state.repositories) {
if (!uri.toString().equals(r)) {
Repository rep = repositories.getRepository(r);
repos.addAll(repositories.getRepositoryClosure(rep));
}
}
for (Repository rep : repos) {
for (Feature f : rep.getFeatures()) {
features.remove(new FeatureReq(f).toRequirement());
}
}
reqsToRemove = new HashMap<>();
for (Map.Entry<String, Set<String>> entry : state.requirements.entrySet()) {
Set<String> reqs = new HashSet<>(entry.getValue());
reqs.retainAll(features);
if (!reqs.isEmpty()) {
reqsToRemove.put(entry.getKey(), reqs);
}
}
}
if (!features.isEmpty()) {
if (uninstall) {
removeRequirements(reqsToRemove, EnumSet.noneOf(Option.class));
} else {
throw new IllegalStateException("The following features are required from the repository: " + String.join(", ", features));
}
}
synchronized (lock) {
// Remove repo
if (!state.repositories.remove(uri.toString())) {
return;
}
// Clean cache
featureCache = null;
repositories.removeRepository(uri);
saveState();
}
callListeners(new RepositoryEvent(repo, RepositoryEvent.EventType.RepositoryRemoved, false));
}
use of org.apache.karaf.features.Repository in project karaf by apache.
the class FeaturesServiceMBeanImpl method getRepositories.
/**
* {@inheritDoc}
*/
public TabularData getRepositories() throws Exception {
try {
List<Repository> allRepositories = Arrays.asList(featuresService.listRepositories());
ArrayList<JmxRepository> repositories = new ArrayList<>();
for (Repository repository : allRepositories) {
try {
repositories.add(new JmxRepository(repository));
} catch (Throwable t) {
t.printStackTrace();
}
}
return JmxRepository.tableFrom(repositories);
} catch (Throwable t) {
t.printStackTrace();
return null;
}
}
Aggregations