View Javadoc
1   package org.apache.maven.plugin.compiler.module;
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.util.Collections;
23  import java.util.HashSet;
24  import java.util.Set;
25  
26  /**
27   * Simple representation of a Module containing info required by this plugin.
28   * It will provide only methods matching Java 9 ModuleDescriptor, so once Java 9  is required, we can easily switch 
29   * 
30   * @author Robert Scholte
31   * @since 3.7.0
32   *
33   */
34  public class JavaModuleDescriptor
35  {
36      private String name;
37      
38      private boolean automatic;
39  
40      private Set<JavaRequires> requires = new HashSet<JavaRequires>();
41      
42      private Set<JavaExports> exports = new HashSet<JavaExports>();
43  
44      public String name()
45      {
46          return name;
47      }
48  
49      public boolean isAutomatic()
50      {
51          return automatic;
52      }
53      
54      public Set<JavaRequires> requires()
55      {
56          return Collections.unmodifiableSet( requires );
57      }
58      
59      public Set<JavaExports> exports()
60      {
61          return Collections.unmodifiableSet( exports );
62      }
63      
64      public static JavaModuleDescriptor.Builder newModule( String name )
65      {
66          return new Builder( name ).setAutomatic( false );
67      }
68      
69      public static Builder newAutomaticModule( String name )
70      {
71          return new Builder( name ).setAutomatic( true );
72      }  
73  
74      /**
75       * A JavaModuleDescriptor Builder
76       * 
77       * @author Robert Scholte
78       * @since 3.7.0
79       */
80      public static final class Builder
81      {
82          private JavaModuleDescriptor jModule;
83          
84          private Builder( String name )
85          {
86              jModule = new JavaModuleDescriptor();
87              jModule.name = name;
88          }
89          
90          private Builder setAutomatic( boolean isAutomatic )
91          {
92              jModule.automatic = isAutomatic;
93              return this;
94          }
95  
96          public Builder requires( String name )
97          {
98              JavaRequires requires = new JavaRequires( name );
99              jModule.requires.add( requires );
100             return this;
101         }
102         
103         public Builder exports( String source )
104         {
105             JavaExports exports = new JavaExports( source );
106             jModule.exports.add( exports );
107             return this;
108         }
109         
110         public JavaModuleDescriptor build()
111         {
112             return jModule;
113         }
114     }
115     
116     /**
117      * Represents Module.Requires
118      * 
119      * @author Robert Scholte
120      * @since 3.7.0
121      */
122     public static class JavaRequires
123     {
124         private final String name;
125 
126         private JavaRequires( String name )
127         {
128             this.name = name;
129         }
130 
131         public String name()
132         {
133             return name;
134         }
135     }
136     
137     /**
138      * Represents Module.Exports
139      * 
140      * @author Robert Scholte
141      * @since 3.7.0
142      *
143      */
144     public static class JavaExports
145     {
146         private final String source;
147         
148         private JavaExports( String source )
149         {
150             this.source = source;
151         }
152         
153         public String source()
154         {
155             return source;
156         }
157     }
158     
159 }