4
4
import org .gradle .api .Project ;
5
5
6
6
import java .io .File ;
7
+ import java .nio .charset .Charset ;
7
8
import java .nio .charset .StandardCharsets ;
8
9
import java .util .ArrayList ;
9
- import java .util .Arrays ;
10
- import java .util .Collections ;
11
10
import java .util .HashMap ;
12
11
import java .util .List ;
13
12
import java .util .Map ;
13
+ import org .gradle .execution .commandline .TaskConfigurationException ;
14
14
15
15
@ Data
16
16
public class JcpPreprocessExtension {
17
17
18
18
/**
19
- * Source root folders for preprocessing, if it is empty then project provided folders will be used.
20
- *
21
- * @since 7.0.0
19
+ * Source root folders for preprocessing, if it is empty then project provided
20
+ * folders will be used.
22
21
*/
23
22
private List <String > sources = null ;
24
23
25
24
/**
26
- * End of line string to be used in reprocessed results. It supports java escaping chars.
25
+ * End of line string to be used in reprocessed results. It supports java
26
+ * escaping chars.
27
27
*/
28
28
private String eol = null ;
29
29
@@ -33,15 +33,11 @@ public class JcpPreprocessExtension {
33
33
private boolean keepAttributes = false ;
34
34
35
35
/**
36
- * Target folder to place preprocessing result in regular source processing phase.
36
+ * Target folder to place preprocessing result in regular source processing
37
+ * phase.
37
38
*/
38
39
private File target = null ;
39
40
40
- /**
41
- * Target folder to place preprocessing result in test source processing phase.
42
- */
43
- private File targetTest = null ;
44
-
45
41
/**
46
42
* Encoding for text read operations.
47
43
*/
@@ -53,19 +49,22 @@ public class JcpPreprocessExtension {
53
49
private String targetEncoding = StandardCharsets .UTF_8 .name ();
54
50
55
51
/**
56
- * Flag to ignore missing source folders, if false then mojo fail for any missing source folder, if true then missing folder will be ignored.
52
+ * Flag to ignore missing source folders, if false then mojo fail for any
53
+ * missing source folder, if true then missing folder will be ignored.
57
54
*/
58
55
private boolean ignoreMissingSources = false ;
59
56
60
57
/**
61
- * List of file extensions to be excluded from preprocessing. By default excluded xml.
58
+ * List of file extensions to be excluded from preprocessing. By default
59
+ * excluded xml.
62
60
*/
63
- private List <String > excludeExtensions = Collections . singletonList ( "xml" ) ;
61
+ private List <String > excludeExtensions = null ;
64
62
65
63
/**
66
- * List of file extensions to be included into preprocessing. By default java,txt,htm,html
64
+ * List of file extensions to be included into preprocessing. By default
65
+ * java,txt,htm,html
67
66
*/
68
- private List <String > extensions = new ArrayList <>( Arrays . asList ( "java" , "txt" , "htm" , "html" )) ;
67
+ private List <String > extensions = null ;
69
68
70
69
/**
71
70
* Interpretate unknown variable as containing boolean false flag.
@@ -90,18 +89,13 @@ public class JcpPreprocessExtension {
90
89
/**
91
90
* Set base directory which will be used for relative source paths.
92
91
*/
93
- private File baseDir = new File ( "." ) ;
92
+ private File baseDir = null ;
94
93
95
94
/**
96
95
* Carefully reproduce last EOL in result files.
97
96
*/
98
97
private boolean careForLastEol = false ;
99
98
100
- /**
101
- * Replace source root folders in maven project after preprocessing for following processing.
102
- */
103
- private boolean replaceSources = true ;
104
-
105
99
/**
106
100
* Keep comments in result files.
107
101
*/
@@ -113,7 +107,8 @@ public class JcpPreprocessExtension {
113
107
private Map <String , String > vars = new HashMap <>();
114
108
115
109
/**
116
- * List of patterns of folder paths to be excluded from preprocessing, It uses ANT path pattern format.
110
+ * List of patterns of folder paths to be excluded from preprocessing, It uses
111
+ * ANT path pattern format.
117
112
*/
118
113
private List <String > excludeFolders = new ArrayList <>();
119
114
@@ -123,17 +118,20 @@ public class JcpPreprocessExtension {
123
118
private List <String > configFiles = new ArrayList <>();
124
119
125
120
/**
126
- * Keep preprocessing directives in result files as commented ones, it is useful to not break line numeration in result files.
121
+ * Keep preprocessing directives in result files as commented ones, it is
122
+ * useful to not break line numeration in result files.
127
123
*/
128
124
private boolean keepLines = true ;
129
125
130
126
/**
131
- * Turn on support of white spaces in preprocessor directives between '//' and the '#'.
127
+ * Turn on support of white spaces in preprocessor directives between '//' and
128
+ * the '#'.
132
129
*/
133
130
private boolean allowWhitespaces = false ;
134
131
135
132
/**
136
- * Preserve indents in lines marked by '//$' and '//$$' directives. Directives will be replaced by white spaces chars.
133
+ * Preserve indents in lines marked by '//$' and '//$$' directives. Directives
134
+ * will be replaced by white spaces chars.
137
135
*/
138
136
private boolean preserveIndents = false ;
139
137
@@ -148,19 +146,48 @@ public class JcpPreprocessExtension {
148
146
private boolean skip = false ;
149
147
150
148
/**
151
- * Turn on check of content body compare with existing result file to prevent overwriting, if content is the same then preprocessor will not be writing new result content.
149
+ * Turn on check of content body compare with existing result file to prevent
150
+ * overwriting, if content is the same then preprocessor will not be writing
151
+ * new result content.
152
152
*/
153
153
private boolean dontOverwriteSameContent = false ;
154
154
155
-
156
155
public JcpPreprocessExtension (final Project project ) {
156
+ if (this .baseDir == null ) {
157
+ this .baseDir = project .getProjectDir ();
158
+ project .getLogger ().debug ("Got basedir from project: " + this .baseDir );
159
+ }
157
160
}
158
161
159
- public void validate (final Project project ) {
160
- // if (this.sources == null ) {
161
- // throw new GradleException("Sources are not provided" );
162
- // }
162
+ private void assertCharSet (final String name ) {
163
+ if (! Charset . isSupported ( name ) ) {
164
+ throw new TaskConfigurationException ( "preprocess" , "Unsupported charset: " + name , null );
165
+ }
163
166
}
164
167
168
+ public void validate (final Project project ) {
169
+ if (this .baseDir == null ) {
170
+ throw new TaskConfigurationException ("preprocess" , "Basedir must be defined" , null );
171
+ }
172
+
173
+ if (!this .baseDir .isDirectory ()) {
174
+ throw new TaskConfigurationException ("preprocess" , "Basedir doesn't exist: " + this .baseDir , null );
175
+ }
176
+
177
+ assertCharSet (this .sourceEncoding );
178
+ assertCharSet (this .targetEncoding );
179
+
180
+ if (this .sources == null ) {
181
+ throw new TaskConfigurationException ("preprocess" , "Source folders are not deined in 'sources'" , null );
182
+ }
183
+
184
+ if (this .sources .isEmpty ()) {
185
+ throw new TaskConfigurationException ("preprocess" , "Source folders are empty" , null );
186
+ }
187
+
188
+ if (this .target == null ) {
189
+ throw new TaskConfigurationException ("preprocess" , "Target folder is not deined in 'target'" , null );
190
+ }
191
+ }
165
192
166
193
}
0 commit comments