use of org.apache.maven.shared.project.install.ProjectInstallerRequest in project maven-plugins by apache.
the class InstallFileMojo method execute.
/**
* @see org.apache.maven.plugin.Mojo#execute()
*/
public void execute() throws MojoExecutionException, MojoFailureException {
if (!file.exists()) {
String message = "The specified file '" + file.getPath() + "' not exists";
getLog().error(message);
throw new MojoFailureException(message);
}
ProjectBuildingRequest buildingRequest = session.getProjectBuildingRequest();
// ----------------------------------------------------------------------
if (localRepositoryPath != null) {
buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, localRepositoryPath);
getLog().debug("localRepoPath: " + repositoryManager.getLocalRepositoryBasedir(buildingRequest));
}
File temporaryPom = null;
if (pomFile != null) {
processModel(readModel(pomFile));
} else {
temporaryPom = readingPomFromJarFile();
pomFile = temporaryPom;
}
MavenProject project = createMavenProject();
// We need to set a new ArtifactHandler otherwise
// the extension will be set to the packaging type
// which is sometimes wrong.
DefaultArtifactHandler ah = new DefaultArtifactHandler(packaging);
ah.setExtension(FileUtils.getExtension(file.getName()));
project.getArtifact().setArtifactHandler(ah);
Artifact artifact = project.getArtifact();
if (file.equals(getLocalRepoFile(buildingRequest, artifact))) {
throw new MojoFailureException("Cannot install artifact. " + "Artifact is already in the local repository.\n\nFile in question is: " + file + "\n");
}
if (classifier == null) {
artifact.setFile(file);
if ("pom".equals(packaging)) {
project.setFile(file);
}
} else {
projectHelper.attachArtifact(project, packaging, classifier, file);
}
if (!"pom".equals(packaging)) {
if (pomFile != null) {
if (classifier == null) {
artifact.addMetadata(new ProjectArtifactMetadata(artifact, pomFile));
} else {
project.setFile(pomFile);
}
} else {
temporaryPom = generatePomFile();
ProjectArtifactMetadata pomMetadata = new ProjectArtifactMetadata(artifact, temporaryPom);
if (Boolean.TRUE.equals(generatePom) || (generatePom == null && !getLocalRepoFile(buildingRequest, pomMetadata).exists())) {
getLog().debug("Installing generated POM");
if (classifier == null) {
artifact.addMetadata(pomMetadata);
} else {
project.setFile(temporaryPom);
}
} else if (generatePom == null) {
getLog().debug("Skipping installation of generated POM, already present in local repository");
}
}
}
if (sources != null) {
projectHelper.attachArtifact(project, "jar", "sources", sources);
}
if (javadoc != null) {
projectHelper.attachArtifact(project, "jar", "javadoc", javadoc);
}
try {
// CHECKSTYLE_OFF: LineLength
ProjectInstallerRequest projectInstallerRequest = new ProjectInstallerRequest().setProject(project).setCreateChecksum(createChecksum).setUpdateReleaseInfo(updateReleaseInfo);
// CHECKSTYLE_ON: LineLength
installer.install(buildingRequest, projectInstallerRequest);
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
if (temporaryPom != null) {
// noinspection ResultOfMethodCallIgnored
temporaryPom.delete();
}
}
}
use of org.apache.maven.shared.project.install.ProjectInstallerRequest in project maven-plugins by apache.
the class InstallMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
boolean addedInstallRequest = false;
if (skip) {
getLog().info("Skipping artifact installation");
} else {
// CHECKSTYLE_OFF: LineLength
ProjectInstallerRequest projectInstallerRequest = new ProjectInstallerRequest().setProject(project).setCreateChecksum(createChecksum).setUpdateReleaseInfo(updateReleaseInfo);
if (!installAtEnd) {
installProject(session.getProjectBuildingRequest(), projectInstallerRequest);
} else {
INSTALLREQUESTS.add(projectInstallerRequest);
addedInstallRequest = true;
}
}
boolean projectsReady = READYPROJECTSCOUTNER.incrementAndGet() == reactorProjects.size();
if (projectsReady) {
synchronized (INSTALLREQUESTS) {
while (!INSTALLREQUESTS.isEmpty()) {
installProject(session.getProjectBuildingRequest(), INSTALLREQUESTS.remove(0));
}
}
} else if (addedInstallRequest) {
getLog().info("Installing " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + " at end");
}
}
Aggregations