You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2021/02/02 15:53:18 UTC
[maven-invoker] branch MSHARED-976 updated (21fca60 -> cad743f)
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a change to branch MSHARED-976
in repository https://gitbox.apache.org/repos/asf/maven-invoker.git.
from 21fca60 [MSHARED-976] Assume Maven 3.1.1/migrate from Plexus to JSR-330
add 38835b5 Bump maven-shared-utils from 3.2.1 to 3.3.3
new 14b1277 Adjust to catch new CommandLineException
new cad743f Misc code cleanup
The 2 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.
Summary of changes:
pom.xml | 2 +-
.../shared/invoker/DefaultInvocationRequest.java | 2 +-
.../maven/shared/invoker/DefaultInvoker.java | 2 +-
.../maven/shared/invoker/InvocationRequest.java | 2 +-
.../shared/invoker/MavenCommandLineBuilder.java | 66 +++++++++----------
.../maven/shared/invoker/PrintStreamLogger.java | 2 +-
.../maven/shared/invoker/DefaultInvokerTest.java | 15 ++---
.../invoker/MavenCommandLineBuilderTest.java | 77 +++++++++-------------
8 files changed, 74 insertions(+), 94 deletions(-)
[maven-invoker] 02/02: Misc code cleanup
Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch MSHARED-976
in repository https://gitbox.apache.org/repos/asf/maven-invoker.git
commit cad743f39ff38dbf89634402330b8d61dffe6690
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Tue Feb 2 16:51:18 2021 +0100
Misc code cleanup
---
.../shared/invoker/DefaultInvocationRequest.java | 2 +-
.../maven/shared/invoker/DefaultInvoker.java | 2 +-
.../maven/shared/invoker/InvocationRequest.java | 2 +-
.../shared/invoker/MavenCommandLineBuilder.java | 54 +++++++----------
.../maven/shared/invoker/PrintStreamLogger.java | 2 +-
.../maven/shared/invoker/DefaultInvokerTest.java | 15 +++--
.../invoker/MavenCommandLineBuilderTest.java | 69 +++++++++-------------
7 files changed, 60 insertions(+), 86 deletions(-)
diff --git a/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java b/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
index 0b71906..a389338 100644
--- a/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
+++ b/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
@@ -444,7 +444,7 @@ public class DefaultInvocationRequest
{
if ( this.shellEnvironments == null )
{
- this.shellEnvironments = new HashMap<String, String>();
+ this.shellEnvironments = new HashMap<>();
}
this.shellEnvironments.put( name, value );
return this;
diff --git a/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java b/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java
index be0f30c..0dd77da 100644
--- a/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java
+++ b/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java
@@ -125,7 +125,7 @@ public class DefaultInvoker
private int executeCommandLine( Commandline cli, InvocationRequest request, int timeoutInSeconds )
throws CommandLineException
{
- int result = Integer.MIN_VALUE;
+ int result;
InputStream inputStream = request.getInputStream( this.inputStream );
InvocationOutputHandler outputHandler = request.getOutputHandler( this.outputHandler );
diff --git a/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java b/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
index d867331..e4318ff 100644
--- a/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
+++ b/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
@@ -371,7 +371,7 @@ public interface InvocationRequest
throw new IllegalArgumentException( "The string '" + longOption
+ "' can not be converted to enumeration." );
}
- };
+ }
// ----------------------------------------------------------------------
// Artifact repository policies
diff --git a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
index 3e21919..65e1062 100644
--- a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
+++ b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
@@ -65,7 +65,7 @@ public class MavenCommandLineBuilder
{
throw new CommandLineConfigurationException( e.getMessage(), e );
}
- File mvn = null;
+ File mvn;
try
{
mvn = findMavenExecutable();
@@ -139,8 +139,7 @@ public class MavenCommandLineBuilder
{
try
{
- File canSet = userSettingsFile.getCanonicalFile();
- userSettingsFile = canSet;
+ userSettingsFile = userSettingsFile.getCanonicalFile();
}
catch ( IOException e )
{
@@ -158,8 +157,7 @@ public class MavenCommandLineBuilder
{
try
{
- File canSet = globalSettingsFile.getCanonicalFile();
- globalSettingsFile = canSet;
+ globalSettingsFile = globalSettingsFile.getCanonicalFile();
}
catch ( IOException e )
{
@@ -181,8 +179,7 @@ public class MavenCommandLineBuilder
{
try
{
- File canSet = toolchainsFile.getCanonicalFile();
- toolchainsFile = canSet;
+ toolchainsFile = toolchainsFile.getCanonicalFile();
}
catch ( IOException e )
{
@@ -208,21 +205,14 @@ public class MavenCommandLineBuilder
// proper value
cli.addEnvironment( "M2_HOME", getMavenHome().getAbsolutePath() );
}
+ catch ( RuntimeException e )
+ {
+ throw e;
+ }
catch ( Exception e )
{
- if ( e instanceof RuntimeException )
- {
- throw (RuntimeException) e;
- }
- else
- {
- IllegalStateException error =
- new IllegalStateException( "Unknown error retrieving shell environment variables. Reason: "
- + e.getMessage() );
- error.initCause( e );
-
- throw error;
- }
+ throw new IllegalStateException(
+ "Unknown error retrieving shell environment variables. Reason: " + e.getMessage(), e );
}
}
@@ -329,8 +319,7 @@ public class MavenCommandLineBuilder
{
try
{
- File canPom = pom.getCanonicalFile();
- pom = canPom;
+ pom = pom.getCanonicalFile();
}
catch ( IOException e )
{
@@ -339,8 +328,8 @@ public class MavenCommandLineBuilder
if ( !"pom.xml".equals( pom.getName() ) )
{
- logger.debug( "Specified POM file is not named \'pom.xml\'. "
- + "Using the \'-f\' command-line option to accommodate non-standard filename..." );
+ logger.debug( "Specified POM file is not named 'pom.xml'. "
+ + "Using the '-f' command-line option to accommodate non-standard filename..." );
cli.createArg().setValue( "-f" );
cli.createArg().setValue( pom.getName() );
@@ -395,8 +384,7 @@ public class MavenCommandLineBuilder
{
try
{
- File canLRD = localRepositoryDirectory.getCanonicalFile();
- localRepositoryDirectory = canLRD;
+ localRepositoryDirectory = localRepositoryDirectory.getCanonicalFile();
}
catch ( IOException e )
{
@@ -406,8 +394,8 @@ public class MavenCommandLineBuilder
if ( !localRepositoryDirectory.isDirectory() )
{
- throw new IllegalArgumentException( "Local repository location: \'" + localRepositoryDirectory
- + "\' is NOT a directory." );
+ throw new IllegalArgumentException( "Local repository location: '" + localRepositoryDirectory
+ + "' is NOT a directory." );
}
cli.createArg().setValue( "-D" );
@@ -546,8 +534,8 @@ public class MavenCommandLineBuilder
}
else
{
- throw new IllegalStateException( "${maven.home} is not specified as a directory: \'"
- + mavenHomeProperty + "\'." );
+ throw new IllegalStateException( "${maven.home} is not specified as a directory: '"
+ + mavenHomeProperty + "'." );
}
}
}
@@ -558,7 +546,7 @@ public class MavenCommandLineBuilder
}
}
- logger.debug( "Using ${maven.home} of: \'" + mavenHome + "\'." );
+ logger.debug( "Using ${maven.home} of: '" + mavenHome + "'." );
if ( mavenExecutable == null || !mavenExecutable.isAbsolute() )
{
@@ -587,8 +575,7 @@ public class MavenCommandLineBuilder
try
{
- File canonicalMvn = mavenExecutable.getCanonicalFile();
- mavenExecutable = canonicalMvn;
+ mavenExecutable = mavenExecutable.getCanonicalFile();
}
catch ( IOException e )
{
@@ -605,7 +592,6 @@ public class MavenCommandLineBuilder
}
private Properties getSystemEnvVars()
- throws IOException
{
if ( this.systemEnvVars == null )
{
diff --git a/src/main/java/org/apache/maven/shared/invoker/PrintStreamLogger.java b/src/main/java/org/apache/maven/shared/invoker/PrintStreamLogger.java
index 1de5898..55bdb36 100644
--- a/src/main/java/org/apache/maven/shared/invoker/PrintStreamLogger.java
+++ b/src/main/java/org/apache/maven/shared/invoker/PrintStreamLogger.java
@@ -87,7 +87,7 @@ public class PrintStreamLogger
return;
}
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
switch ( level )
{
diff --git a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
index 874f51d..6fe7c93 100644
--- a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
+++ b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
@@ -25,6 +25,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Properties;
import org.apache.maven.shared.utils.StringUtils;
@@ -113,7 +114,7 @@ public class DefaultInvokerTest
request.setBaseDirectory( basedir );
request.setPomFileName( "pom with spaces.xml" );
request.setDebug( true );
- request.setGoals( Arrays.asList( "clean" ) );
+ request.setGoals( Collections.singletonList( "clean" ) );
request.setProperties( getProperties() );
InvocationResult result = invoker.execute( request );
@@ -135,7 +136,7 @@ public class DefaultInvokerTest
request.setBaseDirectory( basedir );
request.setPomFileName( "pom with spaces & special char.xml" );
request.setDebug( true );
- request.setGoals( Arrays.asList( "clean" ) );
+ request.setGoals( Collections.singletonList( "clean" ) );
request.setProperties( getProperties() );
InvocationResult result = invoker.execute( request );
@@ -157,7 +158,7 @@ public class DefaultInvokerTest
request.setBaseDirectory( basedir );
request.setUserSettingsFile( new File( basedir, "settings with spaces.xml" ) );
request.setDebug( true );
- request.setGoals( Arrays.asList( "validate" ) );
+ request.setGoals( Collections.singletonList( "validate" ) );
request.setProperties( getProperties() );
InvocationResult result = invoker.execute( request );
@@ -179,7 +180,7 @@ public class DefaultInvokerTest
request.setBaseDirectory( basedir );
request.setLocalRepositoryDirectory( new File( basedir, "repo with spaces" ) );
request.setDebug( true );
- request.setGoals( Arrays.asList( "validate" ) );
+ request.setGoals( Collections.singletonList( "validate" ) );
request.setProperties( getProperties() );
InvocationResult result = invoker.execute( request );
@@ -205,7 +206,7 @@ public class DefaultInvokerTest
props.setProperty( "key with spaces", "value" );
request.setProperties( props );
request.setDebug( true );
- request.setGoals( Arrays.asList( "validate" ) );
+ request.setGoals( Collections.singletonList( "validate" ) );
InvocationResult result = invoker.execute( request );
@@ -213,7 +214,6 @@ public class DefaultInvokerTest
}
private Invoker newInvoker()
- throws IOException
{
Invoker invoker = new DefaultInvoker();
@@ -229,7 +229,6 @@ public class DefaultInvokerTest
}
private File findMavenHome()
- throws IOException
{
String mavenHome = System.getProperty( "maven.home" );
@@ -241,7 +240,7 @@ public class DefaultInvokerTest
if ( mavenHome == null )
{
throw new IllegalStateException( "Cannot find Maven application "
- + "directory. Either specify \'maven.home\' system property, or M2_HOME environment variable." );
+ + "directory. Either specify 'maven.home' system property, or M2_HOME environment variable." );
}
return new File( mavenHome );
diff --git a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
index e41d51d..bc3e229 100644
--- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
@@ -31,7 +31,6 @@ import java.util.Properties;
import java.util.Set;
import org.apache.maven.shared.utils.Os;
-import org.apache.maven.shared.utils.cli.CommandLineException;
import org.apache.maven.shared.utils.cli.Commandline;
import org.junit.After;
import org.junit.Assume;
@@ -72,7 +71,6 @@ public class MavenCommandLineBuilderTest
@After
public void tearDown()
- throws IOException
{
System.setProperties( sysProps );
}
@@ -80,7 +78,6 @@ public class MavenCommandLineBuilderTest
@Test
public void testShouldFailToSetLocalRepoLocationGloballyWhenItIsAFile()
- throws Exception
{
tcb.setLocalRepositoryDirectory( lrd );
@@ -97,7 +94,6 @@ public class MavenCommandLineBuilderTest
@Test
public void testShouldFailToSetLocalRepoLocationFromRequestWhenItIsAFile()
- throws IOException
{
try
{
@@ -201,7 +197,7 @@ public class MavenCommandLineBuilderTest
{
String mavenHome = System.getProperty( "maven.home" );
- File appDir = null;
+ File appDir;
if ( forceDummy || ( mavenHome == null ) || !new File( mavenHome ).exists() )
{
@@ -430,7 +426,7 @@ public class MavenCommandLineBuilderTest
tcb.setReactorBehavior( newRequest().setReactorFailureBehavior( InvocationRequest.ReactorFailureBehavior.FailFast ),
cli );
- Set<String> banned = new HashSet<String>();
+ Set<String> banned = new HashSet<>();
banned.add( "-fae" );
banned.add( "-fn" );
@@ -453,7 +449,7 @@ public class MavenCommandLineBuilderTest
assertEquals( projectDir.getCanonicalFile(), cli.getWorkingDirectory() );
- Set<String> args = new HashSet<String>();
+ Set<String> args = new HashSet<>();
args.add( "-f" );
args.add( "non-standard-pom.xml" );
@@ -476,7 +472,7 @@ public class MavenCommandLineBuilderTest
assertEquals( projectDir.getCanonicalFile(), cli.getWorkingDirectory() );
- Set<String> args = new HashSet<String>();
+ Set<String> args = new HashSet<>();
args.add( "-f" );
args.add( "non-standard-pom.xml" );
@@ -499,7 +495,7 @@ public class MavenCommandLineBuilderTest
assertEquals( projectDir.getCanonicalFile(), cli.getWorkingDirectory() );
- Set<String> args = new HashSet<String>();
+ Set<String> args = new HashSet<>();
args.add( "-f" );
args.add( "pom.xml" );
@@ -522,7 +518,7 @@ public class MavenCommandLineBuilderTest
assertEquals( projectDir.getCanonicalFile(), cli.getWorkingDirectory() );
- Set<String> args = new HashSet<String>();
+ Set<String> args = new HashSet<>();
args.add( "-f" );
args.add( "pom.xml" );
@@ -543,7 +539,7 @@ public class MavenCommandLineBuilderTest
assertEquals( projectDir.getCanonicalFile(), cli.getWorkingDirectory() );
- Set<String> args = new HashSet<String>();
+ Set<String> args = new HashSet<>();
args.add( "-f" );
args.add( "pom.xml" );
@@ -564,7 +560,7 @@ public class MavenCommandLineBuilderTest
assertEquals( projectDir.getCanonicalFile(), cli.getWorkingDirectory() );
- Set<String> args = new HashSet<String>();
+ Set<String> args = new HashSet<>();
args.add( "-f" );
args.add( "non-standard-pom.xml" );
@@ -582,7 +578,7 @@ public class MavenCommandLineBuilderTest
tcb.setSettingsLocation( newRequest().setUserSettingsFile( settingsFile ), cli );
- Set<String> args = new HashSet<String>();
+ Set<String> args = new HashSet<>();
args.add( "-s" );
args.add( settingsFile.getCanonicalPath() );
@@ -600,7 +596,7 @@ public class MavenCommandLineBuilderTest
tcb.setSettingsLocation( newRequest().setGlobalSettingsFile( settingsFile ), cli );
- Set<String> args = new HashSet<String>();
+ Set<String> args = new HashSet<>();
args.add( "-gs" );
args.add( settingsFile.getCanonicalPath() );
@@ -618,7 +614,7 @@ public class MavenCommandLineBuilderTest
tcb.setToolchainsLocation( newRequest().setToolchainsFile( toolchainsFile ), cli );
- Set<String> args = new HashSet<String>();
+ Set<String> args = new HashSet<>();
args.add( "-t" );
args.add( toolchainsFile.getCanonicalPath() );
@@ -627,7 +623,6 @@ public class MavenCommandLineBuilderTest
@Test
public void testShouldSpecifyCustomPropertyFromRequest()
- throws IOException
{
Properties properties = new Properties();
@@ -640,7 +635,6 @@ public class MavenCommandLineBuilderTest
@Test
public void testShouldSpecifyCustomPropertyWithSpacesInValueFromRequest()
- throws IOException
{
Properties properties = new Properties();
@@ -653,7 +647,6 @@ public class MavenCommandLineBuilderTest
@Test
public void testShouldSpecifyCustomPropertyWithSpacesInKeyFromRequest()
- throws IOException
{
Properties properties = new Properties();
@@ -668,7 +661,7 @@ public class MavenCommandLineBuilderTest
public void testShouldSpecifySingleGoalFromRequest() throws CommandLineConfigurationException
{
- List<String> goals = new ArrayList<String>();
+ List<String> goals = new ArrayList<>();
goals.add( "test" );
tcb.setGoals( newRequest().setGoals( goals ), cli );
@@ -679,19 +672,18 @@ public class MavenCommandLineBuilderTest
@Test
public void testShouldSpecifyTwoGoalsFromRequest() throws CommandLineConfigurationException
{
- List<String> goals = new ArrayList<String>();
+ List<String> goals = new ArrayList<>();
goals.add( "test" );
goals.add( "clean" );
tcb.setGoals( newRequest().setGoals( goals ), cli );
- assertArgumentsPresent( cli, new HashSet<String>( goals ) );
+ assertArgumentsPresent( cli, new HashSet<>( goals ) );
assertArgumentsPresentInOrder( cli, goals );
}
@Test
public void testShouldSpecifyThreadsFromRequest()
- throws IOException
{
tcb.setThreads( newRequest().setThreads( "2.0C" ), cli );
@@ -710,8 +702,8 @@ public class MavenCommandLineBuilderTest
request.setBaseDirectory( projectDir );
- Set<String> expectedArgs = new HashSet<String>();
- Set<String> bannedArgs = new HashSet<String>();
+ Set<String> expectedArgs = new HashSet<>();
+ Set<String> bannedArgs = new HashSet<>();
createDummyFile( projectDir, "pom.xml" );
@@ -730,7 +722,7 @@ public class MavenCommandLineBuilderTest
expectedArgs.add( "-o" );
- List<String> goals = new ArrayList<String>();
+ List<String> goals = new ArrayList<>();
goals.add( "post-clean" );
goals.add( "deploy" );
@@ -748,7 +740,7 @@ public class MavenCommandLineBuilderTest
String executable = commandline.getExecutable();
- assertTrue( executable.indexOf( new File( mavenDir, "bin/mvn" ).getCanonicalPath() ) > -1 );
+ assertTrue( executable.contains( new File( mavenDir, "bin/mvn" ).getCanonicalPath() ) );
assertEquals( projectDir.getCanonicalPath(), commandline.getWorkingDirectory().getCanonicalPath() );
}
@@ -766,7 +758,7 @@ public class MavenCommandLineBuilderTest
createDummyFile( projectDir, "pom.xml" );
- List<String> goals = new ArrayList<String>();
+ List<String> goals = new ArrayList<>();
goals.add( "clean" );
request.setGoals( goals );
@@ -777,9 +769,8 @@ public class MavenCommandLineBuilderTest
String[] environmentVariables = commandline.getEnvironmentVariables();
String envVarMavenTerminateCmd = null;
- for ( int i = 0; i < environmentVariables.length; i++ )
+ for ( String envVar : environmentVariables )
{
- String envVar = environmentVariables[i];
if ( envVar.startsWith( "MAVEN_TERMINATE_CMD=" ) )
{
envVarMavenTerminateCmd = envVar;
@@ -801,7 +792,7 @@ public class MavenCommandLineBuilderTest
InvocationRequest request = newRequest();
- List<String> profiles = new ArrayList<String>();
+ List<String> profiles = new ArrayList<>();
profiles.add( profile1 );
profiles.add( profile2 );
@@ -830,7 +821,7 @@ public class MavenCommandLineBuilderTest
createDummyFile( projectDir, "pom.xml" );
- List<String> goals = new ArrayList<String>();
+ List<String> goals = new ArrayList<>();
goals.add( "clean" );
request.setGoals( goals );
@@ -843,9 +834,8 @@ public class MavenCommandLineBuilderTest
String[] environmentVariables = commandline.getEnvironmentVariables();
String m2Home = null;
- for ( int i = 0; i < environmentVariables.length; i++ )
+ for ( String envVar : environmentVariables )
{
- String envVar = environmentVariables[i];
if ( envVar.startsWith( "M2_HOME=" ) )
{
m2Home = envVar;
@@ -894,13 +884,12 @@ public class MavenCommandLineBuilderTest
}
private void assertEnvironmentVariablePresent( Commandline cli, String varName, String varValue )
- throws CommandLineException
{
List<String> environmentVariables = Arrays.asList( cli.getEnvironmentVariables() );
String expectedDeclaration = varName + "=" + varValue;
- assertTrue( "Environment variable setting: \'" + expectedDeclaration + "\' is mssing in "
+ assertTrue( "Environment variable setting: '" + expectedDeclaration + "' is mssing in "
+ environmentVariables, environmentVariables.contains( expectedDeclaration ) );
}
@@ -915,9 +904,9 @@ public class MavenCommandLineBuilderTest
int expectedCounter = 0;
- for ( int i = 0; i < arguments.length; i++ )
+ for ( String argument : arguments )
{
- if ( arguments[i].equals( expected.get( expectedCounter ) ) )
+ if ( argument.equals( expected.get( expectedCounter ) ) )
{
expectedCounter++;
}
@@ -934,7 +923,7 @@ public class MavenCommandLineBuilderTest
for ( String arg : requiredArgs )
{
- assertTrue( "Command-line argument: \'" + arg + "\' is missing in " + args, args.contains( arg ) );
+ assertTrue( "Command-line argument: '" + arg + "' is missing in " + args, args.contains( arg ) );
}
}
@@ -945,7 +934,7 @@ public class MavenCommandLineBuilderTest
for ( String arg : bannedArgs )
{
- assertFalse( "Command-line argument: \'" + arg + "\' should not be present.", args.contains( arg ) );
+ assertFalse( "Command-line argument: '" + arg + "' should not be present.", args.contains( arg ) );
}
}
@@ -954,7 +943,7 @@ public class MavenCommandLineBuilderTest
{
File dummyFile = new File( directory, filename );
- try ( FileWriter writer = new FileWriter( dummyFile ); )
+ try ( FileWriter writer = new FileWriter( dummyFile ) )
{
writer.write( "This is a dummy file." );
}
[maven-invoker] 01/02: Adjust to catch new CommandLineException
Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch MSHARED-976
in repository https://gitbox.apache.org/repos/asf/maven-invoker.git
commit 14b12776ee1487cb2215686e826133bf1d431a66
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Tue Feb 2 16:43:09 2021 +0100
Adjust to catch new CommandLineException
---
.../apache/maven/shared/invoker/MavenCommandLineBuilder.java | 12 ++++++++++--
.../maven/shared/invoker/MavenCommandLineBuilderTest.java | 8 +++-----
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
index 57021a0..3e21919 100644
--- a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
+++ b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
@@ -30,6 +30,7 @@ import org.apache.maven.shared.invoker.InvocationRequest.CheckSumPolicy;
import org.apache.maven.shared.invoker.InvocationRequest.ReactorFailureBehavior;
import org.apache.maven.shared.utils.Os;
import org.apache.maven.shared.utils.StringUtils;
+import org.apache.maven.shared.utils.cli.CommandLineException;
import org.apache.maven.shared.utils.cli.CommandLineUtils;
import org.apache.maven.shared.utils.cli.Commandline;
@@ -253,13 +254,20 @@ public class MavenCommandLineBuilder
}
- protected void setGoals( InvocationRequest request, Commandline cli )
+ protected void setGoals( InvocationRequest request, Commandline cli ) throws CommandLineConfigurationException
{
List<String> goals = request.getGoals();
if ( ( goals != null ) && !goals.isEmpty() )
{
- cli.createArg().setLine( StringUtils.join( goals.iterator(), " " ) );
+ try
+ {
+ cli.createArg().setLine( StringUtils.join( goals.iterator(), " " ) );
+ }
+ catch ( CommandLineException e )
+ {
+ throw new CommandLineConfigurationException( "Problem to set goals: " + e.getMessage(), e );
+ }
}
}
diff --git a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
index f9e29bb..e41d51d 100644
--- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
@@ -665,8 +665,7 @@ public class MavenCommandLineBuilderTest
}
@Test
- public void testShouldSpecifySingleGoalFromRequest()
- throws IOException
+ public void testShouldSpecifySingleGoalFromRequest() throws CommandLineConfigurationException
{
List<String> goals = new ArrayList<String>();
@@ -678,8 +677,7 @@ public class MavenCommandLineBuilderTest
}
@Test
- public void testShouldSpecifyTwoGoalsFromRequest()
- throws IOException
+ public void testShouldSpecifyTwoGoalsFromRequest() throws CommandLineConfigurationException
{
List<String> goals = new ArrayList<String>();
goals.add( "test" );
@@ -989,7 +987,7 @@ public class MavenCommandLineBuilderTest
super.setFlags( request, cli );
}
- public void setGoals( InvocationRequest request, Commandline cli )
+ public void setGoals( InvocationRequest request, Commandline cli ) throws CommandLineConfigurationException
{
super.setGoals( request, cli );
}