4
4
import java .nio .file .Path ;
5
5
import java .util .*;
6
6
import 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 .*;
11
8
import org .eclipse .aether .artifact .Artifact ;
12
9
import org .eclipse .aether .resolution .DependencyResolutionException ;
13
10
11
+ /** The class implementing all the jpm command actions. */
14
12
public class Jpm {
15
13
private final Path directory ;
16
14
private final boolean noLinks ;
@@ -20,41 +18,81 @@ private Jpm(Path directory, boolean noLinks) {
20
18
this .noLinks = noLinks ;
21
19
}
22
20
21
+ /**
22
+ * Create a new {@link Builder} instance for the {@link Jpm} class.
23
+ *
24
+ * @return A new {@link Builder} instance.
25
+ */
23
26
public static Builder builder () {
24
27
return new Builder ();
25
28
}
26
29
30
+ /** Builder class for the {@link Jpm} class. */
27
31
public static class Builder {
28
32
private Path directory ;
29
33
private boolean noLinks ;
30
34
31
35
private Builder () {}
32
36
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
+ */
33
43
public Builder directory (Path directory ) {
34
44
this .directory = directory ;
35
45
return this ;
36
46
}
37
47
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
+ */
38
54
public Builder noLinks (boolean noLinks ) {
39
55
this .noLinks = noLinks ;
40
56
return this ;
41
57
}
42
58
59
+ /**
60
+ * Builds the {@link Jpm} instance.
61
+ *
62
+ * @return A {@link Jpm} instance.
63
+ */
43
64
public Jpm build () {
44
65
return new Jpm (directory , noLinks );
45
66
}
46
67
}
47
68
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
+ */
48
78
public SyncStats copy (String [] artifactNames , boolean sync )
49
79
throws IOException , DependencyResolutionException {
50
80
List <Path > files = ResolverUtils .resolveArtifactPaths (artifactNames );
51
81
return FileUtils .syncArtifacts (files , directory , noLinks , !sync );
52
82
}
53
83
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
+ */
54
92
public String [] search (String artifactPattern , int count ) throws IOException {
55
93
List <Artifact > artifacts = new ArrayList <>();
56
94
int max = count <= 0 || count > 200 ? 200 : count ;
57
- SearchUtils . SearchResult result = SearchUtils .findArtifacts (artifactPattern , max );
95
+ SearchResult result = SearchUtils .findArtifacts (artifactPattern , max );
58
96
while (result != null ) {
59
97
artifacts .addAll (result .artifacts );
60
98
result = count <= 0 ? SearchUtils .findNextArtifacts (result ) : null ;
@@ -66,6 +104,17 @@ private static String artifactGav(Artifact artifact) {
66
104
return artifact .getGroupId () + ":" + artifact .getArtifactId () + ":" + artifact .getVersion ();
67
105
}
68
106
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
+ */
69
118
public SyncStats install (String [] artifactNames )
70
119
throws IOException , DependencyResolutionException {
71
120
AppInfo appInfo = AppInfo .read ();
@@ -88,6 +137,15 @@ public SyncStats install(String[] artifactNames)
88
137
}
89
138
}
90
139
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
+ */
91
149
public List <Path > path (String [] artifactNames )
92
150
throws DependencyResolutionException , IOException {
93
151
AppInfo appInfo = AppInfo .read ();
0 commit comments