View Javadoc
1   package org.codehaus.plexus.languages.java.jpms;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.nio.file.Path;
24  import java.nio.file.Paths;
25  import java.util.Collection;
26  
27  /**
28   * Contains all information required to analyze the project
29   * 
30   * @author Robert Scholte
31   * @since 1.0.0
32   */
33  public abstract class ResolvePathsRequest<T>
34  {
35      private Path jdkHome;
36  
37      private Path mainModuleDescriptor;
38  
39      private Collection<T> pathElements;
40      
41      private ResolvePathsRequest()
42      {
43      }
44      
45      public static ResolvePathsRequest<File> withFiles( Collection<File> files )
46      {
47          ResolvePathsRequest<File> request = new ResolvePathsRequest<File>()
48          {
49              @Override
50              protected Path toPath( File t )
51              {
52                  return t.toPath();
53              }
54          };
55              
56          request.pathElements = files;
57          return request;
58      }
59  
60      public static ResolvePathsRequest<Path> withPaths( Collection<Path> paths )
61      {
62          ResolvePathsRequest<Path> request = new ResolvePathsRequest<Path>() {
63              @Override
64              protected Path toPath( Path t )
65              {
66                  return t;
67              }
68          };
69          request.pathElements = paths;
70          return request;
71      }
72      
73      public static ResolvePathsRequest<String> withStrings( Collection<String> strings )
74      {
75          ResolvePathsRequest<String> request = new ResolvePathsRequest<String>() {
76              @Override
77              protected Path toPath( String t )
78              {
79                  return Paths.get( t );
80              }
81          };
82          request.pathElements = strings;
83          return request;
84      }
85      
86      protected abstract Path toPath( T t );
87  
88      final ResolvePathsResult<T> createResult() {
89          return new ResolvePathsResult<>();
90      }
91      
92      public Path getMainModuleDescriptor()
93      {
94          return mainModuleDescriptor;
95      }
96  
97      /**
98       * Must be either {@code module-info.java} or {@code module-info.class} 
99       * 
100      * @param mainModuleDescriptor
101      * @return this request
102      */
103     public ResolvePathsRequest<T> setMainModuleDescriptor( T mainModuleDescriptor )
104     {
105         this.mainModuleDescriptor = toPath( mainModuleDescriptor );
106         return this;
107     }
108 
109     public Collection<T> getPathElements()
110     {
111         return pathElements;
112     }
113 
114     /**
115      * In case the JRE is Java 8 or before, this jdkHome is used to extract the module name.
116      * 
117      * @param jdkHome
118      */
119     public ResolvePathsRequest<T> setJdkHome( T jdkHome )
120     {
121         this.jdkHome = toPath( jdkHome );
122         return this;
123     }
124 
125     public Path getJdkHome()
126     {
127         return jdkHome;
128     }
129 
130 }