Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
- missing Deprecated annotations
- use diamond operator
- remove unused fields
  • Loading branch information
slawekjaranowski committed Sep 22, 2022
1 parent 0cbeed0 commit b8474f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
Expand All @@ -31,6 +30,7 @@
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;
Expand Down Expand Up @@ -149,7 +149,7 @@ private static ClassLoader getBootLoader( String mavenHome, List<URL> classpath

if ( urls == null )
{
urls = new ArrayList<URL>();
urls = new ArrayList<>();

File bootDir = new File( mavenHome, "boot" );
addUrls( urls, bootDir );
Expand All @@ -160,7 +160,7 @@ private static ClassLoader getBootLoader( String mavenHome, List<URL> classpath
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() );
}
Expand Down Expand Up @@ -193,7 +193,8 @@ private static void addUrls( List<URL> urls, File directory )
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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
46 changes: 20 additions & 26 deletions src/main/java/org/apache/maven/shared/verifier/Verifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
*/

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -211,6 +206,7 @@ public void setLocalRepo( String localRepo )
/**
* @deprecated will be removed without replacement
*/
@Deprecated
public void resetStreams()
{
}
Expand All @@ -219,6 +215,7 @@ public void resetStreams()
/**
* @deprecated will be removed without replacement
*/
@Deprecated
public void displayStreamBuffers()
{
}
Expand Down Expand Up @@ -332,7 +329,7 @@ public Properties loadProperties( String filename )
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 ) )
{
Expand All @@ -355,11 +352,11 @@ private BufferedReader getReader( String filename, String encoding ) throws IOEx

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() );
}
}

Expand All @@ -372,7 +369,7 @@ public List<String> loadFile( String basedir, String filename, boolean hasComman
public List<String> loadFile( File file, boolean hasCommand )
throws VerificationException
{
List<String> lines = new ArrayList<String>();
List<String> lines = new ArrayList<>();

if ( file.exists() )
{
Expand All @@ -391,10 +388,6 @@ public List<String> loadFile( File file, boolean hasCommand )
line = reader.readLine();
}
}
catch ( FileNotFoundException e )
{
throw new VerificationException( e );
}
catch ( IOException e )
{
throw new VerificationException( e );
Expand Down Expand Up @@ -422,7 +415,7 @@ private List<String> replaceArtifacts( String line, boolean hasCommand )
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( '/' );
Expand Down Expand Up @@ -565,7 +558,7 @@ else if ( "default".equals( localRepoLayout ) )

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 );
Expand Down Expand Up @@ -1157,6 +1150,7 @@ public void executeGoal( String goal )
* verifier.execute();
* </pre>
*/
@Deprecated
public void executeGoal( String goal, Map<String, String> envVars )
throws VerificationException
{
Expand All @@ -1174,6 +1168,7 @@ public void executeGoal( String goal, Map<String, String> envVars )
* verifier.execute();
* </pre>
*/
@Deprecated
public void executeGoals( List<String> goals )
throws VerificationException
{
Expand Down Expand Up @@ -1208,6 +1203,7 @@ public String getExecutable()
* verifier.execute();
* </pre>
*/
@Deprecated
public void executeGoals( List<String> goals, Map<String, String> envVars )
throws VerificationException
{
Expand Down Expand Up @@ -1356,7 +1352,7 @@ private static List<URL> parseClasspath( String classpath )
{
return null;
}
ArrayList<URL> classpathUrls = new ArrayList<URL>();
ArrayList<URL> classpathUrls = new ArrayList<>();
StringTokenizer st = new StringTokenizer( classpath, File.pathSeparator );
while ( st.hasMoreTokens() )
{
Expand All @@ -1377,13 +1373,9 @@ public String getMavenVersion()
{
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 );
}
Expand Down Expand Up @@ -1460,7 +1452,7 @@ static class UserModelReader
{
private String localRepository;

private StringBuffer currentBody = new StringBuffer();
private StringBuilder currentBody = new StringBuilder();

public void parse( File file )
throws VerificationException
Expand Down Expand Up @@ -1535,7 +1527,7 @@ public void endElement( String uri, String localName, String rawName )
}
}

currentBody = new StringBuffer();
currentBody = new StringBuilder();
}

private boolean notEmpty( String test )
Expand Down Expand Up @@ -1713,6 +1705,7 @@ public void setLogFileName( String logFileName )
/**
* @deprecated will be removed without replacement
*/
@Deprecated
public void setDebug( boolean debug )
{
}
Expand All @@ -1734,6 +1727,7 @@ public boolean isMavenDebug()
*
* @deprecated will be removed without replacement.
*/
@Deprecated
public void setMavenDebug( boolean mavenDebug )
{
this.mavenDebug = mavenDebug;
Expand Down

0 comments on commit b8474f0

Please sign in to comment.