|
16 | 16 | package de.jjohannes.gradle.javamodules; |
17 | 17 |
|
18 | 18 | import java.io.Serializable; |
19 | | -import java.util.ArrayList; |
20 | 19 | import java.util.LinkedHashSet; |
21 | | -import java.util.List; |
22 | 20 | import java.util.Set; |
23 | 21 |
|
24 | 22 | /** |
25 | 23 | * Data class to hold the information that should be added as module-info.class to an existing Jar file. |
26 | 24 | */ |
27 | 25 | public class ModuleInfo implements Serializable { |
28 | | - private String moduleName; |
29 | | - private String moduleVersion; |
30 | | - private List<String> exports = new ArrayList<>(); |
31 | | - private List<String> requires = new ArrayList<>(); |
32 | | - private List<String> requiresTransitive = new ArrayList<>(); |
33 | | - private List<String> requiresStatic = new ArrayList<>(); |
34 | | - private Set<String> ignoredServiceProviders = new LinkedHashSet<>(); |
| 26 | + |
| 27 | + final String moduleName; |
| 28 | + final String moduleVersion; |
| 29 | + final Set<String> exports = new LinkedHashSet<>(); |
| 30 | + final Set<String> requires = new LinkedHashSet<>(); |
| 31 | + final Set<String> requiresTransitive = new LinkedHashSet<>(); |
| 32 | + final Set<String> requiresStatic = new LinkedHashSet<>(); |
| 33 | + final Set<String> ignoreServiceProviders = new LinkedHashSet<>(); |
35 | 34 |
|
36 | 35 | ModuleInfo(String moduleName, String moduleVersion) { |
37 | 36 | this.moduleName = moduleName; |
38 | 37 | this.moduleVersion = moduleVersion; |
39 | 38 | } |
40 | 39 |
|
41 | 40 | public void exports(String exports) { |
42 | | - this.exports.add(exports); |
| 41 | + addOrThrow(this.exports, exports); |
43 | 42 | } |
44 | 43 |
|
45 | 44 | public void requires(String requires) { |
46 | | - this.requires.add(requires); |
| 45 | + addOrThrow(this.requires, requires); |
47 | 46 | } |
48 | 47 |
|
49 | 48 | public void requiresTransitive(String requiresTransitive) { |
50 | | - this.requiresTransitive.add(requiresTransitive); |
| 49 | + addOrThrow(this.requiresTransitive, requiresTransitive); |
51 | 50 | } |
52 | 51 |
|
53 | 52 | public void requiresStatic(String requiresStatic) { |
54 | | - this.requiresStatic.add(requiresStatic); |
| 53 | + addOrThrow(this.requiresStatic, requiresStatic); |
55 | 54 | } |
56 | 55 |
|
57 | 56 | public void ignoreServiceProvider(String ignoreServiceProvider) { |
58 | | - this.ignoredServiceProviders.add(ignoreServiceProvider); |
59 | | - } |
60 | | - |
61 | | - public String getModuleName() { |
62 | | - return moduleName; |
63 | | - } |
64 | | - |
65 | | - protected String getModuleVersion() { |
66 | | - return moduleVersion; |
67 | | - } |
68 | | - |
69 | | - protected List<String> getExports() { |
70 | | - return exports; |
71 | | - } |
72 | | - |
73 | | - protected List<String> getRequires() { |
74 | | - return requires; |
75 | | - } |
76 | | - |
77 | | - protected List<String> getRequiresTransitive() { |
78 | | - return requiresTransitive; |
79 | | - } |
80 | | - |
81 | | - protected List<String> getRequiresStatic() { |
82 | | - return requiresStatic; |
| 57 | + addOrThrow(this.ignoreServiceProviders, ignoreServiceProvider); |
83 | 58 | } |
84 | 59 |
|
85 | | - protected Set<String> getIgnoredServiceProviders() { |
86 | | - return ignoredServiceProviders; |
| 60 | + private static void addOrThrow(Set<String> target, String element) { |
| 61 | + if (!target.add(element)) { |
| 62 | + throw new IllegalArgumentException("The element '" + element + "' is already specified"); |
| 63 | + } |
87 | 64 | } |
88 | 65 |
|
89 | 66 | } |
0 commit comments