Skip to content

Commit

Permalink
Reduce scope of META-INF customizations to main, source, and javadoc …
Browse files Browse the repository at this point in the history
…jars

Closes gh-23955
  • Loading branch information
wilkinsona committed Nov 5, 2020
1 parent 49ea023 commit 1e10067
Showing 1 changed file with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -106,19 +107,25 @@ private void configureJarManifestConventions(Project project) {
.collect(Collectors.toSet());
Set<String> javadocJarTaskNames = sourceSets.stream().map(SourceSet::getJavadocJarTaskName)
.collect(Collectors.toSet());
project.getTasks().withType(Jar.class, (jar) -> project.afterEvaluate((evaluated) -> {
jar.metaInf((metaInf) -> metaInf.from(extractLegalResources));
jar.manifest((manifest) -> {
Map<String, Object> attributes = new TreeMap<>();
attributes.put("Automatic-Module-Name", project.getName().replace("-", "."));
attributes.put("Build-Jdk-Spec", project.property("sourceCompatibility"));
attributes.put("Built-By", "Spring");
attributes.put("Implementation-Title",
determineImplementationTitle(project, sourceJarTaskNames, javadocJarTaskNames, jar));
attributes.put("Implementation-Version", project.getVersion());
manifest.attributes(attributes);
});
}));
Set<String> jarTaskNames = sourceSets.stream().map(SourceSet::getJarTaskName).collect(Collectors.toSet());
Set<String> jarTasksOfInterest = new HashSet<String>();
jarTasksOfInterest.addAll(sourceJarTaskNames);
jarTasksOfInterest.addAll(javadocJarTaskNames);
jarTasksOfInterest.addAll(jarTaskNames);
project.getTasks().matching((task) -> jarTasksOfInterest.contains(task.getName())).withType(Jar.class,
(jar) -> project.afterEvaluate((evaluated) -> {
jar.metaInf((metaInf) -> metaInf.from(extractLegalResources));
jar.manifest((manifest) -> {
Map<String, Object> attributes = new TreeMap<>();
attributes.put("Automatic-Module-Name", project.getName().replace("-", "."));
attributes.put("Build-Jdk-Spec", project.property("sourceCompatibility"));
attributes.put("Built-By", "Spring");
attributes.put("Implementation-Title",
determineImplementationTitle(project, sourceJarTaskNames, javadocJarTaskNames, jar));
attributes.put("Implementation-Version", project.getVersion());
manifest.attributes(attributes);
});
}));
}

private String determineImplementationTitle(Project project, Set<String> sourceJarTaskNames,
Expand Down

0 comments on commit 1e10067

Please sign in to comment.