use of org.apache.karaf.features.Repository in project karaf by apache.
the class FeatureDeploymentListener method bundleChanged.
public synchronized void bundleChanged(BundleEvent bundleEvent) {
// Only handle resolved and uninstalled events
if (bundleEvent.getType() != BundleEvent.RESOLVED && bundleEvent.getType() != BundleEvent.UNINSTALLED) {
return;
}
Bundle bundle = bundleEvent.getBundle();
try {
// Remove previous informations
List<URI> repsToRemove = new ArrayList<>();
List<String> reqsToRemove = new ArrayList<>();
// Remove old properties
String prefix = "bundle." + bundle.getBundleId();
String countStr = (String) properties.remove(prefix + ".reps.count");
if (countStr != null) {
int count = Integer.parseInt(countStr);
for (int i = 0; i < count; i++) {
String rep = (String) properties.remove(prefix + ".reps.item" + i);
repsToRemove.add(URI.create(rep));
}
}
countStr = (String) properties.remove(prefix + ".reqs.count");
if (countStr != null) {
int count = Integer.parseInt(countStr);
for (int i = 0; i < count; i++) {
String req = (String) properties.remove(prefix + ".reqs.item" + i);
reqsToRemove.add(req);
}
}
saveProperties();
// Compute new informations
List<URI> repsToAdd = new ArrayList<>();
List<String> reqsToAdd = new ArrayList<>();
if (bundleEvent.getType() == BundleEvent.RESOLVED) {
Enumeration featuresUrlEnumeration = bundle.findEntries("/META-INF/" + FEATURE_PATH + "/", "*.xml", false);
while (featuresUrlEnumeration != null && featuresUrlEnumeration.hasMoreElements()) {
URL url = (URL) featuresUrlEnumeration.nextElement();
URI uri = url.toURI();
repsToAdd.add(uri);
Repository rep = featuresService.createRepository(uri);
Stream.of(rep.getFeatures()).filter(f -> f.getInstall() == null || Feature.DEFAULT_INSTALL_MODE.equals(f.getInstall())).map(f -> "feature:" + f.getName() + "/" + new VersionRange(f.getVersion(), true)).forEach(reqsToAdd::add);
}
if (!repsToAdd.isEmpty()) {
properties.put(prefix + ".reps.count", Integer.toString(repsToAdd.size()));
for (int i = 0; i < repsToAdd.size(); i++) {
properties.put(prefix + ".reps.item" + i, repsToAdd.get(i).toASCIIString());
}
properties.put(prefix + ".reqs.count", Integer.toString(reqsToAdd.size()));
for (int i = 0; i < reqsToAdd.size(); i++) {
properties.put(prefix + ".reqs.item" + i, reqsToAdd.get(i));
}
}
}
saveProperties();
// Call features service
List<Repository> requiredRepos = Arrays.asList(featuresService.listRequiredRepositories());
Set<URI> requiredReposUris = requiredRepos.stream().map(Repository::getURI).collect(Collectors.toSet());
requiredReposUris.removeAll(repsToRemove);
requiredReposUris.addAll(repsToAdd);
Map<String, Set<String>> requirements = featuresService.listRequirements();
requirements.get(ROOT_REGION).removeAll(reqsToRemove);
requirements.get(ROOT_REGION).addAll(reqsToAdd);
if (!reqsToRemove.isEmpty() || !reqsToAdd.isEmpty()) {
featuresService.updateReposAndRequirements(requiredReposUris, requirements, EnumSet.noneOf(FeaturesService.Option.class));
}
} catch (Exception e) {
logger.error("Unable to update deployed features for bundle: " + bundle.getSymbolicName() + " - " + bundle.getVersion(), e);
}
}
use of org.apache.karaf.features.Repository in project karaf by apache.
the class ListFeaturesCommand method doExecute.
protected void doExecute(FeaturesService featuresService) throws Exception {
boolean needsLegend = false;
ShellTable table = new ShellTable();
table.column("Name");
table.column("Version");
table.column("Required");
table.column("State");
table.column("Repository");
table.column("Description").maxSize(50);
if (showBlacklisted) {
table.column("Blacklisted");
}
table.emptyTableText(onlyInstalled ? "No features installed" : "No features available");
List<Repository> repos = Arrays.asList(featuresService.listRepositories());
for (Repository r : repos) {
List<Feature> features = Arrays.asList(r.getFeatures());
if (ordered) {
Collections.sort(features, new FeatureComparator());
}
for (Feature f : features) {
if (onlyInstalled && !featuresService.isInstalled(f)) {
// Filter out not installed features if we only want to see the installed ones
continue;
}
if (onlyRequired && !featuresService.isRequired(f)) {
// Filter out not installed features if we only want to see the installed ones
continue;
}
if (!showBlacklisted && f.isBlacklisted()) {
// Filter out blacklisted
continue;
}
if (!showHidden && f.isHidden()) {
// Filter out hidden feature if not asked to display those
continue;
}
Row row = table.addRow();
row.addContent(f.getName(), f.getVersion(), featuresService.isRequired(f) ? "x" : "", featuresService.getState(f.getId()), r.getName(), f.getDescription());
if (showBlacklisted) {
row.addContent(f.isBlacklisted() ? "yes" : "no");
}
if (isInstalledViaDeployDir(r.getName())) {
needsLegend = true;
}
}
}
table.print(System.out, !noFormat);
if (needsLegend) {
System.out.println("* Installed via deploy directory");
}
}
use of org.apache.karaf.features.Repository in project karaf by apache.
the class ListFeaturesCommandTest method testShowHiddenFeatures.
@Test
public void testShowHiddenFeatures() throws Exception {
FeaturesService service = EasyMock.createMock(FeaturesService.class);
Repository repo = EasyMock.createMock(Repository.class);
Feature feature = EasyMock.createMock(Feature.class);
EasyMock.expect(service.listRepositories()).andReturn(new Repository[] { repo });
EasyMock.expect(repo.getFeatures()).andReturn(new Feature[] { feature });
EasyMock.expect(feature.isHidden()).andReturn(true).anyTimes();
EasyMock.expect(feature.isBlacklisted()).andReturn(false).anyTimes();
EasyMock.expect(feature.getName()).andReturn("feature");
EasyMock.expect(feature.getId()).andReturn("feature/1.0.0");
EasyMock.expect(service.getState(EasyMock.eq("feature/1.0.0"))).andReturn(FeatureState.Started);
EasyMock.expect(feature.getDescription()).andReturn("description");
EasyMock.expect(feature.getVersion()).andReturn("1.0.0");
EasyMock.expect(service.isRequired(feature)).andReturn(true);
EasyMock.expect(repo.getName()).andReturn("repository").anyTimes();
EasyMock.replay(service, repo, feature);
ListFeaturesCommand command = new ListFeaturesCommand();
command.setFeaturesService(service);
command.noFormat = true;
command.showHidden = true;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream out = new PrintStream(baos);
System.setOut(out);
command.execute();
out.flush();
assertTrue(baos.toString().contains("feature"));
EasyMock.verify(service, repo, feature);
}
use of org.apache.karaf.features.Repository in project karaf by apache.
the class ListFeaturesCommandTest method testHiddenFeatures.
@Test
public void testHiddenFeatures() throws Exception {
FeaturesService service = EasyMock.createMock(FeaturesService.class);
Repository repo = EasyMock.createMock(Repository.class);
Feature feature = EasyMock.createMock(Feature.class);
EasyMock.expect(service.listRepositories()).andReturn(new Repository[] { repo });
EasyMock.expect(repo.getFeatures()).andReturn(new Feature[] { feature });
EasyMock.expect(feature.isHidden()).andReturn(true);
EasyMock.expect(feature.isBlacklisted()).andReturn(false);
EasyMock.replay(service, repo, feature);
ListFeaturesCommand command = new ListFeaturesCommand();
command.setFeaturesService(service);
command.noFormat = true;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream out = new PrintStream(baos);
System.setOut(out);
command.execute();
out.flush();
assertFalse(baos.toString().contains("feature"));
EasyMock.verify(service, repo, feature);
}
use of org.apache.karaf.features.Repository in project karaf by apache.
the class FeaturesValidationTest method testNs10.
@Test
public void testNs10() throws Exception {
Repository features = unmarshalAndValidate("f02.xml");
assertNotNull(features);
}
Aggregations