Skip to content

Commit d7917e4

Browse files
authored
IT: Move ITs off maven-shared-utils (#1941)
No dependency change yet, just remote all the use of maven-shared-utils from IT classes. Plexus Utils in present anyways, but also modern Java offers many of used stuff as well.
1 parent 9238d2f commit d7917e4

26 files changed

+107
-82
lines changed

its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0108SnapshotUpdateTest.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020

2121
import java.io.File;
2222
import java.io.IOException;
23+
import java.nio.file.Files;
2324
import java.text.SimpleDateFormat;
2425
import java.util.Calendar;
2526
import java.util.Date;
2627
import java.util.Locale;
2728

28-
import org.apache.maven.shared.utils.io.FileUtils;
2929
import org.apache.maven.shared.verifier.VerificationException;
3030
import org.apache.maven.shared.verifier.util.ResourceExtractor;
31+
import org.codehaus.plexus.util.FileUtils;
3132
import org.junit.jupiter.api.BeforeEach;
3233
import org.junit.jupiter.api.Disabled;
3334
import org.junit.jupiter.api.Test;
@@ -69,7 +70,7 @@ protected void setUp() throws Exception {
6970
repository,
7071
"org/apache/maven/maven-core-it-support/1.0-SNAPSHOT/maven-core-it-support-1.0-SNAPSHOT.jar");
7172
artifact.getParentFile().mkdirs();
72-
FileUtils.fileWrite(artifact.getAbsolutePath(), "originalArtifact");
73+
Files.writeString(artifact.getAbsoluteFile().toPath(), "originalArtifact");
7374

7475
verifier.verifyArtifactNotPresent("org.apache.maven", "maven-core-it-support", "1.0-SNAPSHOT", "jar");
7576
}
@@ -86,7 +87,7 @@ public void testSnapshotUpdated() throws Exception {
8687
// set in the past to ensure it is downloaded
8788
localRepoFile.setLastModified(System.currentTimeMillis() - TIME_OFFSET);
8889

89-
FileUtils.fileWrite(artifact.getAbsolutePath(), "updatedArtifact");
90+
Files.writeString(artifact.getAbsoluteFile().toPath(), "updatedArtifact");
9091

9192
verifier.addCliArgument("package");
9293
verifier.execute();
@@ -99,8 +100,9 @@ public void testSnapshotUpdated() throws Exception {
99100
@Test
100101
public void testSnapshotUpdatedWithMetadata() throws Exception {
101102
File metadata = new File(repository, "org/apache/maven/maven-core-it-support/1.0-SNAPSHOT/maven-metadata.xml");
102-
FileUtils.fileWrite(
103-
metadata.getAbsolutePath(), constructMetadata("1", System.currentTimeMillis() - TIME_OFFSET, true));
103+
Files.writeString(
104+
metadata.getAbsoluteFile().toPath(),
105+
constructMetadata("1", System.currentTimeMillis() - TIME_OFFSET, true));
104106

105107
verifier.addCliArgument("package");
106108
verifier.execute();
@@ -109,9 +111,10 @@ public void testSnapshotUpdatedWithMetadata() throws Exception {
109111

110112
verifyArtifactContent("originalArtifact");
111113

112-
FileUtils.fileWrite(artifact.getAbsolutePath(), "updatedArtifact");
114+
Files.writeString(artifact.getAbsoluteFile().toPath(), "updatedArtifact");
113115
metadata = new File(repository, "org/apache/maven/maven-core-it-support/1.0-SNAPSHOT/maven-metadata.xml");
114-
FileUtils.fileWrite(metadata.getAbsolutePath(), constructMetadata("2", System.currentTimeMillis(), true));
116+
Files.writeString(
117+
metadata.getAbsoluteFile().toPath(), constructMetadata("2", System.currentTimeMillis(), true));
115118

116119
verifier.addCliArgument("package");
117120
verifier.execute();
@@ -130,8 +133,9 @@ public void testSnapshotUpdatedWithLocalMetadata() throws Exception {
130133
localMetadata.getParentFile().mkdirs();
131134

132135
File metadata = new File(repository, "org/apache/maven/maven-core-it-support/1.0-SNAPSHOT/maven-metadata.xml");
133-
FileUtils.fileWrite(
134-
metadata.getAbsolutePath(), constructMetadata("1", System.currentTimeMillis() - TIME_OFFSET, true));
136+
Files.writeString(
137+
metadata.getAbsoluteFile().toPath(),
138+
constructMetadata("1", System.currentTimeMillis() - TIME_OFFSET, true));
135139

136140
verifier.addCliArgument("package");
137141
verifier.execute();
@@ -141,9 +145,9 @@ public void testSnapshotUpdatedWithLocalMetadata() throws Exception {
141145
verifyArtifactContent("originalArtifact");
142146
assertFalse(localMetadata.exists());
143147

144-
FileUtils.fileWrite(localRepoFile.getAbsolutePath(), "localArtifact");
145-
FileUtils.fileWrite(
146-
localMetadata.getAbsolutePath(),
148+
Files.writeString(localRepoFile.getAbsoluteFile().toPath(), "localArtifact");
149+
Files.writeString(
150+
localMetadata.getAbsoluteFile().toPath(),
147151
constructLocalMetadata("org.apache.maven", "maven-core-it-support", System.currentTimeMillis(), true));
148152
// update the remote file, but we shouldn't be looking
149153
artifact.setLastModified(System.currentTimeMillis());
@@ -157,11 +161,11 @@ public void testSnapshotUpdatedWithLocalMetadata() throws Exception {
157161

158162
Calendar cal = Calendar.getInstance();
159163
cal.add(Calendar.YEAR, -1);
160-
FileUtils.fileWrite(
161-
localMetadata.getAbsolutePath(),
164+
Files.writeString(
165+
localMetadata.getAbsoluteFile().toPath(),
162166
constructLocalMetadata("org.apache.maven", "maven-core-it-support", cal.getTimeInMillis(), true));
163-
FileUtils.fileWrite(
164-
metadata.getAbsolutePath(), constructMetadata("2", System.currentTimeMillis() - 2000, true));
167+
Files.writeString(
168+
metadata.getAbsoluteFile().toPath(), constructMetadata("2", System.currentTimeMillis() - 2000, true));
165169
artifact.setLastModified(System.currentTimeMillis());
166170

167171
verifier.addCliArgument("package");
@@ -175,8 +179,9 @@ public void testSnapshotUpdatedWithLocalMetadata() throws Exception {
175179
@Test
176180
public void testSnapshotUpdatedWithMetadataUsingFileTimestamp() throws Exception {
177181
File metadata = new File(repository, "org/apache/maven/maven-core-it-support/1.0-SNAPSHOT/maven-metadata.xml");
178-
FileUtils.fileWrite(
179-
metadata.getAbsolutePath(), constructMetadata("1", System.currentTimeMillis() - TIME_OFFSET, false));
182+
Files.writeString(
183+
metadata.getAbsoluteFile().toPath(),
184+
constructMetadata("1", System.currentTimeMillis() - TIME_OFFSET, false));
180185
metadata.setLastModified(System.currentTimeMillis() - TIME_OFFSET);
181186

182187
verifier.addCliArgument("package");
@@ -186,9 +191,10 @@ public void testSnapshotUpdatedWithMetadataUsingFileTimestamp() throws Exception
186191

187192
verifyArtifactContent("originalArtifact");
188193

189-
FileUtils.fileWrite(artifact.getAbsolutePath(), "updatedArtifact");
194+
Files.writeString(artifact.getAbsoluteFile().toPath(), "updatedArtifact");
190195
metadata = new File(repository, "org/apache/maven/maven-core-it-support/1.0-SNAPSHOT/maven-metadata.xml");
191-
FileUtils.fileWrite(metadata.getAbsolutePath(), constructMetadata("2", System.currentTimeMillis(), false));
196+
Files.writeString(
197+
metadata.getAbsoluteFile().toPath(), constructMetadata("2", System.currentTimeMillis(), false));
192198

193199
verifier.addCliArgument("package");
194200
verifier.execute();

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng1751ForcedMetadataUpdateDuringDeploymentTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
package org.apache.maven.it;
2020

2121
import java.io.File;
22+
import java.nio.file.Files;
23+
import java.nio.file.StandardCopyOption;
2224
import java.util.Properties;
2325

24-
import org.apache.maven.shared.utils.io.FileUtils;
2526
import org.apache.maven.shared.verifier.util.ResourceExtractor;
2627
import org.junit.jupiter.api.Test;
2728

@@ -52,9 +53,9 @@ public void testit() throws Exception {
5253
File dir = new File(testDir, "repo/org/apache/maven/its/mng1751/dep/0.1-SNAPSHOT");
5354
File templateMetadataFile = new File(dir, "template-metadata.xml");
5455
File metadataFile = new File(dir, "maven-metadata.xml");
55-
FileUtils.copyFile(templateMetadataFile, metadataFile);
56+
Files.copy(templateMetadataFile.toPath(), metadataFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
5657
String checksum = ItUtils.calcHash(metadataFile, "SHA-1");
57-
FileUtils.fileWrite(metadataFile.getPath() + ".sha1", checksum);
58+
Files.writeString(metadataFile.toPath().getParent().resolve(metadataFile.getName() + ".sha1"), checksum);
5859

5960
// phase 1: deploy a new snapshot, this should update the metadata despite its future timestamp
6061
Verifier verifier = newVerifier(new File(testDir, "dep").getAbsolutePath());

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2362DeployedPomEncodingTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
package org.apache.maven.it;
2020

2121
import java.io.File;
22+
import java.nio.charset.StandardCharsets;
23+
import java.nio.file.Files;
2224

23-
import org.apache.maven.shared.utils.io.FileUtils;
2425
import org.apache.maven.shared.verifier.util.ResourceExtractor;
2526
import org.junit.jupiter.api.Test;
2627

@@ -72,13 +73,13 @@ public void testit() throws Exception {
7273
}
7374

7475
private void assertPomUtf8(File pomFile) throws Exception {
75-
String pom = FileUtils.fileRead(pomFile, "UTF-8");
76+
String pom = Files.readString(pomFile.toPath());
7677
String chars = "\u00DF\u0131\u03A3\u042F\u05D0\u20AC";
7778
assertPom(pomFile, pom, chars);
7879
}
7980

8081
private void assertPomLatin1(File pomFile) throws Exception {
81-
String pom = FileUtils.fileRead(pomFile, "ISO-8859-1");
82+
String pom = Files.readString(pomFile.toPath(), StandardCharsets.ISO_8859_1);
8283
String chars = "\u00C4\u00D6\u00DC\u00E4\u00F6\u00FC\u00DF";
8384
assertPom(pomFile, pom, chars);
8485
}

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2790LastUpdatedMetadataTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
package org.apache.maven.it;
2020

2121
import java.io.File;
22+
import java.nio.file.Files;
2223
import java.text.SimpleDateFormat;
2324
import java.util.Date;
2425
import java.util.TimeZone;
2526

26-
import org.apache.maven.shared.utils.io.FileUtils;
2727
import org.apache.maven.shared.verifier.util.ResourceExtractor;
2828
import org.junit.jupiter.api.Test;
2929

@@ -102,7 +102,7 @@ public void testitMNG2790() throws Exception {
102102
}
103103

104104
private Date getLastUpdated(File metadataFile) throws Exception {
105-
String xml = FileUtils.fileRead(metadataFile, "UTF-8");
105+
String xml = Files.readString(metadataFile.toPath());
106106
String timestamp = xml.replaceAll("(?s)\\A.*<lastUpdated>\\s*([0-9]++)\\s*</lastUpdated>.*\\z", "$1");
107107
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
108108
format.setTimeZone(TimeZone.getTimeZone("UTC"));

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2820PomCommentsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
package org.apache.maven.it;
2020

2121
import java.io.File;
22+
import java.nio.file.Files;
2223

23-
import org.apache.maven.shared.utils.io.FileUtils;
2424
import org.apache.maven.shared.verifier.util.ResourceExtractor;
2525
import org.junit.jupiter.api.Test;
2626

@@ -62,7 +62,7 @@ public void testit() throws Exception {
6262
}
6363

6464
private void assertPomComments(File pomFile) throws Exception {
65-
String pom = FileUtils.fileRead(pomFile, "UTF-8");
65+
String pom = Files.readString(pomFile.toPath());
6666
assertPomComment(pom, "DOCUMENT-COMMENT-PRE-1");
6767
assertPomComment(pom, "DOCUMENT-COMMENT-PRE-2");
6868
assertPomComment(pom, "DOCUMENT-COMMENT-POST-1");

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3415JunkRepositoryMetadataTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323

2424
import java.io.File;
2525
import java.io.IOException;
26+
import java.nio.file.Files;
27+
import java.nio.file.StandardCopyOption;
2628
import java.util.Deque;
2729
import java.util.Map;
2830
import java.util.concurrent.ConcurrentLinkedDeque;
2931

30-
import org.apache.maven.shared.utils.io.FileUtils;
3132
import org.apache.maven.shared.verifier.util.ResourceExtractor;
3233
import org.eclipse.jetty.server.Handler;
3334
import org.eclipse.jetty.server.NetworkConnector;
@@ -260,7 +261,8 @@ private void setupDummyDependency(Verifier verifier, File testDir, boolean reset
260261
File pomSrc = new File(testDir, "dependency-pom.xml");
261262

262263
System.out.println("Copying dependency POM\nfrom: " + pomSrc + "\nto: " + pom);
263-
FileUtils.copyFile(pomSrc, pom);
264+
Files.createDirectories(pom.toPath().getParent());
265+
Files.copy(pomSrc.toPath(), pom.toPath(), StandardCopyOption.REPLACE_EXISTING);
264266
}
265267

266268
private File getMetadataFile(Verifier verifier) {

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3441MetadataUpdatedFromDeploymentRepositoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import java.io.FileReader;
2323
import java.io.IOException;
2424

25-
import org.apache.maven.shared.utils.io.FileUtils;
2625
import org.apache.maven.shared.verifier.util.ResourceExtractor;
26+
import org.codehaus.plexus.util.FileUtils;
2727
import org.codehaus.plexus.util.xml.Xpp3Dom;
2828
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
2929
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3503Xpp3ShadingTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
package org.apache.maven.it;
2020

2121
import java.io.File;
22+
import java.nio.file.Files;
2223

23-
import org.apache.maven.shared.utils.io.FileUtils;
2424
import org.apache.maven.shared.verifier.util.ResourceExtractor;
2525
import org.junit.jupiter.api.Test;
2626

@@ -49,7 +49,7 @@ public void testitMNG3503NoLinkageErrors() throws Exception {
4949

5050
verifier.verifyErrorFreeLog();
5151

52-
assertEquals("<root />", FileUtils.fileRead(new File(dir, "target/serialized.xml"), "UTF-8"));
52+
assertEquals("<root />", Files.readString(new File(dir, "target/serialized.xml").toPath()));
5353
}
5454

5555
@Test
@@ -62,6 +62,6 @@ public void testitMNG3503Xpp3Shading() throws Exception {
6262

6363
verifier.verifyErrorFreeLog();
6464

65-
assertEquals("root", FileUtils.fileRead(new File(dir, "target/serialized.xml"), "UTF-8"));
65+
assertEquals("root", Files.readString(new File(dir, "target/serialized.xml").toPath()));
6666
}
6767
}

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3599useHttpProxyForWebDAVMk2Test.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
import java.io.File;
2525
import java.io.IOException;
26+
import java.nio.file.Files;
2627

27-
import org.apache.maven.shared.utils.StringUtils;
28-
import org.apache.maven.shared.utils.io.FileUtils;
2928
import org.apache.maven.shared.verifier.util.ResourceExtractor;
29+
import org.codehaus.plexus.util.StringUtils;
3030
import org.eclipse.jetty.server.Handler;
3131
import org.eclipse.jetty.server.NetworkConnector;
3232
import org.eclipse.jetty.server.Request;
@@ -145,11 +145,11 @@ public void testitUseHttpProxyForHttp() throws Exception {
145145
verifier.execute();
146146
verifier.verifyErrorFreeLog();
147147

148-
String settings = FileUtils.fileRead(new File(testDir, "settings-template.xml"));
148+
String settings = Files.readString(new File(testDir, "settings-template.xml").toPath());
149149
settings = StringUtils.replace(settings, "@port@", Integer.toString(port));
150150
String newSettings = StringUtils.replace(settings, "@protocol@", "http");
151151

152-
FileUtils.fileWrite(new File(testDir, "settings.xml").getAbsolutePath(), newSettings);
152+
Files.writeString(new File(testDir, "settings.xml").getAbsoluteFile().toPath(), newSettings);
153153

154154
verifier = newVerifier(testDir.getAbsolutePath());
155155

@@ -187,11 +187,11 @@ public void testitUseHttpProxyForWebDAV() throws Exception {
187187
verifier.execute();
188188
verifier.verifyErrorFreeLog();
189189

190-
String settings = FileUtils.fileRead(new File(testDir, "settings-template.xml"));
190+
String settings = Files.readString(new File(testDir, "settings-template.xml").toPath());
191191
settings = StringUtils.replace(settings, "@port@", Integer.toString(port));
192192
String newSettings = StringUtils.replace(settings, "@protocol@", "dav");
193193

194-
FileUtils.fileWrite(new File(testDir, "settings.xml").getAbsolutePath(), newSettings);
194+
Files.writeString(new File(testDir, "settings.xml").getAbsoluteFile().toPath(), newSettings);
195195

196196
verifier = newVerifier(testDir.getAbsolutePath());
197197

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3693PomFileBasedirChangeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import java.io.File;
2222

23-
import org.apache.maven.shared.utils.io.FileUtils;
2423
import org.apache.maven.shared.verifier.util.ResourceExtractor;
24+
import org.codehaus.plexus.util.FileUtils;
2525
import org.junit.jupiter.api.Test;
2626

2727
/**

0 commit comments

Comments
 (0)