in src/main/java/org/apache/sling/feature/maven/mojos/AttachFeaturesMojo.java [90:143]
private void attach(final Feature feature)
throws MojoExecutionException {
final String classifier = feature.getId().getClassifier();
boolean changed = false;
// check for metadata
if ( this.includeBundleMetadata ) {
for(final Artifact bundle : feature.getBundles()) {
if ( bundle.getMetadata().get(Constants.BUNDLE_SYMBOLICNAME) == null ) {
Map.Entry<String, String> value = METADATA_CACHE.get(bundle.getId().toMvnId());
if ( value == null ) {
final org.apache.maven.artifact.Artifact source = ProjectHelper.getOrResolveArtifact(this.project,
this.mavenSession,
this.artifactHandlerManager,
this.repoSystem,
bundle.getId());
try (final JarFile jarFile = new JarFile(source.getFile())) {
final String symbolicName = jarFile.getManifest().getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
final String version = jarFile.getManifest().getMainAttributes().getValue(Constants.BUNDLE_VERSION);
if ( symbolicName != null && version != null ) {
final int idx = symbolicName.indexOf(";");
value = new AbstractMap.SimpleImmutableEntry<>(idx == -1 ? symbolicName : symbolicName.substring(0, idx), version);
}
} catch (final IOException e) {
// we ignore this
}
if ( value == null ) {
value = NOT_FOUND;
}
METADATA_CACHE.put(bundle.getId().toMvnId(), value);
}
if ( value != NOT_FOUND ) {
bundle.getMetadata().put(Constants.BUNDLE_SYMBOLICNAME, value.getKey());
bundle.getMetadata().put(Constants.BUNDLE_VERSION, value.getValue());
changed = true;
}
}
}
}
// write the feature
final File outputFile = ProjectHelper.createTmpFeatureFile(project, feature, changed);
// if this project is a feature, it's the main artifact
if ( project.getPackaging().equals(FeatureConstants.PACKAGING_FEATURE)
&& classifier == null) {
project.getArtifact().setFile(outputFile);
} else {
// otherwise attach it as an additional artifact
projectHelper.attachArtifact(project, FeatureConstants.PACKAGING_FEATURE,
classifier, outputFile);
}
}