You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/09/22 07:08:17 UTC

[maven-verifier] branch cleanup created (now cc18602)

This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a change to branch cleanup
in repository https://gitbox.apache.org/repos/asf/maven-verifier.git


      at cc18602  Code cleanup

This branch includes the following new commits:

     new cc18602  Code cleanup

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-verifier] 01/01: Code cleanup

Posted by sj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch cleanup
in repository https://gitbox.apache.org/repos/asf/maven-verifier.git

commit cc1860281bb4125c2a4a761622b38e2015fe7214
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Thu Sep 22 09:07:38 2022 +0200

    Code cleanup
    
    - missing Deprecated annotations
    - use diamond operator
    - remove unused fields
---
 .../maven/shared/verifier/Embedded3xLauncher.java  |  9 ++---
 .../maven/shared/verifier/ForkedLauncher.java      |  2 +-
 .../org/apache/maven/shared/verifier/Verifier.java | 42 ++++++++++------------
 3 files changed, 24 insertions(+), 29 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/verifier/Embedded3xLauncher.java b/src/main/java/org/apache/maven/shared/verifier/Embedded3xLauncher.java
index c5f5d7b..8042d5f 100644
--- a/src/main/java/org/apache/maven/shared/verifier/Embedded3xLauncher.java
+++ b/src/main/java/org/apache/maven/shared/verifier/Embedded3xLauncher.java
@@ -21,7 +21,6 @@ package org.apache.maven.shared.verifier;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
@@ -31,6 +30,7 @@ import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
@@ -149,7 +149,7 @@ class Embedded3xLauncher
 
         if ( urls == null )
         {
-            urls = new ArrayList<URL>();
+            urls = new ArrayList<>();
 
             File bootDir = new File( mavenHome, "boot" );
             addUrls( urls, bootDir );
@@ -160,7 +160,7 @@ class Embedded3xLauncher
             throw new IllegalArgumentException( "Invalid Maven home directory " + mavenHome );
         }
 
-        URL[] ucp = (URL[]) urls.toArray( new URL[urls.size()] );
+        URL[] ucp = urls.toArray( new URL[0] );
 
         return new URLClassLoader( ucp, ClassLoader.getSystemClassLoader().getParent() );
     }
