Skip to content

Commit a7aff6b

Browse files
committed
<refactor>: use getResolvedArtifacts() instead of getFiles().
1 parent 2ae940c commit a7aff6b

File tree

1 file changed

+25
-7
lines changed
  • buildSrc/src/main/java/org/springframework/boot/build/bom

1 file changed

+25
-7
lines changed

buildSrc/src/main/java/org/springframework/boot/build/bom/CheckBom.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.gradle.api.DefaultTask;
3333
import org.gradle.api.GradleException;
3434
import org.gradle.api.artifacts.ConfigurationContainer;
35+
import org.gradle.api.artifacts.ResolvedArtifact;
3536
import org.gradle.api.artifacts.dsl.DependencyHandler;
3637
import org.gradle.api.tasks.TaskAction;
3738

@@ -46,6 +47,7 @@
4647
* Checks the validity of a bom.
4748
*
4849
* @author Andy Wilkinson
50+
* @author Wick Dynex
4951
*/
5052
public abstract class CheckBom extends DefaultTask {
5153

@@ -207,16 +209,32 @@ private void checkDependencyManagementAlignment(Library library, List<String> er
207209
}
208210
}
209211

212+
// private File resolveBom(Library library, String alignsWithBom) {
213+
// String coordinates = alignsWithBom + ":" + library.getVersion().getVersion() + "@pom";
214+
// Set<File> files = this.configurations.detachedConfiguration(this.dependencies.create(coordinates))
215+
// .getResolvedConfiguration()
216+
// .getFiles();
217+
// if (files.size() != 1) {
218+
// throw new IllegalStateException(
219+
// "Expected a single file but '" + coordinates + "' resolved to " + files.size());
220+
// }
221+
// return files.iterator().next();
222+
// }
223+
224+
210225
private File resolveBom(Library library, String alignsWithBom) {
211226
String coordinates = alignsWithBom + ":" + library.getVersion().getVersion() + "@pom";
212-
Set<File> files = this.configurations.detachedConfiguration(this.dependencies.create(coordinates))
213-
.getResolvedConfiguration()
214-
.getFiles();
215-
if (files.size() != 1) {
227+
228+
Set<ResolvedArtifact> artifacts = this.configurations
229+
.detachedConfiguration(this.dependencies.create(coordinates))
230+
.getResolvedConfiguration()
231+
.getResolvedArtifacts();
232+
233+
if (artifacts.size() != 1) {
216234
throw new IllegalStateException(
217-
"Expected a single file but '" + coordinates + "' resolved to " + files.size());
235+
"Expected a single file but '" + coordinates + "' resolved to " + artifacts.size());
218236
}
219-
return files.iterator().next();
220-
}
221237

238+
return artifacts.iterator().next().getFile();
239+
}
222240
}

0 commit comments

Comments
 (0)