You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2024/07/28 21:56:46 UTC

(maven-site-plugin) branch maven-site-plugin-3.x updated: [MSITE-945] More modern temporary file handling (#203)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch maven-site-plugin-3.x
in repository https://gitbox.apache.org/repos/asf/maven-site-plugin.git


The following commit(s) were added to refs/heads/maven-site-plugin-3.x by this push:
     new 6fc5d171 [MSITE-945] More modern temporary file handling (#203)
6fc5d171 is described below

commit 6fc5d171b7f7e539c7107fc89612c949be5e813e
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Sun Jul 28 17:18:31 2024 -0400

    [MSITE-945] More modern temporary file handling (#203)
    
    * More modern temporary file handling
---
 .../site/deploy/AbstractSiteDeployWebDavTest.java   | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/test/java/org/apache/maven/plugins/site/deploy/AbstractSiteDeployWebDavTest.java b/src/test/java/org/apache/maven/plugins/site/deploy/AbstractSiteDeployWebDavTest.java
index 3e952413..a245f79d 100644
--- a/src/test/java/org/apache/maven/plugins/site/deploy/AbstractSiteDeployWebDavTest.java
+++ b/src/test/java/org/apache/maven/plugins/site/deploy/AbstractSiteDeployWebDavTest.java
@@ -40,7 +40,9 @@ import org.apache.maven.settings.Proxy;
 import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.util.ReflectionUtils;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
@@ -51,15 +53,19 @@ import org.junit.runners.JUnit4;
 @RunWith(JUnit4.class)
 public abstract class AbstractSiteDeployWebDavTest extends AbstractMojoTestCase {
 
-    File siteTargetPath = new File(getBasedir() + File.separator + "target" + File.separator + "siteTargetDeploy");
+    // Can use @TempDir with JUnit 5
+    @Rule
+    public TemporaryFolder directory = new TemporaryFolder();
+
+    private File siteTargetPath;
 
     @Override
     @Before
     public void setUp() throws Exception {
         super.setUp();
+        siteTargetPath = new File(directory.newFolder(), "target");
         if (!siteTargetPath.exists()) {
             siteTargetPath.mkdirs();
-            FileUtils.cleanDirectory(siteTargetPath);
         }
     }
 
@@ -69,7 +75,6 @@ public abstract class AbstractSiteDeployWebDavTest extends AbstractMojoTestCase
 
     @Test
     public void noAuthzDavDeploy() throws Exception {
-        FileUtils.cleanDirectory(siteTargetPath);
         SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler(siteTargetPath);
 
         try {
@@ -104,8 +109,6 @@ public abstract class AbstractSiteDeployWebDavTest extends AbstractMojoTestCase
 
     @Test
     public void davDeployThruProxyWithoutAuthzInProxy() throws Exception {
-
-        FileUtils.cleanDirectory(siteTargetPath);
         SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler(siteTargetPath);
         try {
             File pluginXmlFile = getTestFile("src/test/resources/unit/deploy-dav/pom.xml");
@@ -151,10 +154,6 @@ public abstract class AbstractSiteDeployWebDavTest extends AbstractMojoTestCase
 
     @Test
     public void davDeployThruProxyWitAuthzInProxy() throws Exception {
-
-        FileUtils.cleanDirectory(siteTargetPath);
-        // SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler( siteTargetPath );
-
         Map<String, String> authentications = new HashMap<>();
         authentications.put("foo", "titi");
 
@@ -226,8 +225,8 @@ public abstract class AbstractSiteDeployWebDavTest extends AbstractMojoTestCase
 
         File cssFile = new File(siteTargetPath, "site" + File.separator + "css" + File.separator + "maven-base.css");
         assertTrue(cssFile.exists());
-        fileContent = FileUtils.readFileToString(cssFile, StandardCharsets.UTF_8);
-        assertTrue(fileContent.contains("background-image: url(../images/collapsed.gif);"));
+        String cssContent = FileUtils.readFileToString(cssFile, StandardCharsets.UTF_8);
+        assertTrue(cssContent.contains("background-image: url(../images/collapsed.gif);"));
     }
 
     /**