44import java .nio .file .Path ;
55import java .util .*;
66import org .codejive .jpm .json .AppInfo ;
7- import org .codejive .jpm .util .FileUtils ;
8- import org .codejive .jpm .util .ResolverUtils ;
9- import org .codejive .jpm .util .SearchUtils ;
10- import org .codejive .jpm .util .SyncStats ;
7+ import org .codejive .jpm .util .*;
118import org .eclipse .aether .artifact .Artifact ;
129import org .eclipse .aether .resolution .DependencyResolutionException ;
1310
11+ /** The class implementing all the jpm command actions. */
1412public class Jpm {
1513 private final Path directory ;
1614 private final boolean noLinks ;
@@ -20,41 +18,81 @@ private Jpm(Path directory, boolean noLinks) {
2018 this .noLinks = noLinks ;
2119 }
2220
21+ /**
22+ * Create a new {@link Builder} instance for the {@link Jpm} class.
23+ *
24+ * @return A new {@link Builder} instance.
25+ */
2326 public static Builder builder () {
2427 return new Builder ();
2528 }
2629
30+ /** Builder class for the {@link Jpm} class. */
2731 public static class Builder {
2832 private Path directory ;
2933 private boolean noLinks ;
3034
3135 private Builder () {}
3236
37+ /**
38+ * Set the target directory to use for the jpm commands.
39+ *
40+ * @param directory The target directory.
41+ * @return The builder instance for chaining.
42+ */
3343 public Builder directory (Path directory ) {
3444 this .directory = directory ;
3545 return this ;
3646 }
3747
48+ /**
49+ * Set whether to create symbolic links or not.
50+ *
51+ * @param noLinks Whether to create symbolic links or not.
52+ * @return The builder instance for chaining.
53+ */
3854 public Builder noLinks (boolean noLinks ) {
3955 this .noLinks = noLinks ;
4056 return this ;
4157 }
4258
59+ /**
60+ * Builds the {@link Jpm} instance.
61+ *
62+ * @return A {@link Jpm} instance.
63+ */
4364 public Jpm build () {
4465 return new Jpm (directory , noLinks );
4566 }
4667 }
4768
69+ /**
70+ * Copies the given artifacts to the target directory.
71+ *
72+ * @param artifactNames The artifacts to copy.
73+ * @param sync Whether to sync the target directory or not.
74+ * @return An instance of {@link SyncStats} containing the statistics of the copy operation.
75+ * @throws IOException If an error occurred during the copy operation.
76+ * @throws DependencyResolutionException If an error occurred during the dependency resolution.
77+ */
4878 public SyncStats copy (String [] artifactNames , boolean sync )
4979 throws IOException , DependencyResolutionException {
5080 List <Path > files = ResolverUtils .resolveArtifactPaths (artifactNames );
5181 return FileUtils .syncArtifacts (files , directory , noLinks , !sync );
5282 }
5383
84+ /**
85+ * Searches for artifacts matching the given pattern.
86+ *
87+ * @param artifactPattern The pattern to search for.
88+ * @param count The maximum number of results to return.
89+ * @return An array of artifact names matching the given pattern.
90+ * @throws IOException If an error occurred during the search.
91+ */
5492 public String [] search (String artifactPattern , int count ) throws IOException {
5593 List <Artifact > artifacts = new ArrayList <>();
5694 int max = count <= 0 || count > 200 ? 200 : count ;
57- SearchUtils . SearchResult result = SearchUtils .findArtifacts (artifactPattern , max );
95+ SearchResult result = SearchUtils .findArtifacts (artifactPattern , max );
5896 while (result != null ) {
5997 artifacts .addAll (result .artifacts );
6098 result = count <= 0 ? SearchUtils .findNextArtifacts (result ) : null ;
@@ -66,6 +104,17 @@ private static String artifactGav(Artifact artifact) {
66104 return artifact .getGroupId () + ":" + artifact .getArtifactId () + ":" + artifact .getVersion ();
67105 }
68106
107+ /**
108+ * Installs the given artifacts to the target directory while also registering them as
109+ * dependencies in the app.json file in the current directory. If no artifacts are given, all
110+ * dependencies in the app.json file will be installed. NB: "installation" in this context
111+ * basically means sync-copying the artifacts to the target directory.
112+ *
113+ * @param artifactNames The artifacts to install.
114+ * @return An instance of {@link SyncStats} containing the statistics of the install operation.
115+ * @throws IOException If an error occurred during the install operation.
116+ * @throws DependencyResolutionException If an error occurred during the dependency resolution.
117+ */
69118 public SyncStats install (String [] artifactNames )
70119 throws IOException , DependencyResolutionException {
71120 AppInfo appInfo = AppInfo .read ();
@@ -88,6 +137,15 @@ public SyncStats install(String[] artifactNames)
88137 }
89138 }
90139
140+ /**
141+ * Returns the paths of the given artifacts. If no artifacts are given, the paths for all
142+ * dependencies in the app.json file will be returned instead.
143+ *
144+ * @param artifactNames The artifacts to get the paths for.
145+ * @return A list of paths.
146+ * @throws DependencyResolutionException If an error occurred during the dependency resolution.
147+ * @throws IOException If an error occurred during the operation.
148+ */
91149 public List <Path > path (String [] artifactNames )
92150 throws DependencyResolutionException , IOException {
93151 AppInfo appInfo = AppInfo .read ();
0 commit comments