From ef2eb2f652a445bf64b79d22e0872423a6249451 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Sat, 14 Dec 2019 17:41:47 +0000 Subject: [PATCH] Remove accidental usage of Plexus's CollectionUtils See gh-16655 and 8f5777cf --- .../boot/loader/JarLauncherTests.java | 8 ++++--- .../boot/loader/PropertiesLauncherTests.java | 22 ++++++++++++------- .../boot/loader/WarLauncherTests.java | 8 ++++--- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java index d892b564a5..35f148cbf3 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java @@ -18,9 +18,9 @@ package org.springframework.boot.loader; import java.io.File; import java.net.URL; +import java.util.ArrayList; import java.util.List; -import org.codehaus.plexus.util.CollectionUtils; import org.junit.jupiter.api.Test; import org.springframework.boot.loader.archive.Archive; @@ -40,7 +40,8 @@ class JarLauncherTests extends AbstractExecutableArchiveLauncherTests { void explodedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath() throws Exception { File explodedRoot = explode(createJarArchive("archive.jar", "BOOT-INF")); JarLauncher launcher = new JarLauncher(new ExplodedArchive(explodedRoot, true)); - List archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator()); + List archives = new ArrayList<>(); + launcher.getClassPathArchivesIterator().forEachRemaining(archives::add); assertThat(archives).hasSize(2); assertThat(getUrls(archives)).containsOnly(new File(explodedRoot, "BOOT-INF/classes").toURI().toURL(), new File(explodedRoot, "BOOT-INF/lib/foo.jar").toURI().toURL()); @@ -54,7 +55,8 @@ class JarLauncherTests extends AbstractExecutableArchiveLauncherTests { File jarRoot = createJarArchive("archive.jar", "BOOT-INF"); try (JarFileArchive archive = new JarFileArchive(jarRoot)) { JarLauncher launcher = new JarLauncher(archive); - List classPathArchives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator()); + List classPathArchives = new ArrayList<>(); + launcher.getClassPathArchivesIterator().forEachRemaining(classPathArchives::add); assertThat(classPathArchives).hasSize(2); assertThat(getUrls(classPathArchives)).containsOnly( new URL("jar:" + jarRoot.toURI().toURL() + "!/BOOT-INF/classes!/"), diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java index 5c65cbc29f..71fce71184 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java @@ -30,7 +30,6 @@ import java.util.jar.Manifest; import org.assertj.core.api.Condition; import org.awaitility.Awaitility; -import org.codehaus.plexus.util.CollectionUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -140,7 +139,8 @@ class PropertiesLauncherTests { System.setProperty("loader.path", "jars/"); PropertiesLauncher launcher = new PropertiesLauncher(); assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()).isEqualTo("[jars/]"); - List archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator()); + List archives = new ArrayList<>(); + launcher.getClassPathArchivesIterator().forEachRemaining(archives::add); assertThat(archives).areExactly(1, endingWith("app.jar")); } @@ -170,7 +170,8 @@ class PropertiesLauncherTests { PropertiesLauncher launcher = new PropertiesLauncher(); assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()) .isEqualTo("[jar:file:./src/test/resources/nested-jars/app.jar!/]"); - List archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator()); + List archives = new ArrayList<>(); + launcher.getClassPathArchivesIterator().forEachRemaining(archives::add); assertThat(archives).areExactly(1, endingWith("foo.jar!/")); assertThat(archives).areExactly(1, endingWith("app.jar")); } @@ -179,7 +180,8 @@ class PropertiesLauncherTests { void testUserSpecifiedRootOfJarPathWithDot() throws Exception { System.setProperty("loader.path", "nested-jars/app.jar!/./"); PropertiesLauncher launcher = new PropertiesLauncher(); - List archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator()); + List archives = new ArrayList<>(); + launcher.getClassPathArchivesIterator().forEachRemaining(archives::add); assertThat(archives).areExactly(1, endingWith("foo.jar!/")); assertThat(archives).areExactly(1, endingWith("app.jar")); } @@ -188,7 +190,8 @@ class PropertiesLauncherTests { void testUserSpecifiedRootOfJarPathWithDotAndJarPrefix() throws Exception { System.setProperty("loader.path", "jar:file:./src/test/resources/nested-jars/app.jar!/./"); PropertiesLauncher launcher = new PropertiesLauncher(); - List archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator()); + List archives = new ArrayList<>(); + launcher.getClassPathArchivesIterator().forEachRemaining(archives::add); assertThat(archives).areExactly(1, endingWith("foo.jar!/")); } @@ -197,7 +200,8 @@ class PropertiesLauncherTests { System.setProperty("loader.path", "nested-jars/app.jar"); System.setProperty("loader.main", "demo.Application"); PropertiesLauncher launcher = new PropertiesLauncher(); - List archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator()); + List archives = new ArrayList<>(); + launcher.getClassPathArchivesIterator().forEachRemaining(archives::add); assertThat(archives).areExactly(1, endingWith("foo.jar!/")); assertThat(archives).areExactly(1, endingWith("app.jar")); } @@ -207,7 +211,8 @@ class PropertiesLauncherTests { System.setProperty("loader.path", "nested-jars/app.jar!/foo.jar"); System.setProperty("loader.main", "demo.Application"); PropertiesLauncher launcher = new PropertiesLauncher(); - List archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator()); + List archives = new ArrayList<>(); + launcher.getClassPathArchivesIterator().forEachRemaining(archives::add); assertThat(archives).hasSize(1).areExactly(1, endingWith("foo.jar!/")); } @@ -336,7 +341,8 @@ class PropertiesLauncherTests { loaderPath.mkdir(); System.setProperty("loader.path", loaderPath.toURI().toURL().toString()); PropertiesLauncher launcher = new PropertiesLauncher(); - List archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator()); + List archives = new ArrayList<>(); + launcher.getClassPathArchivesIterator().forEachRemaining(archives::add); assertThat(archives.size()).isEqualTo(1); File archiveRoot = (File) ReflectionTestUtils.getField(archives.get(0), "root"); assertThat(archiveRoot).isEqualTo(loaderPath); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java index eede7587a4..0bdb8ce0ba 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java @@ -18,9 +18,9 @@ package org.springframework.boot.loader; import java.io.File; import java.net.URL; +import java.util.ArrayList; import java.util.List; -import org.codehaus.plexus.util.CollectionUtils; import org.junit.jupiter.api.Test; import org.springframework.boot.loader.archive.Archive; @@ -40,7 +40,8 @@ class WarLauncherTests extends AbstractExecutableArchiveLauncherTests { void explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath() throws Exception { File explodedRoot = explode(createJarArchive("archive.war", "WEB-INF")); WarLauncher launcher = new WarLauncher(new ExplodedArchive(explodedRoot, true)); - List archives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator()); + List archives = new ArrayList<>(); + launcher.getClassPathArchivesIterator().forEachRemaining(archives::add); assertThat(archives).hasSize(2); assertThat(getUrls(archives)).containsOnly(new File(explodedRoot, "WEB-INF/classes").toURI().toURL(), new File(explodedRoot, "WEB-INF/lib/foo.jar").toURI().toURL()); @@ -54,7 +55,8 @@ class WarLauncherTests extends AbstractExecutableArchiveLauncherTests { File jarRoot = createJarArchive("archive.war", "WEB-INF"); try (JarFileArchive archive = new JarFileArchive(jarRoot)) { WarLauncher launcher = new WarLauncher(archive); - List classPathArchives = CollectionUtils.iteratorToList(launcher.getClassPathArchivesIterator()); + List classPathArchives = new ArrayList<>(); + launcher.getClassPathArchivesIterator().forEachRemaining(classPathArchives::add); assertThat(classPathArchives).hasSize(2); assertThat(getUrls(classPathArchives)).containsOnly( new URL("jar:" + jarRoot.toURI().toURL() + "!/WEB-INF/classes!/"),