Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractHelpMojo |
|
| 2.0;2 |
1 | package org.apache.maven.plugins.help; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.File; | |
23 | import java.io.IOException; | |
24 | import java.io.Writer; | |
25 | ||
26 | import org.apache.maven.plugin.AbstractMojo; | |
27 | import org.codehaus.plexus.util.IOUtil; | |
28 | import org.codehaus.plexus.util.WriterFactory; | |
29 | ||
30 | /** | |
31 | * Base class with some Help Mojo functionalities. | |
32 | * | |
33 | * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a> | |
34 | * @version $Id: AbstractHelpMojo.java 689770 2008-08-28 09:47:18Z vsiveton $ | |
35 | * @since 2.1 | |
36 | */ | |
37 | 0 | public abstract class AbstractHelpMojo |
38 | extends AbstractMojo | |
39 | { | |
40 | /** The maximum length of a display line. */ | |
41 | protected static final int LINE_LENGTH = 79; | |
42 | ||
43 | /** | |
44 | * Optional parameter to write the output of this help in a given file, instead of writing to the console. | |
45 | * <br/> | |
46 | * <b>Note</b>: Could be a relative path. | |
47 | * | |
48 | * @parameter expression="${output}" | |
49 | */ | |
50 | protected File output; | |
51 | ||
52 | /** | |
53 | * Utility method to write a content in a given file. | |
54 | * | |
55 | * @param output is the wanted output file. | |
56 | * @param content contains the content to be written to the file. | |
57 | * @throws IOException if any | |
58 | * @see #writeFile(File, String) | |
59 | */ | |
60 | protected static void writeFile( File output, StringBuffer content ) | |
61 | throws IOException | |
62 | { | |
63 | 0 | writeFile( output, content.toString() ); |
64 | 0 | } |
65 | ||
66 | /** | |
67 | * Utility method to write a content in a given file. | |
68 | * | |
69 | * @param output is the wanted output file. | |
70 | * @param content contains the content to be written to the file. | |
71 | * @throws IOException if any | |
72 | */ | |
73 | protected static void writeFile( File output, String content ) | |
74 | throws IOException | |
75 | { | |
76 | 0 | if ( output == null ) |
77 | { | |
78 | 0 | return; |
79 | } | |
80 | ||
81 | 0 | Writer out = null; |
82 | try | |
83 | { | |
84 | 0 | output.getParentFile().mkdirs(); |
85 | ||
86 | 0 | out = WriterFactory.newPlatformWriter( output ); |
87 | ||
88 | 0 | out.write( content ); |
89 | ||
90 | 0 | out.flush(); |
91 | } | |
92 | finally | |
93 | { | |
94 | 0 | IOUtil.close( out ); |
95 | 0 | } |
96 | 0 | } |
97 | } |