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

Use try with resources #14

Merged
merged 2 commits into from
Nov 16, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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