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