maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject [maven-release] branch master updated: Use try-with-resources Remove unnecessary @SuppressWarnings( "unchecked" )
Date Thu, 11 Jan 2018 17:47:46 GMT
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-release.git


The following commit(s) were added to refs/heads/master by this push:
     new 4cf927f  Use try-with-resources Remove unnecessary @SuppressWarnings( "unchecked"
)
4cf927f is described below

commit 4cf927fa86e39aeb9c2228ee06fa0a068644a54c
Author: rfscholte <rfscholte@apache.org>
AuthorDate: Thu Jan 11 18:47:34 2018 +0100

    Use try-with-resources
    Remove unnecessary @SuppressWarnings( "unchecked" )
---
 .../config/PropertiesReleaseDescriptorStore.java   | 21 ++----------
 .../shared/release/exec/ForkedMavenExecutor.java   | 10 ++----
 .../shared/release/exec/InvokerMavenExecutor.java  | 38 +++++++++++-----------
 .../phase/CheckDependencySnapshotsPhase.java       | 12 +------
 .../release/phase/GenerateReleasePomsPhase.java    | 14 ++------
 .../release/transform/jdom/JDomModelETL.java       | 11 ++-----
 .../maven/shared/release/util/PomFinder.java       | 31 ++----------------
 .../maven/shared/release/util/ReleaseUtil.java     |  8 +----
 .../src/main/mdo/release-descriptor.mdo            |  2 +-
 9 files changed, 33 insertions(+), 114 deletions(-)

diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStore.java
b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStore.java
index 78f55c0..9498e42 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStore.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStore.java
@@ -37,7 +37,6 @@ import org.apache.maven.shared.release.scm.IdentifiedScm;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.IOUtil;
 import org.sonatype.plexus.components.cipher.DefaultPlexusCipher;
 import org.sonatype.plexus.components.cipher.PlexusCipherException;
 import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
@@ -82,11 +81,8 @@ public class PropertiesReleaseDescriptorStore
     {
         Properties properties = new Properties();
 
-        InputStream inStream = null;
-        try
+        try ( InputStream inStream = new FileInputStream( file ) )
         {
-            inStream = new FileInputStream( file );
-
             properties.load( inStream );
         }
         catch ( FileNotFoundException e )
@@ -98,10 +94,6 @@ public class PropertiesReleaseDescriptorStore
             throw new ReleaseDescriptorStoreException(
                 "Error reading properties file '" + file.getName() + "': " + e.getMessage(),
e );
         }
-        finally
-        {
-            IOUtil.close( inStream );
-        }
 
         ReleaseDescriptor releaseDescriptor = ReleaseUtils.copyPropertiesToReleaseDescriptor(
properties );
 
@@ -301,12 +293,8 @@ public class PropertiesReleaseDescriptorStore
             processResolvedDependencies( properties, config.getResolvedSnapshotDependencies()
);
         }
 
-        OutputStream outStream = null;
-        //noinspection OverlyBroadCatchBlock
-        try
+        try ( OutputStream outStream = new FileOutputStream( file ) )
         {
-            outStream = new FileOutputStream( file );
-
             properties.store( outStream, "release configuration" );
         }
         catch ( IOException e )
@@ -314,11 +302,6 @@ public class PropertiesReleaseDescriptorStore
             throw new ReleaseDescriptorStoreException(
                 "Error writing properties file '" + file.getName() + "': " + e.getMessage(),
e );
         }
-        finally
-        {
-            IOUtil.close( outStream );
-        }
-
     }
 
     private void processResolvedDependencies( Properties prop, Map<?, ?> resolvedDependencies
)
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java
b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java
index aeb0a30..472d385 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java
@@ -31,7 +31,6 @@ import org.apache.maven.shared.release.ReleaseResult;
 import org.apache.maven.shared.release.env.ReleaseEnvironment;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.Commandline;
