1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package npanday.plugin;
20
21 import org.apache.maven.plugin.AbstractMojo;
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugin.MojoFailureException;
24 import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
25 import org.apache.maven.artifact.deployer.ArtifactDeployer;
26 import org.apache.maven.artifact.repository.ArtifactRepository;
27 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
28 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
29 import org.apache.maven.artifact.Artifact;
30 import org.apache.maven.artifact.metadata.ArtifactMetadata;
31 import org.apache.maven.artifact.factory.ArtifactFactory;
32 import org.apache.maven.project.artifact.ProjectArtifactMetadata;
33
34 import java.io.File;
35 import java.util.HashMap;
36
37 /**
38 * Deploys the .NET assembly file to the remote repository.
39 *
40 * @goal deploy-file
41 * @phase deploy
42 * @requiresProject false
43 * @description Deploys the .NET assembly file to the remote repository
44 */
45 public class DeployFileMojo
46 extends AbstractMojo
47 {
48
49 /**
50 * The local Maven repository.
51 *
52 * @parameter expression="${localRepository}"
53 * @required
54 */
55 private ArtifactRepository localRepository;
56
57 /**
58 * The artifact file to deploy.
59 *
60 * @parameter expression = "${file}
61 * @required
62 */
63 private File artifactFile;
64
65 /**
66 * The pom file of the artifact to deploy.
67 *
68 * @parameter expression = "${pomFile}
69 */
70 private File pomFile;
71
72 /**
73 * The groupId of the artifact to deploy.
74 *
75 * @parameter expression = "${groupId}
76 * @required
77 */
78 private String groupId;
79
80 /**
81 * The artifact id of the artifact to deploy.
82 *
83 * @parameter expression = "${artifactId}
84 * @required
85 */
86 private String artifactId;
87
88 /**
89 * The version of the artifact to deploy.
90 *
91 * @parameter expression = "${artifactVersion}
92 * @required
93 */
94 private String version;
95
96 /**
97 * The id of the repository to deploy the artifact to.
98 *
99 * @parameter expression = "${repositoryId}
100 */
101 private String repositoryId;
102
103
104 /**
105 * The artifact packaging type.
106 *
107 * @parameter expression = "${packaging}
108 * @required
109 */
110 private String packaging;
111
112 /**
113 * The project classifier type
114 *
115 * @parameter
116 */
117 private String classifier;
118
119 /**
120 * @component
121 */
122 private ArtifactDeployer artifactDeployer;
123
124 /**
125 * Component used to create a repository
126 *
127 * @component
128 */
129 private ArtifactRepositoryFactory repositoryFactory;
130
131 /**
132 * @component
133 */
134 private ArtifactFactory artifactFactory;
135
136 /**
137 * The URL of the repository to deploy the artifact to.
138 *
139 * @parameter expression="${url}"
140 * @required
141 */
142 private String url;
143 static HashMap<String, String> __packagingExtensions = new HashMap<String, String>();
144 static
145 {
146 __packagingExtensions.put("exe", "exe");
147 __packagingExtensions.put("winexe", "exe");
148 __packagingExtensions.put("dll", "dll");
149 __packagingExtensions.put("library", "dll");
150 }
151
152 public void execute()
153 throws MojoExecutionException, MojoFailureException
154 {
155
156 Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, packaging, __packagingExtensions.get(packaging) );
157 ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pomFile );
158 artifact.addMetadata( metadata );
159
160 ArtifactRepository deploymentRepository = repositoryFactory.createDeploymentArtifactRepository( repositoryId,
161 url,
162 new DefaultRepositoryLayout(),
163 true );
164
165 try
166 {
167 artifactDeployer.deploy( artifactFile, artifact, deploymentRepository, localRepository );
168 }
169 catch ( ArtifactDeploymentException e )
170 {
171 throw new MojoExecutionException( "NPANDAY-DEPLOY: Deploy Failed", e );
172 }
173 }
174 }