@@ -155,6 +155,38 @@ public void testBasicInstallWithAttachedArtifacts() throws Exception {
155
155
assertEquals (13 , FileUtils .getFiles (new File (LOCAL_REPO ), null , null ).size ());
156
156
}
157
157
158
+ public void testNonPomInstallWithAttachedArtifactsOnly () throws Exception {
159
+ File testPom = new File (
160
+ getBasedir (),
161
+ "target/test-classes/unit/basic-install-test-with-attached-artifacts/" + "plugin-config.xml" );
162
+
163
+ AbstractMojo mojo = (AbstractMojo ) lookupMojo ("install" , testPom );
164
+
165
+ assertNotNull (mojo );
166
+
167
+ MavenProject project = (MavenProject ) getVariableValueFromObject (mojo , "project" );
168
+ updateMavenProject (project );
169
+
170
+ setVariableValueToObject (mojo , "pluginContext" , new ConcurrentHashMap <>());
171
+ setVariableValueToObject (mojo , "pluginDescriptor" , new PluginDescriptor ());
172
+ setVariableValueToObject (mojo , "session" , createMavenSession ());
173
+
174
+ artifact = (InstallArtifactStub ) project .getArtifact ();
175
+
176
+ artifact .setFile (null );
177
+
178
+ try {
179
+ mojo .execute ();
180
+ fail ("Did not throw mojo execution exception" );
181
+ } catch (MojoExecutionException e ) {
182
+ // expected, message should include artifactId
183
+ assertEquals (
184
+ "The packaging plugin for project maven-install-test did not assign a main file to the project "
185
+ + "but it has attachments. Change packaging to 'pom'." ,
186
+ e .getMessage ());
187
+ }
188
+ }
189
+
158
190
public void testUpdateReleaseParamSetToTrue () throws Exception {
159
191
File testPom = new File (getBasedir (), "target/test-classes/unit/configured-install-test/plugin-config.xml" );
160
192
@@ -210,15 +242,44 @@ public void testInstallIfArtifactFileIsNull() throws Exception {
210
242
211
243
try {
212
244
mojo .execute ();
213
-
214
245
fail ("Did not throw mojo execution exception" );
215
246
} catch (MojoExecutionException e ) {
216
- // expected
247
+ // expected, message should include artifactId
248
+ assertEquals (
249
+ "The packaging plugin for project maven-install-test did not assign a file to the build artifact" ,
250
+ e .getMessage ());
217
251
}
218
252
219
253
assertFalse (new File (LOCAL_REPO ).exists ());
220
254
}
221
255
256
+ public void testInstallIfProjectFileIsNull () throws Exception {
257
+ File testPom = new File (getBasedir (), "target/test-classes/unit/basic-install-test/plugin-config.xml" );
258
+
259
+ AbstractMojo mojo = (AbstractMojo ) lookupMojo ("install" , testPom );
260
+
261
+ assertNotNull (mojo );
262
+
263
+ MavenProject project = (MavenProject ) getVariableValueFromObject (mojo , "project" );
264
+ updateMavenProject (project );
265
+
266
+ setVariableValueToObject (mojo , "pluginContext" , new ConcurrentHashMap <>());
267
+ setVariableValueToObject (mojo , "pluginDescriptor" , new PluginDescriptor ());
268
+ setVariableValueToObject (mojo , "session" , createMavenSession ());
269
+
270
+ project .setFile (null );
271
+
272
+ assertNull (project .getFile ());
273
+
274
+ try {
275
+ mojo .execute ();
276
+ fail ("Did not throw mojo execution exception" );
277
+ } catch (MojoExecutionException e ) {
278
+ // expected, message should include artifactId
279
+ assertEquals ("The POM for project maven-install-test could not be attached" , e .getMessage ());
280
+ }
281
+ }
282
+
222
283
public void testInstallIfPackagingIsPom () throws Exception {
223
284
File testPom = new File (
224
285
getBasedir (), "target/test-classes/unit/basic-install-test-packaging-pom/" + "plugin-config.xml" );
0 commit comments