View Javadoc
1   package org.apache.maven.plugin.coreit;
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  
24  import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
25  import org.apache.maven.plugin.MojoExecutionException;
26  
27  /**
28   * Installs the project artifacts into a local repository with a custom base directory and a custom layout.
29   *
30   * @goal install-custom
31   *
32   * @author Benjamin Bentmann
33   *
34   */
35  public class InstallCustomMojo
36      extends InstallMojo
37  {
38  
39      /**
40       * @component
41       */
42      private ArtifactRepositoryFactory repositoryFactory;
43  
44      /**
45       * The base directory of the local repository to install to.
46       *
47       * @parameter property="install.localRepoDir"
48       */
49      private File localRepoDir;
50  
51      /**
52       * Runs this mojo.
53       *
54       * @throws MojoExecutionException If any artifact could not be installed.
55       */
56      public void execute()
57          throws MojoExecutionException
58      {
59          try
60          {
61              String url = "file://" + localRepoDir.toURL().getPath();
62  
63              localRepository =
64                  repositoryFactory.createArtifactRepository( localRepository.getId(), url, new CustomRepositoryLayout(),
65                                                              localRepository.getSnapshots(),
66                                                              localRepository.getReleases() );
67          }
68          catch ( Exception e )
69          {
70              throw new MojoExecutionException( "Failed to create custom local repository", e );
71          }
72  
73          super.execute();
74      }
75  
76  }