private void writeFeatures(PrintStream out) throws ArtifactResolutionException, ArtifactNotFoundException,
IOException, JAXBException, SAXException, ParserConfigurationException, XMLStreamException, MojoExecutionException {
getLogger().info("Generating feature descriptor file " + outputFile.getAbsolutePath());
//read in an existing feature.xml
ObjectFactory objectFactory = new ObjectFactory();
Features features;
if (inputFile.exists()) {
filter(inputFile, filteredInputFile);
features = readFeaturesFile(filteredInputFile);
} else {
features = objectFactory.createFeaturesRoot();
}
if (features.getName() == null) {
features.setName(project.getArtifactId());
}
Feature feature = null;
for (Feature test : features.getFeature()) {
if (test.getName().equals(project.getArtifactId())) {
feature = test;
}
}
if (feature == null) {
feature = objectFactory.createFeature();
feature.setName(project.getArtifactId());
}
if (!feature.hasVersion()) {
feature.setVersion(project.getArtifact().getBaseVersion());
}
if (feature.getDescription() == null) {
feature.setDescription(project.getName());
}
if (resolver != null) {
feature.setResolver(resolver);
}
if (installMode != null) {
feature.setInstall(installMode);
}
if (project.getDescription() != null && feature.getDetails() == null) {
feature.setDetails(project.getDescription());
}
for (Map.Entry<?, String> entry : localDependencies.entrySet()) {
Object artifact = entry.getKey();
if (excludedArtifactIds.contains(this.dependencyHelper.getArtifactId(artifact))) {
continue;
}
if (this.dependencyHelper.isArtifactAFeature(artifact)) {
if (aggregateFeatures && 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);
//TODO check for duplicates?
features.getFeature().addAll(includedFeatures.getFeature());
}
} else if (addBundlesToPrimaryFeature) {
String bundleName = this.dependencyHelper.artifactToMvn(artifact);
File bundleFile = this.dependencyHelper.resolve(artifact, getLog());
Manifest manifest = getManifest(bundleFile);