View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.cling.invoker;
20  
21  import java.nio.file.Path;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.Optional;
25  
26  import org.apache.maven.api.annotations.Nonnull;
27  import org.apache.maven.api.annotations.Nullable;
28  import org.apache.maven.api.cli.InvokerRequest;
29  import org.apache.maven.api.cli.ParserRequest;
30  import org.apache.maven.api.cli.extensions.CoreExtension;
31  
32  import static java.util.Objects.requireNonNull;
33  
34  public abstract class BaseInvokerRequest implements InvokerRequest {
35      private final ParserRequest parserRequest;
36      private final boolean parsingFailed;
37      private final Path cwd;
38      private final Path installationDirectory;
39      private final Path userHomeDirectory;
40      private final Map<String, String> userProperties;
41      private final Map<String, String> systemProperties;
42      private final Path topDirectory;
43      private final Path rootDirectory;
44      private final List<CoreExtension> coreExtensions;
45  
46      @SuppressWarnings("ParameterNumber")
47      public BaseInvokerRequest(
48              @Nonnull ParserRequest parserRequest,
49              boolean parsingFailed,
50              @Nonnull Path cwd,
51              @Nonnull Path installationDirectory,
52              @Nonnull Path userHomeDirectory,
53              @Nonnull Map<String, String> userProperties,
54              @Nonnull Map<String, String> systemProperties,
55              @Nonnull Path topDirectory,
56              @Nullable Path rootDirectory,
57              @Nullable List<CoreExtension> coreExtensions) {
58          this.parserRequest = requireNonNull(parserRequest);
59          this.parsingFailed = parsingFailed;
60          this.cwd = requireNonNull(cwd);
61          this.installationDirectory = requireNonNull(installationDirectory);
62          this.userHomeDirectory = requireNonNull(userHomeDirectory);
63  
64          this.userProperties = requireNonNull(userProperties);
65          this.systemProperties = requireNonNull(systemProperties);
66          this.topDirectory = requireNonNull(topDirectory);
67          this.rootDirectory = rootDirectory;
68          this.coreExtensions = coreExtensions;
69      }
70  
71      @Override
72      public ParserRequest parserRequest() {
73          return parserRequest;
74      }
75  
76      @Override
77      public boolean parsingFailed() {
78          return parsingFailed;
79      }
80  
81      @Override
82      public Path cwd() {
83          return cwd;
84      }
85  
86      @Override
87      public Path installationDirectory() {
88          return installationDirectory;
89      }
90  
91      @Override
92      public Path userHomeDirectory() {
93          return userHomeDirectory;
94      }
95  
96      @Override
97      public Map<String, String> userProperties() {
98          return userProperties;
99      }
100 
101     @Override
102     public Map<String, String> systemProperties() {
103         return systemProperties;
104     }
105 
106     @Override
107     public Path topDirectory() {
108         return topDirectory;
109     }
110 
111     @Override
112     public Optional<Path> rootDirectory() {
113         return Optional.ofNullable(rootDirectory);
114     }
115 
116     @Override
117     public Optional<List<CoreExtension>> coreExtensions() {
118         return Optional.ofNullable(coreExtensions);
119     }
120 }