33import java .io .IOException ;
44import java .nio .file .Path ;
55import java .util .*;
6- import org .codejive .jpm .json .AppInfo ;
6+ import org .codejive .jpm .config .AppInfo ;
77import org .codejive .jpm .util .*;
88import org .eclipse .aether .artifact .Artifact ;
99import org .eclipse .aether .resolution .DependencyResolutionException ;
@@ -91,7 +91,22 @@ public Jpm build() {
9191 */
9292 public SyncStats copy (String [] artifactNames , boolean sync )
9393 throws IOException , DependencyResolutionException {
94- List <Path > files = Resolver .create (artifactNames ).resolvePaths ();
94+ return copy (artifactNames , Collections .emptyMap (), sync );
95+ }
96+
97+ /**
98+ * Copies the given artifacts to the target directory.
99+ *
100+ * @param artifactNames The artifacts to copy.
101+ * @param repos A map of additional repository names to URLs where artifacts can be found.
102+ * @param sync Whether to sync the target directory or not.
103+ * @return An instance of {@link SyncStats} containing the statistics of the copy operation.
104+ * @throws IOException If an error occurred during the copy operation.
105+ * @throws DependencyResolutionException If an error occurred during the dependency resolution.
106+ */
107+ public SyncStats copy (String [] artifactNames , Map <String , String > repos , boolean sync )
108+ throws IOException , DependencyResolutionException {
109+ List <Path > files = Resolver .create (artifactNames , repos ).resolvePaths ();
95110 return FileUtils .syncArtifacts (files , directory , noLinks , !sync );
96111 }
97112
@@ -131,10 +146,28 @@ private static String artifactGav(Artifact artifact) {
131146 */
132147 public SyncStats install (String [] artifactNames )
133148 throws IOException , DependencyResolutionException {
149+ return install (artifactNames , Collections .emptyMap ());
150+ }
151+
152+ /**
153+ * Installs the given artifacts to the target directory while also registering them as
154+ * dependencies in the app.yml file in the current directory. If no artifacts are given, all
155+ * dependencies in the app.yml file will be installed. NB: "installation" in this context
156+ * basically means sync-copying the artifacts to the target directory.
157+ *
158+ * @param artifactNames The artifacts to install.
159+ * @param extraRepos A map of additional repository names to URLs where artifacts can be found.
160+ * @return An instance of {@link SyncStats} containing the statistics of the install operation.
161+ * @throws IOException If an error occurred during the install operation.
162+ * @throws DependencyResolutionException If an error occurred during the dependency resolution.
163+ */
164+ public SyncStats install (String [] artifactNames , Map <String , String > extraRepos )
165+ throws IOException , DependencyResolutionException {
134166 AppInfo appInfo = AppInfo .read ();
135167 String [] artifacts = getArtifacts (artifactNames , appInfo );
168+ Map <String , String > repos = getRepositories (extraRepos , appInfo );
136169 if (artifacts .length > 0 ) {
137- List <Path > files = Resolver .create (artifacts ).resolvePaths ();
170+ List <Path > files = Resolver .create (artifacts , repos ).resolvePaths ();
138171 SyncStats stats = FileUtils .syncArtifacts (files , directory , noLinks , true );
139172 if (artifactNames .length > 0 ) {
140173 for (String dep : artifactNames ) {
@@ -162,10 +195,26 @@ public SyncStats install(String[] artifactNames)
162195 */
163196 public List <Path > path (String [] artifactNames )
164197 throws DependencyResolutionException , IOException {
198+ return path (artifactNames , Collections .emptyMap ());
199+ }
200+
201+ /**
202+ * Returns the paths of the given artifacts. If no artifacts are given, the paths for all
203+ * dependencies in the app.yml file will be returned instead.
204+ *
205+ * @param artifactNames The artifacts to get the paths for.
206+ * @param extraRepos A map of additional repository names to URLs where artifacts can be found.
207+ * @return A list of paths.
208+ * @throws DependencyResolutionException If an error occurred during the dependency resolution.
209+ * @throws IOException If an error occurred during the operation.
210+ */
211+ public List <Path > path (String [] artifactNames , Map <String , String > extraRepos )
212+ throws DependencyResolutionException , IOException {
165213 AppInfo appInfo = AppInfo .read ();
166214 String [] deps = getArtifacts (artifactNames , appInfo );
215+ Map <String , String > repos = getRepositories (extraRepos , appInfo );
167216 if (deps .length > 0 ) {
168- return Resolver .create (deps ).resolvePaths ();
217+ return Resolver .create (deps , repos ).resolvePaths ();
169218 } else {
170219 return Collections .emptyList ();
171220 }
@@ -181,6 +230,12 @@ private static String[] getArtifacts(String[] artifactNames, AppInfo appInfo) {
181230 return deps ;
182231 }
183232
233+ private Map <String , String > getRepositories (Map <String , String > extraRepos , AppInfo appInfo ) {
234+ Map <String , String > repos = new HashMap <>(appInfo .repositories );
235+ repos .putAll (extraRepos );
236+ return repos ;
237+ }
238+
184239 /**
185240 * Executes an action defined in app.yml file.
186241 *
0 commit comments