|
17 | 17 | import org.elasticsearch.gradle.internal.conventions.info.GitInfo;
|
18 | 18 | import org.elasticsearch.gradle.internal.conventions.precommit.PomValidationPrecommitPlugin;
|
19 | 19 | import org.elasticsearch.gradle.internal.conventions.util.Util;
|
20 |
| -import org.gradle.api.Action; |
21 | 20 | import org.gradle.api.NamedDomainObjectSet;
|
22 | 21 | import org.gradle.api.Plugin;
|
23 | 22 | import org.gradle.api.Project;
|
24 |
| -import org.gradle.api.Task; |
25 | 23 | import org.gradle.api.XmlProvider;
|
26 | 24 | import org.gradle.api.file.ProjectLayout;
|
27 | 25 | import org.gradle.api.plugins.BasePlugin;
|
@@ -69,6 +67,7 @@ public void apply(Project project) {
|
69 | 67 | configureSourcesJar(project);
|
70 | 68 | configurePomGeneration(project);
|
71 | 69 | configurePublications(project);
|
| 70 | + formatGeneratedPom(project); |
72 | 71 | }
|
73 | 72 |
|
74 | 73 | private void configurePublications(Project project) {
|
@@ -127,42 +126,27 @@ private void configurePomGeneration(Project project) {
|
127 | 126 | projectVersion.get()
|
128 | 127 | )
|
129 | 128 | );
|
130 |
| - pomTask.doFirst(t -> pomTask.getPom().withXml(xml -> formatDependencies(xml))); |
131 | 129 | });
|
132 | 130 |
|
133 | 131 | var publishing = extensions.getByType(PublishingExtension.class);
|
134 | 132 | final var mavenPublications = publishing.getPublications().withType(MavenPublication.class);
|
135 |
| - |
136 | 133 | addNameAndDescriptionToPom(project, mavenPublications);
|
137 | 134 | mavenPublications.configureEach(publication -> {
|
138 |
| - // Add git origin info to generated POM files for internal builds |
139 |
| - publication.getPom().withXml(xml -> addScmInfo(xml, gitInfo.get())); |
| 135 | + publication.getPom().withXml(xml -> { |
| 136 | + // Add git origin info to generated POM files for internal builds |
| 137 | + addScmInfo(xml, gitInfo.get()); |
| 138 | + }); |
140 | 139 | // have to defer this until archivesBaseName is set
|
141 | 140 | project.afterEvaluate(p -> publication.setArtifactId(archivesBaseName.get()));
|
142 | 141 | generatePomTask.configure(t -> t.dependsOn(generateMavenPoms));
|
143 | 142 | });
|
144 | 143 | }
|
145 | 144 |
|
146 |
| - /** |
147 |
| - * just ensure we put dependencies to the end. more a cosmetic thing than anything else |
148 |
| - * */ |
149 |
| - private void formatDependencies(XmlProvider xml) { |
150 |
| - Element rootElement = xml.asElement(); |
151 |
| - var dependencies = rootElement.getElementsByTagName("dependencies"); |
152 |
| - if (dependencies.getLength() == 1 && dependencies.item(0) != null) { |
153 |
| - org.w3c.dom.Node item = dependencies.item(0); |
154 |
| - rootElement.removeChild(item); |
155 |
| - rootElement.appendChild(item); |
156 |
| - } |
157 |
| - } |
158 |
| - |
159 | 145 | private void addNameAndDescriptionToPom(Project project, NamedDomainObjectSet<MavenPublication> mavenPublications) {
|
160 | 146 | var name = project.getName();
|
161 | 147 | var description = providerFactory.provider(() -> project.getDescription() != null ? project.getDescription() : "");
|
162 | 148 | mavenPublications.configureEach(p -> p.getPom().withXml(xml -> {
|
163 | 149 | var root = xml.asNode();
|
164 |
| - // Node versionNode = root.get("version"); |
165 |
| - // versionNode.plus(1, "name", name); |
166 | 150 | root.appendNode("name", name);
|
167 | 151 | root.appendNode("description", description.get());
|
168 | 152 | }));
|
@@ -209,4 +193,32 @@ static void configureSourcesJar(Project project) {
|
209 | 193 | project.getTasks().named(BasePlugin.ASSEMBLE_TASK_NAME).configure(t -> t.dependsOn(sourcesJarTask));
|
210 | 194 | });
|
211 | 195 | }
|
| 196 | + |
| 197 | + |
| 198 | + /** |
| 199 | + * Format the generated pom files to be in a sort of reproducible order. |
| 200 | + */ |
| 201 | + private void formatGeneratedPom(Project project) { |
| 202 | + var publishing = project.getExtensions().getByType(PublishingExtension.class); |
| 203 | + final var mavenPublications = publishing.getPublications().withType(MavenPublication.class); |
| 204 | + mavenPublications.configureEach(publication -> { |
| 205 | + publication.getPom().withXml(xml -> { |
| 206 | + // Add some pom formatting |
| 207 | + formatDependencies(xml); |
| 208 | + }); |
| 209 | + }); |
| 210 | + } |
| 211 | + |
| 212 | + /** |
| 213 | + * just ensure we put dependencies to the end. more a cosmetic thing than anything else |
| 214 | + * */ |
| 215 | + private void formatDependencies(XmlProvider xml) { |
| 216 | + Element rootElement = xml.asElement(); |
| 217 | + var dependencies = rootElement.getElementsByTagName("dependencies"); |
| 218 | + if (dependencies.getLength() == 1 && dependencies.item(0) != null) { |
| 219 | + org.w3c.dom.Node item = dependencies.item(0); |
| 220 | + rootElement.removeChild(item); |
| 221 | + rootElement.appendChild(item); |
| 222 | + } |
| 223 | + } |
212 | 224 | }
|
0 commit comments