Skip to content

Commit ef2eb2f

Browse files
committed
Remove accidental usage of Plexus's CollectionUtils
See gh-16655 and 8f5777c
1 parent 1b1c61a commit ef2eb2f

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import java.io.File;
2020
import java.net.URL;
21+
import java.util.ArrayList;
2122
import java.util.List;
2223

23-
import org.codehaus.plexus.util.CollectionUtils;
2424
import org.junit.jupiter.api.Test;
2525

2626
import org.springframework.boot.loader.archive.Archive;
@@ -40,7 +40,8 @@ class JarLauncherTests extends AbstractExecutableArchiveLauncherTests {
4040
void explodedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath() throws Exception {
4141
File explodedRoot = explode(createJarArchive("archive.jar", "BOOT-INF"));
4242
JarLauncher launcher = new JarLauncher(new ExplodedArchive(explodedRoot, true));
43-
List<Archive> archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator());
43+
List<Archive> archives = new ArrayList<>();
44+
launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
4445
assertThat(archives).hasSize(2);
4546
assertThat(getUrls(archives)).containsOnly(new File(explodedRoot, "BOOT-INF/classes").toURI().toURL(),
4647
new File(explodedRoot, "BOOT-INF/lib/foo.jar").toURI().toURL());
@@ -54,7 +55,8 @@ void archivedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath() throws
5455
File jarRoot = createJarArchive("archive.jar", "BOOT-INF");
5556
try (JarFileArchive archive = new JarFileArchive(jarRoot)) {
5657
JarLauncher launcher = new JarLauncher(archive);
57-
List<Archive> classPathArchives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator());
58+
List<Archive> classPathArchives = new ArrayList<>();
59+
launcher.getClassPathArchivesIterator().forEachRemaining(classPathArchives::add);
5860
assertThat(classPathArchives).hasSize(2);
5961
assertThat(getUrls(classPathArchives)).containsOnly(
6062
new URL("jar:" + jarRoot.toURI().toURL() + "!/BOOT-INF/classes!/"),

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import org.assertj.core.api.Condition;
3232
import org.awaitility.Awaitility;
33-
import org.codehaus.plexus.util.CollectionUtils;
3433
import org.junit.jupiter.api.AfterEach;
3534
import org.junit.jupiter.api.BeforeEach;
3635
import org.junit.jupiter.api.Test;
@@ -140,7 +139,8 @@ void testUserSpecifiedSlashPath() throws Exception {
140139
System.setProperty("loader.path", "jars/");
141140
PropertiesLauncher launcher = new PropertiesLauncher();
142141
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()).isEqualTo("[jars/]");
143-
List<Archive> archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator());
142+
List<Archive> archives = new ArrayList<>();
143+
launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
144144
assertThat(archives).areExactly(1, endingWith("app.jar"));
145145
}
146146

@@ -170,7 +170,8 @@ void testUserSpecifiedRootOfJarPath() throws Exception {
170170
PropertiesLauncher launcher = new PropertiesLauncher();
171171
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
172172
.isEqualTo("[jar:file:./src/test/resources/nested-jars/app.jar!/]");
173-
List<Archive> archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator());
173+
List<Archive> archives = new ArrayList<>();
174+
launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
174175
assertThat(archives).areExactly(1, endingWith("foo.jar!/"));
175176
assertThat(archives).areExactly(1, endingWith("app.jar"));
176177
}
@@ -179,7 +180,8 @@ void testUserSpecifiedRootOfJarPath() throws Exception {
179180
void testUserSpecifiedRootOfJarPathWithDot() throws Exception {
180181
System.setProperty("loader.path", "nested-jars/app.jar!/./");
181182
PropertiesLauncher launcher = new PropertiesLauncher();
182-
List<Archive> archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator());
183+
List<Archive> archives = new ArrayList<>();
184+
launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
183185
assertThat(archives).areExactly(1, endingWith("foo.jar!/"));
184186
assertThat(archives).areExactly(1, endingWith("app.jar"));
185187
}
@@ -188,7 +190,8 @@ void testUserSpecifiedRootOfJarPathWithDot() throws Exception {
188190
void testUserSpecifiedRootOfJarPathWithDotAndJarPrefix() throws Exception {
189191
System.setProperty("loader.path", "jar:file:./src/test/resources/nested-jars/app.jar!/./");
190192
PropertiesLauncher launcher = new PropertiesLauncher();
191-
List<Archive> archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator());
193+
List<Archive> archives = new ArrayList<>();
194+
launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
192195
assertThat(archives).areExactly(1, endingWith("foo.jar!/"));
193196
}
194197

