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
commit 0205f09545b8df009700c158c0a58c4f25c1c39f Author: rfscholte <rfscho...@apache.org> AuthorDate: Sun Feb 9 16:21:44 2020 +0100 Initial setup of wrapper mojo --- .gitignore | 4 + Jenkinsfile | 20 +++ pom.xml | 124 +++++++++++++++ src/it/projects/default/invoker.properties | 18 +++ src/it/projects/extension/invoker.properties | 18 +++ src/it/projects/extension/pom.xml | 40 +++++ src/it/settings.xml | 54 +++++++ .../apache/maven/plugins/wrapper/WrapperMojo.java | 175 +++++++++++++++++++++ src/main/resources/META-INF/plexus/components.xml | 42 +++++ 9 files changed, 495 insertions(+) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..06a84e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target/ +/.classpath +/.project +/.settings diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..e9f05f7 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,20 @@ +/** + * 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. + */ + +asfMavenTlpPlgnBuild() diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..52eee3c --- /dev/null +++ b/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.plugins</groupId> + <artifactId>maven-plugins</artifactId> + <version>33</version> + <relativePath/> + </parent> + + <artifactId>maven-wrapper-plugin</artifactId> + <version>3.0.0-SNAPSHOT</version> + <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. + </description> + <inceptionYear>2020</inceptionYear> + + <prerequisites> + <maven>3.6.9999</maven> + </prerequisites> + + <scm> + <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-wrapper-plugin.git</connection> + <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-wrapper-plugin.git</developerConnection> + <url>https://github.com/apache/maven-wrapper-plugin/tree/${project.scm.tag}</url> + <tag>HEAD</tag> + </scm> + <issueManagement> + <system>JIRA</system> + <url>https://issues.apache.org/jira/browse/MWRAPPER</url> + </issueManagement> + <ciManagement> + <system>Jenkins</system> + <url>https://builds.apache.org/job/maven-box/job/maven-wrapper-plugin/</url> + </ciManagement> + <distributionManagement> + <site> + <id>apache.website</id> + <url>scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}</url> + </site> + </distributionManagement> + + <properties> + <mavenVersion>3.1.1</mavenVersion> + <javaVersion>8</javaVersion> + </properties> + + <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-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>wrapper</goal> + </goals> + <projectsDirectory>src/it/projects</projectsDirectory> + <pomIncludes> + <pomInclude>*</pomInclude> + </pomIncludes> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/src/it/projects/default/invoker.properties b/src/it/projects/default/invoker.properties new file mode 100644 index 0000000..7b22bf3 --- /dev/null +++ b/src/it/projects/default/invoker.properties @@ -0,0 +1,18 @@ +# 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. + +invoker.maven.version = 3.7.0+ diff --git a/src/it/projects/extension/invoker.properties b/src/it/projects/extension/invoker.properties new file mode 100644 index 0000000..7b22bf3 --- /dev/null +++ b/src/it/projects/extension/invoker.properties @@ -0,0 +1,18 @@ +# 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. + +invoker.maven.version = 3.7.0+ diff --git a/src/it/projects/extension/pom.xml b/src/it/projects/extension/pom.xml new file mode 100644 index 0000000..0cbaa78 --- /dev/null +++ b/src/it/projects/extension/pom.xml @@ -0,0 +1,40 @@ +<?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> + + <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/src/it/settings.xml b/src/it/settings.xml new file mode 100644 index 0000000..fef4268 --- /dev/null +++ b/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/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java b/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java new file mode 100644 index 0000000..9b8a14c --- /dev/null +++ b/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java @@ -0,0 +1,175 @@ +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.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; + +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.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; + +/** + * Adds the maven-wrapper files to this project + * + * @author Robert Scholte + * @since 3.0.0 + */ +@Mojo( name = "wrapper", requiresProject = false, aggregator = true ) +public class WrapperMojo extends AbstractMojo +{ + // CONFIGURATION PARAMETERS + + /** + * The version of Maven to require, default value is the Runtime version of Maven + */ + @Parameter + private String mavenVersion; + + /** + * Options are: + * <dl> + * <dt>bin (default)</dt> + * <dd>precompiled and packaged code</dd> + * <dt>java</dt> + * <dd>sourcecode, will be compiled on the fly</dd> + * </dl> + * + * Value will be used as classifier of the downloaded file + */ + @Parameter( defaultValue = "bin" ) + private String distributionType; + + // READONLY PARAMETERS + + @Parameter( defaultValue = "${session}", readonly = true, required = true ) + private MavenSession session; + + @Parameter( defaultValue = "org.apache.maven", readonly = true, required = true ) + private String groupId; + + @Parameter( defaultValue = "maven-wrapper", readonly = true, required = true ) + private String artifactId; + + @Parameter( defaultValue = "tar.gz", readonly = true, required = true ) + private String extension; + + // COMPONENTS + + @Inject + private ArtifactResolver artifactResolver; + + @Inject + private Map<String, UnArchiver> unarchivers; + + @Override + public void execute() throws MojoExecutionException + { + Artifact artifact; + try + { + artifact = download(); + } + catch ( ArtifactResolverException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + + Path targetFolder = Paths.get( ".mvn/wrapper" ); + + try + { + unpack( artifact, targetFolder ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + + update( targetFolder ); + } + + private Artifact download() + throws ArtifactResolverException + { + ProjectBuildingRequest buildingRequest = + new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() ); + + DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate(); + coordinate.setGroupId( groupId ); + coordinate.setArtifactId( artifactId ); + coordinate.setVersion( getVersion() ); // + coordinate.setClassifier( distributionType ); + coordinate.setExtension( extension ); + + return artifactResolver.resolveArtifact( buildingRequest, coordinate ).getArtifact(); + } + + private void unpack( Artifact artifact, Path targetFolder ) throws IOException + { + targetFolder = Files.createDirectories( targetFolder ); + UnArchiver unarchiver = unarchivers.get( extension ); + unarchiver.setDestDirectory( targetFolder.toFile() ); + unarchiver.setSourceFile( artifact.getFile() ); + unarchiver.extract(); + } + + private void update( Path targetFolder ) + { + // update wrapper.properties + } + + private String getVersion() + { + String version = this.mavenVersion; + if ( version == null ) + { + Properties props = new Properties(); + try ( InputStream is = + Maven.class.getResourceAsStream( "/META-INF/maven/org.apache.maven/maven-core/pom.properties" ) ) + { + props.load( is ); + version = props.getProperty( "version" ); + } + catch ( IOException e ) + { + // noop + } + } + return version; + } +} diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 0000000..ab72818 --- /dev/null +++ b/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> + + <!-- TODO move to 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>