Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clear up deprecations, resource leaks, and unused imports #13

Merged
merged 1 commit into from Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -332,8 +333,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