This is an automated email from the ASF dual-hosted git repository. hboutemy pushed a commit to branch MWRAPPER-14 in repository https://gitbox.apache.org/repos/asf/maven-studies.git
commit 6d8ea60b2985603fd04e072e41dff70f0918284d Author: Hervé Boutemy <hbout...@apache.org> AuthorDate: Sat Nov 27 00:50:39 2021 +0100 [MWRAPPER-14] add maven-wrapper-plugin --- maven-wrapper-distribution/pom.xml | 4 +- .../src/assembly/{distribution.xml => bin.xml} | 9 +- .../src/assembly/{distribution.xml => script.xml} | 19 +- .../src/assembly/{distribution.xml => source.xml} | 12 +- maven-wrapper-plugin/pom.xml | 124 ++++++++++ .../src/it/projects/default/pom.xml | 32 +-- .../src/it/projects/default/verify.groovy | 27 +++ .../src/it/projects/excludeDebug/pom.xml | 32 +-- .../src/it/projects/excludeDebug/test.properties | 7 +- .../src/it/projects/excludeDebug/verify.groovy | 24 ++ .../src/it/projects/extension/invoker.properties | 8 +- .../src/it/projects/extension/pom.xml | 43 ++-- .../src/it/projects/extension/verify.groovy | 25 +++ .../src/it/projects/mavenversion/pom.xml | 32 +-- .../src/it/projects/mavenversion/test.properties | 7 +- .../src/it/projects/mavenversion/verify.groovy | 34 +++ .../src/it/projects/type_bin/pom.xml | 32 +-- .../src/it/projects/type_bin/test.properties | 7 +- .../src/it/projects/type_bin/verify.groovy | 26 +++ .../src/it/projects/type_source/pom.xml | 32 +-- .../src/it/projects/type_source/test.properties | 7 +- .../src/it/projects/type_source/verify.groovy | 27 +++ maven-wrapper-plugin/src/it/settings.xml | 54 +++++ .../apache/maven/plugins/wrapper/WrapperMojo.java | 249 +++++++++++++++++++++ .../main/resources/META-INF/plexus/components.xml | 42 ++++ maven-wrapper-plugin/src/site/markdown/index.md.vm | 51 +++++ maven-wrapper-plugin/src/site/markdown/usage.md | 59 +++++ maven-wrapper-plugin/src/site/site.xml | 34 +++ pom.xml | 3 + 29 files changed, 854 insertions(+), 208 deletions(-) diff --git a/maven-wrapper-distribution/pom.xml b/maven-wrapper-distribution/pom.xml index b8ae22c..cdccd4b 100644 --- a/maven-wrapper-distribution/pom.xml +++ b/maven-wrapper-distribution/pom.xml @@ -56,7 +56,9 @@ under the License. </executions> <configuration> <descriptors> - <descriptor>src/assembly/distribution.xml</descriptor> + <descriptor>src/assembly/script.xml</descriptor> + <descriptor>src/assembly/source.xml</descriptor> + <descriptor>src/assembly/bin.xml</descriptor> </descriptors> </configuration> </plugin> diff --git a/maven-wrapper-distribution/src/assembly/distribution.xml b/maven-wrapper-distribution/src/assembly/bin.xml similarity index 90% copy from maven-wrapper-distribution/src/assembly/distribution.xml copy to maven-wrapper-distribution/src/assembly/bin.xml index 2df7db1..6fb0c10 100644 --- a/maven-wrapper-distribution/src/assembly/distribution.xml +++ b/maven-wrapper-distribution/src/assembly/bin.xml @@ -21,7 +21,7 @@ under the License. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd"> - <id>distribution</id> + <id>bin</id> <formats> <format>zip</format> </formats> @@ -49,11 +49,4 @@ under the License. <fileMode>0755</fileMode> </file> </files> - <fileSets> - <fileSet> - <directory>src/resources/mvn</directory> - <outputDirectory>.mvn</outputDirectory> - <filtered>true</filtered> - </fileSet> - </fileSets> </assembly> diff --git a/maven-wrapper-distribution/src/assembly/distribution.xml b/maven-wrapper-distribution/src/assembly/script.xml similarity index 72% copy from maven-wrapper-distribution/src/assembly/distribution.xml copy to maven-wrapper-distribution/src/assembly/script.xml index 2df7db1..e641506 100644 --- a/maven-wrapper-distribution/src/assembly/distribution.xml +++ b/maven-wrapper-distribution/src/assembly/script.xml @@ -21,21 +21,11 @@ under the License. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd"> - <id>distribution</id> + <id>script</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> - <dependencySets> - <dependencySet> - <useProjectArtifact>false</useProjectArtifact> - <includes> - <include>org.apache.maven.wrapper:maven-wrapper:jar:*</include> - </includes> - <outputDirectory>.mvn/wrapper</outputDirectory> - <outputFileNameMapping>maven-wrapper.jar</outputFileNameMapping> - </dependencySet> - </dependencySets> <files> <file> <source>src/resources/mvnw.cmd</source> @@ -49,11 +39,4 @@ under the License. <fileMode>0755</fileMode> </file> </files> - <fileSets> - <fileSet> - <directory>src/resources/mvn</directory> - <outputDirectory>.mvn</outputDirectory> - <filtered>true</filtered> - </fileSet> - </fileSets> </assembly> diff --git a/maven-wrapper-distribution/src/assembly/distribution.xml b/maven-wrapper-distribution/src/assembly/source.xml similarity index 81% rename from maven-wrapper-distribution/src/assembly/distribution.xml rename to maven-wrapper-distribution/src/assembly/source.xml index 2df7db1..344cd94 100644 --- a/maven-wrapper-distribution/src/assembly/distribution.xml +++ b/maven-wrapper-distribution/src/assembly/source.xml @@ -21,21 +21,11 @@ under the License. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd"> - <id>distribution</id> + <id>source</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> - <dependencySets> - <dependencySet> - <useProjectArtifact>false</useProjectArtifact> - <includes> - <include>org.apache.maven.wrapper:maven-wrapper:jar:*</include> - </includes> - <outputDirectory>.mvn/wrapper</outputDirectory> - <outputFileNameMapping>maven-wrapper.jar</outputFileNameMapping> - </dependencySet> - </dependencySets> <files> <file> <source>src/resources/mvnw.cmd</source> diff --git a/maven-wrapper-plugin/pom.xml b/maven-wrapper-plugin/pom.xml new file mode 100644 index 0000000..02df490 --- /dev/null +++ b/maven-wrapper-plugin/pom.xml @@ -0,0 +1,124 @@ +<?xml version='1.0' encoding='UTF-8'?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.maven.wrapper</groupId> + <artifactId>maven-wrapper-parent</artifactId> + <version>3.0.3-SNAPSHOT</version> + </parent> + + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-wrapper-plugin</artifactId> + <packaging>maven-plugin</packaging> + + <name>Apache Maven Wrapper Plugin</name> + <description> + The Maven Wrapper Plugin is a plugin that provides support for the Maven Wrapper by unpacking Maven Wrapper Distribution to current project. + </description> + + <prerequisites> + <maven>${mavenVersion}</maven> + </prerequisites> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>${mavenVersion}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>${mavenVersion}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-shared-utils</artifactId> + <version>3.3.4</version> + </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-artifact-transfer</artifactId> + <version>0.12.0</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-archiver</artifactId> + <version>4.2.1</version> + </dependency> + + <!-- dependencies to annotations --> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <optional>true</optional> + </dependency> + </dependencies> + + <profiles> + <profile> + <id>run-its</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-invoker-plugin</artifactId> + <configuration> + <goals> + <goal>${project.groupId}:${project.artifactId}:${project.version}:wrapper</goal> + </goals> + <projectsDirectory>src/it/projects</projectsDirectory> + <debug>false</debug> + <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> + <preBuildHookScript>setup</preBuildHookScript> + <postBuildHookScript>verify</postBuildHookScript> + <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> + <settingsFile>src/it/settings.xml</settingsFile> + <pomIncludes> + <pomInclude>*/pom.xml</pomInclude> + </pomIncludes> + <properties> + <maven.compiler.source>${invoker.maven.compiler.source}</maven.compiler.source> + <maven.compiler.target>${invoker.maven.compiler.target}</maven.compiler.target> + <!-- e.g. ensure that Java7 picks up TLSv1.2 when connecting with Central --> + <https.protocols>${https.protocols}</https.protocols> + </properties> + <ignoreFailures>${maven.it.failure.ignore}</ignoreFailures> + </configuration> + <executions> + <execution> + <id>integration-test</id> + <goals> + <goal>install</goal> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/pom.xml b/maven-wrapper-plugin/src/it/projects/default/pom.xml similarity index 55% copy from pom.xml copy to maven-wrapper-plugin/src/it/projects/default/pom.xml index 125d62c..ed54d55 100644 --- a/pom.xml +++ b/maven-wrapper-plugin/src/it/projects/default/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version='1.0' encoding='UTF-8'?> <!-- Licensed to the Apache Software Foundation (ASF) under one @@ -9,7 +9,7 @@ to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an @@ -19,29 +19,11 @@ specific language governing permissions and limitations under the License. --> -<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"> +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.maven</groupId> - <artifactId>maven-parent</artifactId> - <version>34</version> - </parent> - - <groupId>org.apache.maven.wrapper</groupId> - <artifactId>maven-wrapper-parent</artifactId> - <version>3.0.3-SNAPSHOT</version> + <groupId>org.apache.maven.plugins.it.wrapper</groupId> + <artifactId>extension</artifactId> + <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> - - <name>Apache Maven Wrapper</name> - - <properties> - <javaVersion>8</javaVersion> - <project.build.outputTimestamp>2021-11-26T10:03:59Z</project.build.outputTimestamp> - </properties> - - <modules> - <module>maven-wrapper</module> - <module>maven-wrapper-distribution</module> - </modules> -</project> +</project> \ No newline at end of file diff --git a/maven-wrapper-plugin/src/it/projects/default/verify.groovy b/maven-wrapper-plugin/src/it/projects/default/verify.groovy new file mode 100644 index 0000000..d05b9ae --- /dev/null +++ b/maven-wrapper-plugin/src/it/projects/default/verify.groovy @@ -0,0 +1,27 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +assert new File(basedir,'mvnw').exists() +assert new File(basedir,'mvnw.cmd').exists() +//assert new File(basedir,'mvnwDebug').exists() +//assert new File(basedir,'mvnwDebug.cmd').exists() +assert new File(basedir,'.mvn/wrapper/maven-wrapper.properties').exists() +assert !(new File(basedir,'.mvn/wrapper/maven-wrapper.jar').exists()) +assert new File(basedir, 'build.log').text.contains('[INFO] Unpacked script type wrapper distribution org.apache.maven.wrapper:maven-wrapper-distribution:zip:script:') \ No newline at end of file diff --git a/pom.xml b/maven-wrapper-plugin/src/it/projects/excludeDebug/pom.xml similarity index 55% copy from pom.xml copy to maven-wrapper-plugin/src/it/projects/excludeDebug/pom.xml index 125d62c..ed54d55 100644 --- a/pom.xml +++ b/maven-wrapper-plugin/src/it/projects/excludeDebug/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version='1.0' encoding='UTF-8'?> <!-- Licensed to the Apache Software Foundation (ASF) under one @@ -9,7 +9,7 @@ to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an @@ -19,29 +19,11 @@ specific language governing permissions and limitations under the License. --> -<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"> +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.maven</groupId> - <artifactId>maven-parent</artifactId> - <version>34</version> - </parent> - - <groupId>org.apache.maven.wrapper</groupId> - <artifactId>maven-wrapper-parent</artifactId> - <version>3.0.3-SNAPSHOT</version> + <groupId>org.apache.maven.plugins.it.wrapper</groupId> + <artifactId>extension</artifactId> + <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> - - <name>Apache Maven Wrapper</name> - - <properties> - <javaVersion>8</javaVersion> - <project.build.outputTimestamp>2021-11-26T10:03:59Z</project.build.outputTimestamp> - </properties> - - <modules> - <module>maven-wrapper</module> - <module>maven-wrapper-distribution</module> - </modules> -</project> +</project> \ No newline at end of file diff --git a/maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties b/maven-wrapper-plugin/src/it/projects/excludeDebug/test.properties similarity index 74% copy from maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties copy to maven-wrapper-plugin/src/it/projects/excludeDebug/test.properties index 43a290b..6600e23 100644 --- a/maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties +++ b/maven-wrapper-plugin/src/it/projects/excludeDebug/test.properties @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -15,5 +15,4 @@ # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/${project.version}/maven-wrapper-${project.version}.jar +includeDebug=false \ No newline at end of file diff --git a/maven-wrapper-plugin/src/it/projects/excludeDebug/verify.groovy b/maven-wrapper-plugin/src/it/projects/excludeDebug/verify.groovy new file mode 100644 index 0000000..5d269c2 --- /dev/null +++ b/maven-wrapper-plugin/src/it/projects/excludeDebug/verify.groovy @@ -0,0 +1,24 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +assert new File(basedir,'mvnw').exists() +assert new File(basedir,'mvnw.cmd').exists() +assert !(new File(basedir,'mvnwDebug').exists()) +assert !(new File(basedir,'mvnwDebug.cmd').exists()) diff --git a/maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties b/maven-wrapper-plugin/src/it/projects/extension/invoker.properties similarity index 74% copy from maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties copy to maven-wrapper-plugin/src/it/projects/extension/invoker.properties index 43a290b..ad41e67 100644 --- a/maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties +++ b/maven-wrapper-plugin/src/it/projects/extension/invoker.properties @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -15,5 +15,5 @@ # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/${project.version}/maven-wrapper-${project.version}.jar +# wrapper lifecycle available because maven-wrapper-plugin is put as extension +invoker.goals = wrapper diff --git a/pom.xml b/maven-wrapper-plugin/src/it/projects/extension/pom.xml similarity index 55% copy from pom.xml copy to maven-wrapper-plugin/src/it/projects/extension/pom.xml index 125d62c..0cbaa78 100644 --- a/pom.xml +++ b/maven-wrapper-plugin/src/it/projects/extension/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version='1.0' encoding='UTF-8'?> <!-- Licensed to the Apache Software Foundation (ASF) under one @@ -9,7 +9,7 @@ to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an @@ -19,29 +19,22 @@ specific language governing permissions and limitations under the License. --> -<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"> +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.maven</groupId> - <artifactId>maven-parent</artifactId> - <version>34</version> - </parent> - - <groupId>org.apache.maven.wrapper</groupId> - <artifactId>maven-wrapper-parent</artifactId> - <version>3.0.3-SNAPSHOT</version> + <groupId>org.apache.maven.plugins.it.wrapper</groupId> + <artifactId>extension</artifactId> + <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> - - <name>Apache Maven Wrapper</name> - - <properties> - <javaVersion>8</javaVersion> - <project.build.outputTimestamp>2021-11-26T10:03:59Z</project.build.outputTimestamp> - </properties> - - <modules> - <module>maven-wrapper</module> - <module>maven-wrapper-distribution</module> - </modules> -</project> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-wrapper-plugin</artifactId> + <version>@project.version@</version> + <extensions>true</extensions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file diff --git a/maven-wrapper-plugin/src/it/projects/extension/verify.groovy b/maven-wrapper-plugin/src/it/projects/extension/verify.groovy new file mode 100644 index 0000000..97eed83 --- /dev/null +++ b/maven-wrapper-plugin/src/it/projects/extension/verify.groovy @@ -0,0 +1,25 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +assert new File(basedir,'mvnw').exists() +assert new File(basedir,'mvnw.cmd').exists() +//assert new File(basedir,'mvnwDebug').exists() +//assert new File(basedir,'mvnwDebug.cmd').exists() +assert new File(basedir,'.mvn/wrapper/maven-wrapper.properties').exists() diff --git a/pom.xml b/maven-wrapper-plugin/src/it/projects/mavenversion/pom.xml similarity index 55% copy from pom.xml copy to maven-wrapper-plugin/src/it/projects/mavenversion/pom.xml index 125d62c..ed54d55 100644 --- a/pom.xml +++ b/maven-wrapper-plugin/src/it/projects/mavenversion/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version='1.0' encoding='UTF-8'?> <!-- Licensed to the Apache Software Foundation (ASF) under one @@ -9,7 +9,7 @@ to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an @@ -19,29 +19,11 @@ specific language governing permissions and limitations under the License. --> -<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"> +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.maven</groupId> - <artifactId>maven-parent</artifactId> - <version>34</version> - </parent> - - <groupId>org.apache.maven.wrapper</groupId> - <artifactId>maven-wrapper-parent</artifactId> - <version>3.0.3-SNAPSHOT</version> + <groupId>org.apache.maven.plugins.it.wrapper</groupId> + <artifactId>extension</artifactId> + <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> - - <name>Apache Maven Wrapper</name> - - <properties> - <javaVersion>8</javaVersion> - <project.build.outputTimestamp>2021-11-26T10:03:59Z</project.build.outputTimestamp> - </properties> - - <modules> - <module>maven-wrapper</module> - <module>maven-wrapper-distribution</module> - </modules> -</project> +</project> \ No newline at end of file diff --git a/maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties b/maven-wrapper-plugin/src/it/projects/mavenversion/test.properties similarity index 74% copy from maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties copy to maven-wrapper-plugin/src/it/projects/mavenversion/test.properties index 43a290b..2814600 100644 --- a/maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties +++ b/maven-wrapper-plugin/src/it/projects/mavenversion/test.properties @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -15,5 +15,4 @@ # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/${project.version}/maven-wrapper-${project.version}.jar +maven=3.6.3 \ No newline at end of file diff --git a/maven-wrapper-plugin/src/it/projects/mavenversion/verify.groovy b/maven-wrapper-plugin/src/it/projects/mavenversion/verify.groovy new file mode 100644 index 0000000..9262011 --- /dev/null +++ b/maven-wrapper-plugin/src/it/projects/mavenversion/verify.groovy @@ -0,0 +1,34 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +assert new File(basedir,'mvnw').exists() +assert new File(basedir,'mvnw.cmd').exists() +//assert new File(basedir,'mvnwDebug').exists() +//assert new File(basedir,'mvnwDebug.cmd').exists() + +def propertiesFile = new File(basedir,'.mvn/wrapper/maven-wrapper.properties') +assert propertiesFile.exists() + +def props = new Properties() +propertiesFile.withInputStream { + props.load(it) +} + +assert props.distributionUrl == 'https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip' diff --git a/pom.xml b/maven-wrapper-plugin/src/it/projects/type_bin/pom.xml similarity index 55% copy from pom.xml copy to maven-wrapper-plugin/src/it/projects/type_bin/pom.xml index 125d62c..ed54d55 100644 --- a/pom.xml +++ b/maven-wrapper-plugin/src/it/projects/type_bin/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version='1.0' encoding='UTF-8'?> <!-- Licensed to the Apache Software Foundation (ASF) under one @@ -9,7 +9,7 @@ to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an @@ -19,29 +19,11 @@ specific language governing permissions and limitations under the License. --> -<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"> +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.maven</groupId> - <artifactId>maven-parent</artifactId> - <version>34</version> - </parent> - - <groupId>org.apache.maven.wrapper</groupId> - <artifactId>maven-wrapper-parent</artifactId> - <version>3.0.3-SNAPSHOT</version> + <groupId>org.apache.maven.plugins.it.wrapper</groupId> + <artifactId>extension</artifactId> + <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> - - <name>Apache Maven Wrapper</name> - - <properties> - <javaVersion>8</javaVersion> - <project.build.outputTimestamp>2021-11-26T10:03:59Z</project.build.outputTimestamp> - </properties> - - <modules> - <module>maven-wrapper</module> - <module>maven-wrapper-distribution</module> - </modules> -</project> +</project> \ No newline at end of file diff --git a/maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties b/maven-wrapper-plugin/src/it/projects/type_bin/test.properties similarity index 74% copy from maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties copy to maven-wrapper-plugin/src/it/projects/type_bin/test.properties index 43a290b..b77cbfd 100644 --- a/maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties +++ b/maven-wrapper-plugin/src/it/projects/type_bin/test.properties @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -15,5 +15,4 @@ # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/${project.version}/maven-wrapper-${project.version}.jar +type=bin \ No newline at end of file diff --git a/maven-wrapper-plugin/src/it/projects/type_bin/verify.groovy b/maven-wrapper-plugin/src/it/projects/type_bin/verify.groovy new file mode 100644 index 0000000..66b2e23 --- /dev/null +++ b/maven-wrapper-plugin/src/it/projects/type_bin/verify.groovy @@ -0,0 +1,26 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +assert new File(basedir,'mvnw').exists() +assert new File(basedir,'mvnw.cmd').exists() +//assert new File(basedir,'mvnwDebug').exists() +//assert new File(basedir,'mvnwDebug.cmd').exists() +assert new File(basedir,'.mvn/wrapper/maven-wrapper.properties').exists() +assert new File(basedir,'.mvn/wrapper/maven-wrapper.jar').exists() \ No newline at end of file diff --git a/pom.xml b/maven-wrapper-plugin/src/it/projects/type_source/pom.xml similarity index 55% copy from pom.xml copy to maven-wrapper-plugin/src/it/projects/type_source/pom.xml index 125d62c..ed54d55 100644 --- a/pom.xml +++ b/maven-wrapper-plugin/src/it/projects/type_source/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version='1.0' encoding='UTF-8'?> <!-- Licensed to the Apache Software Foundation (ASF) under one @@ -9,7 +9,7 @@ to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an @@ -19,29 +19,11 @@ specific language governing permissions and limitations under the License. --> -<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"> +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.maven</groupId> - <artifactId>maven-parent</artifactId> - <version>34</version> - </parent> - - <groupId>org.apache.maven.wrapper</groupId> - <artifactId>maven-wrapper-parent</artifactId> - <version>3.0.3-SNAPSHOT</version> + <groupId>org.apache.maven.plugins.it.wrapper</groupId> + <artifactId>extension</artifactId> + <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> - - <name>Apache Maven Wrapper</name> - - <properties> - <javaVersion>8</javaVersion> - <project.build.outputTimestamp>2021-11-26T10:03:59Z</project.build.outputTimestamp> - </properties> - - <modules> - <module>maven-wrapper</module> - <module>maven-wrapper-distribution</module> - </modules> -</project> +</project> \ No newline at end of file diff --git a/maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties b/maven-wrapper-plugin/src/it/projects/type_source/test.properties similarity index 74% rename from maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties rename to maven-wrapper-plugin/src/it/projects/type_source/test.properties index 43a290b..1c83fbb 100644 --- a/maven-wrapper-distribution/src/resources/mvn/wrapper/maven-wrapper.properties +++ b/maven-wrapper-plugin/src/it/projects/type_source/test.properties @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -15,5 +15,4 @@ # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/${project.version}/maven-wrapper-${project.version}.jar +type=source \ No newline at end of file diff --git a/maven-wrapper-plugin/src/it/projects/type_source/verify.groovy b/maven-wrapper-plugin/src/it/projects/type_source/verify.groovy new file mode 100644 index 0000000..f318d71 --- /dev/null +++ b/maven-wrapper-plugin/src/it/projects/type_source/verify.groovy @@ -0,0 +1,27 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +assert new File(basedir,'mvnw').exists() +assert new File(basedir,'mvnw.cmd').exists() +//assert new File(basedir,'mvnwDebug').exists() +//assert new File(basedir,'mvnwDebug.cmd').exists() +assert new File(basedir,'.mvn/wrapper/maven-wrapper.properties').exists() +assert new File(basedir,'.mvn/wrapper/MavenWrapperDownloader.java').exists() +assert !(new File(basedir,'.mvn/wrapper/maven-wrapper.jar').exists()) diff --git a/maven-wrapper-plugin/src/it/settings.xml b/maven-wrapper-plugin/src/it/settings.xml new file mode 100644 index 0000000..fef4268 --- /dev/null +++ b/maven-wrapper-plugin/src/it/settings.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<settings> + <profiles> + <profile> + <id>it-repo</id> + <repositories> + <repository> + <id>local.central</id> + <url>@localRepositoryUrl@</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> + <pluginRepositories> + <pluginRepository> + <id>local.central</id> + <url>@localRepositoryUrl@</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </pluginRepository> + </pluginRepositories> + </profile> + </profiles> + <activeProfiles> + <activeProfile>it-repo</activeProfile> + </activeProfiles> +</settings> diff --git a/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java b/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java new file mode 100644 index 0000000..54bbb14 --- /dev/null +++ b/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java @@ -0,0 +1,249 @@ +package org.apache.maven.plugins.wrapper; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.BufferedWriter; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Map; +import java.util.Properties; + +import javax.inject.Inject; + +import org.apache.maven.Maven; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.DefaultProjectBuildingRequest; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate; +import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver; +import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException; +import org.codehaus.plexus.archiver.UnArchiver; +import org.codehaus.plexus.components.io.fileselectors.FileSelector; + +import static org.apache.maven.shared.utils.logging.MessageUtils.buffer; + +/** + * Unpacks the maven-wrapper distribution files to the current project source tree. + * + * @author Robert Scholte + * @since 3.0.0 + */ +@Mojo( name = "wrapper", aggregator = true, requiresDirectInvocation = true ) +public class WrapperMojo extends AbstractMojo +{ + // CONFIGURATION PARAMETERS + + /** + * The version of Maven to require, default value is the Runtime version of Maven. + * Can be any valid release above 2.0.9 + */ + @Parameter( property = "maven" ) + private String mavenVersion; + + /** + * Options are: + * <dl> + * <dt>script (default)</dt> + * <dd>only mvnw scripts</dd> + * <dt>bin</dt> + * <dd>precompiled and packaged code</dd> + * <dt>source</dt> + * <dd>sourcecode, will be compiled on the fly</dd> + * </dl> + * + * Value will be used as classifier of the downloaded file + */ + @Parameter( defaultValue = "script", property = "type" ) + private String distributionType; + + @Parameter( defaultValue = "true", property = "includeDebug" ) + private boolean includeDebugScript; + + // READONLY PARAMETERS + + @Parameter( defaultValue = "${session}", readonly = true, required = true ) + private MavenSession session; + + // Waiting for org.codehaus.plexus.component.configurator.converters.basic.PathConverter + @Parameter( defaultValue = "${project.basedir}", readonly = true, required = true ) + private File basedir; + + // CONSTANTS + + private static final String WRAPPER_DISTRIBUTION_GROUP_ID = "org.apache.maven.wrapper"; + + private static final String WRAPPER_DISTRIBUTION_ARTIFACT_ID = "maven-wrapper-distribution"; + + private static final String WRAPPER_DISTRIBUTION_EXTENSION = "zip"; + + // COMPONENTS + + @Inject + private ArtifactResolver artifactResolver; + + @Inject + private Map<String, UnArchiver> unarchivers; + + @Override + public void execute() + throws MojoExecutionException, MojoFailureException + { + String wrapperVersion = getVersion( null, this.getClass(), "org.apache.maven.plugins/maven-wrapper-plugin" ); + + Artifact artifact; + try + { + artifact = downloadWrapperDistribution( wrapperVersion ); + } + catch ( ArtifactResolverException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + + try + { + unpack( artifact, basedir.toPath() ); + getLog().info( "Unpacked " + buffer().strong( distributionType ) + " type wrapper distribution " + + artifact ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + + mavenVersion = getVersion( mavenVersion, Maven.class, "org.apache.maven/maven-core" ); + try + { + replaceProperties( wrapperVersion, Files.createDirectories( basedir.toPath().resolve( ".mvn/wrapper" ) ) ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "can't create maven-wrapper.properties", e ); + } + } + + private Artifact downloadWrapperDistribution( String wrapperVersion ) + throws ArtifactResolverException + { + ProjectBuildingRequest buildingRequest = + new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() ); + + DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate(); + coordinate.setGroupId( WRAPPER_DISTRIBUTION_GROUP_ID ); + coordinate.setArtifactId( WRAPPER_DISTRIBUTION_ARTIFACT_ID ); + coordinate.setVersion( wrapperVersion ); + coordinate.setClassifier( distributionType ); + coordinate.setExtension( WRAPPER_DISTRIBUTION_EXTENSION ); + + return artifactResolver.resolveArtifact( buildingRequest, coordinate ).getArtifact(); + } + + private void unpack( Artifact artifact, Path targetFolder ) throws IOException + { + targetFolder = Files.createDirectories( targetFolder ); + UnArchiver unarchiver = unarchivers.get( WRAPPER_DISTRIBUTION_EXTENSION ); + unarchiver.setDestDirectory( targetFolder.toFile() ); + unarchiver.setSourceFile( artifact.getFile() ); + if ( !includeDebugScript ) + { + unarchiver.setFileSelectors( new FileSelector[] + { + f -> !f.getName().contains( "Debug" ) + } ); + } + unarchiver.extract(); + } + + /** + * As long as the content only contains the license and the distributionUrl, we can simply replace it. + * No need to look for other properties, restore them, respecting comments, etc. + * + * @param wrapperVersion the wrapper version + * @param targetFolder the folder containing the wrapper.properties + * @throws IOException if writing fails + */ + private void replaceProperties( String wrapperVersion, Path targetFolder ) throws IOException + { + String repoUrl = "https://repo.maven.apache.org/maven2"; + String distributionUrl = + repoUrl + "/org/apache/maven/apache-maven/" + mavenVersion + "/apache-maven-" + mavenVersion + "-bin.zip"; + String wrapperUrl = repoUrl + "/org/apache/maven/wrapper/maven-wrapper/" + wrapperVersion + + "/maven-wrapper-" + wrapperVersion + ".zip"; + + Path wrapperPropertiesFile = targetFolder.resolve( "maven-wrapper.properties" ); + + getLog().info( "Configuring .mvn/wrapper/maven-wrapper.properties to use " + + buffer().strong( "Maven " + mavenVersion ) + " and download from " + repoUrl ); + + final String license = "# Licensed to the Apache Software Foundation (ASF) under one\n" + + "# or more contributor license agreements. See the NOTICE file\n" + + "# distributed with this work for additional information\n" + + "# regarding copyright ownership. The ASF licenses this file\n" + + "# to you under the Apache License, Version 2.0 (the\n" + + "# \"License\"); you may not use this file except in compliance\n" + + "# with the License. You may obtain a copy of the License at\n" + + "# \n" + + "# http://www.apache.org/licenses/LICENSE-2.0\n" + + "# \n" + + "# Unless required by applicable law or agreed to in writing,\n" + + "# software distributed under the License is distributed on an\n" + + "# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" + + "# KIND, either express or implied. See the License for the\n" + + "# specific language governing permissions and limitations\n" + + "# under the License.\n"; + + try ( BufferedWriter out = Files.newBufferedWriter( wrapperPropertiesFile ) ) + { + out.append( license ); + out.append( "distributionUrl=" + distributionUrl + "\n" ); + out.append( "wrapperUrl=" + wrapperUrl + "\n" ); + } + } + + private String getVersion( String defaultVersion, Class<?> clazz, String path ) + { + String version = defaultVersion; + if ( version == null ) + { + Properties props = new Properties(); + try ( InputStream is = + clazz.getResourceAsStream( "/META-INF/maven/" + path + "/pom.properties" ) ) + { + props.load( is ); + version = props.getProperty( "version" ); + } + catch ( IOException e ) + { + // noop + } + } + return version; + } +} diff --git a/maven-wrapper-plugin/src/main/resources/META-INF/plexus/components.xml b/maven-wrapper-plugin/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 0000000..05b1156 --- /dev/null +++ b/maven-wrapper-plugin/src/main/resources/META-INF/plexus/components.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> + +<component-set> + <components> + + <!-- Delete once available in maven-core --> + <component> + <role>org.apache.maven.lifecycle.Lifecycle</role> + <implementation>org.apache.maven.lifecycle.Lifecycle</implementation> + <role-hint>wrapper</role-hint> + <configuration> + <id>wrapper</id> + <phases> + <phase>wrapper</phase> + </phases> + <default-phases> + <wrapper>org.apache.maven.plugins:maven-wrapper-plugin:wrapper</wrapper> + </default-phases> + </configuration> + </component> + + </components> +</component-set> diff --git a/maven-wrapper-plugin/src/site/markdown/index.md.vm b/maven-wrapper-plugin/src/site/markdown/index.md.vm new file mode 100644 index 0000000..8746af6 --- /dev/null +++ b/maven-wrapper-plugin/src/site/markdown/index.md.vm @@ -0,0 +1,51 @@ +# Apache Maven Wrapper Plugin +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +The Apache Maven Wrapper Plugin helps with downloading and unpacking the [wrapper distribution](../maven-wrapper-distribution/). + +Goals Overview +-------------- + + + * [wrapper:wrapper](./wrapper-mojo.html) is the default goal invoked during the + `wrapper` phase. It downloads and unpacks the maven-wrapper distribution, + +Usage +----- + + General instructions on how to use the Wrapper Plugin can be found on the + [usage page](./usage.html). + + In case you still have questions regarding the plugin's usage, please have a look at the + [FAQ](./faq.html) and feel free to contact the [user mailing list](./mailing-lists.html). + The posts to the mailing list are archived and could already contain the answer to your + question as part of an older thread. Hence, it is also worth browsing/searching + the [mail archive](./mailing-lists.html). + + If you feel like the plugin is missing a feature or has a defect, you can fill a + feature request or bug report in our [issue tracker](./issue-management.html). + When creating a new issue, please provide a comprehensive description of your + concern. Especially for fixing bugs it is crucial that the developers can + reproduce your problem. For this reason, entire debug logs, POMs or most + preferably little demo projects attached to the issue are very much appreciated. + Of course, patches are welcome, too. Contributors can check out the project from + our [source repository](./scm.html) and will find supplementary + information in the + [guide to helping with Maven](/guides/development/guide-helping.html). diff --git a/maven-wrapper-plugin/src/site/markdown/usage.md b/maven-wrapper-plugin/src/site/markdown/usage.md new file mode 100644 index 0000000..e7b8671 --- /dev/null +++ b/maven-wrapper-plugin/src/site/markdown/usage.md @@ -0,0 +1,59 @@ +# Usage +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +Wrapper scripts are a set of files that can be added to your Maven project. +If people want to build this project, they don't need to install Maven first. +Instead they can call the Maven wrapper script (like `mvnw`/`mvnw.cmd`), which will download and unpack Maven into their `${user.home}/.m2/wrapper/dists` folder. +It is also an easy way to let everyone build the project with the same Maven version. + +The Apache Maven Wrapper Plugin makes it easier to add these wrapper scripts to your project. + +The scripts work like this: +- download the maven-wrapper jar, if it is not available yet, +- the wrapper-jar contains the code to download and run Apache Maven + +Apache Maven Wrapper Distribution Types +----- + +Wrapper scripts are provided by Maven 4 releases as ["Apache Maven Wrapper Distribution"](/ref/4-LATEST/apache-maven-wrapper/). + +There are 3 types available: + +- **script** _(default)_: With this type the scripts will try to download the scripts via wget or curl in case of Unix based system, or use Powershell in case of Windows + + +- **bin**: With this type the maven-wrapper jar is already available in the `.mvn/wrapper` folder, so you don't have to rely on wget/curl or Powershell +The downside is that the project will contain a binary file in the source control management system. + +- **source**: Since Maven already requires Java to run, why not compile and run a classfile to download the maven-wrapper jar? +This type comes with a `.mvn/wrapper/MavenWrapperDownloader.java` which will be compiled and executed on the fly. + +Maven Version +------------- +By default the plugin will assume the same version as the Maven runtime (calling `mvn -v`). But you can pick a different version. +Either call `mvn wrapper:wrapper -DmavenVersion=x`, where x is any valid Apache Maven Release, see https://search.maven.org/artifact/org.apache.maven/apache-maven +Another option is adjust the `distributionUrl` in `.mvn/wrapper/maven-wrapper.properties` + +Debugging +--------- + +The apache-maven-wrapper distributions all contains the `mvnwDebug`-script for both Windows and Unix based operating systems. +This makes it possible to debug through Apache Maven, Maven Plugin or Maven Extension. +You can exclude these scripts by calling `mvn wrapper:wrapper -DincludeDebug=false` \ No newline at end of file diff --git a/maven-wrapper-plugin/src/site/site.xml b/maven-wrapper-plugin/src/site/site.xml new file mode 100644 index 0000000..9678ca4 --- /dev/null +++ b/maven-wrapper-plugin/src/site/site.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project xmlns="http://maven.apache.org/DECORATION/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd"> + <body> + <menu name="Overview"> + <item name="Introduction" href="index.html"/> + <item name="Goals" href="plugin-info.html"/> + <item name="Usage" href="usage.html"/> + </menu> + <menu ref="parent"/> + <menu ref="reports"/> + </body> +</project> diff --git a/pom.xml b/pom.xml index 125d62c..8891d32 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,8 @@ under the License. <name>Apache Maven Wrapper</name> <properties> + <maven.site.path>wrapper-archives/wrapper-LATEST</maven.site.path> + <mavenVersion>3.1.0</mavenVersion> <javaVersion>8</javaVersion> <project.build.outputTimestamp>2021-11-26T10:03:59Z</project.build.outputTimestamp> </properties> @@ -43,5 +45,6 @@ under the License. <modules> <module>maven-wrapper</module> <module>maven-wrapper-distribution</module> + <module>maven-wrapper-plugin</module> </modules> </project>