Skip to content

Commit

Permalink
use try with resources (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo authored Nov 16, 2020
1 parent c4fe61e commit 99df7a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/apache/maven/archiver/MavenArchiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private void addManifestAttribute( Manifest manifest, String key, String value )
}
else
{
// if the value is empty we have create an entry with an empty string
// if the value is empty, create an entry with an empty string
// to prevent null print in the manifest file
Manifest.Attribute attr = new Manifest.Attribute( key, "" );
manifest.addConfiguredAttribute( attr );
Expand Down
43 changes: 12 additions & 31 deletions src/main/java/org/apache/maven/archiver/PomPropertiesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.utils.io.IOUtil;
import org.codehaus.plexus.archiver.Archiver;

/**
Expand All @@ -47,19 +46,11 @@ private Properties loadPropertiesFile( File file )
throws IOException
{
Properties fileProps = new Properties();
InputStream istream = null;
try
try ( InputStream istream = new FileInputStream( file ) )
{
istream = new FileInputStream( file );
fileProps.load( istream );
istream.close();
istream = null;
return fileProps;
}
finally
{
IOUtil.close( istream );
}
}

private boolean sameContents( Properties props, File file )
Expand Down Expand Up @@ -87,41 +78,31 @@ private void createPropertiesFile( MavenSession session, Properties properties,
{
return;
}
PrintWriter pw = new PrintWriter( outputFile, "ISO-8859-1" );
try

try ( PrintWriter pw = new PrintWriter( outputFile, "ISO-8859-1" );
StringWriter sw = new StringWriter(); )
{
StringWriter sw = new StringWriter();

properties.store( sw, null );

BufferedReader r = new BufferedReader( new StringReader( sw.toString() ) );

List<String> lines = new ArrayList<String>();
String line;
while ( ( line = r.readLine() ) != null )
try ( BufferedReader r = new BufferedReader( new StringReader( sw.toString() ) ) )
{
if ( !line.startsWith( "#" ) )
String line;
while ( ( line = r.readLine() ) != null )
{
lines.add( line );
if ( !line.startsWith( "#" ) )
{
lines.add( line );
}
}
}

r.close();
r = null;
sw.close();
sw = null;

Collections.sort( lines );
for ( String l : lines )
{
pw.println( l );
}

pw.close();
pw = null;
}
finally
{
IOUtil.close( pw );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.codehaus.plexus.archiver.jar.ManifestException;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
Expand Down Expand Up @@ -131,9 +130,7 @@ public boolean isAddExtensions()
}
};

Manifest manifest;

manifest = archiver.getManifest( session, project, config );
Manifest manifest = archiver.getManifest( session, project, config );

assertThat( manifest.getMainAttributes() ).isNotNull();

Expand Down Expand Up @@ -273,7 +270,7 @@ public void testRecreation()
}

archiver.createArchive( session, project, config );

config.setForced( true );
archiver.createArchive( session, project, config );
// I'm not sure if it could only be greater than time or if it is sufficient to be greater or equal..
Expand Down

0 comments on commit 99df7a0

Please sign in to comment.