use of org.apache.karaf.features.internal.model.Features in project karaf by apache.
the class GenerateDescriptorMojo method processFeatureArtifact.
private void processFeatureArtifact(Features features, Feature feature, Map<Dependency, Feature> otherFeatures, Map<Feature, String> featureRepositories, Object artifact, Object parent, boolean add) throws MojoExecutionException, XMLStreamException, JAXBException, IOException {
if (this.dependencyHelper.isArtifactAFeature(artifact) && FEATURE_CLASSIFIER.equals(this.dependencyHelper.getClassifier(artifact))) {
File featuresFile = this.dependencyHelper.resolve(artifact, getLog());
if (featuresFile == null || !featuresFile.exists()) {
throw new MojoExecutionException("Cannot locate file for feature: " + artifact + " at " + featuresFile);
}
Features includedFeatures = readFeaturesFile(featuresFile);
for (String repository : includedFeatures.getRepository()) {
processFeatureArtifact(features, feature, otherFeatures, featureRepositories, new DefaultArtifact(MavenUtil.mvnToAether(repository)), parent, false);
}
for (Feature includedFeature : includedFeatures.getFeature()) {
Dependency dependency = new Dependency(includedFeature.getName(), includedFeature.getVersion());
dependency.setPrerequisite(prerequisiteFeatures.contains(dependency.getName()));
dependency.setDependency(dependencyFeatures.contains(dependency.getName()));
// Determine what dependency we're actually going to use
Dependency matchingDependency = findMatchingDependency(feature.getFeature(), dependency);
if (matchingDependency != null) {
// The feature already has a matching dependency, merge
mergeDependencies(matchingDependency, dependency);
dependency = matchingDependency;
}
// We mustn't de-duplicate here, we may have seen a feature in !add mode
otherFeatures.put(dependency, includedFeature);
if (add) {
if (!feature.getFeature().contains(dependency)) {
feature.getFeature().add(dependency);
}
if (aggregateFeatures) {
features.getFeature().add(includedFeature);
}
}
if (!featureRepositories.containsKey(includedFeature)) {
featureRepositories.put(includedFeature, this.dependencyHelper.artifactToMvn(artifact, getVersionOrRange(parent, artifact)));
}
}
}
}
use of org.apache.karaf.features.internal.model.Features in project karaf by apache.
the class GenerateDescriptorMojoTest method testReadXml100.
@Test
public void testReadXml100() throws JAXBException, SAXException, ParserConfigurationException, XMLStreamException {
URL url = getClass().getClassLoader().getResource("input-features-1.0.0.xml");
Features featuresRoot = JaxbUtil.unmarshal(url.toExternalForm(), false);
assertEquals(featuresRoot.getRepository().size(), 1);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JaxbUtil.marshal(featuresRoot, baos);
String text = new String(baos.toByteArray());
assertTrue(text.contains("repository"));
assertTrue(text.contains(FeaturesNamespaces.URI_CURRENT));
}
use of org.apache.karaf.features.internal.model.Features in project karaf by apache.
the class Builder method loadRepositories.
private Map<String, Features> loadRepositories(DownloadManager manager, Collection<String> repositories, final boolean install) throws Exception {
final Map<String, Features> loaded = new HashMap<>();
final Downloader downloader = manager.createDownloader();
final List<String> blacklist = new ArrayList<>();
blacklist.addAll(blacklistedBundles);
blacklist.addAll(blacklistedFeatures);
final List<String> blacklistRepos = new ArrayList<>();
blacklistRepos.addAll(blacklistedRepositories);
final Clause[] clauses = org.apache.felix.utils.manifest.Parser.parseClauses(blacklist.toArray(new String[blacklist.size()]));
final Clause[] clausesRepos = org.apache.felix.utils.manifest.Parser.parseClauses(blacklistRepos.toArray(new String[blacklistRepos.size()]));
for (String repository : repositories) {
downloader.download(repository, new DownloadCallback() {
@Override
public void downloaded(final StreamProvider provider) throws Exception {
String url = provider.getUrl();
if (Blacklist.isBlacklisted(clausesRepos, url, TYPE_REPOSITORY)) {
return;
}
synchronized (loaded) {
if (!loaded.containsKey(provider.getUrl())) {
if (install) {
synchronized (provider) {
Path path = pathFromProviderUrl(url);
Files.createDirectories(path.getParent());
Files.copy(provider.getFile().toPath(), path, StandardCopyOption.REPLACE_EXISTING);
}
}
try (InputStream is = provider.open()) {
Features featuresModel = JaxbUtil.unmarshal(url, is, false);
if (blacklistPolicy == BlacklistPolicy.Discard) {
Blacklist.blacklist(featuresModel, clauses);
}
loaded.put(provider.getUrl(), featuresModel);
for (String innerRepository : featuresModel.getRepository()) {
downloader.download(innerRepository, this);
}
}
}
}
}
});
}
downloader.await();
return loaded;
}
use of org.apache.karaf.features.internal.model.Features in project karaf by apache.
the class Builder method addFeatures.
private void addFeatures(Set<Feature> allFeatures, String feature, Set<Feature> features, boolean mandatory) {
String name;
VersionRange range;
int idx = feature.indexOf('/');
if (idx > 0) {
name = feature.substring(0, idx);
String version = feature.substring(idx + 1);
version = version.trim();
if (version.equals(org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)) {
range = new VersionRange(Version.emptyVersion);
} else {
range = new VersionRange(version, true, true);
}
} else {
name = feature;
range = new VersionRange(Version.emptyVersion);
}
Set<Feature> set = allFeatures.stream().filter(f -> f.getName().equals(name) && range.contains(VersionTable.getVersion(f.getVersion()))).collect(Collectors.toSet());
if (mandatory && set.isEmpty()) {
throw new IllegalStateException("Could not find matching feature for " + feature);
}
for (Feature f : set) {
features.add(f);
for (Dependency dep : f.getFeature()) {
addFeatures(allFeatures, dep.toString(), features, !dep.isDependency() && !dep.isPrerequisite());
}
}
}
use of org.apache.karaf.features.internal.model.Features in project karaf by apache.
the class Builder method installStage.
private void installStage(Profile installedProfile, Set<Feature> allBootFeatures) throws Exception {
LOGGER.info("Install stage");
//
// Handle installed profiles
//
Profile installedOverlay = Profiles.getOverlay(installedProfile, allProfiles, environment);
Profile installedEffective = Profiles.getEffective(installedOverlay, false);
Downloader downloader = manager.createDownloader();
// Load startup repositories
Map<String, Features> installedRepositories = loadRepositories(manager, installedEffective.getRepositories(), true);
// Compute startup feature dependencies
Set<Feature> allInstalledFeatures = new HashSet<>();
for (Features repo : installedRepositories.values()) {
allInstalledFeatures.addAll(repo.getFeature());
}
Set<Feature> installedFeatures = new LinkedHashSet<>();
// Add boot features for search
allInstalledFeatures.addAll(allBootFeatures);
for (String feature : installedEffective.getFeatures()) {
addFeatures(allInstalledFeatures, feature, installedFeatures, true);
}
for (Feature feature : installedFeatures) {
LOGGER.info(" Feature {} is defined as an installed feature", feature.getId());
for (Bundle bundle : feature.getBundle()) {
if (!ignoreDependencyFlag || !bundle.isDependency()) {
installArtifact(downloader, bundle.getLocation().trim());
}
}
// Install config files
for (ConfigFile configFile : feature.getConfigfile()) {
installArtifact(downloader, configFile.getLocation().trim());
}
for (Conditional cond : feature.getConditional()) {
for (Bundle bundle : cond.getBundle()) {
if (!ignoreDependencyFlag || !bundle.isDependency()) {
installArtifact(downloader, bundle.getLocation().trim());
}
}
}
}
for (String location : installedEffective.getBundles()) {
installArtifact(downloader, location);
}
downloader.await();
}
Aggregations