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 13:53:43 UTC
[maven-verifier] branch master updated: Code cleanup
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-verifier.git
The following commit(s) were added to refs/heads/master by this push:
new b8474f0 Code cleanup
b8474f0 is described below
commit b8474f06cf4276e57b61aaa55f4280cbc3bf69c3
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 | 46 ++++++++++------------
3 files changed, 26 insertions(+), 31 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..02035bd 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;
@@ -28,9 +27,9 @@ import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
+import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -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,11 +352,11 @@ public class Verifier
if ( StringUtils.isNotEmpty( encoding ) )
{
- return new BufferedReader( new InputStreamReader( new FileInputStream( file ), encoding ) );
+ return Files.newBufferedReader( file.toPath(), Charset.forName( encoding ) );
}
else
{
- return new BufferedReader( new FileReader( file ) );
+ return Files.newBufferedReader( file.toPath() );
}
}
@@ -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;