| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
package org.apache.maven.profiles.io.xpp3; |
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
import java.io.Writer; |
| 12 | |
import java.text.DateFormat; |
| 13 | |
import java.util.Iterator; |
| 14 | |
import java.util.Locale; |
| 15 | |
import org.apache.maven.profiles.Activation; |
| 16 | |
import org.apache.maven.profiles.ActivationFile; |
| 17 | |
import org.apache.maven.profiles.ActivationOS; |
| 18 | |
import org.apache.maven.profiles.ActivationProperty; |
| 19 | |
import org.apache.maven.profiles.Profile; |
| 20 | |
import org.apache.maven.profiles.ProfilesRoot; |
| 21 | |
import org.apache.maven.profiles.Repository; |
| 22 | |
import org.apache.maven.profiles.RepositoryBase; |
| 23 | |
import org.apache.maven.profiles.RepositoryPolicy; |
| 24 | |
import org.codehaus.plexus.util.xml.pull.MXSerializer; |
| 25 | |
import org.codehaus.plexus.util.xml.pull.XmlSerializer; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 0 | public class ProfilesXpp3Writer { |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
private String NAMESPACE; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
public void write( Writer writer, ProfilesRoot profilesRoot ) |
| 57 | |
throws java.io.IOException |
| 58 | |
{ |
| 59 | 0 | XmlSerializer serializer = new MXSerializer(); |
| 60 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); |
| 61 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); |
| 62 | 0 | serializer.setOutput( writer ); |
| 63 | 0 | serializer.startDocument( profilesRoot.getModelEncoding(), null ); |
| 64 | 0 | writeProfilesRoot( profilesRoot, "profilesXml", serializer ); |
| 65 | 0 | serializer.endDocument(); |
| 66 | 0 | } |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
private void writeActivation( Activation activation, String tagName, XmlSerializer serializer ) |
| 77 | |
throws java.io.IOException |
| 78 | |
{ |
| 79 | 0 | if ( activation != null ) |
| 80 | |
{ |
| 81 | 0 | serializer.startTag( NAMESPACE, tagName ); |
| 82 | 0 | if ( activation.isActiveByDefault() != false ) |
| 83 | |
{ |
| 84 | 0 | serializer.startTag( NAMESPACE, "activeByDefault" ).text( String.valueOf( activation.isActiveByDefault() ) ).endTag( NAMESPACE, "activeByDefault" ); |
| 85 | |
} |
| 86 | 0 | if ( activation.getJdk() != null ) |
| 87 | |
{ |
| 88 | 0 | serializer.startTag( NAMESPACE, "jdk" ).text( activation.getJdk() ).endTag( NAMESPACE, "jdk" ); |
| 89 | |
} |
| 90 | 0 | if ( activation.getOs() != null ) |
| 91 | |
{ |
| 92 | 0 | writeActivationOS( (ActivationOS) activation.getOs(), "os", serializer ); |
| 93 | |
} |
| 94 | 0 | if ( activation.getProperty() != null ) |
| 95 | |
{ |
| 96 | 0 | writeActivationProperty( (ActivationProperty) activation.getProperty(), "property", serializer ); |
| 97 | |
} |
| 98 | 0 | if ( activation.getFile() != null ) |
| 99 | |
{ |
| 100 | 0 | writeActivationFile( (ActivationFile) activation.getFile(), "file", serializer ); |
| 101 | |
} |
| 102 | 0 | serializer.endTag( NAMESPACE, tagName ); |
| 103 | |
} |
| 104 | 0 | } |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
private void writeActivationFile( ActivationFile activationFile, String tagName, XmlSerializer serializer ) |
| 115 | |
throws java.io.IOException |
| 116 | |
{ |
| 117 | 0 | if ( activationFile != null ) |
| 118 | |
{ |
| 119 | 0 | serializer.startTag( NAMESPACE, tagName ); |
| 120 | 0 | if ( activationFile.getMissing() != null ) |
| 121 | |
{ |
| 122 | 0 | serializer.startTag( NAMESPACE, "missing" ).text( activationFile.getMissing() ).endTag( NAMESPACE, "missing" ); |
| 123 | |
} |
| 124 | 0 | if ( activationFile.getExists() != null ) |
| 125 | |
{ |
| 126 | 0 | serializer.startTag( NAMESPACE, "exists" ).text( activationFile.getExists() ).endTag( NAMESPACE, "exists" ); |
| 127 | |
} |
| 128 | 0 | serializer.endTag( NAMESPACE, tagName ); |
| 129 | |
} |
| 130 | 0 | } |
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
private void writeActivationOS( ActivationOS activationOS, String tagName, XmlSerializer serializer ) |
| 141 | |
throws java.io.IOException |
| 142 | |
{ |
| 143 | 0 | if ( activationOS != null ) |
| 144 | |
{ |
| 145 | 0 | serializer.startTag( NAMESPACE, tagName ); |
| 146 | 0 | if ( activationOS.getName() != null ) |
| 147 | |
{ |
| 148 | 0 | serializer.startTag( NAMESPACE, "name" ).text( activationOS.getName() ).endTag( NAMESPACE, "name" ); |
| 149 | |
} |
| 150 | 0 | if ( activationOS.getFamily() != null ) |
| 151 | |
{ |
| 152 | 0 | serializer.startTag( NAMESPACE, "family" ).text( activationOS.getFamily() ).endTag( NAMESPACE, "family" ); |
| 153 | |
} |
| 154 | 0 | if ( activationOS.getArch() != null ) |
| 155 | |
{ |
| 156 | 0 | serializer.startTag( NAMESPACE, "arch" ).text( activationOS.getArch() ).endTag( NAMESPACE, "arch" ); |
| 157 | |
} |
| 158 | 0 | if ( activationOS.getVersion() != null ) |
| 159 | |
{ |
| 160 | 0 | serializer.startTag( NAMESPACE, "version" ).text( activationOS.getVersion() ).endTag( NAMESPACE, "version" ); |
| 161 | |
} |
| 162 | 0 | serializer.endTag( NAMESPACE, tagName ); |
| 163 | |
} |
| 164 | 0 | } |
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
private void writeActivationProperty( ActivationProperty activationProperty, String tagName, XmlSerializer serializer ) |
| 175 | |
throws java.io.IOException |
| 176 | |
{ |
| 177 | 0 | if ( activationProperty != null ) |
| 178 | |
{ |
| 179 | 0 | serializer.startTag( NAMESPACE, tagName ); |
| 180 | 0 | if ( activationProperty.getName() != null ) |
| 181 | |
{ |
| 182 | 0 | serializer.startTag( NAMESPACE, "name" ).text( activationProperty.getName() ).endTag( NAMESPACE, "name" ); |
| 183 | |
} |
| 184 | 0 | if ( activationProperty.getValue() != null ) |
| 185 | |
{ |
| 186 | 0 | serializer.startTag( NAMESPACE, "value" ).text( activationProperty.getValue() ).endTag( NAMESPACE, "value" ); |
| 187 | |
} |
| 188 | 0 | serializer.endTag( NAMESPACE, tagName ); |
| 189 | |
} |
| 190 | 0 | } |
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
private void writeProfile( Profile profile, String tagName, XmlSerializer serializer ) |
| 201 | |
throws java.io.IOException |
| 202 | |
{ |
| 203 | 0 | if ( profile != null ) |
| 204 | |
{ |
| 205 | 0 | serializer.startTag( NAMESPACE, tagName ); |
| 206 | 0 | if ( profile.getId() != null ) |
| 207 | |
{ |
| 208 | 0 | serializer.startTag( NAMESPACE, "id" ).text( profile.getId() ).endTag( NAMESPACE, "id" ); |
| 209 | |
} |
| 210 | 0 | if ( profile.getActivation() != null ) |
| 211 | |
{ |
| 212 | 0 | writeActivation( (Activation) profile.getActivation(), "activation", serializer ); |
| 213 | |
} |
| 214 | 0 | if ( profile.getProperties() != null && profile.getProperties().size() > 0 ) |
| 215 | |
{ |
| 216 | 0 | serializer.startTag( NAMESPACE, "properties" ); |
| 217 | 0 | for ( Iterator iter = profile.getProperties().keySet().iterator(); iter.hasNext(); ) |
| 218 | |
{ |
| 219 | 0 | String key = (String) iter.next(); |
| 220 | 0 | String value = (String) profile.getProperties().get( key ); |
| 221 | 0 | serializer.startTag( NAMESPACE, "" + key + "" ).text( value ).endTag( NAMESPACE, "" + key + "" ); |
| 222 | 0 | } |
| 223 | 0 | serializer.endTag( NAMESPACE, "properties" ); |
| 224 | |
} |
| 225 | 0 | if ( profile.getRepositories() != null && profile.getRepositories().size() > 0 ) |
| 226 | |
{ |
| 227 | 0 | serializer.startTag( NAMESPACE, "repositories" ); |
| 228 | 0 | for ( Iterator iter = profile.getRepositories().iterator(); iter.hasNext(); ) |
| 229 | |
{ |
| 230 | 0 | Repository o = (Repository) iter.next(); |
| 231 | 0 | writeRepository( o, "repository", serializer ); |
| 232 | 0 | } |
| 233 | 0 | serializer.endTag( NAMESPACE, "repositories" ); |
| 234 | |
} |
| 235 | 0 | if ( profile.getPluginRepositories() != null && profile.getPluginRepositories().size() > 0 ) |
| 236 | |
{ |
| 237 | 0 | serializer.startTag( NAMESPACE, "pluginRepositories" ); |
| 238 | 0 | for ( Iterator iter = profile.getPluginRepositories().iterator(); iter.hasNext(); ) |
| 239 | |
{ |
| 240 | 0 | Repository o = (Repository) iter.next(); |
| 241 | 0 | writeRepository( o, "pluginRepository", serializer ); |
| 242 | 0 | } |
| 243 | 0 | serializer.endTag( NAMESPACE, "pluginRepositories" ); |
| 244 | |
} |
| 245 | 0 | serializer.endTag( NAMESPACE, tagName ); |
| 246 | |
} |
| 247 | 0 | } |
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
private void writeProfilesRoot( ProfilesRoot profilesRoot, String tagName, XmlSerializer serializer ) |
| 258 | |
throws java.io.IOException |
| 259 | |
{ |
| 260 | 0 | if ( profilesRoot != null ) |
| 261 | |
{ |
| 262 | 0 | serializer.startTag( NAMESPACE, tagName ); |
| 263 | 0 | if ( profilesRoot.getProfiles() != null && profilesRoot.getProfiles().size() > 0 ) |
| 264 | |
{ |
| 265 | 0 | serializer.startTag( NAMESPACE, "profiles" ); |
| 266 | 0 | for ( Iterator iter = profilesRoot.getProfiles().iterator(); iter.hasNext(); ) |
| 267 | |
{ |
| 268 | 0 | Profile o = (Profile) iter.next(); |
| 269 | 0 | writeProfile( o, "profile", serializer ); |
| 270 | 0 | } |
| 271 | 0 | serializer.endTag( NAMESPACE, "profiles" ); |
| 272 | |
} |
| 273 | 0 | if ( profilesRoot.getActiveProfiles() != null && profilesRoot.getActiveProfiles().size() > 0 ) |
| 274 | |
{ |
| 275 | 0 | serializer.startTag( NAMESPACE, "activeProfiles" ); |
| 276 | 0 | for ( Iterator iter = profilesRoot.getActiveProfiles().iterator(); iter.hasNext(); ) |
| 277 | |
{ |
| 278 | 0 | String activeProfile = (String) iter.next(); |
| 279 | 0 | serializer.startTag( NAMESPACE, "activeProfile" ).text( activeProfile ).endTag( NAMESPACE, "activeProfile" ); |
| 280 | 0 | } |
| 281 | 0 | serializer.endTag( NAMESPACE, "activeProfiles" ); |
| 282 | |
} |
| 283 | 0 | serializer.endTag( NAMESPACE, tagName ); |
| 284 | |
} |
| 285 | 0 | } |
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
private void writeRepository( Repository repository, String tagName, XmlSerializer serializer ) |
| 296 | |
throws java.io.IOException |
| 297 | |
{ |
| 298 | 0 | if ( repository != null ) |
| 299 | |
{ |
| 300 | 0 | serializer.startTag( NAMESPACE, tagName ); |
| 301 | 0 | if ( repository.getReleases() != null ) |
| 302 | |
{ |
| 303 | 0 | writeRepositoryPolicy( (RepositoryPolicy) repository.getReleases(), "releases", serializer ); |
| 304 | |
} |
| 305 | 0 | if ( repository.getSnapshots() != null ) |
| 306 | |
{ |
| 307 | 0 | writeRepositoryPolicy( (RepositoryPolicy) repository.getSnapshots(), "snapshots", serializer ); |
| 308 | |
} |
| 309 | 0 | if ( repository.getId() != null ) |
| 310 | |
{ |
| 311 | 0 | serializer.startTag( NAMESPACE, "id" ).text( repository.getId() ).endTag( NAMESPACE, "id" ); |
| 312 | |
} |
| 313 | 0 | if ( repository.getName() != null ) |
| 314 | |
{ |
| 315 | 0 | serializer.startTag( NAMESPACE, "name" ).text( repository.getName() ).endTag( NAMESPACE, "name" ); |
| 316 | |
} |
| 317 | 0 | if ( repository.getUrl() != null ) |
| 318 | |
{ |
| 319 | 0 | serializer.startTag( NAMESPACE, "url" ).text( repository.getUrl() ).endTag( NAMESPACE, "url" ); |
| 320 | |
} |
| 321 | 0 | if ( repository.getLayout() != null && !repository.getLayout().equals( "default" ) ) |
| 322 | |
{ |
| 323 | 0 | serializer.startTag( NAMESPACE, "layout" ).text( repository.getLayout() ).endTag( NAMESPACE, "layout" ); |
| 324 | |
} |
| 325 | 0 | serializer.endTag( NAMESPACE, tagName ); |
| 326 | |
} |
| 327 | 0 | } |
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
private void writeRepositoryBase( RepositoryBase repositoryBase, String tagName, XmlSerializer serializer ) |
| 338 | |
throws java.io.IOException |
| 339 | |
{ |
| 340 | 0 | if ( repositoryBase != null ) |
| 341 | |
{ |
| 342 | 0 | serializer.startTag( NAMESPACE, tagName ); |
| 343 | 0 | if ( repositoryBase.getId() != null ) |
| 344 | |
{ |
| 345 | 0 | serializer.startTag( NAMESPACE, "id" ).text( repositoryBase.getId() ).endTag( NAMESPACE, "id" ); |
| 346 | |
} |
| 347 | 0 | if ( repositoryBase.getName() != null ) |
| 348 | |
{ |
| 349 | 0 | serializer.startTag( NAMESPACE, "name" ).text( repositoryBase.getName() ).endTag( NAMESPACE, "name" ); |
| 350 | |
} |
| 351 | 0 | if ( repositoryBase.getUrl() != null ) |
| 352 | |
{ |
| 353 | 0 | serializer.startTag( NAMESPACE, "url" ).text( repositoryBase.getUrl() ).endTag( NAMESPACE, "url" ); |
| 354 | |
} |
| 355 | 0 | if ( repositoryBase.getLayout() != null && !repositoryBase.getLayout().equals( "default" ) ) |
| 356 | |
{ |
| 357 | 0 | serializer.startTag( NAMESPACE, "layout" ).text( repositoryBase.getLayout() ).endTag( NAMESPACE, "layout" ); |
| 358 | |
} |
| 359 | 0 | serializer.endTag( NAMESPACE, tagName ); |
| 360 | |
} |
| 361 | 0 | } |
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | |
private void writeRepositoryPolicy( RepositoryPolicy repositoryPolicy, String tagName, XmlSerializer serializer ) |
| 372 | |
throws java.io.IOException |
| 373 | |
{ |
| 374 | 0 | if ( repositoryPolicy != null ) |
| 375 | |
{ |
| 376 | 0 | serializer.startTag( NAMESPACE, tagName ); |
| 377 | 0 | if ( repositoryPolicy.isEnabled() != true ) |
| 378 | |
{ |
| 379 | 0 | serializer.startTag( NAMESPACE, "enabled" ).text( String.valueOf( repositoryPolicy.isEnabled() ) ).endTag( NAMESPACE, "enabled" ); |
| 380 | |
} |
| 381 | 0 | if ( repositoryPolicy.getUpdatePolicy() != null ) |
| 382 | |
{ |
| 383 | 0 | serializer.startTag( NAMESPACE, "updatePolicy" ).text( repositoryPolicy.getUpdatePolicy() ).endTag( NAMESPACE, "updatePolicy" ); |
| 384 | |
} |
| 385 | 0 | if ( repositoryPolicy.getChecksumPolicy() != null ) |
| 386 | |
{ |
| 387 | 0 | serializer.startTag( NAMESPACE, "checksumPolicy" ).text( repositoryPolicy.getChecksumPolicy() ).endTag( NAMESPACE, "checksumPolicy" ); |
| 388 | |
} |
| 389 | 0 | serializer.endTag( NAMESPACE, tagName ); |
| 390 | |
} |
| 391 | 0 | } |
| 392 | |
|
| 393 | |
|
| 394 | |
} |