1 package org.apache.maven.plugins.mavenone;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.artifact.deployer.ArtifactDeployer;
28 import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
29 import org.apache.maven.artifact.repository.ArtifactRepository;
30 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
31 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
32 import org.apache.maven.plugin.AbstractMojo;
33 import org.apache.maven.plugin.MojoExecutionException;
34
35
36
37
38
39
40
41 public class MavenOneRepositoryDeployMojo
42 extends AbstractMojo
43 {
44
45
46
47
48
49 protected String packaging;
50
51
52
53
54
55
56 private File pomFile;
57
58
59
60
61
62
63 private Artifact artifact;
64
65
66
67
68
69 protected ArtifactDeployer deployer;
70
71
72
73
74
75 protected ArtifactRepositoryFactory factory;
76
77
78
79
80
81
82
83 protected String remoteRepositoryId;
84
85
86
87
88
89
90
91 protected String remoteRepositoryUrl;
92
93
94
95
96
97
98 private ArtifactRepositoryLayout legacyLayout;
99
100
101
102
103
104
105 private ArtifactRepository localRepository;
106
107
108
109
110
111
112 private List attachedArtifacts;
113
114 public void execute()
115 throws MojoExecutionException
116 {
117 try
118 {
119 ArtifactRepository deploymentRepository = factory.createDeploymentArtifactRepository( remoteRepositoryId,
120 remoteRepositoryUrl,
121 legacyLayout, false );
122
123 boolean isPomArtifact = "pom".equals( packaging );
124
125 if ( isPomArtifact )
126 {
127 deployer.deploy( pomFile, artifact, deploymentRepository, localRepository );
128 }
129 else
130 {
131 File file = artifact.getFile();
132 if ( file == null )
133 {
134 throw new MojoExecutionException(
135 "The packaging for this project did not assign a file to the build artifact" );
136 }
137 deployer.deploy( file, artifact, deploymentRepository, localRepository );
138 }
139
140 if ( attachedArtifacts != null && !attachedArtifacts.isEmpty() )
141 {
142 for ( Iterator i = attachedArtifacts.iterator(); i.hasNext(); )
143 {
144 Artifact attached = (Artifact) i.next();
145
146 deployer.deploy( attached.getFile(), attached, deploymentRepository, localRepository );
147 }
148 }
149 }
150 catch ( ArtifactDeploymentException e )
151 {
152 throw new MojoExecutionException( e.getMessage(), e );
153 }
154 }
155 }