1
- package org .apache .maven .plugins .help ;
2
-
3
1
/*
4
2
* Licensed to the Apache Software Foundation (ASF) under one
5
3
* or more contributor license agreements. See the NOTICE file
18
16
* specific language governing permissions and limitations
19
17
* under the License.
20
18
*/
19
+ package org .apache .maven .plugins .help ;
20
+
21
+ import javax .xml .XMLConstants ;
21
22
22
23
import java .io .File ;
23
24
import java .io .IOException ;
40
41
import org .jdom2 .output .Format ;
41
42
import org .jdom2 .output .XMLOutputter ;
42
43
43
- import javax .xml .XMLConstants ;
44
-
45
44
/**
46
45
* Base class with common utilities to write effective Pom/settings.
47
46
*
48
47
* @author <a href="mailto:[email protected] ">Vincent Siveton</a>
49
48
* @since 2.1
50
49
*/
51
- public abstract class AbstractEffectiveMojo
52
- extends AbstractHelpMojo
53
- {
50
+ public abstract class AbstractEffectiveMojo extends AbstractHelpMojo {
54
51
/**
55
52
* Utility method to write an XML content in a given file.
56
53
*
@@ -59,18 +56,14 @@ public abstract class AbstractEffectiveMojo
59
56
* @throws IOException if any
60
57
* @see AbstractHelpMojo#writeFile(File, String) if encoding is null.
61
58
*/
62
- protected static void writeXmlFile ( File output , String content )
63
- throws IOException
64
- {
65
- if ( output == null )
66
- {
59
+ protected static void writeXmlFile (File output , String content ) throws IOException {
60
+ if (output == null ) {
67
61
return ;
68
62
}
69
63
70
64
output .getParentFile ().mkdirs ();
71
- try ( Writer out = WriterFactory .newXmlWriter ( output ) )
72
- {
73
- out .write ( content );
65
+ try (Writer out = WriterFactory .newXmlWriter (output )) {
66
+ out .write (content );
74
67
}
75
68
}
76
69
@@ -79,14 +72,13 @@ protected static void writeXmlFile( File output, String content )
79
72
*
80
73
* @param writer not null
81
74
*/
82
- protected static void writeHeader ( XMLWriter writer )
83
- {
84
- XmlWriterUtil .writeCommentLineBreak ( writer );
85
- XmlWriterUtil .writeComment ( writer , " " );
86
- XmlWriterUtil .writeComment ( writer , "Generated by Maven Help Plugin" );
87
- XmlWriterUtil .writeComment ( writer , "See: https://maven.apache.org/plugins/maven-help-plugin/" );
88
- XmlWriterUtil .writeComment ( writer , " " );
89
- XmlWriterUtil .writeCommentLineBreak ( writer );
75
+ protected static void writeHeader (XMLWriter writer ) {
76
+ XmlWriterUtil .writeCommentLineBreak (writer );
77
+ XmlWriterUtil .writeComment (writer , " " );
78
+ XmlWriterUtil .writeComment (writer , "Generated by Maven Help Plugin" );
79
+ XmlWriterUtil .writeComment (writer , "See: https://maven.apache.org/plugins/maven-help-plugin/" );
80
+ XmlWriterUtil .writeComment (writer , " " );
81
+ XmlWriterUtil .writeCommentLineBreak (writer );
90
82
}
91
83
92
84
/**
@@ -95,13 +87,12 @@ protected static void writeHeader( XMLWriter writer )
95
87
* @param writer not null
96
88
* @param comment not null
97
89
*/
98
- protected static void writeComment ( XMLWriter writer , String comment )
99
- {
100
- XmlWriterUtil .writeCommentLineBreak ( writer );
101
- XmlWriterUtil .writeComment ( writer , " " );
102
- XmlWriterUtil .writeComment ( writer , comment );
103
- XmlWriterUtil .writeComment ( writer , " " );
104
- XmlWriterUtil .writeCommentLineBreak ( writer );
90
+ protected static void writeComment (XMLWriter writer , String comment ) {
91
+ XmlWriterUtil .writeCommentLineBreak (writer );
92
+ XmlWriterUtil .writeComment (writer , " " );
93
+ XmlWriterUtil .writeComment (writer , comment );
94
+ XmlWriterUtil .writeComment (writer , " " );
95
+ XmlWriterUtil .writeCommentLineBreak (writer );
105
96
}
106
97
107
98
/**
@@ -110,54 +101,46 @@ protected static void writeComment( XMLWriter writer, String comment )
110
101
* @param omitDeclaration whether the XML declaration should be omitted from the effective pom
111
102
* @return pretty format of the xml or the original {@code effectiveModel} if an error occurred.
112
103
*/
113
- protected static String prettyFormat ( String effectiveModel , String encoding , boolean omitDeclaration )
114
- {
104
+ protected static String prettyFormat (String effectiveModel , String encoding , boolean omitDeclaration ) {
115
105
SAXBuilder builder = new SAXBuilder ();
116
- builder .setProperty ( XMLConstants .ACCESS_EXTERNAL_DTD , "" );
117
- builder .setProperty ( XMLConstants .ACCESS_EXTERNAL_SCHEMA , "" );
118
- try
119
- {
120
- Document effectiveDocument = builder .build ( new StringReader ( effectiveModel ) );
106
+ builder .setProperty (XMLConstants .ACCESS_EXTERNAL_DTD , "" );
107
+ builder .setProperty (XMLConstants .ACCESS_EXTERNAL_SCHEMA , "" );
108
+ try {
109
+ Document effectiveDocument = builder .build (new StringReader (effectiveModel ));
121
110
122
111
StringWriter w = new StringWriter ();
123
112
Format format = Format .getPrettyFormat ();
124
- if ( encoding != null )
125
- {
113
+ if (encoding != null ) {
126
114
// This is a design flaw in JDOM, no NPE on null arguments, but null is not prohibited
127
- format .setEncoding ( encoding );
115
+ format .setEncoding (encoding );
128
116
}
129
- format .setLineSeparator ( System .lineSeparator () );
130
- format .setOmitDeclaration ( omitDeclaration );
131
- XMLOutputter out = new XMLOutputter ( format );
132
- out .output ( effectiveDocument , w );
117
+ format .setLineSeparator (System .lineSeparator ());
118
+ format .setOmitDeclaration (omitDeclaration );
119
+ XMLOutputter out = new XMLOutputter (format );
120
+ out .output (effectiveDocument , w );
133
121
134
122
return w .toString ();
135
- }
136
- catch ( JDOMException | IOException e )
137
- {
123
+ } catch (JDOMException | IOException e ) {
138
124
return effectiveModel ;
139
125
}
140
126
}
141
127
142
128
/**
143
129
* Properties which provides a sorted keySet().
144
130
*/
145
- protected static class SortedProperties
146
- extends Properties
147
- {
131
+ protected static class SortedProperties extends Properties {
148
132
/** serialVersionUID */
149
133
static final long serialVersionUID = -8985316072702233744L ;
150
134
151
135
/** {@inheritDoc} */
152
- @ SuppressWarnings ( { "rawtypes" , "unchecked" } )
136
+ @ SuppressWarnings ({ "rawtypes" , "unchecked" } )
153
137
@ Override
154
- public Set <Object > keySet ()
155
- {
138
+ public Set <Object > keySet () {
156
139
Set <Object > keynames = super .keySet ();
157
- List list = new ArrayList ( keynames );
158
- Collections .sort ( list );
140
+ List list = new ArrayList (keynames );
141
+ Collections .sort (list );
159
142
160
- return new LinkedHashSet <>( list );
143
+ return new LinkedHashSet <>(list );
161
144
}
162
145
}
163
146
}
0 commit comments