New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MSHARED-1007] Add MavenHome and MavenExecutable options to InvocationRequest #34
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,26 +64,22 @@ public class MavenCommandLineBuilder | |
public Commandline build( InvocationRequest request ) | ||
throws CommandLineConfigurationException | ||
{ | ||
|
||
setupMavenHome( request ); | ||
checkRequiredState(); | ||
|
||
try | ||
{ | ||
checkRequiredState(); | ||
} | ||
catch ( IOException e ) | ||
{ | ||
throw new CommandLineConfigurationException( e.getMessage(), e ); | ||
} | ||
File mvn; | ||
try | ||
{ | ||
mvn = findMavenExecutable(); | ||
setupMavenExecutable( request ); | ||
} | ||
catch ( IOException e ) | ||
{ | ||
throw new CommandLineConfigurationException( e.getMessage(), e ); | ||
} | ||
|
||
Commandline cli = new Commandline(); | ||
|
||
cli.setExecutable( mvn.getAbsolutePath() ); | ||
cli.setExecutable( mavenExecutable.getAbsolutePath() ); | ||
|
||
// handling for OS-level envars | ||
setShellEnvironment( request, cli ); | ||
|
@@ -119,28 +115,13 @@ public Commandline build( InvocationRequest request ) | |
|
||
/** | ||
* <p>checkRequiredState.</p> | ||
* | ||
* @throws java.io.IOException if any. | ||
*/ | ||
protected void checkRequiredState() | ||
throws IOException | ||
{ | ||
if ( logger == null ) | ||
{ | ||
throw new IllegalStateException( "A logger instance is required." ); | ||
} | ||
|
||
if ( ( mavenHome == null ) && ( System.getProperty( "maven.home" ) == null ) ) | ||
// can be restored with 1.5 | ||
// && ( System.getenv( "M2_HOME" ) != null ) ) | ||
{ | ||
if ( !getSystemEnvVars().containsKey( "M2_HOME" ) ) | ||
{ | ||
throw new IllegalStateException( "Maven application directory was not " | ||
+ "specified, and ${maven.home} is not provided in the system " | ||
+ "properties. Specify at least one of these." ); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -221,10 +202,8 @@ protected void setToolchainsLocation( InvocationRequest request, Commandline cli | |
* | ||
* @param request a {@link org.apache.maven.shared.invoker.InvocationRequest} object. | ||
* @param cli a {@link org.apache.maven.shared.utils.cli.Commandline} object. | ||
* @throws org.apache.maven.shared.invoker.CommandLineConfigurationException if any. | ||
*/ | ||
protected void setShellEnvironment( InvocationRequest request, Commandline cli ) | ||
throws CommandLineConfigurationException | ||
{ | ||
if ( request.isShellEnvironmentInherited() ) | ||
{ | ||
|
@@ -599,46 +578,61 @@ protected void setThreads( InvocationRequest request, Commandline cli ) | |
|
||
} | ||
|
||
/** | ||
* <p>findMavenExecutable.</p> | ||
* | ||
* @return a {@link java.io.File} object. | ||
* @throws org.apache.maven.shared.invoker.CommandLineConfigurationException if any. | ||
* @throws java.io.IOException if any. | ||
*/ | ||
protected File findMavenExecutable() | ||
throws CommandLineConfigurationException, IOException | ||
void setupMavenHome( InvocationRequest request ) | ||
{ | ||
if ( request.getMavenHome() != null ) | ||
{ | ||
mavenHome = request.getMavenHome(); | ||
} | ||
|
||
if ( mavenHome == null ) | ||
{ | ||
String mavenHomeProperty = System.getProperty( "maven.home" ); | ||
if ( mavenHomeProperty == null && getSystemEnvVars().getProperty( "M2_HOME" ) != null ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop this. |
||
{ | ||
mavenHomeProperty = getSystemEnvVars().getProperty( "M2_HOME" ); | ||
} | ||
|
||
if ( mavenHomeProperty != null ) | ||
{ | ||
mavenHome = new File( mavenHomeProperty ); | ||
if ( !mavenHome.isDirectory() ) | ||
{ | ||
File binDir = mavenHome.getParentFile(); | ||
if ( binDir != null && "bin".equals( binDir.getName() ) ) | ||
{ | ||
// ah, they specified the mvn | ||
// executable instead... | ||
mavenHome = binDir.getParentFile(); | ||
} | ||
else | ||
{ | ||
throw new IllegalStateException( "${maven.home} is not specified as a directory: '" | ||
+ mavenHomeProperty + "'." ); | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ( ( mavenHome == null ) && ( getSystemEnvVars().getProperty( "M2_HOME" ) != null ) ) | ||
if ( mavenHome != null && !mavenHome.isDirectory() ) | ||
michael-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
File binDir = mavenHome.getParentFile(); | ||
if ( binDir != null && "bin".equals( binDir.getName() ) ) | ||
{ | ||
mavenHome = new File( getSystemEnvVars().getProperty( "M2_HOME" ) ); | ||
// ah, they specified the mvn | ||
// executable instead... | ||
mavenHome = binDir.getParentFile(); | ||
} | ||
} | ||
|
||
logger.debug( "Using ${maven.home} of: '" + mavenHome + "'." ); | ||
if ( mavenHome != null && !mavenHome.isDirectory() ) | ||
{ | ||
throw new IllegalStateException( "maven home is not specified as a directory: '" + mavenHome + "'." ); | ||
} | ||
|
||
logger.debug( "Using maven.home of: '" + mavenHome + "'." ); | ||
} | ||
|
||
|
||
/** | ||
* <p>setupMavenExecutable.</p> | ||
* | ||
* @param request a Invoker request | ||
* @throws org.apache.maven.shared.invoker.CommandLineConfigurationException if any. | ||
* @throws java.io.IOException if any. | ||
*/ | ||
protected void setupMavenExecutable( InvocationRequest request ) | ||
throws CommandLineConfigurationException, IOException | ||
{ | ||
if ( request.getMavenExecutable() != null ) | ||
{ | ||
mavenExecutable = request.getMavenExecutable(); | ||
} | ||
|
||
if ( mavenExecutable == null || !mavenExecutable.isAbsolute() ) | ||
{ | ||
|
@@ -679,8 +673,6 @@ else if ( Os.isFamily( "windows" ) ) | |
throw new CommandLineConfigurationException( "Maven executable not found at: " + mavenExecutable ); | ||
} | ||
} | ||
|
||
return mavenExecutable; | ||
} | ||
|
||
private Properties getSystemEnvVars() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
M2_HOME
variable is long dead. Don't use it.