@@ -58,12 +58,79 @@ public class InstallFileMojoTest
58
58
59
59
private final String LOCAL_REPO = "target/local-repo/" ;
60
60
61
+ private final String SPECIFIC_LOCAL_REPO = "target/specific-local-repo/" ;
62
+
61
63
public void setUp ()
62
64
throws Exception
63
65
{
64
66
super .setUp ();
65
67
66
68
FileUtils .deleteDirectory ( new File ( getBasedir () + "/" + LOCAL_REPO ) );
69
+ FileUtils .deleteDirectory ( new File ( getBasedir () + "/" + SPECIFIC_LOCAL_REPO ) );
70
+ }
71
+
72
+ public void testInstallFileFromLocalRepositoryToLocalRepositoryPath ()
73
+ throws Exception
74
+ {
75
+ File localRepository =
76
+ new File ( getBasedir (), "target/test-classes/unit/install-file-from-local-repository-test/target" );
77
+
78
+ File testPom = new File ( localRepository .getParentFile (), "plugin-config.xml" );
79
+
80
+ InstallFileMojo mojo = (InstallFileMojo ) lookupMojo ( "install-file" , testPom );
81
+
82
+ assertNotNull ( mojo );
83
+
84
+ setVariableValueToObject ( mojo , "session" , createMavenSession ( localRepository .getAbsolutePath () ) );
85
+
86
+ File specificLocalRepositoryPath = new File ( getBasedir () + "/" + SPECIFIC_LOCAL_REPO );
87
+
88
+ setVariableValueToObject ( mojo , "localRepositoryPath" , specificLocalRepositoryPath );
89
+
90
+ assignValuesForParameter ( mojo );
91
+
92
+ mojo .execute ();
93
+
94
+ String localPath = getBasedir () + "/" + SPECIFIC_LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/"
95
+ + artifactId + "-" + version ;
96
+
97
+ File installedArtifact = new File ( localPath + "." + "jar" );
98
+
99
+ assertTrue ( installedArtifact .exists () );
100
+
101
+ assertEquals ( FileUtils .getFiles ( new File ( SPECIFIC_LOCAL_REPO ), null , null ).toString (), 5 ,
102
+ FileUtils .getFiles ( new File ( SPECIFIC_LOCAL_REPO ), null , null ).size () );
103
+ }
104
+
105
+ public void testInstallFileWithLocalRepositoryPath ()
106
+ throws Exception
107
+ {
108
+ File testPom =
109
+ new File ( getBasedir (), "target/test-classes/unit/install-file-with-checksum/" + "plugin-config.xml" );
110
+
111
+ InstallFileMojo mojo = (InstallFileMojo ) lookupMojo ( "install-file" , testPom );
112
+
113
+ assertNotNull ( mojo );
114
+
115
+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
116
+
117
+ File specificLocalRepositoryPath = new File ( getBasedir () + "/" + SPECIFIC_LOCAL_REPO );
118
+
119
+ setVariableValueToObject ( mojo , "localRepositoryPath" , specificLocalRepositoryPath );
120
+
121
+ assignValuesForParameter ( mojo );
122
+
123
+ mojo .execute ();
124
+
125
+ String localPath = getBasedir () + "/" + SPECIFIC_LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/"
126
+ + artifactId + "-" + version ;
127
+
128
+ File installedArtifact = new File ( localPath + "." + "jar" );
129
+
130
+ assertTrue ( installedArtifact .exists () );
131
+
132
+ assertEquals ( FileUtils .getFiles ( new File ( SPECIFIC_LOCAL_REPO ), null , null ).toString (), 5 ,
133
+ FileUtils .getFiles ( new File ( SPECIFIC_LOCAL_REPO ), null , null ).size () );
67
134
}
68
135
69
136
public void testInstallFileTestEnvironment ()
@@ -73,7 +140,7 @@ public void testInstallFileTestEnvironment()
73
140
74
141
InstallFileMojo mojo = (InstallFileMojo ) lookupMojo ( "install-file" , testPom );
75
142
76
- setVariableValueToObject ( mojo , "session" , createMavenSession () );
143
+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
77
144
78
145
assertNotNull ( mojo );
79
146
}
@@ -87,7 +154,7 @@ public void testBasicInstallFile()
87
154
88
155
assertNotNull ( mojo );
89
156
90
- setVariableValueToObject ( mojo , "session" , createMavenSession () );
157
+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
91
158
92
159
assignValuesForParameter ( mojo );
93
160
@@ -111,7 +178,7 @@ public void testInstallFileWithClassifier()
111
178
112
179
assertNotNull ( mojo );
113
180
114
- setVariableValueToObject ( mojo , "session" , createMavenSession () );
181
+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
115
182
116
183
assignValuesForParameter ( mojo );
117
184
@@ -137,7 +204,7 @@ public void testInstallFileWithGeneratePom()
137
204
138
205
assertNotNull ( mojo );
139
206
140
- setVariableValueToObject ( mojo , "session" , createMavenSession () );
207
+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
141
208
142
209
assignValuesForParameter ( mojo );
143
210
@@ -178,7 +245,7 @@ public void testInstallFileWithPomFile()
178
245
179
246
assertNotNull ( mojo );
180
247
181
- setVariableValueToObject ( mojo , "session" , createMavenSession () );
248
+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
182
249
183
250
assignValuesForParameter ( mojo );
184
251
@@ -211,7 +278,7 @@ public void testInstallFileWithPomAsPackaging()
211
278
212
279
assertNotNull ( mojo );
213
280
214
- setVariableValueToObject ( mojo , "session" , createMavenSession () );
281
+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
215
282
216
283
assignValuesForParameter ( mojo );
217
284
@@ -239,7 +306,7 @@ public void testInstallFile()
239
306
240
307
assertNotNull ( mojo );
241
308
242
- setVariableValueToObject ( mojo , "session" , createMavenSession () );
309
+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
243
310
244
311
assignValuesForParameter ( mojo );
245
312
@@ -276,13 +343,14 @@ private String dotToSlashReplacer( String parameter )
276
343
return parameter .replace ( '.' , '/' );
277
344
}
278
345
279
- private MavenSession createMavenSession () throws NoLocalRepositoryManagerException
346
+ private MavenSession createMavenSession ( String localRepositoryBaseDir )
347
+ throws NoLocalRepositoryManagerException
280
348
{
281
349
MavenSession session = mock ( MavenSession .class );
282
350
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession ();
283
351
repositorySession .setLocalRepositoryManager (
284
352
new EnhancedLocalRepositoryManagerFactory ().newInstance (
285
- repositorySession , new LocalRepository ( LOCAL_REPO )
353
+ repositorySession , new LocalRepository ( localRepositoryBaseDir )
286
354
)
287
355
);
288
356
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest ();
0 commit comments