[
https://issues.apache.org/jira/browse/MWRAPPER-68?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17555149#comment-17555149
]
ASF GitHub Bot commented on MWRAPPER-68:
----------------------------------------
jorsol commented on code in PR #51:
URL: https://github.com/apache/maven-wrapper/pull/51#discussion_r899185055
##########
maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java:
##########
@@ -105,6 +111,27 @@ private URI prepareDistributionUri()
}
else
{
+ String mvnwRepoUrl = getEnv( MVNW_REPOURL );
+ if ( mvnwRepoUrl != null && !mvnwRepoUrl.isEmpty() )
+ {
+ Logger.info( "Detected MVNW_REPOURL environment variable " +
mvnwRepoUrl );
+ if ( mvnwRepoUrl.endsWith( "/" ) )
+ {
+ mvnwRepoUrl = mvnwRepoUrl.substring( 0,
mvnwRepoUrl.length() - 1 );
+ }
+ String distributionPath = source.getPath();
+ int index = distributionPath.indexOf( "org/apache/maven" );
+ if ( index > 0 )
+ {
+ distributionPath = "/" + distributionPath.substring( index
);
+ }
+ else
+ {
+ Logger.info( "distributionUrl don't contain package name "
+ mvnwRepoUrl );
Review Comment:
So, now it allows that the distributionUrl might be a random url and not a
repo style url?
##########
maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java:
##########
@@ -93,6 +95,10 @@ public static WrapperExecutor forWrapperPropertiesFile( Path
propertiesFile )
}
}
}
+ protected String getEnv( String key )
Review Comment:
Insert a new line between the previous method.
##########
maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java:
##########
@@ -105,6 +111,27 @@ private URI prepareDistributionUri()
}
else
{
+ String mvnwRepoUrl = getEnv( MVNW_REPOURL );
+ if ( mvnwRepoUrl != null && !mvnwRepoUrl.isEmpty() )
+ {
+ Logger.info( "Detected MVNW_REPOURL environment variable " +
mvnwRepoUrl );
+ if ( mvnwRepoUrl.endsWith( "/" ) )
+ {
+ mvnwRepoUrl = mvnwRepoUrl.substring( 0,
mvnwRepoUrl.length() - 1 );
+ }
+ String distributionPath = source.getPath();
+ int index = distributionPath.indexOf( "org/apache/maven" );
+ if ( index > 0 )
+ {
+ distributionPath = "/" + distributionPath.substring( index
);
+ }
+ else
+ {
+ Logger.info( "distributionUrl don't contain package name "
+ mvnwRepoUrl );
+ }
+ return new URI( mvnwRepoUrl + "" + distributionPath );
Review Comment:
This looks odd, why add an empty string and not just `mvnwRepoUrl +
distributionPath`?
##########
maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java:
##########
@@ -105,6 +111,27 @@ private URI prepareDistributionUri()
}
else
{
+ String mvnwRepoUrl = getEnv( MVNW_REPOURL );
+ if ( mvnwRepoUrl != null && !mvnwRepoUrl.isEmpty() )
+ {
+ Logger.info( "Detected MVNW_REPOURL environment variable " +
mvnwRepoUrl );
+ if ( mvnwRepoUrl.endsWith( "/" ) )
+ {
+ mvnwRepoUrl = mvnwRepoUrl.substring( 0,
mvnwRepoUrl.length() - 1 );
+ }
+ String distributionPath = source.getPath();
+ int index = distributionPath.indexOf( "org/apache/maven" );
+ if ( index > 0 )
Review Comment:
Small optimization: index > 1
##########
maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java:
##########
@@ -105,6 +111,27 @@ private URI prepareDistributionUri()
}
else
{
+ String mvnwRepoUrl = getEnv( MVNW_REPOURL );
+ if ( mvnwRepoUrl != null && !mvnwRepoUrl.isEmpty() )
+ {
+ Logger.info( "Detected MVNW_REPOURL environment variable " +
mvnwRepoUrl );
+ if ( mvnwRepoUrl.endsWith( "/" ) )
+ {
+ mvnwRepoUrl = mvnwRepoUrl.substring( 0,
mvnwRepoUrl.length() - 1 );
+ }
+ String distributionPath = source.getPath();
+ int index = distributionPath.indexOf( "org/apache/maven" );
+ if ( index > 0 )
+ {
+ distributionPath = "/" + distributionPath.substring( index
);
Review Comment:
Just to fool some static analyzers that thinks URI’s or path delimiters are
hard coded.
`"/".concat( distributionPath.substring( index ) );`
> MVNW_REPOURL improperly formed distributionUrl
> ----------------------------------------------
>
> Key: MWRAPPER-68
> URL: https://issues.apache.org/jira/browse/MWRAPPER-68
> Project: Maven Wrapper
> Issue Type: Bug
> Components: Maven Wrapper Jar
> Affects Versions: 3.1.1
> Reporter: HumanFund
> Priority: Major
>
> In Maven Wrapper v3.1.1, Installer::createDist(), file
> maven-wrapper/src/main/java/org/apache/maven/wrapper/Installer.java, was
> updated on line 74 to be:
> distributionUrl = new URI( mvnwRepoUrl ).resolve( "/" ).resolve( mvnPath );
> The above update is causing the distributionUrl to be improperly formed based
> on the MVNW_REPOURL environment variable and the mvnPath which is extracted
> from the distributionUrl in maven-wrapper.properties, specifically the
> substring starting with "org/apache/maven".
> The update was introduced in the following commit:
> [https://github.com/apache/maven-wrapper/commit/22a3268def96e5e648aa97a49d9e146e529b7c87#diff-193f3775e6efb0b6ed01219b21272f9eb3861965ce3af3586a0ce8eb153359c0]
> An example of the results are shown below. Note the "Downloading" URI does
> not include the entire repo url, only the scheme, host, and port, then the
> maven path is appended.
> The repo url is getting truncated by the call to resolve( "/" ) on line 74.
> I do not currently see a purpose for having this call in place. I made the
> following update to line 74 and it works fine:
> distributionUrl = new URI( mvnwRepoUrl ).resolve( mvnPath );
> Note that in Maven Wrapper v3.1.0, the distributionUrl was formed simply by
> appending the maven path to the MVNW_REPOURL:
> distributionUrl = new URI( mvnwRepoUrl + "/" + mvnPath );
> Example output demonstrating issue:
> [exec] [INFO] Apache Maven Wrapper 3.1.1
> [exec] [INFO] Detected MVNW_REPOURL environment variable
> [http://localhost:8081/repository/repo-maven-apache-org-maven2/]
> [exec] [INFO] Installing Maven distribution
> /home/myexamplehome/maven/wrapper/dists/apache-maven-3.6.3-bin/cf3cf814
> [exec] [INFO] Downloading
> [http://localhost:8081/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip]
>
>
--
This message was sent by Atlassian Jira
(v8.20.7#820007)