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.CoreExtensions;
29  import org.apache.maven.api.cli.InvokerRequest;
30  import org.apache.maven.api.cli.Options;
31  import org.apache.maven.api.cli.ParserRequest;
32  import org.apache.maven.api.cli.cisupport.CIInfo;
33  
34  import static java.util.Objects.requireNonNull;
35  
36  public class BaseInvokerRequest implements InvokerRequest {
37      private final ParserRequest parserRequest;
38      private final boolean parsingFailed;
39      private final Path cwd;
40      private final Path installationDirectory;
41      private final Path userHomeDirectory;
42      private final Map<String, String> userProperties;
43      private final Map<String, String> systemProperties;
44      private final Path topDirectory;
45      private final Path rootDirectory;
46      private final List<CoreExtensions> coreExtensions;
47      private final CIInfo ciInfo;
48      private final Options options;
49  
50      @SuppressWarnings("ParameterNumber")
51      public BaseInvokerRequest(
52              @Nonnull ParserRequest parserRequest,
53              boolean parsingFailed,
54              @Nonnull Path cwd,
55              @Nonnull Path installationDirectory,
56              @Nonnull Path userHomeDirectory,
57              @Nonnull Map<String, String> userProperties,
58              @Nonnull Map<String, String> systemProperties,
59              @Nonnull Path topDirectory,
60              @Nullable Path rootDirectory,
61              @Nullable List<CoreExtensions> coreExtensions,
62              @Nullable CIInfo ciInfo,
63              @Nullable Options options) {
64          this.parserRequest = requireNonNull(parserRequest);
65          this.parsingFailed = parsingFailed;
66          this.cwd = requireNonNull(cwd);
67          this.installationDirectory = requireNonNull(installationDirectory);
68          this.userHomeDirectory = requireNonNull(userHomeDirectory);
69  
70          this.userProperties = requireNonNull(userProperties);
71          this.systemProperties = requireNonNull(systemProperties);
72          this.topDirectory = requireNonNull(topDirectory);
73          this.rootDirectory = rootDirectory;
74          this.coreExtensions = coreExtensions;
75          this.ciInfo = ciInfo;
76          this.options = options;
77      }
78  
79      @Override
80      public ParserRequest parserRequest() {
81          return parserRequest;
82      }
83  
84      @Override
85      public boolean parsingFailed() {
86          return parsingFailed;
87      }
88  
89      @Override
90      public Path cwd() {
91          return cwd;
92      }
93  
94      @Override
95      public Path installationDirectory() {
96          return installationDirectory;
97      }
98  
99      @Override
100     public Path userHomeDirectory() {
101         return userHomeDirectory;
102     }
103 
104     @Override
105     public Map<String, String> userProperties() {
106         return userProperties;
107     }
108 
109     @Override
110     public Map<String, String> systemProperties() {
111         return systemProperties;
112     }
113 
114     @Override
115     public Path topDirectory() {
116         return topDirectory;
117     }
118 
119     @Override
120     public Optional<Path> rootDirectory() {
121         return Optional.ofNullable(rootDirectory);
122     }
123 
124     @Override
125     public Optional<List<CoreExtensions>> coreExtensions() {
126         return Optional.ofNullable(coreExtensions);
127     }
128 
129     @Override
130     public Optional<CIInfo> ciInfo() {
131         return Optional.ofNullable(ciInfo);
132     }
133 
134     public Optional<Options> options() {
135         return Optional.ofNullable(options);
136     }
137 }