This is an automated email from the ASF dual-hosted git repository. rfscholte pushed a commit to branch MWRAPPER-0_WIP in repository https://gitbox.apache.org/repos/asf/maven-wrapper-plugin.git
The following commit(s) were added to refs/heads/MWRAPPER-0_WIP by this push: new 278a2aa Add integration tests 278a2aa is described below commit 278a2aac1c347e961f086a49af5ddf3667b8a1e8 Author: rfscholte <rfscho...@apache.org> AuthorDate: Sat May 23 13:27:01 2020 +0200 Add integration tests --- pom.xml | 3 - src/it/projects/default/invoker.properties | 2 +- src/it/projects/default/pom.xml | 29 ++++++ src/it/projects/default/verify.groovy | 26 +++++ .../{default => excludeDebug}/invoker.properties | 2 +- src/it/projects/excludeDebug/pom.xml | 29 ++++++ .../test.properties} | 2 +- src/it/projects/excludeDebug/verify.groovy | 24 +++++ src/it/projects/extension/verify.groovy | 25 +++++ src/it/projects/{extension => }/invoker.properties | 0 .../{default => mavenversion}/invoker.properties | 2 +- src/it/projects/mavenversion/pom.xml | 29 ++++++ .../test.properties} | 2 +- src/it/projects/mavenversion/verify.groovy | 34 +++++++ .../{default => type_bin}/invoker.properties | 2 +- src/it/projects/type_bin/pom.xml | 29 ++++++ .../test.properties} | 2 +- src/it/projects/type_bin/verify.groovy | 26 +++++ .../{default => type_source}/invoker.properties | 2 +- src/it/projects/type_source/pom.xml | 29 ++++++ .../test.properties} | 2 +- src/it/projects/type_source/verify.groovy | 27 +++++ .../apache/maven/plugins/wrapper/WrapperMojo.java | 110 ++++++++++++++++----- src/main/resources/META-INF/plexus/components.xml | 2 +- 24 files changed, 404 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index 52eee3c..d3e8f83 100644 --- a/pom.xml +++ b/pom.xml @@ -112,9 +112,6 @@ under the License. <goal>wrapper</goal> </goals> <projectsDirectory>src/it/projects</projectsDirectory> - <pomIncludes> - <pomInclude>*</pomInclude> - </pomIncludes> </configuration> </plugin> </plugins> diff --git a/src/it/projects/default/invoker.properties b/src/it/projects/default/invoker.properties index 7b22bf3..a9aec42 100644 --- a/src/it/projects/default/invoker.properties +++ b/src/it/projects/default/invoker.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.maven.version = 3.7.0+ +invoker.goals = org.apache.maven.plugins:maven-wrapper-plugin:${project.version}:wrapper \ No newline at end of file diff --git a/src/it/projects/default/pom.xml b/src/it/projects/default/pom.xml new file mode 100644 index 0000000..ed54d55 --- /dev/null +++ b/src/it/projects/default/pom.xml @@ -0,0 +1,29 @@ +<?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> + + <groupId>org.apache.maven.plugins.it.wrapper</groupId> + <artifactId>extension</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> +</project> \ No newline at end of file diff --git a/src/it/projects/default/verify.groovy b/src/it/projects/default/verify.groovy new file mode 100644 index 0000000..04369ef --- /dev/null +++ b/src/it/projects/default/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/src/it/projects/default/invoker.properties b/src/it/projects/excludeDebug/invoker.properties similarity index 89% copy from src/it/projects/default/invoker.properties copy to src/it/projects/excludeDebug/invoker.properties index 7b22bf3..a9aec42 100644 --- a/src/it/projects/default/invoker.properties +++ b/src/it/projects/excludeDebug/invoker.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.maven.version = 3.7.0+ +invoker.goals = org.apache.maven.plugins:maven-wrapper-plugin:${project.version}:wrapper \ No newline at end of file diff --git a/src/it/projects/excludeDebug/pom.xml b/src/it/projects/excludeDebug/pom.xml new file mode 100644 index 0000000..ed54d55 --- /dev/null +++ b/src/it/projects/excludeDebug/pom.xml @@ -0,0 +1,29 @@ +<?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> + + <groupId>org.apache.maven.plugins.it.wrapper</groupId> + <artifactId>extension</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> +</project> \ No newline at end of file diff --git a/src/it/projects/default/invoker.properties b/src/it/projects/excludeDebug/test.properties similarity index 96% copy from src/it/projects/default/invoker.properties copy to src/it/projects/excludeDebug/test.properties index 7b22bf3..6600e23 100644 --- a/src/it/projects/default/invoker.properties +++ b/src/it/projects/excludeDebug/test.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.maven.version = 3.7.0+ +includeDebug=false \ No newline at end of file diff --git a/src/it/projects/excludeDebug/verify.groovy b/src/it/projects/excludeDebug/verify.groovy new file mode 100644 index 0000000..5d269c2 --- /dev/null +++ b/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/src/it/projects/extension/verify.groovy b/src/it/projects/extension/verify.groovy new file mode 100644 index 0000000..627b37e --- /dev/null +++ b/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/src/it/projects/extension/invoker.properties b/src/it/projects/invoker.properties similarity index 100% rename from src/it/projects/extension/invoker.properties rename to src/it/projects/invoker.properties diff --git a/src/it/projects/default/invoker.properties b/src/it/projects/mavenversion/invoker.properties similarity index 89% copy from src/it/projects/default/invoker.properties copy to src/it/projects/mavenversion/invoker.properties index 7b22bf3..a9aec42 100644 --- a/src/it/projects/default/invoker.properties +++ b/src/it/projects/mavenversion/invoker.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.maven.version = 3.7.0+ +invoker.goals = org.apache.maven.plugins:maven-wrapper-plugin:${project.version}:wrapper \ No newline at end of file diff --git a/src/it/projects/mavenversion/pom.xml b/src/it/projects/mavenversion/pom.xml new file mode 100644 index 0000000..ed54d55 --- /dev/null +++ b/src/it/projects/mavenversion/pom.xml @@ -0,0 +1,29 @@ +<?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> + + <groupId>org.apache.maven.plugins.it.wrapper</groupId> + <artifactId>extension</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> +</project> \ No newline at end of file diff --git a/src/it/projects/default/invoker.properties b/src/it/projects/mavenversion/test.properties similarity index 96% copy from src/it/projects/default/invoker.properties copy to src/it/projects/mavenversion/test.properties index 7b22bf3..46c2d1b 100644 --- a/src/it/projects/default/invoker.properties +++ b/src/it/projects/mavenversion/test.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.maven.version = 3.7.0+ +mavenVersion=3.6.3 \ No newline at end of file diff --git a/src/it/projects/mavenversion/verify.groovy b/src/it/projects/mavenversion/verify.groovy new file mode 100644 index 0000000..f972b23 --- /dev/null +++ b/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/src/it/projects/default/invoker.properties b/src/it/projects/type_bin/invoker.properties similarity index 89% copy from src/it/projects/default/invoker.properties copy to src/it/projects/type_bin/invoker.properties index 7b22bf3..a9aec42 100644 --- a/src/it/projects/default/invoker.properties +++ b/src/it/projects/type_bin/invoker.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.maven.version = 3.7.0+ +invoker.goals = org.apache.maven.plugins:maven-wrapper-plugin:${project.version}:wrapper \ No newline at end of file diff --git a/src/it/projects/type_bin/pom.xml b/src/it/projects/type_bin/pom.xml new file mode 100644 index 0000000..ed54d55 --- /dev/null +++ b/src/it/projects/type_bin/pom.xml @@ -0,0 +1,29 @@ +<?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> + + <groupId>org.apache.maven.plugins.it.wrapper</groupId> + <artifactId>extension</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> +</project> \ No newline at end of file diff --git a/src/it/projects/default/invoker.properties b/src/it/projects/type_bin/test.properties similarity index 96% copy from src/it/projects/default/invoker.properties copy to src/it/projects/type_bin/test.properties index 7b22bf3..b77cbfd 100644 --- a/src/it/projects/default/invoker.properties +++ b/src/it/projects/type_bin/test.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.maven.version = 3.7.0+ +type=bin \ No newline at end of file diff --git a/src/it/projects/type_bin/verify.groovy b/src/it/projects/type_bin/verify.groovy new file mode 100644 index 0000000..e079d58 --- /dev/null +++ b/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/src/it/projects/default/invoker.properties b/src/it/projects/type_source/invoker.properties similarity index 89% copy from src/it/projects/default/invoker.properties copy to src/it/projects/type_source/invoker.properties index 7b22bf3..a9aec42 100644 --- a/src/it/projects/default/invoker.properties +++ b/src/it/projects/type_source/invoker.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.maven.version = 3.7.0+ +invoker.goals = org.apache.maven.plugins:maven-wrapper-plugin:${project.version}:wrapper \ No newline at end of file diff --git a/src/it/projects/type_source/pom.xml b/src/it/projects/type_source/pom.xml new file mode 100644 index 0000000..ed54d55 --- /dev/null +++ b/src/it/projects/type_source/pom.xml @@ -0,0 +1,29 @@ +<?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> + + <groupId>org.apache.maven.plugins.it.wrapper</groupId> + <artifactId>extension</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> +</project> \ No newline at end of file diff --git a/src/it/projects/default/invoker.properties b/src/it/projects/type_source/test.properties similarity index 96% copy from src/it/projects/default/invoker.properties copy to src/it/projects/type_source/test.properties index 7b22bf3..1c83fbb 100644 --- a/src/it/projects/default/invoker.properties +++ b/src/it/projects/type_source/test.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.maven.version = 3.7.0+ +type=source \ No newline at end of file diff --git a/src/it/projects/type_source/verify.groovy b/src/it/projects/type_source/verify.groovy new file mode 100644 index 0000000..a4a2ed6 --- /dev/null +++ b/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/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java b/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java index 9b8a14c..afd548b 100644 --- a/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java +++ b/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java @@ -19,11 +19,13 @@ package org.apache.maven.plugins.wrapper; * 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.nio.file.Paths; import java.util.Map; import java.util.Properties; @@ -42,6 +44,7 @@ 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; /** * Adds the maven-wrapper files to this project @@ -49,44 +52,59 @@ import org.codehaus.plexus.archiver.UnArchiver; * @author Robert Scholte * @since 3.0.0 */ -@Mojo( name = "wrapper", requiresProject = false, aggregator = true ) +@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 + * The version of Maven to require, default value is the Runtime version of Maven. + * Can be any valid release above 2.0.9 */ - @Parameter + @Parameter( property = "mavenVersion" ) private String mavenVersion; - + + /** + * The version of the wrapper, default value is the Runtime version of Maven, should be at least 3.7.0 + */ + @Parameter( property = "wrapperVersion" ) + private String wrapperVersion; + /** * Options are: * <dl> - * <dt>bin (default)</dt> + * <dt>script (default)</dt> + * <dd>only mvnw scripts</dd> + * <dt>bin</dt> * <dd>precompiled and packaged code</dd> - * <dt>java</dt> + * <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 = "bin" ) + @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}" ) + private File basedir; + + // CONSTANTS - @Parameter( defaultValue = "org.apache.maven", readonly = true, required = true ) - private String groupId; + private String groupId = "org.apache.maven"; - @Parameter( defaultValue = "maven-wrapper", readonly = true, required = true ) - private String artifactId; + private String artifactId = "apache-maven-wrapper"; - @Parameter( defaultValue = "tar.gz", readonly = true, required = true ) - private String extension; + private String extension = "zip"; // COMPONENTS @@ -109,18 +127,26 @@ public class WrapperMojo extends AbstractMojo throw new MojoExecutionException( e.getMessage(), e ); } - Path targetFolder = Paths.get( ".mvn/wrapper" ); - try { - unpack( artifact, targetFolder ); + unpack( artifact, basedir.toPath() ); } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } - update( targetFolder ); + if ( mavenVersion != null ) + { + try + { + replaceProperties( Files.createDirectories( basedir.toPath().resolve( ".mvn/wrapper" ) ) ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "can't create wrapper.proeprties", e ); + } + } } private Artifact download() @@ -132,7 +158,7 @@ public class WrapperMojo extends AbstractMojo DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate(); coordinate.setGroupId( groupId ); coordinate.setArtifactId( artifactId ); - coordinate.setVersion( getVersion() ); // + coordinate.setVersion( getVersion( this.wrapperVersion ) ); coordinate.setClassifier( distributionType ); coordinate.setExtension( extension ); @@ -145,17 +171,55 @@ public class WrapperMojo extends AbstractMojo UnArchiver unarchiver = unarchivers.get( extension ); unarchiver.setDestDirectory( targetFolder.toFile() ); unarchiver.setSourceFile( artifact.getFile() ); + if ( !includeDebugScript ) + { + unarchiver.setFileSelectors( new FileSelector[] + { + f -> !f.getName().contains( "Debug" ) + } ); + } unarchiver.extract(); } - private void update( Path targetFolder ) + /** + * 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 targetFolder the folder containing the wrapper.properties + * @throws IOException if writing fails + */ + private void replaceProperties( Path targetFolder ) throws IOException { - // update wrapper.properties + Path wrapperPropertiesFile = targetFolder.resolve( "maven-wrapper.properties" ); + + 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=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/" + + mavenVersion + + "/apache-maven-" + + mavenVersion + + "-bin.zip" ); + } } - private String getVersion() + private String getVersion( String defaultVersion ) { - String version = this.mavenVersion; + String version = defaultVersion; if ( version == null ) { Properties props = new Properties(); diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml index ab72818..05b1156 100644 --- a/src/main/resources/META-INF/plexus/components.xml +++ b/src/main/resources/META-INF/plexus/components.xml @@ -22,7 +22,7 @@ <component-set> <components> - <!-- TODO move to maven-core --> + <!-- Delete once available in maven-core --> <component> <role>org.apache.maven.lifecycle.Lifecycle</role> <implementation>org.apache.maven.lifecycle.Lifecycle</implementation>