View Javadoc
1   package org.apache.maven.plugins.install;
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.Artifact;
25  import org.apache.maven.execution.MavenSession;
26  import org.apache.maven.plugin.AbstractMojo;
27  import org.apache.maven.plugins.annotations.Component;
28  import org.apache.maven.plugins.annotations.Parameter;
29  import org.apache.maven.project.ProjectBuildingRequest;
30  import org.apache.maven.project.artifact.ProjectArtifactMetadata;
31  import org.apache.maven.shared.transfer.repository.RepositoryManager;
32  
33  /**
34   * Common fields for installation mojos.
35   *
36   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37   */
38  public abstract class AbstractInstallMojo
39      extends AbstractMojo
40  {
41  
42      @Component
43      protected RepositoryManager repositoryManager;
44  
45      @Parameter( defaultValue = "${session}", required = true, readonly = true )
46      protected MavenSession session;
47  
48      /**
49       * Gets the path of the specified artifact within the local repository. Note that the returned path need not exist
50       * (yet).
51       *
52       * @param buildingRequest {@link ProjectBuildingRequest}.
53       * @param artifact The artifact whose local repo path should be determined, must not be <code>null</code>.
54       * @return The absolute path to the artifact when installed, never <code>null</code>.
55       */
56      protected File getLocalRepoFile( ProjectBuildingRequest buildingRequest, Artifact artifact )
57      {
58          String path = repositoryManager.getPathForLocalArtifact( buildingRequest, artifact );
59          return new File( repositoryManager.getLocalRepositoryBasedir( buildingRequest ), path );
60      }
61  
62      /**
63       * Gets the path of the specified artifact metadata within the local repository. Note that the returned path need
64       * not exist (yet).
65       *
66       * @param buildingRequest {@link ProjectBuildingRequest}.
67       * @param metadata The artifact metadata whose local repo path should be determined, must not be <code>null</code>.
68       * @return The absolute path to the artifact metadata when installed, never <code>null</code>.
69       */
70      protected File getLocalRepoFile( ProjectBuildingRequest buildingRequest, ProjectArtifactMetadata metadata )
71      {
72          String path = repositoryManager.getPathForLocalMetadata( buildingRequest, metadata );
73          return new File( repositoryManager.getLocalRepositoryBasedir( buildingRequest ), path );
74      }
75  
76  }