@@ -197,7 +200,8 @@ void testUserSpecifiedJarFileWithNestedArchives() throws Exception {
197200
System.setProperty("loader.path", "nested-jars/app.jar");
198201
System.setProperty("loader.main", "demo.Application");
199202
PropertiesLauncher launcher = new PropertiesLauncher();
200-
List<Archive> archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator());
203+
List<Archive> archives = new ArrayList<>();
204+
launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
201205
assertThat(archives).areExactly(1, endingWith("foo.jar!/"));
202206
assertThat(archives).areExactly(1, endingWith("app.jar"));
203207
}
@@ -207,7 +211,8 @@ void testUserSpecifiedNestedJarPath() throws Exception {
207211
System.setProperty("loader.path", "nested-jars/app.jar!/foo.jar");
208212
System.setProperty("loader.main", "demo.Application");
209213
PropertiesLauncher launcher = new PropertiesLauncher();
210-
List<Archive> archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator());
214+
List<Archive> archives = new ArrayList<>();
215+
launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
211216
assertThat(archives).hasSize(1).areExactly(1, endingWith("foo.jar!/"));
212217
}
213218

@@ -336,7 +341,8 @@ void encodedFileUrlLoaderPathIsHandledCorrectly() throws Exception {
336341
loaderPath.mkdir();
337342
System.setProperty("loader.path", loaderPath.toURI().toURL().toString());
338343
PropertiesLauncher launcher = new PropertiesLauncher();
339-
List<Archive> archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator());
344+
List<Archive> archives = new ArrayList<>();
345+
launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
340346
assertThat(archives.size()).isEqualTo(1);
341347
File archiveRoot = (File) ReflectionTestUtils.getField(archives.get(0), "root");
342348
assertThat(archiveRoot).isEqualTo(loaderPath);

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import java.io.File;
2020
import java.net.URL;
21+
import java.util.ArrayList;
2122
import java.util.List;
2223

23-
import org.codehaus.plexus.util.CollectionUtils;
2424
import org.junit.jupiter.api.Test;
2525

2626
import org.springframework.boot.loader.archive.Archive;
@@ -40,7 +40,8 @@ class WarLauncherTests extends AbstractExecutableArchiveLauncherTests {
4040
void explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath() throws Exception {
4141
File explodedRoot = explode(createJarArchive("archive.war", "WEB-INF"));
4242
WarLauncher launcher = new WarLauncher(new ExplodedArchive(explodedRoot, true));
43-
List<Archive> archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator());
43+
List<Archive> archives = new ArrayList<>();
44+
launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
4445
assertThat(archives).hasSize(2);
4546
assertThat(getUrls(archives)).containsOnly(new File(explodedRoot, "WEB-INF/classes").toURI().toURL(),
4647
new File(explodedRoot, "WEB-INF/lib/foo.jar").toURI().toURL());
@@ -54,7 +55,8 @@ void archivedWarHasOnlyWebInfClassesAndContentsOWebInfLibOnClasspath() throws Ex
5455
File jarRoot = createJarArchive("archive.war", "WEB-INF");
5556
try (JarFileArchive archive = new JarFileArchive(jarRoot)) {
5657
WarLauncher launcher = new WarLauncher(archive);
57-
List<Archive> classPathArchives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator());
58+
List<Archive> classPathArchives = new ArrayList<>();
59+
launcher.getClassPathArchivesIterator().forEachRemaining(classPathArchives::add);
5860
assertThat(classPathArchives).hasSize(2);
5961
assertThat(getUrls(classPathArchives)).containsOnly(
6062
new URL("jar:" + jarRoot.toURI().toURL() + "!/WEB-INF/classes!/"),

0 commit comments

Comments
 (0)