Skip to content

Commit 36886fa

Browse files
Support for snapshot distributions - fix (#352)
* Support for snapshot distributions - fix - fix detecting Maven distribution in script - fix in IT - use time based snapshot in mock repo - check in IT proper result code of Maven executable - set distributionUrl in setup invoker task, as test.properties is not filtered
1 parent d02d845 commit 36886fa

File tree

10 files changed

+112
-25
lines changed

10 files changed

+112
-25
lines changed

maven-wrapper-distribution/src/resources/only-mvnw

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ fi
268268

269269
# If not found, search for any directory with the Maven executable (for snapshots)
270270
if [ -z "$actualDistributionDir" ]; then
271+
# enable globbing to iterate over items
272+
set +f
271273
for dir in "$TMP_DOWNLOAD_DIR"/*; do
272274
if [ -d "$dir" ]; then
273275
if [ -f "$dir/bin/$MVN_CMD" ]; then
@@ -276,9 +278,12 @@ if [ -z "$actualDistributionDir" ]; then
276278
fi
277279
fi
278280
done
281+
set -f
279282
fi
280283

281284
if [ -z "$actualDistributionDir" ]; then
285+
verbose "Contents of $TMP_DOWNLOAD_DIR:"
286+
verbose "$(ls -la "$TMP_DOWNLOAD_DIR")"
282287
die "Could not find Maven distribution directory in extracted archive"
283288
fi
284289

maven-wrapper-plugin/pom.xml

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ under the License.
174174
</extraArtifacts>
175175
<scriptVariables>
176176
<wrapperCurrentVersion>${project.version}</wrapperCurrentVersion>
177+
<mrmRepositoryUrl>${mrm.repository.url}</mrmRepositoryUrl>
177178
</scriptVariables>
178179
</configuration>
179180
<executions>
@@ -188,33 +189,16 @@ under the License.
188189
</executions>
189190
</plugin>
190191

191-
<plugin>
192-
<groupId>org.apache.maven.plugins</groupId>
193-
<artifactId>maven-antrun-plugin</artifactId>
194-
<version>3.1.0</version>
195-
<executions>
196-
<execution>
197-
<id>copy-snapshot-distribution</id>
198-
<goals>
199-
<goal>run</goal>
200-
</goals>
201-
<phase>pre-integration-test</phase>
202-
<configuration>
203-
<target>
204-
<mkdir dir="${project.build.directory}/local-repo/org/apache/maven/apache-maven/4.1.0-SNAPSHOT" />
205-
<copy file="${project.basedir}/../src/test/resources/repository/org/apache/maven/apache-maven/4.1.0-SNAPSHOT/apache-maven-4.1.0-20250710.120440-1-bin.zip" todir="${project.build.directory}/local-repo/org/apache/maven/apache-maven/4.1.0-SNAPSHOT" />
206-
</target>
207-
</configuration>
208-
</execution>
209-
</executions>
210-
</plugin>
211-
212192
<plugin>
213193
<groupId>org.codehaus.mojo</groupId>
214194
<artifactId>mrm-maven-plugin</artifactId>
215195
<version>1.7.0</version>
216196
<configuration>
217197
<repositories>
198+
<mockRepo>
199+
<source>src/it/repository</source>
200+
<cloneTo>${project.build.directory}/mock-repo</cloneTo>
201+
</mockRepo>
218202
<localRepo>
219203
<source>${project.build.directory}/local-repo</source>
220204
</localRepo>

maven-wrapper-plugin/src/it/projects/snapshot_distribution_test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ under the License.
4343
<configuration>
4444
<executable>mvnw${cmd}</executable>
4545
<successCodes>
46-
<successCode>1</successCode>
46+
<successCode>0</successCode>
4747
</successCodes>
4848
<arguments>
4949
<argument>-v</argument>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
def userProperties = context.get('userProperties')
21+
22+
userProperties.put('distributionUrl', mrmRepositoryUrl + '/org/apache/maven/apache-maven/4.9.999-SNAPSHOT/apache-maven-4.9.999-20250710.120440-1-bin.zip')

maven-wrapper-plugin/src/it/projects/snapshot_distribution_test/test.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@
1717

1818
# Test properties for snapshot distribution integration test
1919
type=only-script
20-
distributionUrl=@mrm.repository.url@/org/apache/maven/apache-maven/4.1.0-SNAPSHOT/apache-maven-4.1.0-20250710.120440-1-bin.zip

maven-wrapper-plugin/src/it/projects/snapshot_distribution_test/verify.groovy

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ assert props.distributionType.equals("only-script")
3535

3636
// The plugin should have used our custom timestamped snapshot URL
3737
println "Generated distribution URL: ${props.distributionUrl}"
38-
assert props.distributionUrl.contains("apache-maven-4.1.0-20250710.120440-1-bin.zip"), "Expected timestamped snapshot distribution URL but got: ${props.distributionUrl}"
39-
assert props.distributionUrl.contains("/org/apache/maven/apache-maven/4.1.0-SNAPSHOT/"), "Expected Maven repository path but got: ${props.distributionUrl}"
38+
assert props.distributionUrl.contains("apache-maven-4.9.999-20250710.120440-1-bin.zip"), "Expected timestamped snapshot distribution URL but got: ${props.distributionUrl}"
39+
assert props.distributionUrl.contains("/org/apache/maven/apache-maven/4.9.999-SNAPSHOT/"), "Expected Maven repository path but got: ${props.distributionUrl}"
4040

4141
println "✓ Plugin correctly used custom distributionUrl parameter"
4242
println "✓ Distribution URL: ${props.distributionUrl}"
@@ -54,3 +54,7 @@ println "✓ Plugin correctly accepted custom distributionUrl parameter"
5454
println "✓ Wrapper configured to use timestamped snapshot URL: ${props.distributionUrl}"
5555
println "✓ This tests the scenario where ZIP filename != directory name inside ZIP"
5656
println "✓ Our fix should handle: apache-maven-4.1.0-20250710.120440-1-bin.zip -> apache-maven-4.1.0-SNAPSHOT/"
57+
58+
log = new File(basedir, 'build.log').text
59+
// check "mvnw" output
60+
assert log.contains('Apache Maven 4.9.999 from SNAPSHOT distribution'), "Expected 'Apache Maven 4.9.999 from SNAPSHOT distribution' in build.log but not found"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#\!/bin/bash
2+
# ----------------------------------------------------------------------------
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
# ----------------------------------------------------------------------------
20+
21+
# Minimal fake Maven script for testing
22+
echo "Apache Maven 4.9.999 from SNAPSHOT distribution"
23+
echo "Maven home: $(dirname "$(dirname "$(readlink -f "$0")")")"
24+
exit 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@echo off
2+
@REM ----------------------------------------------------------------------------
3+
@REM Licensed to the Apache Software Foundation (ASF) under one
4+
@REM or more contributor license agreements. See the NOTICE file
5+
@REM distributed with this work for additional information
6+
@REM regarding copyright ownership. The ASF licenses this file
7+
@REM to you under the Apache License, Version 2.0 (the
8+
@REM "License"); you may not use this file except in compliance
9+
@REM with the License. You may obtain a copy of the License at
10+
@REM
11+
@REM http://www.apache.org/licenses/LICENSE-2.0
12+
@REM
13+
@REM Unless required by applicable law or agreed to in writing,
14+
@REM software distributed under the License is distributed on an
15+
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
@REM KIND, either express or implied. See the License for the
17+
@REM specific language governing permissions and limitations
18+
@REM under the License.
19+
@REM ----------------------------------------------------------------------------
20+
21+
rem Minimal fake Maven script for testing
22+
echo Apache Maven 4.9.999 from SNAPSHOT distribution
23+
echo Maven home: %~dp0..
24+
exit /b 0
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<groupId>org.apache.maven</groupId>
23+
<artifactId>apache-maven</artifactId>
24+
<version>4.9.999-SNAPSHOT</version>
25+
</project>

0 commit comments

Comments
 (0)