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.nio.file.Path;
22 import java.util.List;
23 import java.util.Optional;
24
25 import org.apache.maven.api.RemoteRepository;
26 import org.apache.maven.api.Session;
27 import org.apache.maven.api.annotations.Experimental;
28 import org.apache.maven.api.annotations.Immutable;
29 import org.apache.maven.api.annotations.Nonnull;
30 import org.apache.maven.api.annotations.NotThreadSafe;
31 import org.apache.maven.api.annotations.Nullable;
32
33 import static org.apache.maven.api.services.BaseRequest.nonNull;
34
35
36
37
38
39
40
41
42
43 @Experimental
44 @Immutable
45 public interface ProjectBuilderRequest {
46
47 @Nonnull
48 Session getSession();
49
50 @Nonnull
51 Optional<Path> getPath();
52
53 @Nonnull
54 Optional<Source> getSource();
55
56 boolean isAllowStubModel();
57
58 boolean isRecursive();
59
60 boolean isProcessPlugins();
61
62 @Nullable
63 List<RemoteRepository> getRepositories();
64
65 @Nonnull
66 static ProjectBuilderRequest build(@Nonnull Session session, @Nonnull Source source) {
67 return builder()
68 .session(nonNull(session, "session cannot be null"))
69 .source(nonNull(source, "source cannot be null"))
70 .build();
71 }
72
73 @Nonnull
74 static ProjectBuilderRequest build(@Nonnull Session session, @Nonnull Path path) {
75 return builder()
76 .session(nonNull(session, "session cannot be null"))
77 .path(nonNull(path, "path cannot be null"))
78 .build();
79 }
80
81 @Nonnull
82 static ProjectBuilderRequestBuilder builder() {
83 return new ProjectBuilderRequestBuilder();
84 }
85
86 @NotThreadSafe
87 class ProjectBuilderRequestBuilder {
88 Session session;
89 Path path;
90 Source source;
91 boolean allowStubModel;
92 boolean recursive;
93 boolean processPlugins = true;
94 List<RemoteRepository> repositories;
95
96 ProjectBuilderRequestBuilder() {}
97
98 public ProjectBuilderRequestBuilder session(Session session) {
99 this.session = session;
100 return this;
101 }
102
103 public ProjectBuilderRequestBuilder path(Path path) {
104 this.path = path;
105 return this;
106 }
107
108 public ProjectBuilderRequestBuilder source(Source source) {
109 this.source = source;
110 return this;
111 }
112
113 public ProjectBuilderRequestBuilder processPlugins(boolean processPlugins) {
114 this.processPlugins = processPlugins;
115 return this;
116 }
117
118 public ProjectBuilderRequestBuilder repositories(List<RemoteRepository> repositories) {
119 this.repositories = repositories;
120 return this;
121 }
122
123 public ProjectBuilderRequest build() {
124 return new DefaultProjectBuilderRequest(
125 session, path, source, allowStubModel, recursive, processPlugins, repositories);
126 }
127
128 private static class DefaultProjectBuilderRequest extends BaseRequest implements ProjectBuilderRequest {
129 private final Path path;
130 private final Source source;
131 private final boolean allowStubModel;
132 private final boolean recursive;
133 private final boolean processPlugins;
134 private final List<RemoteRepository> repositories;
135
136 @SuppressWarnings("checkstyle:ParameterNumber")
137 DefaultProjectBuilderRequest(
138 @Nonnull Session session,
139 @Nullable Path path,
140 @Nullable Source source,
141 boolean allowStubModel,
142 boolean recursive,
143 boolean processPlugins,
144 @Nullable List<RemoteRepository> repositories) {
145 super(session);
146 this.path = path;
147 this.source = source;
148 this.allowStubModel = allowStubModel;
149 this.recursive = recursive;
150 this.processPlugins = processPlugins;
151 this.repositories = repositories;
152 }
153
154 @Nonnull
155 @Override
156 public Optional<Path> getPath() {
157 return Optional.ofNullable(path);
158 }
159
160 @Nonnull
161 @Override
162 public Optional<Source> getSource() {
163 return Optional.ofNullable(source);
164 }
165
166 @Override
167 public boolean isAllowStubModel() {
168 return allowStubModel;
169 }
170
171 @Override
172 public boolean isRecursive() {
173 return recursive;
174 }
175
176 @Override
177 public boolean isProcessPlugins() {
178 return processPlugins;
179 }
180
181 @Override
182 public List<RemoteRepository> getRepositories() {
183 return repositories;
184 }
185 }
186 }
187 }