blob: 96d0f539c188dc3df2ff540896a83e613639e420 [file] [log] [blame]
package org.apache.maven.plugins.install;
/*
* 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.File;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.maven.shared.transfer.repository.RepositoryManager;
/**
* Common fields for installation mojos.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public abstract class AbstractInstallMojo
extends AbstractMojo
{
@Component
protected RepositoryManager repositoryManager;
@Parameter( defaultValue = "${session}", required = true, readonly = true )
protected MavenSession session;
/**
* Gets the path of the specified artifact within the local repository. Note that the returned path need not exist
* (yet).
*
* @param buildingRequest {@link ProjectBuildingRequest}.
* @param artifact The artifact whose local repo path should be determined, must not be <code>null</code>.
* @return The absolute path to the artifact when installed, never <code>null</code>.
*/
protected File getLocalRepoFile( ProjectBuildingRequest buildingRequest, Artifact artifact )
{
String path = repositoryManager.getPathForLocalArtifact( buildingRequest, artifact );
return new File( repositoryManager.getLocalRepositoryBasedir( buildingRequest ), path );
}
/**
* Gets the path of the specified artifact metadata within the local repository. Note that the returned path need
* not exist (yet).
*
* @param buildingRequest {@link ProjectBuildingRequest}.
* @param metadata The artifact metadata whose local repo path should be determined, must not be <code>null</code>.
* @return The absolute path to the artifact metadata when installed, never <code>null</code>.
*/
protected File getLocalRepoFile( ProjectBuildingRequest buildingRequest, ProjectArtifactMetadata metadata )
{
String path = repositoryManager.getPathForLocalMetadata( buildingRequest, metadata );
return new File( repositoryManager.getLocalRepositoryBasedir( buildingRequest ), path );
}
}