You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/06/18 12:09:05 UTC

[maven-war-plugin] branch master updated: clear up deprecations and resource leaks (#13)

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

elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-war-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 6434336  clear up deprecations and resource leaks (#13)
6434336 is described below

commit 6434336ae3e62032e0b2026d13bca1739e2d3477
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Thu Jun 18 08:08:52 2020 -0400

    clear up deprecations and resource leaks (#13)
---
 pom.xml                                            |  2 +-
 .../maven/plugins/war/overlay/OverlayManager.java  | 12 ++---
 .../war/packaging/WarProjectPackagingTask.java     |  5 ++-
 .../maven/plugins/war/AbstractWarMojoTest.java     |  2 -
 .../org/apache/maven/plugins/war/WarMojoTest.java  | 51 +++++++++++-----------
 .../apache/maven/plugins/war/util/PathSetTest.java |  1 -
 6 files changed, 35 insertions(+), 38 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4e1aee0..7256fb4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -148,7 +148,7 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>4.11</version>
+      <version>4.13</version>
       <scope>test</scope>
     </dependency>
 
diff --git a/src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java b/src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java
index 318ec68..cf83d5e 100644
--- a/src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java
+++ b/src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java
@@ -23,13 +23,13 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.Objects;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.plugins.war.Overlay;
 import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.StringUtils;
 
 /**
  * Manages the overlays.
@@ -222,12 +222,12 @@ public class OverlayManager
      */
     private boolean compareOverlayWithArtifact( Overlay overlay, Artifact artifact )
     {
-        return ( StringUtils.equals( overlay.getGroupId(), artifact.getGroupId() )
-            && StringUtils.equals( overlay.getArtifactId(), artifact.getArtifactId() )
-            && StringUtils.equals( overlay.getType(), artifact.getType() )
+        return ( Objects.equals( overlay.getGroupId(), artifact.getGroupId() )
+            && Objects.equals( overlay.getArtifactId(), artifact.getArtifactId() )
+            && Objects.equals( overlay.getType(), artifact.getType() )
         // MWAR-241 Make sure to treat null and "" as equal when comparing the classifier
-        && StringUtils.equals( StringUtils.defaultString( overlay.getClassifier() ),
-                               StringUtils.defaultString( artifact.getClassifier() ) ) );
+        && Objects.equals( Objects.toString( overlay.getClassifier() ),
+                           Objects.toString( artifact.getClassifier() ) ) );
     }
 
     /**
diff --git a/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java b/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java
index cd7ff46..5993706 100644
--- a/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java
+++ b/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java
@@ -21,6 +21,7 @@ package org.apache.maven.plugins.war.packaging;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Objects;
 
 import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -329,8 +330,8 @@ public class WarProjectPackagingTask
                 // MWAR-129 if targetPath is only a dot <targetPath>.</targetPath> or ./
                 // and the Resource is in a part of the warSourceDirectory the file from sources will override this
                 // that's we don't have to add the targetPath yep not nice but works
-                if ( !StringUtils.equals( ".", resource.getTargetPath() )
-                    && !StringUtils.equals( "./", resource.getTargetPath() ) )
+                if ( !Objects.equals( ".", resource.getTargetPath() )
+                    && !Objects.equals( "./", resource.getTargetPath() ) )
                 {
                     targetFileName = resource.getTargetPath() + File.separator + targetFileName;
                 }
diff --git a/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java
index 3111696..87344ad 100644
--- a/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java
@@ -308,8 +308,6 @@ public abstract class AbstractWarMojoTest
 
             Archiver archiver = new JarArchiver();
 
-            archiver.setUseJvmChmod( true );
-
             archiver.setDestFile( destinationFile );
             archiver.addDirectory( directory );
 
diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java
index 5696965..7a313ec 100644
--- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java
@@ -500,37 +500,36 @@ public class WarMojoTest
 
         assertTrue( "war file not created: " + expectedJarFile.toString(), expectedJarFile.exists() );
         final Map<String, JarEntry> jarContent = new HashMap<>();
-        final JarFile jarFile = new JarFile( expectedJarFile );
-
-        JarEntry entry;
-        Enumeration<JarEntry> enumeration = jarFile.entries();
-        while ( enumeration.hasMoreElements() )
-        {
-            entry = enumeration.nextElement();
-            Object previousValue = jarContent.put( entry.getName(), entry );
-            assertNull( "Duplicate Entry in Jar File: " + entry.getName(), previousValue );
-        }
-
-        for ( int i = 0; i < files.length; i++ )
-        {
-            String file = files[i];
-
-            assertTrue( "File[" + file + "] not found in archive", jarContent.containsKey( file ) );
-            if ( filesContent[i] != null )
+        try ( JarFile jarFile = new JarFile( expectedJarFile ) ) {
+            Enumeration<JarEntry> enumeration = jarFile.entries();
+            while ( enumeration.hasMoreElements() )
             {
-                assertEquals( "Content of file[" + file + "] does not match", filesContent[i],
-                              IOUtil.toString( jarFile.getInputStream( jarContent.get( file ) ) ) );
+                JarEntry entry = enumeration.nextElement();
+                Object previousValue = jarContent.put( entry.getName(), entry );
+                assertNull( "Duplicate Entry in Jar File: " + entry.getName(), previousValue );
             }
-        }
-        if ( mustNotBeInJar != null )
-        {
-            for ( String file : mustNotBeInJar )
+    
+            for ( int i = 0; i < files.length; i++ )
             {
-                assertFalse( "File[" + file + "]  found in archive", jarContent.containsKey( file ) );
-
+                String file = files[i];
+    
+                assertTrue( "File[" + file + "] not found in archive", jarContent.containsKey( file ) );
+                if ( filesContent[i] != null )
+                {
+                    assertEquals( "Content of file[" + file + "] does not match", filesContent[i],
+                                  IOUtil.toString( jarFile.getInputStream( jarContent.get( file ) ) ) );
+                }
+            }
+            if ( mustNotBeInJar != null )
+            {
+                for ( String file : mustNotBeInJar )
+                {
+                    assertFalse( "File[" + file + "]  found in archive", jarContent.containsKey( file ) );
+    
+                }
             }
+            return jarContent;
         }
-        return jarContent;
     }
 
 }
diff --git a/src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java b/src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java
index 2ccfc6b..6375109 100644
--- a/src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java
@@ -26,7 +26,6 @@ import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
 import java.io.IOException;
-import java.nio.file.Path;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;