@@ -58,12 +58,79 @@ public class InstallFileMojoTest
5858
5959 private final String LOCAL_REPO = "target/local-repo/" ;
6060
61+ private final String SPECIFIC_LOCAL_REPO = "target/specific-local-repo/" ;
62+
6163 public void setUp ()
6264 throws Exception
6365 {
6466 super .setUp ();
6567
6668 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 () );
67134 }
68135
69136 public void testInstallFileTestEnvironment ()
@@ -73,7 +140,7 @@ public void testInstallFileTestEnvironment()
73140
74141 InstallFileMojo mojo = (InstallFileMojo ) lookupMojo ( "install-file" , testPom );
75142
76- setVariableValueToObject ( mojo , "session" , createMavenSession () );
143+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
77144
78145 assertNotNull ( mojo );
79146 }
@@ -87,7 +154,7 @@ public void testBasicInstallFile()
87154
88155 assertNotNull ( mojo );
89156
90- setVariableValueToObject ( mojo , "session" , createMavenSession () );
157+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
91158
92159 assignValuesForParameter ( mojo );
93160
@@ -111,7 +178,7 @@ public void testInstallFileWithClassifier()
111178
112179 assertNotNull ( mojo );
113180
114- setVariableValueToObject ( mojo , "session" , createMavenSession () );
181+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
115182
116183 assignValuesForParameter ( mojo );
117184
@@ -137,7 +204,7 @@ public void testInstallFileWithGeneratePom()
137204
138205 assertNotNull ( mojo );
139206
140- setVariableValueToObject ( mojo , "session" , createMavenSession () );
207+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
141208
142209 assignValuesForParameter ( mojo );
143210
@@ -178,7 +245,7 @@ public void testInstallFileWithPomFile()
178245
179246 assertNotNull ( mojo );
180247
181- setVariableValueToObject ( mojo , "session" , createMavenSession () );
248+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
182249
183250 assignValuesForParameter ( mojo );
184251
@@ -211,7 +278,7 @@ public void testInstallFileWithPomAsPackaging()
211278
212279 assertNotNull ( mojo );
213280
214- setVariableValueToObject ( mojo , "session" , createMavenSession () );
281+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
215282
216283 assignValuesForParameter ( mojo );
217284
@@ -239,7 +306,7 @@ public void testInstallFile()
239306
240307 assertNotNull ( mojo );
241308
242- setVariableValueToObject ( mojo , "session" , createMavenSession () );
309+ setVariableValueToObject ( mojo , "session" , createMavenSession ( LOCAL_REPO ) );
243310
244311 assignValuesForParameter ( mojo );
245312
@@ -276,13 +343,14 @@ private String dotToSlashReplacer( String parameter )
276343 return parameter .replace ( '.' , '/' );
277344 }
278345
279- private MavenSession createMavenSession () throws NoLocalRepositoryManagerException
346+ private MavenSession createMavenSession ( String localRepositoryBaseDir )
347+ throws NoLocalRepositoryManagerException
280348 {
281349 MavenSession session = mock ( MavenSession .class );
282350 DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession ();
283351 repositorySession .setLocalRepositoryManager (
284352 new EnhancedLocalRepositoryManagerFactory ().newInstance (
285- repositorySession , new LocalRepository ( LOCAL_REPO )
353+ repositorySession , new LocalRepository ( localRepositoryBaseDir )
286354 )
287355 );
288356 ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest ();
0 commit comments