@@ -79,16 +78,11 @@ public class ForkedMavenExecutor
             {
                 settingsFile = File.createTempFile( "release-settings", ".xml" );
                 SettingsXpp3Writer writer = getSettingsWriter();
-                FileWriter fileWriter = null;
-                try
+                
+                try ( FileWriter fileWriter = new FileWriter( settingsFile ) )
                 {
-                    fileWriter = new FileWriter( settingsFile );
                     writer.write( fileWriter, encryptSettings( releaseEnvironment.getSettings()
) );
                 }
-                finally
-                {
-                    IOUtil.close( fileWriter );
-                }
             }
             catch ( IOException e )
             {
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java
b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java
index 8702b05..c0f9761 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java
@@ -43,7 +43,6 @@ import org.apache.maven.shared.release.ReleaseResult;
 import org.apache.maven.shared.release.env.ReleaseEnvironment;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 
 /**
@@ -390,16 +389,11 @@ public class InvokerMavenExecutor
             {
                 settingsFile = File.createTempFile( "release-settings", ".xml" );
                 SettingsXpp3Writer writer = getSettingsWriter();
-                FileWriter fileWriter = null;
-                try
+                
+                try ( FileWriter fileWriter = new FileWriter( settingsFile ) )
                 {
-                    fileWriter = new FileWriter( settingsFile );
                     writer.write( fileWriter, encryptSettings( releaseEnvironment.getSettings()
) );
                 }
-                finally
-                {
-                    IOUtil.close( fileWriter );
-                }
                 req.setUserSettingsFile( settingsFile );
             }
             catch ( IOException e )
@@ -486,86 +480,91 @@ public class InvokerMavenExecutor
             this.logger = logger;
         }
 
+        @Override
         public void debug( String message, Throwable error )
         {
             logger.debug( message, error );
         }
 
+        @Override
         public void debug( String message )
         {
             logger.debug( message );
         }
 
+        @Override
         public void error( String message, Throwable error )
         {
             logger.error( message, error );
         }
 
+        @Override
         public void error( String message )
         {
             logger.error( message );
         }
 
+        @Override
         public void fatalError( String message, Throwable error )
         {
             logger.fatalError( message, error );
         }
 
+        @Override
         public void fatalError( String message )
         {
             logger.fatalError( message );
         }
 
-        public Logger getChildLogger( String message )
-        {
-            return logger.getChildLogger( message );
-        }
-
-        public String getName()
-        {
-            return logger.getName();
-        }
-
+        @Override
         public int getThreshold()
         {
             return logger.getThreshold();
         }
 
+        @Override
         public void info( String message, Throwable error )
         {
             logger.info( message, error );
         }
 
+        @Override
         public void info( String message )
         {
             logger.info( message );
         }
 
+        @Override
         public boolean isDebugEnabled()
         {
             return logger.isDebugEnabled();
         }
 
+        @Override
         public boolean isErrorEnabled()
         {
             return logger.isErrorEnabled();
         }
 
+        @Override
         public boolean isFatalErrorEnabled()
         {
             return logger.isFatalErrorEnabled();
         }
 
+        @Override
         public boolean isInfoEnabled()
         {
             return logger.isInfoEnabled();
         }
 
+        @Override
         public boolean isWarnEnabled()
         {
             return logger.isWarnEnabled();
         }
 
+        @Override
         public void setThreshold( int level )
         {
             // NOTE:
@@ -573,16 +572,17 @@ public class InvokerMavenExecutor
             // is not supported in plexus-container-default:1.0-alpha-9 as used in Maven
2.x
         }
 
+        @Override
         public void warn( String message, Throwable error )
         {
             logger.warn( message, error );
         }
 
+        @Override
         public void warn( String message )
         {
             logger.warn( message );
         }
-
     }
 
 }
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java
b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java
index f05cb89..36fc403 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java
@@ -32,7 +32,6 @@ import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.ArtifactUtils;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.shared.release.ReleaseExecutionException;
 import org.apache.maven.shared.release.ReleaseFailureException;
@@ -73,12 +72,6 @@ public class CheckDependencySnapshotsPhase
     @Requirement
     private Prompter prompter;
 
-    /**
-     * Component used to create artifacts
-     */
-    @Requirement
-    private ArtifactFactory artifactFactory;
-
     // Be aware of the difference between usedSnapshots and specifiedSnapshots:
     // UsedSnapshots end up on the classpath.
     // SpecifiedSnapshots are defined anywhere in the pom.
@@ -121,7 +114,6 @@ public class CheckDependencySnapshotsPhase
                                ReleaseDescriptor releaseDescriptor )
         throws ReleaseFailureException, ReleaseExecutionException
     {
-        @SuppressWarnings( "unchecked" )
         Map<String, Artifact> artifactMap = ArtifactUtils.artifactMapByVersionlessId(
project.getArtifacts() );
 
         if ( project.getParentArtifact() != null )
@@ -137,16 +129,14 @@ public class CheckDependencySnapshotsPhase
 
         //@todo check dependencyManagement
 
-        @SuppressWarnings( "unchecked" )
         Set<Artifact> pluginArtifacts = project.getPluginArtifacts();
         checkPlugins( originalVersions, releaseDescriptor, artifactMap, pluginArtifacts );
+
         //@todo check pluginManagement
 
-        @SuppressWarnings( "unchecked" )
         Set<Artifact> reportArtifacts = project.getReportArtifacts();
         checkReports( originalVersions, releaseDescriptor, artifactMap, reportArtifacts );
 
-        @SuppressWarnings( "unchecked" )
         Set<Artifact> extensionArtifacts = project.getExtensionArtifacts();
         checkExtensions( originalVersions, releaseDescriptor, artifactMap, extensionArtifacts
);
 
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhase.java
b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhase.java
index 2768fda..0265dfe 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhase.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhase.java
@@ -64,7 +64,6 @@ import org.apache.maven.shared.release.scm.ScmTranslator;
 import org.apache.maven.shared.release.util.ReleaseUtil;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.WriterFactory;
 
 /**
@@ -164,22 +163,16 @@ public class GenerateReleasePomsPhase
             throw new ReleaseExecutionException( "Cannot generate release POM : pom file
is null" );
         }
 
-        Writer fileWriter = null;
+        
 
-        try
+        try ( Writer fileWriter = WriterFactory.newXmlWriter( releasePomFile ) ) 
         {
-            fileWriter = WriterFactory.newXmlWriter( releasePomFile );
-
             pomWriter.write( fileWriter, releasePom );
         }
         catch ( IOException exception )
         {
             throw new ReleaseExecutionException( "Cannot generate release POM", exception
);
         }
-        finally
-        {
-            IOUtil.close( fileWriter );
-        }
 
         return releasePomFile;
     }
@@ -501,7 +494,6 @@ public class GenerateReleasePomsPhase
                                                         Map<String, String> mappedVersions,
MavenProject project )
         throws ReleaseFailureException
     {
-        @SuppressWarnings( "unchecked" )
         Set<Artifact> artifacts = project.getArtifacts();
 
         List<Dependency> releaseDependencies = null;
@@ -584,7 +576,6 @@ public class GenerateReleasePomsPhase
 
             if ( plugins != null )
             {
-                @SuppressWarnings( "unchecked" )
                 Map<String, Artifact> artifactsById = project.getPluginArtifactMap();
 
                 releasePlugins = new ArrayList<>();
@@ -631,7 +622,6 @@ public class GenerateReleasePomsPhase
 
             if ( reportPlugins != null )
             {
-                @SuppressWarnings( "unchecked" )
                 Map<String, Artifact> artifactsById = project.getReportArtifactMap();
 
                 releaseReportPlugins = new ArrayList<>();
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomModelETL.java
b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomModelETL.java
index d7beb7b..a40d03d 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomModelETL.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomModelETL.java
@@ -34,7 +34,6 @@ import org.apache.maven.shared.release.ReleaseExecutionException;
 import org.apache.maven.shared.release.config.ReleaseDescriptor;
 import org.apache.maven.shared.release.transform.ModelETL;
 import org.apache.maven.shared.release.util.ReleaseUtil;
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.WriterFactory;
 import org.jdom.CDATA;
 import org.jdom.Comment;
@@ -212,11 +211,9 @@ public class JDomModelETL implements ModelETL
             }
         }
 
-        Writer writer = null;
-        try
+        
+        try ( Writer writer = WriterFactory.newXmlWriter( pomFile ) )
         {
-            writer = WriterFactory.newXmlWriter( pomFile );
-
             if ( intro != null )
             {
                 writer.write( intro );
@@ -236,10 +233,6 @@ public class JDomModelETL implements ModelETL
         {
             throw new ReleaseExecutionException( "Error writing POM: " + e.getMessage(),
e );
         }
-        finally
-        {
-            IOUtil.close( writer );
-        }
     }
 
 }
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/PomFinder.java
b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/PomFinder.java
index 2cef8cd..a4bd633 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/PomFinder.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/PomFinder.java
@@ -26,7 +26,6 @@ import org.apache.maven.model.Model;
 import org.apache.maven.model.Parent;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.xml.XmlStreamReader;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -189,17 +188,13 @@ public class PomFinder
         PomInfo pomInfo = null;
 
         MavenXpp3Reader reader = new MavenXpp3Reader();
-        XmlStreamReader xmlReader = null;
+        
         Model model = null;
-        try
+        try ( XmlStreamReader xmlReader = ReaderFactory.newXmlReader( pomFile ) )
         {
-            xmlReader = ReaderFactory.newXmlReader( pomFile );
             model = reader.read( xmlReader );
         }
-        finally
-        {
-            IOUtil.close( xmlReader );
-        }
+
         if ( model != null )
         {
             pomInfo = new PomInfo();
@@ -240,41 +235,21 @@ public class PomFinder
             this.fileName = fileName;
         }
 
-        public String getArtifactId()
-        {
-            return artifactId;
-        }
-
         public void setArtifactId( String artifactId )
         {
             this.artifactId = artifactId;
         }
 
-        public String getGroupId()
-        {
-            return groupId;
-        }
-
         public void setGroupId( String groupId )
         {
             this.groupId = groupId;
         }
 
-        public String getParentArtifactId()
-        {
-            return parentArtifactId;
-        }
-
         public void setParentArtifactId( String parentArtifactId )
         {
             this.parentArtifactId = parentArtifactId;
         }
 
-        public String getParentGroupId()
-        {
-            return parentGroupId;
-        }
-
         public void setParentGroupId( String parentGroupId )
         {
             this.parentGroupId = parentGroupId;
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/ReleaseUtil.java
b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/ReleaseUtil.java
index 42ffe63..ea76dba 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/ReleaseUtil.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/ReleaseUtil.java
@@ -141,16 +141,10 @@ public class ReleaseUtil
     public static String readXmlFile( File file, String ls )
         throws IOException
     {
-        Reader reader = null;
-        try
+        try ( Reader reader = ReaderFactory.newXmlReader( file ) )
         {
-            reader = ReaderFactory.newXmlReader( file );
             return normalizeLineEndings( IOUtil.toString( reader ), ls );
         }
-        finally
-        {
-            IOUtil.close( reader );
-        }
     }
 
     /**
diff --git a/maven-release-manager/src/main/mdo/release-descriptor.mdo b/maven-release-manager/src/main/mdo/release-descriptor.mdo
index acaaeef..3c5304b 100644
--- a/maven-release-manager/src/main/mdo/release-descriptor.mdo
+++ b/maven-release-manager/src/main/mdo/release-descriptor.mdo
@@ -539,7 +539,7 @@
     {
         if ( resolvedSnapshotDependencies == null )
         {
-            resolvedSnapshotDependencies = new java.util.HashMap();
+            resolvedSnapshotDependencies = new java.util.HashMap<>();
         }
         else
         {

-- 
To stop receiving notification emails like this one, please contact
['"commits@maven.apache.org" <commits@maven.apache.org>'].

Mime
View raw message