1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.codehaus.mojo.license;
27
28 import org.apache.commons.lang.StringUtils;
29 import org.codehaus.mojo.license.model.License;
30 import org.codehaus.mojo.license.model.LicenseStore;
31
32 import java.util.Arrays;
33
34
35
36
37
38
39
40
41 public abstract class AbstractLicenseNameMojo
42 extends AbstractLicenseMojo
43 {
44
45
46
47
48
49
50
51
52 private String licenseResolver;
53
54
55
56
57
58
59
60 private boolean keepBackup;
61
62
63
64
65
66
67
68 private String licenseName;
69
70
71
72
73 private License license;
74
75
76
77
78 private LicenseStore licenseStore;
79
80
81
82
83
84
85
86
87
88 public abstract boolean isSkip();
89
90
91
92
93
94
95 public abstract void setSkip( boolean skip );
96
97 @Override
98 protected boolean checkSkip()
99 {
100 if ( isSkip() )
101 {
102 getLog().info( "skip flag is on, will skip goal." );
103 return false;
104 }
105 return super.checkSkip();
106 }
107
108 @Override
109 protected void init()
110 throws Exception
111 {
112
113 if ( isSkip() )
114 {
115 return;
116 }
117
118
119 licenseStore = LicenseStore.createLicenseStore( getLog(), getLicenseResolver() );
120
121
122 license = getLicense( licenseName, true );
123 }
124
125 public License getLicense( String licenseName, boolean checkIfExists )
126 throws IllegalArgumentException, IllegalStateException
127 {
128 if ( StringUtils.isEmpty( licenseName ) )
129 {
130 throw new IllegalArgumentException( "licenseName can not be null, nor empty" );
131 }
132 LicenseStore licenseStore = getLicenseStore();
133 if ( licenseStore == null )
134 {
135 throw new IllegalStateException( "No license store initialized!" );
136 }
137 License license = licenseStore.getLicense( licenseName );
138 if ( checkIfExists && license == null )
139 {
140 throw new IllegalArgumentException( "License named '" + licenseName + "' is unknown, use one of " +
141 Arrays.toString( licenseStore.getLicenseNames() ) );
142 }
143 return license;
144 }
145
146 public boolean isKeepBackup()
147 {
148 return keepBackup;
149 }
150
151 public String getLicenseName()
152 {
153 return licenseName;
154 }
155
156 public String getLicenseResolver()
157 {
158 return licenseResolver;
159 }
160
161 public LicenseStore getLicenseStore()
162 {
163 return licenseStore;
164 }
165
166 public License getLicense()
167 {
168 return license;
169 }
170
171 public void setKeepBackup( boolean keepBackup )
172 {
173 this.keepBackup = keepBackup;
174 }
175
176 public void setLicenseResolver( String licenseResolver )
177 {
178 this.licenseResolver = licenseResolver;
179 }
180
181 public void setLicenseName( String licenseName )
182 {
183 this.licenseName = licenseName;
184 }
185
186 public void setLicenseStore( LicenseStore licenseStore )
187 {
188 this.licenseStore = licenseStore;
189 }
190
191 }