Skip to content

Commit

Permalink
clear up deprecations and resource leaks (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Jun 18, 2020
1 parent 1619871 commit 6434336
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -148,7 +148,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.13</version>
<scope>test</scope>
</dependency>

Expand Down
Expand Up @@ -23,13 +23,13 @@
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.
Expand Down Expand Up @@ -222,12 +222,12 @@ Artifact getAssociatedArtifact( final Overlay overlay )
*/
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() ) ) );
}

/**
Expand Down
Expand Up @@ -21,6 +21,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Objects;

import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -329,8 +330,8 @@ public void copyResources( WarPackagingContext context, Resource resource )
// 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;
}
Expand Down
Expand Up @@ -308,8 +308,6 @@ protected void createArchive( final File directory, final File destinationFile )

Archiver archiver = new JarArchiver();

archiver.setUseJvmChmod( true );

archiver.setDestFile( destinationFile );
archiver.addDirectory( directory );

Expand Down
51 changes: 25 additions & 26 deletions src/test/java/org/apache/maven/plugins/war/WarMojoTest.java
Expand Up @@ -500,37 +500,36 @@ protected Map<String, JarEntry> assertJarContent( final File expectedJarFile, fi

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;
}

}
Expand Up @@ -26,7 +26,6 @@

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;
Expand Down

0 comments on commit 6434336

Please sign in to comment.