View Javadoc
1   package org.codehaus.mojo.wagon;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.List;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.artifact.factory.ArtifactFactory;
27  import org.apache.maven.artifact.repository.ArtifactRepository;
28  import org.apache.maven.artifact.resolver.ArtifactResolver;
29  import org.apache.maven.plugin.AbstractMojo;
30  import org.apache.maven.plugin.MojoExecutionException;
31  import org.apache.maven.plugins.annotations.Component;
32  import org.apache.maven.plugins.annotations.Mojo;
33  import org.apache.maven.plugins.annotations.Parameter;
34  import org.codehaus.plexus.util.FileUtils;
35  
36  /**
37   * Work around for WAGON-407 to copy commons-io, commons-lang, and jsoup to ${maven.home}/lib/ext directory.
38   */
39  @Mojo( name = "update-maven-3" , requiresProject = false)
40  public class UpdateMaven3Mojo
41      extends AbstractMojo
42  {
43  
44      @Component
45      private ArtifactResolver artifactResolver;
46  
47      @Component
48      private ArtifactFactory artifactFactory;
49  
50      @Parameter( defaultValue = "${project.remoteArtifactRepositories}")
51      private List<ArtifactRepository> remoteRepositories;
52  
53      @Parameter( defaultValue = "${localRepository}")
54      private ArtifactRepository localRepository;
55  
56      /**
57       * commons-io:commons-io version
58       */
59      @Parameter( property = "commonsIoVersion", defaultValue = "2.2")
60      private String commonsIoVersion = "2.2";
61  
62      /**
63       * commons-lang:commons-lang version
64       */
65      @Parameter( property = "commonsLangVersion", defaultValue = "2.6")
66      private String commonsLangVersion = "2.6";
67  
68      /**
69       * org.jsoup:jsoup version
70       */
71      @Parameter( property = "jsoupVersion", defaultValue = "1.7.2")
72      private String jsoupVersion = "1.7.2";
73  
74      @Override
75      public void execute()
76          throws MojoExecutionException
77      {
78          updateMavenLib( this.artifactFactory.createBuildArtifact( "commons-io", "commons-io", commonsIoVersion, "jar" ) );
79          updateMavenLib( this.artifactFactory.createBuildArtifact( "commons-lang", "commons-lang", commonsLangVersion,
80                                                                    "jar" ) );
81          updateMavenLib( this.artifactFactory.createBuildArtifact( "org.jsoup", "jsoup", jsoupVersion, "jar" ) );
82      }
83  
84      private void updateMavenLib( Artifact artifact )
85          throws MojoExecutionException
86      {
87          try
88          {
89              File mavenLibDir = new File( System.getProperty( "maven.home" ), "lib/ext" );
90              artifactResolver.resolve( artifact, remoteRepositories, localRepository );
91              this.getLog().info( "Copy " + artifact.getFile() + " to " + mavenLibDir );
92              FileUtils.copyFileToDirectory( artifact.getFile(), mavenLibDir );
93          }
94          catch ( Exception e )
95          {
96              throw new MojoExecutionException( "Unable to download artifact", e );
97          }
98  
99      }
100 }