From 16710283b55a9c3e2383e9dd558b3d5ef8391fa0 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Fri, 27 Mar 2020 08:45:11 +1000 Subject: [PATCH] upgrade to last mojo parent and remove restrictions on java 1.5 Signed-off-by: olivier lamy --- pom.xml | 13 ++++++++--- .../codehaus/mojo/flatten/FlattenMojo.java | 22 ++++--------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 4e328861..af519f2c 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ org.codehaus.mojo mojo-parent - 40 + 50 flatten-maven-plugin maven-plugin @@ -37,8 +37,6 @@ 3.2.5 - 1.5 - 1.5 @@ -177,6 +175,15 @@ + + + + org.apache.maven.plugins + maven-invoker-plugin + 3.2.1 + + + org.apache.maven.plugins diff --git a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java index a65d1fe2..4cde5d4b 100644 --- a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java +++ b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java @@ -492,19 +492,16 @@ protected void writePom( Model pom, File pomFile, String headerComment ) protected void writeStringToFile( String data, File file, String encoding ) throws MojoExecutionException { - - OutputStream outStream = null; - try + try (OutputStream outStream = new FileOutputStream( file )) { byte[] binaryData = data.getBytes( encoding ); if ( file.isFile() && file.canRead() && file.length() == binaryData.length ) { - InputStream inputStream = null; - try + + try (InputStream inputStream = new FileInputStream( file )) { byte[] buffer = new byte[ binaryData.length ]; - inputStream = new FileInputStream( file ); inputStream.read( buffer ); if ( Arrays.equals( buffer, binaryData ) ) { return; @@ -513,26 +510,15 @@ protected void writeStringToFile( String data, File file, String encoding ) catch ( IOException e ) { // ignore those exceptions, we will overwrite the file - } - finally - { - IOUtil.close( inputStream ); + getLog().debug( "Issue reading file: " + file.getPath(), e ); } } - - outStream = new FileOutputStream( file ); outStream.write( binaryData ); } catch ( IOException e ) { throw new MojoExecutionException( "Failed to write to " + file, e ); } - finally - { - // resource-handling not perfectly solved but we do not want to require java 1.7 - // and this is not a server application. - IOUtil.close( outStream ); - } } /**