use of org.apache.karaf.features.Conditional in project karaf by apache.
the class InfoFeatureCommand method displayFeatureTree.
/**
* Called originally with featureName and featureVersion that have already been resolved successfully.
*
* @param admin
* @param featureName
* @param featureVersion
* @param prefix
* @return
* @throws Exception
*/
private int displayFeatureTree(FeaturesService admin, String featureName, String featureVersion, String prefix) throws Exception {
int unresolved = 0;
Feature[] resolvedFeatures = admin.getFeatures(featureName, featureVersion);
for (Feature resolved : resolvedFeatures) {
if (resolved != null) {
System.out.println(prefix + " " + resolved.getName() + " " + resolved.getVersion());
} else {
System.out.println(prefix + " " + featureName + " " + featureVersion + " *");
unresolved++;
}
if (resolved != null) {
if (bundle) {
List<String> bundleLocation = new LinkedList<>();
List<BundleInfo> bundles = resolved.getBundles();
for (BundleInfo bundleInfo : bundles) {
bundleLocation.add(bundleInfo.getLocation());
}
if (conditional) {
for (Conditional cond : resolved.getConditional()) {
List<String> condition = cond.getCondition();
List<BundleInfo> conditionalBundles = cond.getBundles();
for (BundleInfo bundleInfo : conditionalBundles) {
bundleLocation.add(bundleInfo.getLocation() + "(condition:" + condition + ")");
}
}
}
for (int i = 0, j = bundleLocation.size(); i < j; i++) {
System.out.println(prefix + " " + (i + 1 == j ? "\\" : "+") + " " + bundleLocation.get(i));
}
}
prefix += " ";
List<Dependency> dependencies = resolved.getDependencies();
for (Dependency toDisplay : dependencies) {
unresolved += displayFeatureTree(admin, toDisplay.getName(), toDisplay.getVersion(), prefix + 1);
}
if (conditional) {
for (Conditional cond : resolved.getConditional()) {
List<Dependency> conditionDependencies = cond.getDependencies();
for (int i = 0, j = conditionDependencies.size(); i < j; i++) {
Dependency toDisplay = dependencies.get(i);
unresolved += displayFeatureTree(admin, toDisplay.getName(), toDisplay.getVersion(), prefix + 1);
}
}
}
}
}
return unresolved;
}
use of org.apache.karaf.features.Conditional in project karaf by apache.
the class InfoFeatureCommand method displayConditionalInfo.
private void displayConditionalInfo(Feature feature) {
List<? extends Conditional> conditionals = feature.getConditional();
if (conditionals.isEmpty()) {
System.out.println("Feature has no conditionals.");
} else {
System.out.println("Feature contains followed conditionals:");
for (Conditional featureConditional : conditionals) {
String conditionDescription = getConditionDescription(featureConditional);
Feature wrappedConditional = featureConditional.asFeature();
if (config) {
displayConfigInformation(wrappedConditional, String.format(CONDITIONAL_CONTENT, conditionDescription));
displayConfigFileInformation(wrappedConditional, String.format(CONDITIONAL_CONTENT, conditionDescription));
}
if (dependency) {
displayDependencyInformation(wrappedConditional, String.format(CONDITIONAL_CONTENT, conditionDescription));
}
if (bundle) {
displayBundleInformation(wrappedConditional, String.format(CONDITIONAL_CONTENT, conditionDescription));
}
}
}
}
use of org.apache.karaf.features.Conditional in project karaf by apache.
the class AbstractFeatureMojo method resolveFeatures.
protected Set<Feature> resolveFeatures() throws MojoExecutionException {
Set<Feature> featuresSet = new HashSet<>();
try {
Set<String> artifactsToCopy = new HashSet<>();
Map<String, Feature> featuresMap = new HashMap<>();
for (String uri : descriptors) {
retrieveDescriptorsRecursively(uri, artifactsToCopy, featuresMap);
}
// no features specified, handle all of them
if (features == null) {
features = new ArrayList<>(featuresMap.keySet());
}
addFeatures(features, featuresSet, featuresMap, addTransitiveFeatures);
getLog().info("Using local repository at: " + localRepo.getUrl());
for (Feature feature : featuresSet) {
try {
for (Bundle bundle : feature.getBundle()) {
resolveArtifact(bundle.getLocation());
}
for (Conditional conditional : feature.getConditional()) {
for (BundleInfo bundle : conditional.getBundles()) {
if (ignoreDependencyFlag || (!ignoreDependencyFlag && !bundle.isDependency())) {
resolveArtifact(bundle.getLocation());
}
}
}
for (ConfigFile configfile : feature.getConfigfile()) {
resolveArtifact(configfile.getLocation());
}
} catch (RuntimeException e) {
throw new RuntimeException("Error resolving feature " + feature.getName() + "/" + feature.getVersion(), e);
}
}
} catch (Exception e) {
throw new MojoExecutionException("Error populating repository", e);
}
return featuresSet;
}
use of org.apache.karaf.features.Conditional in project karaf by apache.
the class AddToRepositoryMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
Set<Feature> featuresSet = resolveFeatures();
for (Artifact descriptor : descriptorArtifacts) {
copy(descriptor, repository);
}
for (Feature feature : featuresSet) {
copyBundlesToDestRepository(feature.getBundle());
for (Conditional conditional : feature.getConditional()) {
copyBundlesConditionalToDestRepository(conditional.getBundles());
}
copyConfigFilesToDestRepository(feature.getConfigfile());
}
copyFileBasedDescriptorsToDestRepository();
}
use of org.apache.karaf.features.Conditional in project karaf by apache.
the class Subsystem method doBuild.
private void doBuild(Collection<Feature> features, boolean mandatory) throws Exception {
for (Subsystem child : children) {
child.doBuild(features, true);
}
if (feature != null) {
for (Dependency dep : feature.getDependencies()) {
Subsystem ss = this;
while (!ss.isAcceptDependencies()) {
ss = ss.getParent();
}
ss.requireFeature(dep.getName(), dep.getVersion(), false);
}
for (Conditional cond : feature.getConditional()) {
Feature fcond = cond.asFeature();
String ssName = this.name + "#" + (fcond.hasVersion() ? fcond.getName() + "-" + fcond.getVersion() : fcond.getName());
Subsystem fs = getChild(ssName);
if (fs == null) {
fs = new Subsystem(ssName, fcond, this, true);
fs.doBuild(features, false);
installable.add(fs);
children.add(fs);
}
}
}
List<Requirement> processed = new ArrayList<>();
while (true) {
List<Requirement> requirements = getRequirements(IDENTITY_NAMESPACE);
requirements.addAll(dependentFeatures);
requirements.removeAll(processed);
if (requirements.isEmpty()) {
break;
}
for (Requirement requirement : requirements) {
String name = (String) requirement.getAttributes().get(IDENTITY_NAMESPACE);
String type = (String) requirement.getAttributes().get(CAPABILITY_TYPE_ATTRIBUTE);
VersionRange range = (VersionRange) requirement.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE);
if (TYPE_FEATURE.equals(type)) {
for (Feature feature : features) {
if (feature.getName().equals(name) && (range == null || range.contains(VersionTable.getVersion(feature.getVersion())))) {
if (feature != this.feature) {
String ssName = this.name + "#" + (feature.hasVersion() ? feature.getName() + "-" + feature.getVersion() : feature.getName());
Subsystem fs = getChild(ssName);
if (fs == null) {
fs = new Subsystem(ssName, feature, this, mandatory && !SubsystemResolveContext.isOptional(requirement));
fs.build(features);
installable.add(fs);
children.add(fs);
}
}
}
}
}
processed.add(requirement);
}
}
}
Aggregations