1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.api.services;
20
21 import java.util.Collection;
22 import java.util.Collections;
23
24 import org.apache.maven.api.Artifact;
25 import org.apache.maven.api.Session;
26 import org.apache.maven.api.annotations.Experimental;
27 import org.apache.maven.api.annotations.Immutable;
28 import org.apache.maven.api.annotations.Nonnull;
29 import org.apache.maven.api.annotations.NotThreadSafe;
30 import org.apache.maven.api.annotations.Nullable;
31
32 import static org.apache.maven.api.services.BaseRequest.nonNull;
33
34
35
36
37
38
39 @Experimental
40 @Immutable
41 public interface ArtifactInstallerRequest {
42
43 @Nonnull
44 Session getSession();
45
46 @Nonnull
47 Collection<Artifact> getArtifacts();
48
49 @Nonnull
50 static ArtifactInstallerRequestBuilder builder() {
51 return new ArtifactInstallerRequestBuilder();
52 }
53
54 @Nonnull
55 static ArtifactInstallerRequest build(Session session, Collection<Artifact> artifacts) {
56 return builder()
57 .session(nonNull(session, "session cannot be null"))
58 .artifacts(nonNull(artifacts, "artifacts cannot be null"))
59 .build();
60 }
61
62 @NotThreadSafe
63 class ArtifactInstallerRequestBuilder {
64 Session session;
65 Collection<Artifact> artifacts = Collections.emptyList();
66
67 ArtifactInstallerRequestBuilder() {}
68
69 @Nonnull
70 public ArtifactInstallerRequestBuilder session(@Nonnull Session session) {
71 this.session = session;
72 return this;
73 }
74
75 @Nonnull
76 public ArtifactInstallerRequestBuilder artifacts(@Nullable Collection<Artifact> artifacts) {
77 this.artifacts = artifacts != null ? artifacts : Collections.emptyList();
78 return this;
79 }
80
81 @Nonnull
82 public ArtifactInstallerRequest build() {
83 return new DefaultArtifactInstallerRequest(session, artifacts);
84 }
85
86 static class DefaultArtifactInstallerRequest extends BaseRequest implements ArtifactInstallerRequest {
87
88 private final Collection<Artifact> artifacts;
89
90 DefaultArtifactInstallerRequest(@Nonnull Session session, @Nonnull Collection<Artifact> artifacts) {
91 super(session);
92 this.artifacts = unmodifiable(nonNull(artifacts, "artifacts cannot be null"));
93 }
94
95 @Nonnull
96 @Override
97 public Collection<Artifact> getArtifacts() {
98 return artifacts;
99 }
100 }
101 }
102 }