|
16 | 16 |
|
17 | 17 | package org.springframework.boot.build.bom; |
18 | 18 |
|
19 | | -import java.io.File; |
20 | | -import java.io.IOException; |
21 | | -import java.io.InputStreamReader; |
22 | | -import java.nio.charset.StandardCharsets; |
23 | 19 | import java.util.ArrayList; |
24 | 20 | import java.util.Collection; |
25 | 21 | import java.util.HashMap; |
|
29 | 25 | import java.util.function.Function; |
30 | 26 |
|
31 | 27 | import javax.inject.Inject; |
32 | | -import javax.xml.parsers.DocumentBuilderFactory; |
33 | | -import javax.xml.transform.TransformerFactory; |
34 | | -import javax.xml.transform.dom.DOMSource; |
35 | | -import javax.xml.transform.stream.StreamResult; |
36 | | -import javax.xml.xpath.XPath; |
37 | | -import javax.xml.xpath.XPathConstants; |
38 | | -import javax.xml.xpath.XPathFactory; |
39 | 28 |
|
40 | 29 | import groovy.lang.Closure; |
41 | 30 | import groovy.lang.GroovyObjectSupport; |
42 | 31 | import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; |
43 | 32 | import org.apache.maven.artifact.versioning.VersionRange; |
44 | 33 | import org.gradle.api.Action; |
45 | | -import org.gradle.api.GradleException; |
46 | 34 | import org.gradle.api.InvalidUserCodeException; |
47 | 35 | import org.gradle.api.InvalidUserDataException; |
48 | 36 | import org.gradle.api.Project; |
49 | | -import org.gradle.api.Task; |
50 | | -import org.gradle.api.artifacts.Configuration; |
51 | 37 | import org.gradle.api.artifacts.dsl.DependencyHandler; |
52 | 38 | import org.gradle.api.model.ObjectFactory; |
53 | 39 | import org.gradle.api.plugins.JavaPlatformPlugin; |
54 | | -import org.gradle.api.publish.maven.tasks.GenerateMavenPom; |
55 | | -import org.gradle.api.tasks.Sync; |
56 | | -import org.gradle.api.tasks.TaskExecutionException; |
57 | | -import org.gradle.api.tasks.TaskProvider; |
58 | | -import org.w3c.dom.Document; |
59 | | -import org.w3c.dom.NodeList; |
60 | | - |
61 | | -import org.springframework.boot.build.DeployedPlugin; |
62 | | -import org.springframework.boot.build.RepositoryTransformersExtension; |
| 40 | + |
63 | 41 | import org.springframework.boot.build.bom.Library.Exclusion; |
64 | 42 | import org.springframework.boot.build.bom.Library.Group; |
65 | 43 | import org.springframework.boot.build.bom.Library.LibraryVersion; |
|
68 | 46 | import org.springframework.boot.build.bom.Library.ProhibitedVersion; |
69 | 47 | import org.springframework.boot.build.bom.Library.VersionAlignment; |
70 | 48 | import org.springframework.boot.build.bom.bomr.version.DependencyVersion; |
71 | | -import org.springframework.boot.build.mavenplugin.MavenExec; |
72 | 49 | import org.springframework.boot.build.properties.BuildProperties; |
73 | | -import org.springframework.util.FileCopyUtils; |
74 | 50 | import org.springframework.util.PropertyPlaceholderHelper; |
75 | 51 | import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; |
76 | 52 |
|
@@ -138,65 +114,6 @@ public void library(String name, String version, Action<LibraryHandler> action) |
138 | 114 | libraryHandler.links)); |
139 | 115 | } |
140 | 116 |
|
141 | | - public void effectiveBomArtifact() { |
142 | | - Configuration effectiveBomConfiguration = this.project.getConfigurations().create("effectiveBom"); |
143 | | - RepositoryTransformersExtension repositoryTransformers = this.project.getExtensions() |
144 | | - .getByType(RepositoryTransformersExtension.class); |
145 | | - this.project.getTasks() |
146 | | - .matching((task) -> task.getName().equals(DeployedPlugin.GENERATE_POM_TASK_NAME)) |
147 | | - .all((task) -> { |
148 | | - File generatedBomDir = this.project.getLayout() |
149 | | - .getBuildDirectory() |
150 | | - .dir("generated/bom") |
151 | | - .get() |
152 | | - .getAsFile(); |
153 | | - TaskProvider<Sync> syncBom = this.project.getTasks().register("syncBom", Sync.class, (sync) -> { |
154 | | - sync.dependsOn(task); |
155 | | - sync.setDestinationDir(generatedBomDir); |
156 | | - sync.from(((GenerateMavenPom) task).getDestination(), (pom) -> pom.rename((name) -> "pom.xml")); |
157 | | - sync.from(this.project.getResources().getText().fromString(loadSettingsXml()), (settingsXml) -> { |
158 | | - settingsXml.rename((name) -> "settings.xml"); |
159 | | - settingsXml.filter(repositoryTransformers.mavenSettings()); |
160 | | - }); |
161 | | - }); |
162 | | - File effectiveBom = this.project.getLayout() |
163 | | - .getBuildDirectory() |
164 | | - .file("generated/effective-bom/" + this.project.getName() + "-effective-bom.xml") |
165 | | - .get() |
166 | | - .getAsFile(); |
167 | | - TaskProvider<MavenExec> generateEffectiveBom = this.project.getTasks() |
168 | | - .register("generateEffectiveBom", MavenExec.class, (maven) -> { |
169 | | - maven.getProjectDir().set(generatedBomDir); |
170 | | - maven.args("--settings", "settings.xml", "help:effective-pom", "-Doutput=" + effectiveBom); |
171 | | - maven.dependsOn(syncBom); |
172 | | - maven.getOutputs().file(effectiveBom); |
173 | | - maven.doLast(new StripUnrepeatableOutputAction(effectiveBom)); |
174 | | - }); |
175 | | - this.project.getArtifacts() |
176 | | - .add(effectiveBomConfiguration.getName(), effectiveBom, |
177 | | - (artifact) -> artifact.builtBy(generateEffectiveBom)); |
178 | | - }); |
179 | | - } |
180 | | - |
181 | | - private String loadSettingsXml() { |
182 | | - try { |
183 | | - return FileCopyUtils |
184 | | - .copyToString(new InputStreamReader( |
185 | | - getClass().getClassLoader().getResourceAsStream("effective-bom-settings.xml"), |
186 | | - StandardCharsets.UTF_8)) |
187 | | - .replace("localRepositoryPath", |
188 | | - this.project.getLayout() |
189 | | - .getBuildDirectory() |
190 | | - .dir("local-m2-repository") |
191 | | - .get() |
192 | | - .getAsFile() |
193 | | - .getAbsolutePath()); |
194 | | - } |
195 | | - catch (IOException ex) { |
196 | | - throw new GradleException("Failed to prepare settings.xml", ex); |
197 | | - } |
198 | | - } |
199 | | - |
200 | 117 | private String createDependencyNotation(String groupId, String artifactId, DependencyVersion version) { |
201 | 118 | return groupId + ":" + artifactId + ":" + version; |
202 | 119 | } |
@@ -655,39 +572,4 @@ public List<String> getIssueLabels() { |
655 | 572 |
|
656 | 573 | } |
657 | 574 |
|
658 | | - private static final class StripUnrepeatableOutputAction implements Action<Task> { |
659 | | - |
660 | | - private final File effectiveBom; |
661 | | - |
662 | | - private StripUnrepeatableOutputAction(File xmlFile) { |
663 | | - this.effectiveBom = xmlFile; |
664 | | - } |
665 | | - |
666 | | - @Override |
667 | | - public void execute(Task task) { |
668 | | - try { |
669 | | - Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(this.effectiveBom); |
670 | | - XPath xpath = XPathFactory.newInstance().newXPath(); |
671 | | - NodeList comments = (NodeList) xpath.evaluate("//comment()", document, XPathConstants.NODESET); |
672 | | - for (int i = 0; i < comments.getLength(); i++) { |
673 | | - org.w3c.dom.Node comment = comments.item(i); |
674 | | - comment.getParentNode().removeChild(comment); |
675 | | - } |
676 | | - org.w3c.dom.Node build = (org.w3c.dom.Node) xpath.evaluate("/project/build", document, |
677 | | - XPathConstants.NODE); |
678 | | - build.getParentNode().removeChild(build); |
679 | | - org.w3c.dom.Node reporting = (org.w3c.dom.Node) xpath.evaluate("/project/reporting", document, |
680 | | - XPathConstants.NODE); |
681 | | - reporting.getParentNode().removeChild(reporting); |
682 | | - TransformerFactory.newInstance() |
683 | | - .newTransformer() |
684 | | - .transform(new DOMSource(document), new StreamResult(this.effectiveBom)); |
685 | | - } |
686 | | - catch (Exception ex) { |
687 | | - throw new TaskExecutionException(task, ex); |
688 | | - } |
689 | | - } |
690 | | - |
691 | | - } |
692 | | - |
693 | 575 | } |
0 commit comments