1 | |
package org.apache.maven.plugin.source; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.Iterator; |
5 | |
import java.util.List; |
6 | |
|
7 | |
import org.apache.maven.plugin.AbstractMojo; |
8 | |
import org.apache.maven.plugin.MojoExecutionException; |
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | 0 | public class HelpMojo |
19 | |
extends AbstractMojo |
20 | |
{ |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
private boolean detail; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
private java.lang.String goal; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
private int lineLength; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
private int indentSize; |
48 | |
|
49 | |
|
50 | |
|
51 | |
public void execute() |
52 | |
throws MojoExecutionException |
53 | |
{ |
54 | 0 | if ( lineLength <= 0 ) |
55 | |
{ |
56 | 0 | getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." ); |
57 | 0 | lineLength = 80; |
58 | |
} |
59 | 0 | if ( indentSize <= 0 ) |
60 | |
{ |
61 | 0 | getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." ); |
62 | 0 | indentSize = 2; |
63 | |
} |
64 | |
|
65 | 0 | StringBuffer sb = new StringBuffer(); |
66 | |
|
67 | 0 | append( sb, "org.apache.maven.plugins:maven-source-plugin:2.1.2", 0 ); |
68 | 0 | append( sb, "", 0 ); |
69 | |
|
70 | 0 | append( sb, "Maven Source Plugin", 0 ); |
71 | 0 | append( sb, "The Maven 2 Source Plugin creates a JAR archive of the source files of the current project.", 1 ); |
72 | 0 | append( sb, "", 0 ); |
73 | |
|
74 | 0 | if ( goal == null || goal.length() <= 0 ) |
75 | |
{ |
76 | 0 | append( sb, "This plugin has 6 goals:", 0 ); |
77 | 0 | append( sb, "", 0 ); |
78 | |
} |
79 | |
|
80 | 0 | if ( goal == null || goal.length() <= 0 || "aggregate".equals( goal ) ) |
81 | |
{ |
82 | 0 | append( sb, "source:aggregate", 0 ); |
83 | 0 | append( sb, "Aggregate sources for all modules in an aggregator project.", 1 ); |
84 | 0 | append( sb, "", 0 ); |
85 | 0 | if ( detail ) |
86 | |
{ |
87 | 0 | append( sb, "Available parameters:", 1 ); |
88 | 0 | append( sb, "", 0 ); |
89 | |
|
90 | 0 | append( sb, "archive", 2 ); |
91 | 0 | append( sb, "The archive configuration to use. See Maven Archiver Reference.", 3 ); |
92 | 0 | append( sb, "", 0 ); |
93 | |
|
94 | 0 | append( sb, "attach (Default: true)", 2 ); |
95 | 0 | append( sb, "Specifies whether or not to attach the artifact to the project", 3 ); |
96 | 0 | append( sb, "", 0 ); |
97 | |
|
98 | 0 | append( sb, "excludeResources (Default: false)", 2 ); |
99 | 0 | append( sb, "Specifies whether or not to exclude resources from the sources-jar. This can be convenient if your project includes large resources, such as images, and you don\'t want to include them in the sources-jar.", 3 ); |
100 | 0 | append( sb, "", 0 ); |
101 | |
|
102 | 0 | append( sb, "excludes", 2 ); |
103 | 0 | append( sb, "List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
104 | 0 | append( sb, "", 0 ); |
105 | |
|
106 | 0 | append( sb, "finalName (Default: ${project.build.finalName})", 2 ); |
107 | 0 | append( sb, "The filename to be used for the generated archive file. For the source:jar goal, \'-sources\' is appended to this filename. For the source:test-jar goal, \'-test-sources\' is appended.", 3 ); |
108 | 0 | append( sb, "", 0 ); |
109 | |
|
110 | 0 | append( sb, "forceCreation (Default: false)", 2 ); |
111 | 0 | append( sb, "Whether creating the archive should be forced. If set to true, the jar will always be created. If set to false, the jar will only be created when the sources are newer than the jar.", 3 ); |
112 | 0 | append( sb, "", 0 ); |
113 | |
|
114 | 0 | append( sb, "includePom (Default: false)", 2 ); |
115 | 0 | append( sb, "Specifies whether or not to include the POM file in the sources-jar.", 3 ); |
116 | 0 | append( sb, "", 0 ); |
117 | |
|
118 | 0 | append( sb, "includes", 2 ); |
119 | 0 | append( sb, "List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
120 | 0 | append( sb, "", 0 ); |
121 | |
|
122 | 0 | append( sb, "outputDirectory (Default: ${project.build.directory})", 2 ); |
123 | 0 | append( sb, "The directory where the generated archive file will be put.", 3 ); |
124 | 0 | append( sb, "", 0 ); |
125 | |
|
126 | 0 | append( sb, "useDefaultExcludes (Default: true)", 2 ); |
127 | 0 | append( sb, "Exclude commonly excluded files such as SCM configuration. These are defined in the plexus FileUtils.getDefaultExcludes()", 3 ); |
128 | 0 | append( sb, "", 0 ); |
129 | |
|
130 | 0 | append( sb, "useDefaultManifestFile (Default: false)", 2 ); |
131 | 0 | append( sb, "Set this to true to enable the use of the defaultManifestFile.\n", 3 ); |
132 | 0 | append( sb, "", 0 ); |
133 | |
} |
134 | |
} |
135 | |
|
136 | 0 | if ( goal == null || goal.length() <= 0 || "help".equals( goal ) ) |
137 | |
{ |
138 | 0 | append( sb, "source:help", 0 ); |
139 | 0 | append( sb, "Display help information on maven-source-plugin.\nCall\n\u00a0\u00a0mvn\u00a0source:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 ); |
140 | 0 | append( sb, "", 0 ); |
141 | 0 | if ( detail ) |
142 | |
{ |
143 | 0 | append( sb, "Available parameters:", 1 ); |
144 | 0 | append( sb, "", 0 ); |
145 | |
|
146 | 0 | append( sb, "detail (Default: false)", 2 ); |
147 | 0 | append( sb, "If true, display all settable properties for each goal.", 3 ); |
148 | 0 | append( sb, "", 0 ); |
149 | |
|
150 | 0 | append( sb, "goal", 2 ); |
151 | 0 | append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 ); |
152 | 0 | append( sb, "", 0 ); |
153 | |
|
154 | 0 | append( sb, "indentSize (Default: 2)", 2 ); |
155 | 0 | append( sb, "The number of spaces per indentation level, should be positive.", 3 ); |
156 | 0 | append( sb, "", 0 ); |
157 | |
|
158 | 0 | append( sb, "lineLength (Default: 80)", 2 ); |
159 | 0 | append( sb, "The maximum length of a display line, should be positive.", 3 ); |
160 | 0 | append( sb, "", 0 ); |
161 | |
} |
162 | |
} |
163 | |
|
164 | 0 | if ( goal == null || goal.length() <= 0 || "jar".equals( goal ) ) |
165 | |
{ |
166 | 0 | append( sb, "source:jar", 0 ); |
167 | 0 | append( sb, "This plugin bundles all the sources into a jar archive.", 1 ); |
168 | 0 | append( sb, "", 0 ); |
169 | 0 | if ( detail ) |
170 | |
{ |
171 | 0 | append( sb, "Available parameters:", 1 ); |
172 | 0 | append( sb, "", 0 ); |
173 | |
|
174 | 0 | append( sb, "archive", 2 ); |
175 | 0 | append( sb, "The archive configuration to use. See Maven Archiver Reference.", 3 ); |
176 | 0 | append( sb, "", 0 ); |
177 | |
|
178 | 0 | append( sb, "attach (Default: true)", 2 ); |
179 | 0 | append( sb, "Specifies whether or not to attach the artifact to the project", 3 ); |
180 | 0 | append( sb, "", 0 ); |
181 | |
|
182 | 0 | append( sb, "excludeResources (Default: false)", 2 ); |
183 | 0 | append( sb, "Specifies whether or not to exclude resources from the sources-jar. This can be convenient if your project includes large resources, such as images, and you don\'t want to include them in the sources-jar.", 3 ); |
184 | 0 | append( sb, "", 0 ); |
185 | |
|
186 | 0 | append( sb, "excludes", 2 ); |
187 | 0 | append( sb, "List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
188 | 0 | append( sb, "", 0 ); |
189 | |
|
190 | 0 | append( sb, "finalName (Default: ${project.build.finalName})", 2 ); |
191 | 0 | append( sb, "The filename to be used for the generated archive file. For the source:jar goal, \'-sources\' is appended to this filename. For the source:test-jar goal, \'-test-sources\' is appended.", 3 ); |
192 | 0 | append( sb, "", 0 ); |
193 | |
|
194 | 0 | append( sb, "forceCreation (Default: false)", 2 ); |
195 | 0 | append( sb, "Whether creating the archive should be forced. If set to true, the jar will always be created. If set to false, the jar will only be created when the sources are newer than the jar.", 3 ); |
196 | 0 | append( sb, "", 0 ); |
197 | |
|
198 | 0 | append( sb, "includePom (Default: false)", 2 ); |
199 | 0 | append( sb, "Specifies whether or not to include the POM file in the sources-jar.", 3 ); |
200 | 0 | append( sb, "", 0 ); |
201 | |
|
202 | 0 | append( sb, "includes", 2 ); |
203 | 0 | append( sb, "List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
204 | 0 | append( sb, "", 0 ); |
205 | |
|
206 | 0 | append( sb, "outputDirectory (Default: ${project.build.directory})", 2 ); |
207 | 0 | append( sb, "The directory where the generated archive file will be put.", 3 ); |
208 | 0 | append( sb, "", 0 ); |
209 | |
|
210 | 0 | append( sb, "useDefaultExcludes (Default: true)", 2 ); |
211 | 0 | append( sb, "Exclude commonly excluded files such as SCM configuration. These are defined in the plexus FileUtils.getDefaultExcludes()", 3 ); |
212 | 0 | append( sb, "", 0 ); |
213 | |
|
214 | 0 | append( sb, "useDefaultManifestFile (Default: false)", 2 ); |
215 | 0 | append( sb, "Set this to true to enable the use of the defaultManifestFile.\n", 3 ); |
216 | 0 | append( sb, "", 0 ); |
217 | |
} |
218 | |
} |
219 | |
|
220 | 0 | if ( goal == null || goal.length() <= 0 || "jar-no-fork".equals( goal ) ) |
221 | |
{ |
222 | 0 | append( sb, "source:jar-no-fork", 0 ); |
223 | 0 | append( sb, "This goal bundles all the sources into a jar archive. This goal functions the same as the jar goal but does not fork the build and is suitable for attaching to the build lifecycle.", 1 ); |
224 | 0 | append( sb, "", 0 ); |
225 | 0 | if ( detail ) |
226 | |
{ |
227 | 0 | append( sb, "Available parameters:", 1 ); |
228 | 0 | append( sb, "", 0 ); |
229 | |
|
230 | 0 | append( sb, "archive", 2 ); |
231 | 0 | append( sb, "The archive configuration to use. See Maven Archiver Reference.", 3 ); |
232 | 0 | append( sb, "", 0 ); |
233 | |
|
234 | 0 | append( sb, "attach (Default: true)", 2 ); |
235 | 0 | append( sb, "Specifies whether or not to attach the artifact to the project", 3 ); |
236 | 0 | append( sb, "", 0 ); |
237 | |
|
238 | 0 | append( sb, "excludeResources (Default: false)", 2 ); |
239 | 0 | append( sb, "Specifies whether or not to exclude resources from the sources-jar. This can be convenient if your project includes large resources, such as images, and you don\'t want to include them in the sources-jar.", 3 ); |
240 | 0 | append( sb, "", 0 ); |
241 | |
|
242 | 0 | append( sb, "excludes", 2 ); |
243 | 0 | append( sb, "List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
244 | 0 | append( sb, "", 0 ); |
245 | |
|
246 | 0 | append( sb, "finalName (Default: ${project.build.finalName})", 2 ); |
247 | 0 | append( sb, "The filename to be used for the generated archive file. For the source:jar goal, \'-sources\' is appended to this filename. For the source:test-jar goal, \'-test-sources\' is appended.", 3 ); |
248 | 0 | append( sb, "", 0 ); |
249 | |
|
250 | 0 | append( sb, "forceCreation (Default: false)", 2 ); |
251 | 0 | append( sb, "Whether creating the archive should be forced. If set to true, the jar will always be created. If set to false, the jar will only be created when the sources are newer than the jar.", 3 ); |
252 | 0 | append( sb, "", 0 ); |
253 | |
|
254 | 0 | append( sb, "includePom (Default: false)", 2 ); |
255 | 0 | append( sb, "Specifies whether or not to include the POM file in the sources-jar.", 3 ); |
256 | 0 | append( sb, "", 0 ); |
257 | |
|
258 | 0 | append( sb, "includes", 2 ); |
259 | 0 | append( sb, "List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
260 | 0 | append( sb, "", 0 ); |
261 | |
|
262 | 0 | append( sb, "outputDirectory (Default: ${project.build.directory})", 2 ); |
263 | 0 | append( sb, "The directory where the generated archive file will be put.", 3 ); |
264 | 0 | append( sb, "", 0 ); |
265 | |
|
266 | 0 | append( sb, "useDefaultExcludes (Default: true)", 2 ); |
267 | 0 | append( sb, "Exclude commonly excluded files such as SCM configuration. These are defined in the plexus FileUtils.getDefaultExcludes()", 3 ); |
268 | 0 | append( sb, "", 0 ); |
269 | |
|
270 | 0 | append( sb, "useDefaultManifestFile (Default: false)", 2 ); |
271 | 0 | append( sb, "Set this to true to enable the use of the defaultManifestFile.\n", 3 ); |
272 | 0 | append( sb, "", 0 ); |
273 | |
} |
274 | |
} |
275 | |
|
276 | 0 | if ( goal == null || goal.length() <= 0 || "test-jar".equals( goal ) ) |
277 | |
{ |
278 | 0 | append( sb, "source:test-jar", 0 ); |
279 | 0 | append( sb, "This plugin bundles all the test sources into a jar archive.", 1 ); |
280 | 0 | append( sb, "", 0 ); |
281 | 0 | if ( detail ) |
282 | |
{ |
283 | 0 | append( sb, "Available parameters:", 1 ); |
284 | 0 | append( sb, "", 0 ); |
285 | |
|
286 | 0 | append( sb, "archive", 2 ); |
287 | 0 | append( sb, "The archive configuration to use. See Maven Archiver Reference.", 3 ); |
288 | 0 | append( sb, "", 0 ); |
289 | |
|
290 | 0 | append( sb, "attach (Default: true)", 2 ); |
291 | 0 | append( sb, "Specifies whether or not to attach the artifact to the project", 3 ); |
292 | 0 | append( sb, "", 0 ); |
293 | |
|
294 | 0 | append( sb, "excludeResources (Default: false)", 2 ); |
295 | 0 | append( sb, "Specifies whether or not to exclude resources from the sources-jar. This can be convenient if your project includes large resources, such as images, and you don\'t want to include them in the sources-jar.", 3 ); |
296 | 0 | append( sb, "", 0 ); |
297 | |
|
298 | 0 | append( sb, "excludes", 2 ); |
299 | 0 | append( sb, "List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
300 | 0 | append( sb, "", 0 ); |
301 | |
|
302 | 0 | append( sb, "finalName (Default: ${project.build.finalName})", 2 ); |
303 | 0 | append( sb, "The filename to be used for the generated archive file. For the source:jar goal, \'-sources\' is appended to this filename. For the source:test-jar goal, \'-test-sources\' is appended.", 3 ); |
304 | 0 | append( sb, "", 0 ); |
305 | |
|
306 | 0 | append( sb, "forceCreation (Default: false)", 2 ); |
307 | 0 | append( sb, "Whether creating the archive should be forced. If set to true, the jar will always be created. If set to false, the jar will only be created when the sources are newer than the jar.", 3 ); |
308 | 0 | append( sb, "", 0 ); |
309 | |
|
310 | 0 | append( sb, "includePom (Default: false)", 2 ); |
311 | 0 | append( sb, "Specifies whether or not to include the POM file in the sources-jar.", 3 ); |
312 | 0 | append( sb, "", 0 ); |
313 | |
|
314 | 0 | append( sb, "includes", 2 ); |
315 | 0 | append( sb, "List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
316 | 0 | append( sb, "", 0 ); |
317 | |
|
318 | 0 | append( sb, "outputDirectory (Default: ${project.build.directory})", 2 ); |
319 | 0 | append( sb, "The directory where the generated archive file will be put.", 3 ); |
320 | 0 | append( sb, "", 0 ); |
321 | |
|
322 | 0 | append( sb, "useDefaultExcludes (Default: true)", 2 ); |
323 | 0 | append( sb, "Exclude commonly excluded files such as SCM configuration. These are defined in the plexus FileUtils.getDefaultExcludes()", 3 ); |
324 | 0 | append( sb, "", 0 ); |
325 | |
|
326 | 0 | append( sb, "useDefaultManifestFile (Default: false)", 2 ); |
327 | 0 | append( sb, "Set this to true to enable the use of the defaultManifestFile.\n", 3 ); |
328 | 0 | append( sb, "", 0 ); |
329 | |
} |
330 | |
} |
331 | |
|
332 | 0 | if ( goal == null || goal.length() <= 0 || "test-jar-no-fork".equals( goal ) ) |
333 | |
{ |
334 | 0 | append( sb, "source:test-jar-no-fork", 0 ); |
335 | 0 | append( sb, "This goal bundles all the test sources into a jar archive. This goal functions the same as the test-jar goal but does not fork the build, and is suitable for attaching to the build lifecycle.", 1 ); |
336 | 0 | append( sb, "", 0 ); |
337 | 0 | if ( detail ) |
338 | |
{ |
339 | 0 | append( sb, "Available parameters:", 1 ); |
340 | 0 | append( sb, "", 0 ); |
341 | |
|
342 | 0 | append( sb, "archive", 2 ); |
343 | 0 | append( sb, "The archive configuration to use. See Maven Archiver Reference.", 3 ); |
344 | 0 | append( sb, "", 0 ); |
345 | |
|
346 | 0 | append( sb, "attach (Default: true)", 2 ); |
347 | 0 | append( sb, "Specifies whether or not to attach the artifact to the project", 3 ); |
348 | 0 | append( sb, "", 0 ); |
349 | |
|
350 | 0 | append( sb, "excludeResources (Default: false)", 2 ); |
351 | 0 | append( sb, "Specifies whether or not to exclude resources from the sources-jar. This can be convenient if your project includes large resources, such as images, and you don\'t want to include them in the sources-jar.", 3 ); |
352 | 0 | append( sb, "", 0 ); |
353 | |
|
354 | 0 | append( sb, "excludes", 2 ); |
355 | 0 | append( sb, "List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
356 | 0 | append( sb, "", 0 ); |
357 | |
|
358 | 0 | append( sb, "finalName (Default: ${project.build.finalName})", 2 ); |
359 | 0 | append( sb, "The filename to be used for the generated archive file. For the source:jar goal, \'-sources\' is appended to this filename. For the source:test-jar goal, \'-test-sources\' is appended.", 3 ); |
360 | 0 | append( sb, "", 0 ); |
361 | |
|
362 | 0 | append( sb, "forceCreation (Default: false)", 2 ); |
363 | 0 | append( sb, "Whether creating the archive should be forced. If set to true, the jar will always be created. If set to false, the jar will only be created when the sources are newer than the jar.", 3 ); |
364 | 0 | append( sb, "", 0 ); |
365 | |
|
366 | 0 | append( sb, "includePom (Default: false)", 2 ); |
367 | 0 | append( sb, "Specifies whether or not to include the POM file in the sources-jar.", 3 ); |
368 | 0 | append( sb, "", 0 ); |
369 | |
|
370 | 0 | append( sb, "includes", 2 ); |
371 | 0 | append( sb, "List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
372 | 0 | append( sb, "", 0 ); |
373 | |
|
374 | 0 | append( sb, "outputDirectory (Default: ${project.build.directory})", 2 ); |
375 | 0 | append( sb, "The directory where the generated archive file will be put.", 3 ); |
376 | 0 | append( sb, "", 0 ); |
377 | |
|
378 | 0 | append( sb, "useDefaultExcludes (Default: true)", 2 ); |
379 | 0 | append( sb, "Exclude commonly excluded files such as SCM configuration. These are defined in the plexus FileUtils.getDefaultExcludes()", 3 ); |
380 | 0 | append( sb, "", 0 ); |
381 | |
|
382 | 0 | append( sb, "useDefaultManifestFile (Default: false)", 2 ); |
383 | 0 | append( sb, "Set this to true to enable the use of the defaultManifestFile.\n", 3 ); |
384 | 0 | append( sb, "", 0 ); |
385 | |
} |
386 | |
} |
387 | |
|
388 | 0 | if ( getLog().isInfoEnabled() ) |
389 | |
{ |
390 | 0 | getLog().info( sb.toString() ); |
391 | |
} |
392 | 0 | } |
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | |
private static String repeat( String str, int repeat ) |
404 | |
{ |
405 | 0 | StringBuffer buffer = new StringBuffer( repeat * str.length() ); |
406 | |
|
407 | 0 | for ( int i = 0; i < repeat; i++ ) |
408 | |
{ |
409 | 0 | buffer.append( str ); |
410 | |
} |
411 | |
|
412 | 0 | return buffer.toString(); |
413 | |
} |
414 | |
|
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
|
422 | |
|
423 | |
private void append( StringBuffer sb, String description, int indent ) |
424 | |
{ |
425 | 0 | for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); ) |
426 | |
{ |
427 | 0 | sb.append( it.next().toString() ).append( '\n' ); |
428 | |
} |
429 | 0 | } |
430 | |
|
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
private static List toLines( String text, int indent, int indentSize, int lineLength ) |
442 | |
{ |
443 | 0 | List lines = new ArrayList(); |
444 | |
|
445 | 0 | String ind = repeat( "\t", indent ); |
446 | 0 | String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); |
447 | 0 | for ( int i = 0; i < plainLines.length; i++ ) |
448 | |
{ |
449 | 0 | toLines( lines, ind + plainLines[i], indentSize, lineLength ); |
450 | |
} |
451 | |
|
452 | 0 | return lines; |
453 | |
} |
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
|
461 | |
|
462 | |
|
463 | |
private static void toLines( List lines, String line, int indentSize, int lineLength ) |
464 | |
{ |
465 | 0 | int lineIndent = getIndentLevel( line ); |
466 | 0 | StringBuffer buf = new StringBuffer( 256 ); |
467 | 0 | String[] tokens = line.split( " +" ); |
468 | 0 | for ( int i = 0; i < tokens.length; i++ ) |
469 | |
{ |
470 | 0 | String token = tokens[i]; |
471 | 0 | if ( i > 0 ) |
472 | |
{ |
473 | 0 | if ( buf.length() + token.length() >= lineLength ) |
474 | |
{ |
475 | 0 | lines.add( buf.toString() ); |
476 | 0 | buf.setLength( 0 ); |
477 | 0 | buf.append( repeat( " ", lineIndent * indentSize ) ); |
478 | |
} |
479 | |
else |
480 | |
{ |
481 | 0 | buf.append( ' ' ); |
482 | |
} |
483 | |
} |
484 | 0 | for ( int j = 0; j < token.length(); j++ ) |
485 | |
{ |
486 | 0 | char c = token.charAt( j ); |
487 | 0 | if ( c == '\t' ) |
488 | |
{ |
489 | 0 | buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); |
490 | |
} |
491 | 0 | else if ( c == '\u00A0' ) |
492 | |
{ |
493 | 0 | buf.append( ' ' ); |
494 | |
} |
495 | |
else |
496 | |
{ |
497 | 0 | buf.append( c ); |
498 | |
} |
499 | |
} |
500 | |
} |
501 | 0 | lines.add( buf.toString() ); |
502 | 0 | } |
503 | |
|
504 | |
|
505 | |
|
506 | |
|
507 | |
|
508 | |
|
509 | |
|
510 | |
private static int getIndentLevel( String line ) |
511 | |
{ |
512 | 0 | int level = 0; |
513 | 0 | for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) |
514 | |
{ |
515 | 0 | level++; |
516 | |
} |
517 | 0 | for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) |
518 | |
{ |
519 | 0 | if ( line.charAt( i ) == '\t' ) |
520 | |
{ |
521 | 0 | level++; |
522 | 0 | break; |
523 | |
} |
524 | |
} |
525 | 0 | return level; |
526 | |
} |
527 | |
} |