@@ -193,7 +193,8 @@ class Embedded3xLauncher
     public int run( String[] cliArgs, Properties systemProperties, String workingDirectory, File logFile )
         throws IOException, LauncherException
     {
-        PrintStream out = ( logFile != null ) ? new PrintStream( new FileOutputStream( logFile ) ) : System.out;
+        PrintStream out = ( logFile != null )
+            ? new PrintStream( Files.newOutputStream( logFile.toPath() ) ) : System.out;
         try
         {
             File workingDirectoryPath = new File( workingDirectory );
diff --git a/src/main/java/org/apache/maven/shared/verifier/ForkedLauncher.java b/src/main/java/org/apache/maven/shared/verifier/ForkedLauncher.java
index 1da1ec3..911d2d5 100644
--- a/src/main/java/org/apache/maven/shared/verifier/ForkedLauncher.java
+++ b/src/main/java/org/apache/maven/shared/verifier/ForkedLauncher.java
@@ -55,7 +55,7 @@ class ForkedLauncher
 
     ForkedLauncher( String mavenHome )
     {
-        this( mavenHome, Collections.<String, String>emptyMap(), false );
+        this( mavenHome, Collections.emptyMap(), false );
     }
 
     ForkedLauncher( String mavenHome, Map<String, String> envVars, boolean debugJvm )
diff --git a/src/main/java/org/apache/maven/shared/verifier/Verifier.java b/src/main/java/org/apache/maven/shared/verifier/Verifier.java
index 018c4da..1fc0103 100644
--- a/src/main/java/org/apache/maven/shared/verifier/Verifier.java
+++ b/src/main/java/org/apache/maven/shared/verifier/Verifier.java
@@ -20,7 +20,6 @@ package org.apache.maven.shared.verifier;
  */
 
 import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -74,17 +73,13 @@ public class Verifier
 
     private final String basedir;
 
-    private final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-
-    private final ByteArrayOutputStream errStream = new ByteArrayOutputStream();
-
     private final String[] defaultCliArguments;
 
     private List<String> cliArguments = new ArrayList<>();
 
     private Properties systemProperties = new Properties();
 
-    private Map<String, String> environmentVariables = new HashMap<String, String>();
+    private Map<String, String> environmentVariables = new HashMap<>();
 
     private Properties verifierProperties = new Properties();
 
@@ -211,6 +206,7 @@ public class Verifier
     /**
      * @deprecated will be removed without replacement
      */
+    @Deprecated
     public void resetStreams()
     {
     }
@@ -219,6 +215,7 @@ public class Verifier
     /**
      * @deprecated will be removed without replacement
      */
+    @Deprecated
     public void displayStreamBuffers()
     {
     }
@@ -332,7 +329,7 @@ public class Verifier
     public List<String> loadLines( String filename, String encoding )
         throws IOException
     {
-        List<String> lines = new ArrayList<String>();
+        List<String> lines = new ArrayList<>();
 
         try ( BufferedReader reader = getReader( filename, encoding ) )
         {
@@ -355,7 +352,7 @@ public class Verifier
 
         if ( StringUtils.isNotEmpty( encoding ) )
         {
-            return new BufferedReader( new InputStreamReader( new FileInputStream( file ), encoding ) );
+            return new BufferedReader( new InputStreamReader( Files.newInputStream( file.toPath() ), encoding ) );
         }
         else
         {
@@ -372,7 +369,7 @@ public class Verifier
     public List<String> loadFile( File file, boolean hasCommand )
         throws VerificationException
     {
-        List<String> lines = new ArrayList<String>();
+        List<String> lines = new ArrayList<>();
 
         if ( file.exists() )
         {
@@ -391,10 +388,6 @@ public class Verifier
                     line = reader.readLine();
                 }
             }
-            catch ( FileNotFoundException e )
-            {
-                throw new VerificationException( e );
-            }
             catch ( IOException e )
             {
                 throw new VerificationException( e );
@@ -422,7 +415,7 @@ public class Verifier
             newLine += getArtifactPath( artifact );
             newLine += line.substring( index + 1 );
 
-            List<String> l = new ArrayList<String>();
+            List<String> l = new ArrayList<>();
             l.add( newLine );
 
             int endIndex = newLine.lastIndexOf( '/' );
@@ -565,7 +558,7 @@ public class Verifier
 
     public List<String> getArtifactFileNameList( String org, String name, String version, String ext )
     {
-        List<String> files = new ArrayList<String>();
+        List<String> files = new ArrayList<>();
         String artifactPath = getArtifactPath( org, name, version, ext );
         File dir = new File( artifactPath );
         files.add( artifactPath );
@@ -1157,6 +1150,7 @@ public class Verifier
      *   verifier.execute();
      * </pre>
      */
+    @Deprecated
     public void executeGoal( String goal, Map<String, String> envVars )
         throws VerificationException
     {
@@ -1174,6 +1168,7 @@ public class Verifier
      *   verifier.execute();
      * </pre>
      */
+    @Deprecated
     public void executeGoals( List<String> goals )
         throws VerificationException
     {
@@ -1208,6 +1203,7 @@ public class Verifier
      *   verifier.execute();
      * </pre>
      */
+    @Deprecated
     public void executeGoals( List<String> goals, Map<String, String> envVars )
         throws VerificationException
     {
@@ -1356,7 +1352,7 @@ public class Verifier
         {
             return null;
         }
-        ArrayList<URL> classpathUrls = new ArrayList<URL>();
+        ArrayList<URL> classpathUrls = new ArrayList<>();
         StringTokenizer st = new StringTokenizer( classpath, File.pathSeparator );
         while ( st.hasMoreTokens() )
         {
@@ -1377,13 +1373,9 @@ public class Verifier
     {
         try
         {
-            return getMavenLauncher( Collections.<String, String>emptyMap() ).getMavenVersion();
+            return getMavenLauncher( Collections.emptyMap() ).getMavenVersion();
         }
-        catch ( LauncherException e )
-        {
-            throw new VerificationException( e );
-        }
-        catch ( IOException e )
+        catch ( LauncherException | IOException e )
         {
             throw new VerificationException( e );
         }
@@ -1460,7 +1452,7 @@ public class Verifier
     {
         private String localRepository;
 
-        private StringBuffer currentBody = new StringBuffer();
+        private StringBuilder currentBody = new StringBuilder();
 
         public void parse( File file )
             throws VerificationException
@@ -1535,7 +1527,7 @@ public class Verifier
                 }
             }
 
-            currentBody = new StringBuffer();
+            currentBody = new StringBuilder();
         }
 
         private boolean notEmpty( String test )
@@ -1713,6 +1705,7 @@ public class Verifier
     /**
      * @deprecated will be removed without replacement
      */
+    @Deprecated
     public void setDebug( boolean debug )
     {
     }
@@ -1734,6 +1727,7 @@ public class Verifier
      *
      * @deprecated will be removed without replacement.
      */
+    @Deprecated
     public void setMavenDebug( boolean mavenDebug )
     {
         this.mavenDebug = mavenDebug;