1 package com.atlassian.maven.plugins.licenses;
2
3 import java.io.File;
4
5 import org.apache.maven.artifact.Artifact;
6 import org.apache.maven.artifact.deployer.ArtifactDeployer;
7 import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
8 import org.apache.maven.artifact.repository.ArtifactRepository;
9 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
10 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
11 import org.apache.maven.model.License;
12 import org.apache.maven.plugin.MojoExecutionException;
13 import org.apache.maven.project.MavenProject;
14
15
16
17
18
19
20
21
22
23
24 public class DeployMojo extends DownloadMojo
25 {
26
27 private ArtifactDeployer deployer;
28
29
30
31
32
33
34 private String repositoryUrl;
35
36
37
38
39 private String repositoryId;
40
41
42
43
44
45
46
47 private boolean forceDeploy;
48
49
50
51
52 protected void downloadLicense(MavenProject depProject, License license, String fileName)
53 throws MojoExecutionException
54 {
55 super.downloadLicense(depProject, license, fileName);
56
57
58 Artifact artifact = depProject.getArtifact();
59 Artifact licenseArtifact = artifactFactory.createArtifact(artifact.getGroupId(), artifact.getArtifactId(),
60 artifact.getVersion(), null, AbstractLicensesMojo.LICENSE_TYPE);
61
62 File file = new File(fileName);
63 ArtifactRepository licenseRepository = new DefaultArtifactRepository(repositoryId, repositoryUrl,
64 new DefaultRepositoryLayout());
65
66 try
67 {
68
69
70 if (!forceDeploy && findLicenseInRepository(artifact) != null)
71 {
72 getLog().info("License for artifact " + artifact + " is found in the repository");
73 return;
74 }
75
76 deployer.deploy(file, artifact, licenseRepository, localRepository);
77 }
78 catch (ArtifactDeploymentException e)
79 {
80 throw new MojoExecutionException("Failed to deploy license artifact " + licenseArtifact, e);
81 }
82 }
83 }