001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 =================== DO NOT EDIT THIS FILE ==================== 019 Generated by Modello 2.5.1, 020 any modifications will be overwritten. 021 ============================================================== 022 */ 023 024package org.apache.maven.tools.plugin.extractor.model.io.xpp3; 025 026 //---------------------------------/ 027 //- Imported classes and packages -/ 028//---------------------------------/ 029 030import java.io.OutputStream; 031import java.io.Writer; 032import java.util.Iterator; 033import org.apache.maven.tools.plugin.extractor.model.Component; 034import org.apache.maven.tools.plugin.extractor.model.LifecycleExecution; 035import org.apache.maven.tools.plugin.extractor.model.Mojo; 036import org.apache.maven.tools.plugin.extractor.model.Parameter; 037import org.apache.maven.tools.plugin.extractor.model.PluginMetadata; 038import org.codehaus.plexus.util.xml.pull.MXSerializer; 039import org.codehaus.plexus.util.xml.pull.XmlSerializer; 040 041/** 042 * Class PluginMetadataXpp3Writer. 043 * 044 * @version $Revision$ $Date$ 045 */ 046@SuppressWarnings( "all" ) 047public class PluginMetadataXpp3Writer 048{ 049 050 //--------------------------/ 051 //- Class/Member Variables -/ 052 //--------------------------/ 053 054 /** 055 * Field NAMESPACE. 056 */ 057 private static final String NAMESPACE = null; 058 059 /** 060 * Field fileComment. 061 */ 062 private String fileComment = null; 063 064 065 //-----------/ 066 //- Methods -/ 067 //-----------/ 068 069 /** 070 * Method setFileComment. 071 * 072 * @param fileComment a fileComment object. 073 */ 074 public void setFileComment( String fileComment ) 075 { 076 this.fileComment = fileComment; 077 } //-- void setFileComment( String ) 078 079 /** 080 * Method write. 081 * 082 * @param writer a writer object. 083 * @param pluginMetadata a pluginMetadata object. 084 * @throws java.io.IOException java.io.IOException if any. 085 */ 086 public void write( Writer writer, PluginMetadata pluginMetadata ) 087 throws java.io.IOException 088 { 089 XmlSerializer serializer = new MXSerializer(); 090 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); 091 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); 092 serializer.setOutput( writer ); 093 serializer.startDocument( pluginMetadata.getModelEncoding(), null ); 094 writePluginMetadata( pluginMetadata, "pluginMetadata", serializer ); 095 serializer.endDocument(); 096 } //-- void write( Writer, PluginMetadata ) 097 098 /** 099 * Method write. 100 * 101 * @param stream a stream object. 102 * @param pluginMetadata a pluginMetadata object. 103 * @throws java.io.IOException java.io.IOException if any. 104 */ 105 public void write( OutputStream stream, PluginMetadata pluginMetadata ) 106 throws java.io.IOException 107 { 108 XmlSerializer serializer = new MXSerializer(); 109 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); 110 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); 111 serializer.setOutput( stream, pluginMetadata.getModelEncoding() ); 112 serializer.startDocument( pluginMetadata.getModelEncoding(), null ); 113 writePluginMetadata( pluginMetadata, "pluginMetadata", serializer ); 114 serializer.endDocument(); 115 } //-- void write( OutputStream, PluginMetadata ) 116 117 /** 118 * Method writeComponent. 119 * 120 * @param component a component object. 121 * @param serializer a serializer object. 122 * @param tagName a tagName object. 123 * @throws java.io.IOException java.io.IOException if any. 124 */ 125 private void writeComponent( Component component, String tagName, XmlSerializer serializer ) 126 throws java.io.IOException 127 { 128 serializer.startTag( NAMESPACE, tagName ); 129 if ( component.getRole() != null ) 130 { 131 serializer.startTag( NAMESPACE, "role" ).text( component.getRole() ).endTag( NAMESPACE, "role" ); 132 } 133 if ( component.getHint() != null ) 134 { 135 serializer.startTag( NAMESPACE, "hint" ).text( component.getHint() ).endTag( NAMESPACE, "hint" ); 136 } 137 serializer.endTag( NAMESPACE, tagName ); 138 } //-- void writeComponent( Component, String, XmlSerializer ) 139 140 /** 141 * Method writeLifecycleExecution. 142 * 143 * @param lifecycleExecution a lifecycleExecution object. 144 * @param serializer a serializer object. 145 * @param tagName a tagName object. 146 * @throws java.io.IOException java.io.IOException if any. 147 */ 148 private void writeLifecycleExecution( LifecycleExecution lifecycleExecution, String tagName, XmlSerializer serializer ) 149 throws java.io.IOException 150 { 151 serializer.startTag( NAMESPACE, tagName ); 152 if ( lifecycleExecution.getLifecycle() != null ) 153 { 154 serializer.startTag( NAMESPACE, "lifecycle" ).text( lifecycleExecution.getLifecycle() ).endTag( NAMESPACE, "lifecycle" ); 155 } 156 if ( lifecycleExecution.getPhase() != null ) 157 { 158 serializer.startTag( NAMESPACE, "phase" ).text( lifecycleExecution.getPhase() ).endTag( NAMESPACE, "phase" ); 159 } 160 if ( lifecycleExecution.getGoal() != null ) 161 { 162 serializer.startTag( NAMESPACE, "goal" ).text( lifecycleExecution.getGoal() ).endTag( NAMESPACE, "goal" ); 163 } 164 serializer.endTag( NAMESPACE, tagName ); 165 } //-- void writeLifecycleExecution( LifecycleExecution, String, XmlSerializer ) 166 167 /** 168 * Method writeMojo. 169 * 170 * @param mojo a mojo object. 171 * @param serializer a serializer object. 172 * @param tagName a tagName object. 173 * @throws java.io.IOException java.io.IOException if any. 174 */ 175 private void writeMojo( Mojo mojo, String tagName, XmlSerializer serializer ) 176 throws java.io.IOException 177 { 178 serializer.startTag( NAMESPACE, tagName ); 179 if ( mojo.getGoal() != null ) 180 { 181 serializer.startTag( NAMESPACE, "goal" ).text( mojo.getGoal() ).endTag( NAMESPACE, "goal" ); 182 } 183 if ( mojo.getPhase() != null ) 184 { 185 serializer.startTag( NAMESPACE, "phase" ).text( mojo.getPhase() ).endTag( NAMESPACE, "phase" ); 186 } 187 if ( mojo.isAggregator() != false ) 188 { 189 serializer.startTag( NAMESPACE, "aggregator" ).text( String.valueOf( mojo.isAggregator() ) ).endTag( NAMESPACE, "aggregator" ); 190 } 191 if ( mojo.getRequiresDependencyResolution() != null ) 192 { 193 serializer.startTag( NAMESPACE, "requiresDependencyResolution" ).text( mojo.getRequiresDependencyResolution() ).endTag( NAMESPACE, "requiresDependencyResolution" ); 194 } 195 if ( mojo.isRequiresProject() != false ) 196 { 197 serializer.startTag( NAMESPACE, "requiresProject" ).text( String.valueOf( mojo.isRequiresProject() ) ).endTag( NAMESPACE, "requiresProject" ); 198 } 199 if ( mojo.isRequiresReports() != false ) 200 { 201 serializer.startTag( NAMESPACE, "requiresReports" ).text( String.valueOf( mojo.isRequiresReports() ) ).endTag( NAMESPACE, "requiresReports" ); 202 } 203 if ( mojo.isRequiresOnline() != false ) 204 { 205 serializer.startTag( NAMESPACE, "requiresOnline" ).text( String.valueOf( mojo.isRequiresOnline() ) ).endTag( NAMESPACE, "requiresOnline" ); 206 } 207 if ( mojo.isInheritByDefault() != false ) 208 { 209 serializer.startTag( NAMESPACE, "inheritByDefault" ).text( String.valueOf( mojo.isInheritByDefault() ) ).endTag( NAMESPACE, "inheritByDefault" ); 210 } 211 if ( mojo.isRequiresDirectInvocation() != false ) 212 { 213 serializer.startTag( NAMESPACE, "requiresDirectInvocation" ).text( String.valueOf( mojo.isRequiresDirectInvocation() ) ).endTag( NAMESPACE, "requiresDirectInvocation" ); 214 } 215 if ( mojo.getExecution() != null ) 216 { 217 writeLifecycleExecution( (LifecycleExecution) mojo.getExecution(), "execution", serializer ); 218 } 219 if ( ( mojo.getComponents() != null ) && ( mojo.getComponents().size() > 0 ) ) 220 { 221 serializer.startTag( NAMESPACE, "components" ); 222 for ( Iterator iter = mojo.getComponents().iterator(); iter.hasNext(); ) 223 { 224 Component o = (Component) iter.next(); 225 writeComponent( o, "component", serializer ); 226 } 227 serializer.endTag( NAMESPACE, "components" ); 228 } 229 if ( ( mojo.getParameters() != null ) && ( mojo.getParameters().size() > 0 ) ) 230 { 231 serializer.startTag( NAMESPACE, "parameters" ); 232 for ( Iterator iter = mojo.getParameters().iterator(); iter.hasNext(); ) 233 { 234 Parameter o = (Parameter) iter.next(); 235 writeParameter( o, "parameter", serializer ); 236 } 237 serializer.endTag( NAMESPACE, "parameters" ); 238 } 239 if ( mojo.getDescription() != null ) 240 { 241 serializer.startTag( NAMESPACE, "description" ).text( mojo.getDescription() ).endTag( NAMESPACE, "description" ); 242 } 243 if ( mojo.getDeprecation() != null ) 244 { 245 serializer.startTag( NAMESPACE, "deprecated" ).text( mojo.getDeprecation() ).endTag( NAMESPACE, "deprecated" ); 246 } 247 if ( mojo.getSince() != null ) 248 { 249 serializer.startTag( NAMESPACE, "since" ).text( mojo.getSince() ).endTag( NAMESPACE, "since" ); 250 } 251 if ( mojo.getCall() != null ) 252 { 253 serializer.startTag( NAMESPACE, "call" ).text( mojo.getCall() ).endTag( NAMESPACE, "call" ); 254 } 255 serializer.endTag( NAMESPACE, tagName ); 256 } //-- void writeMojo( Mojo, String, XmlSerializer ) 257 258 /** 259 * Method writeParameter. 260 * 261 * @param parameter a parameter object. 262 * @param serializer a serializer object. 263 * @param tagName a tagName object. 264 * @throws java.io.IOException java.io.IOException if any. 265 */ 266 private void writeParameter( Parameter parameter, String tagName, XmlSerializer serializer ) 267 throws java.io.IOException 268 { 269 serializer.startTag( NAMESPACE, tagName ); 270 if ( parameter.getName() != null ) 271 { 272 serializer.startTag( NAMESPACE, "name" ).text( parameter.getName() ).endTag( NAMESPACE, "name" ); 273 } 274 if ( parameter.getAlias() != null ) 275 { 276 serializer.startTag( NAMESPACE, "alias" ).text( parameter.getAlias() ).endTag( NAMESPACE, "alias" ); 277 } 278 if ( parameter.getProperty() != null ) 279 { 280 serializer.startTag( NAMESPACE, "property" ).text( parameter.getProperty() ).endTag( NAMESPACE, "property" ); 281 } 282 if ( parameter.isRequired() != false ) 283 { 284 serializer.startTag( NAMESPACE, "required" ).text( String.valueOf( parameter.isRequired() ) ).endTag( NAMESPACE, "required" ); 285 } 286 if ( parameter.isReadonly() != false ) 287 { 288 serializer.startTag( NAMESPACE, "readonly" ).text( String.valueOf( parameter.isReadonly() ) ).endTag( NAMESPACE, "readonly" ); 289 } 290 if ( parameter.getExpression() != null ) 291 { 292 serializer.startTag( NAMESPACE, "expression" ).text( parameter.getExpression() ).endTag( NAMESPACE, "expression" ); 293 } 294 if ( parameter.getDefaultValue() != null ) 295 { 296 serializer.startTag( NAMESPACE, "defaultValue" ).text( parameter.getDefaultValue() ).endTag( NAMESPACE, "defaultValue" ); 297 } 298 if ( parameter.getType() != null ) 299 { 300 serializer.startTag( NAMESPACE, "type" ).text( parameter.getType() ).endTag( NAMESPACE, "type" ); 301 } 302 if ( parameter.getDescription() != null ) 303 { 304 serializer.startTag( NAMESPACE, "description" ).text( parameter.getDescription() ).endTag( NAMESPACE, "description" ); 305 } 306 if ( parameter.getDeprecation() != null ) 307 { 308 serializer.startTag( NAMESPACE, "deprecated" ).text( parameter.getDeprecation() ).endTag( NAMESPACE, "deprecated" ); 309 } 310 if ( parameter.getSince() != null ) 311 { 312 serializer.startTag( NAMESPACE, "since" ).text( parameter.getSince() ).endTag( NAMESPACE, "since" ); 313 } 314 serializer.endTag( NAMESPACE, tagName ); 315 } //-- void writeParameter( Parameter, String, XmlSerializer ) 316 317 /** 318 * Method writePluginMetadata. 319 * 320 * @param pluginMetadata a pluginMetadata object. 321 * @param serializer a serializer object. 322 * @param tagName a tagName object. 323 * @throws java.io.IOException java.io.IOException if any. 324 */ 325 private void writePluginMetadata( PluginMetadata pluginMetadata, String tagName, XmlSerializer serializer ) 326 throws java.io.IOException 327 { 328 serializer.startTag( NAMESPACE, tagName ); 329 if ( ( pluginMetadata.getMojos() != null ) && ( pluginMetadata.getMojos().size() > 0 ) ) 330 { 331 serializer.startTag( NAMESPACE, "mojos" ); 332 for ( Iterator iter = pluginMetadata.getMojos().iterator(); iter.hasNext(); ) 333 { 334 Mojo o = (Mojo) iter.next(); 335 writeMojo( o, "mojo", serializer ); 336 } 337 serializer.endTag( NAMESPACE, "mojos" ); 338 } 339 serializer.endTag( NAMESPACE, tagName ); 340 } //-- void writePluginMetadata( PluginMetadata, String, XmlSerializer ) 341 342}