PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/maven-amps-plugin/src/main/java/org/apache/maven/plugins/shade/pom/MavenJDOMWriter.java

https://bitbucket.org/mmeinhold/amps
Java | 2243 lines | 1488 code | 94 blank | 661 comment | 304 complexity | 7fd6f472e95619f5b4d162f2b5e2ad13 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. package org.apache.maven.plugins.shade.pom;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. //package org.apache.maven.model.io.jdom;
  21. //---------------------------------/
  22. //- Imported classes and packages -/
  23. //---------------------------------/
  24. import java.io.OutputStream;
  25. import java.io.OutputStreamWriter;
  26. import java.io.Writer;
  27. import java.util.ArrayList;
  28. import java.util.Collection;
  29. import java.util.Iterator;
  30. import java.util.ListIterator;
  31. import java.util.Map;
  32. import org.apache.maven.model.ActivationFile;
  33. import org.apache.maven.model.ActivationOS;
  34. import org.apache.maven.model.ActivationProperty;
  35. import org.apache.maven.model.Build;
  36. import org.apache.maven.model.BuildBase;
  37. import org.apache.maven.model.CiManagement;
  38. import org.apache.maven.model.ConfigurationContainer;
  39. import org.apache.maven.model.Contributor;
  40. import org.apache.maven.model.Dependency;
  41. import org.apache.maven.model.DependencyManagement;
  42. import org.apache.maven.model.DeploymentRepository;
  43. import org.apache.maven.model.Developer;
  44. import org.apache.maven.model.DistributionManagement;
  45. import org.apache.maven.model.Exclusion;
  46. import org.apache.maven.model.Extension;
  47. import org.apache.maven.model.FileSet;
  48. import org.apache.maven.model.IssueManagement;
  49. import org.apache.maven.model.License;
  50. import org.apache.maven.model.MailingList;
  51. import org.apache.maven.model.Model;
  52. import org.apache.maven.model.ModelBase;
  53. import org.apache.maven.model.Notifier;
  54. import org.apache.maven.model.Organization;
  55. import org.apache.maven.model.Parent;
  56. import org.apache.maven.model.PatternSet;
  57. import org.apache.maven.model.Plugin;
  58. import org.apache.maven.model.PluginConfiguration;
  59. import org.apache.maven.model.PluginContainer;
  60. import org.apache.maven.model.PluginExecution;
  61. import org.apache.maven.model.PluginManagement;
  62. import org.apache.maven.model.Prerequisites;
  63. import org.apache.maven.model.Profile;
  64. import org.apache.maven.model.Relocation;
  65. import org.apache.maven.model.ReportPlugin;
  66. import org.apache.maven.model.ReportSet;
  67. import org.apache.maven.model.Reporting;
  68. import org.apache.maven.model.Repository;
  69. import org.apache.maven.model.RepositoryBase;
  70. import org.apache.maven.model.RepositoryPolicy;
  71. import org.apache.maven.model.Resource;
  72. import org.apache.maven.model.Scm;
  73. import org.apache.maven.model.Site;
  74. import org.codehaus.plexus.util.xml.Xpp3Dom;
  75. import org.jdom.Content;
  76. import org.jdom.DefaultJDOMFactory;
  77. import org.jdom.Document;
  78. import org.jdom.Element;
  79. import org.jdom.Text;
  80. import org.jdom.output.Format;
  81. import org.jdom.output.XMLOutputter;
  82. /**
  83. * Class MavenJDOMWriter.
  84. *
  85. * @since 3.6
  86. */
  87. public class MavenJDOMWriter
  88. {
  89. // --------------------------/
  90. // - Class/Member Variables -/
  91. // --------------------------/
  92. /**
  93. * Field factory
  94. */
  95. private DefaultJDOMFactory factory;
  96. /**
  97. * Field lineSeparator
  98. */
  99. private String lineSeparator;
  100. // ----------------/
  101. // - Constructors -/
  102. // ----------------/
  103. public MavenJDOMWriter()
  104. {
  105. factory = new DefaultJDOMFactory();
  106. lineSeparator = "\n";
  107. } // -- org.apache.maven.model.io.jdom.MavenJDOMWriter()
  108. // -----------/
  109. // - Methods -/
  110. // -----------/
  111. /**
  112. * Method findAndReplaceProperties
  113. *
  114. * @param counter
  115. * @param props
  116. * @param name
  117. * @param parent
  118. */
  119. protected Element findAndReplaceProperties( Counter counter, Element parent, String name, Map props )
  120. {
  121. boolean shouldExist = props != null && !props.isEmpty();
  122. Element element = updateElement( counter, parent, name, shouldExist );
  123. if ( shouldExist )
  124. {
  125. Iterator it = props.keySet().iterator();
  126. Counter innerCounter = new Counter( counter.getDepth() + 1 );
  127. while ( it.hasNext() )
  128. {
  129. String key = (String) it.next();
  130. findAndReplaceSimpleElement( innerCounter, element, key, (String) props.get( key ), null );
  131. }
  132. ArrayList lst = new ArrayList( props.keySet() );
  133. it = element.getChildren().iterator();
  134. while ( it.hasNext() )
  135. {
  136. Element elem = (Element) it.next();
  137. String key = elem.getName();
  138. if ( !lst.contains( key ) )
  139. {
  140. it.remove();
  141. }
  142. }
  143. }
  144. return element;
  145. } // -- Element findAndReplaceProperties(Counter, Element, String, Map)
  146. /**
  147. * Method findAndReplaceSimpleElement
  148. *
  149. * @param counter
  150. * @param defaultValue
  151. * @param text
  152. * @param name
  153. * @param parent
  154. */
  155. protected Element findAndReplaceSimpleElement( Counter counter, Element parent, String name, String text,
  156. String defaultValue )
  157. {
  158. if ( defaultValue != null && text != null && defaultValue.equals( text ) )
  159. {
  160. Element element = parent.getChild( name, parent.getNamespace() );
  161. // if exist and is default value or if doesn't exist.. just keep the way it is..
  162. if ( ( element != null && defaultValue.equals( element.getText() ) ) || element == null )
  163. {
  164. return element;
  165. }
  166. }
  167. boolean shouldExist = text != null && text.trim().length() > 0;
  168. Element element = updateElement( counter, parent, name, shouldExist );
  169. if ( shouldExist )
  170. {
  171. element.setText( text );
  172. }
  173. return element;
  174. } // -- Element findAndReplaceSimpleElement(Counter, Element, String, String, String)
  175. /**
  176. * Method findAndReplaceSimpleLists
  177. *
  178. * @param counter
  179. * @param childName
  180. * @param parentName
  181. * @param list
  182. * @param parent
  183. */
  184. protected Element findAndReplaceSimpleLists( Counter counter, Element parent, java.util.Collection list,
  185. String parentName, String childName )
  186. {
  187. boolean shouldExist = list != null && list.size() > 0;
  188. Element element = updateElement( counter, parent, parentName, shouldExist );
  189. if ( shouldExist )
  190. {
  191. Iterator it = list.iterator();
  192. Iterator elIt = element.getChildren( childName, element.getNamespace() ).iterator();
  193. if ( !elIt.hasNext() )
  194. elIt = null;
  195. Counter innerCount = new Counter( counter.getDepth() + 1 );
  196. while ( it.hasNext() )
  197. {
  198. String value = (String) it.next();
  199. Element el;
  200. if ( elIt != null && elIt.hasNext() )
  201. {
  202. el = (Element) elIt.next();
  203. if ( !elIt.hasNext() )
  204. elIt = null;
  205. }
  206. else
  207. {
  208. el = factory.element( childName, element.getNamespace() );
  209. insertAtPreferredLocation( element, el, innerCount );
  210. }
  211. el.setText( value );
  212. innerCount.increaseCount();
  213. }
  214. if ( elIt != null )
  215. {
  216. while ( elIt.hasNext() )
  217. {
  218. elIt.next();
  219. elIt.remove();
  220. }
  221. }
  222. }
  223. return element;
  224. } // -- Element findAndReplaceSimpleLists(Counter, Element, java.util.Collection, String, String)
  225. /**
  226. * Method findAndReplaceXpp3DOM
  227. *
  228. * @param counter
  229. * @param dom
  230. * @param name
  231. * @param parent
  232. */
  233. protected Element findAndReplaceXpp3DOM( Counter counter, Element parent, String name, Xpp3Dom dom )
  234. {
  235. boolean shouldExist = dom != null && ( dom.getChildCount() > 0 || dom.getValue() != null );
  236. Element element = updateElement( counter, parent, name, shouldExist );
  237. if ( shouldExist )
  238. {
  239. replaceXpp3DOM( element, dom, new Counter( counter.getDepth() + 1 ) );
  240. }
  241. return element;
  242. } // -- Element findAndReplaceXpp3DOM(Counter, Element, String, Xpp3Dom)
  243. /**
  244. * Method insertAtPreferredLocation
  245. *
  246. * @param parent
  247. * @param counter
  248. * @param child
  249. */
  250. protected void insertAtPreferredLocation( Element parent, Element child, Counter counter )
  251. {
  252. int contentIndex = 0;
  253. int elementCounter = 0;
  254. Iterator it = parent.getContent().iterator();
  255. Text lastText = null;
  256. int offset = 0;
  257. while ( it.hasNext() && elementCounter <= counter.getCurrentIndex() )
  258. {
  259. Object next = it.next();
  260. offset = offset + 1;
  261. if ( next instanceof Element )
  262. {
  263. elementCounter = elementCounter + 1;
  264. contentIndex = contentIndex + offset;
  265. offset = 0;
  266. }
  267. if ( next instanceof Text && it.hasNext() )
  268. {
  269. lastText = (Text) next;
  270. }
  271. }
  272. if ( lastText != null && lastText.getTextTrim().length() == 0 )
  273. {
  274. lastText = (Text) lastText.clone();
  275. }
  276. else
  277. {
  278. String starter = lineSeparator;
  279. for ( int i = 0; i < counter.getDepth(); i++ )
  280. {
  281. starter = starter + " ";
  282. }
  283. lastText = factory.text( starter );
  284. }
  285. if ( parent.getContentSize() == 0 )
  286. {
  287. Text finalText = (Text) lastText.clone();
  288. finalText.setText( finalText.getText().substring( 0, finalText.getText().length() - " ".length() ) );
  289. parent.addContent( contentIndex, finalText );
  290. }
  291. parent.addContent( contentIndex, child );
  292. parent.addContent( contentIndex, lastText );
  293. } // -- void insertAtPreferredLocation(Element, Element, Counter)
  294. /**
  295. * Method iterateContributor
  296. *
  297. * @param counter
  298. * @param childTag
  299. * @param parentTag
  300. * @param list
  301. * @param parent
  302. */
  303. protected void iterateContributor( Counter counter, Element parent, java.util.Collection list,
  304. java.lang.String parentTag, java.lang.String childTag )
  305. {
  306. boolean shouldExist = list != null && list.size() > 0;
  307. Element element = updateElement( counter, parent, parentTag, shouldExist );
  308. if ( shouldExist )
  309. {
  310. Iterator it = list.iterator();
  311. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  312. if ( !elIt.hasNext() )
  313. elIt = null;
  314. Counter innerCount = new Counter( counter.getDepth() + 1 );
  315. while ( it.hasNext() )
  316. {
  317. Contributor value = (Contributor) it.next();
  318. Element el;
  319. if ( elIt != null && elIt.hasNext() )
  320. {
  321. el = (Element) elIt.next();
  322. if ( !elIt.hasNext() )
  323. elIt = null;
  324. }
  325. else
  326. {
  327. el = factory.element( childTag, element.getNamespace() );
  328. insertAtPreferredLocation( element, el, innerCount );
  329. }
  330. updateContributor( value, childTag, innerCount, el );
  331. innerCount.increaseCount();
  332. }
  333. if ( elIt != null )
  334. {
  335. while ( elIt.hasNext() )
  336. {
  337. elIt.next();
  338. elIt.remove();
  339. }
  340. }
  341. }
  342. } // -- void iterateContributor(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  343. /**
  344. * Method iterateDependency
  345. *
  346. * @param counter
  347. * @param childTag
  348. * @param parentTag
  349. * @param list
  350. * @param parent
  351. */
  352. protected void iterateDependency( Counter counter, Element parent, java.util.Collection list,
  353. java.lang.String parentTag, java.lang.String childTag )
  354. {
  355. boolean shouldExist = list != null && list.size() > 0;
  356. Element element = updateElement( counter, parent, parentTag, shouldExist );
  357. if ( shouldExist )
  358. {
  359. Iterator it = list.iterator();
  360. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  361. if ( !elIt.hasNext() )
  362. elIt = null;
  363. Counter innerCount = new Counter( counter.getDepth() + 1 );
  364. while ( it.hasNext() )
  365. {
  366. Dependency value = (Dependency) it.next();
  367. Element el;
  368. if ( elIt != null && elIt.hasNext() )
  369. {
  370. el = (Element) elIt.next();
  371. if ( !elIt.hasNext() )
  372. elIt = null;
  373. }
  374. else
  375. {
  376. el = factory.element( childTag, element.getNamespace() );
  377. insertAtPreferredLocation( element, el, innerCount );
  378. }
  379. updateDependency( value, childTag, innerCount, el );
  380. innerCount.increaseCount();
  381. }
  382. if ( elIt != null )
  383. {
  384. while ( elIt.hasNext() )
  385. {
  386. elIt.next();
  387. elIt.remove();
  388. }
  389. }
  390. }
  391. } // -- void iterateDependency(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  392. /**
  393. * Method iterateDeveloper
  394. *
  395. * @param counter
  396. * @param childTag
  397. * @param parentTag
  398. * @param list
  399. * @param parent
  400. */
  401. protected void iterateDeveloper( Counter counter, Element parent, java.util.Collection list,
  402. java.lang.String parentTag, java.lang.String childTag )
  403. {
  404. boolean shouldExist = list != null && list.size() > 0;
  405. Element element = updateElement( counter, parent, parentTag, shouldExist );
  406. if ( shouldExist )
  407. {
  408. Iterator it = list.iterator();
  409. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  410. if ( !elIt.hasNext() )
  411. elIt = null;
  412. Counter innerCount = new Counter( counter.getDepth() + 1 );
  413. while ( it.hasNext() )
  414. {
  415. Developer value = (Developer) it.next();
  416. Element el;
  417. if ( elIt != null && elIt.hasNext() )
  418. {
  419. el = (Element) elIt.next();
  420. if ( !elIt.hasNext() )
  421. elIt = null;
  422. }
  423. else
  424. {
  425. el = factory.element( childTag, element.getNamespace() );
  426. insertAtPreferredLocation( element, el, innerCount );
  427. }
  428. updateDeveloper( value, childTag, innerCount, el );
  429. innerCount.increaseCount();
  430. }
  431. if ( elIt != null )
  432. {
  433. while ( elIt.hasNext() )
  434. {
  435. elIt.next();
  436. elIt.remove();
  437. }
  438. }
  439. }
  440. } // -- void iterateDeveloper(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  441. /**
  442. * Method iterateExclusion
  443. *
  444. * @param counter
  445. * @param childTag
  446. * @param parentTag
  447. * @param list
  448. * @param parent
  449. */
  450. protected void iterateExclusion( Counter counter, Element parent, java.util.Collection list,
  451. java.lang.String parentTag, java.lang.String childTag )
  452. {
  453. boolean shouldExist = list != null && list.size() > 0;
  454. Element element = updateElement( counter, parent, parentTag, shouldExist );
  455. if ( shouldExist )
  456. {
  457. Iterator it = list.iterator();
  458. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  459. if ( !elIt.hasNext() )
  460. elIt = null;
  461. Counter innerCount = new Counter( counter.getDepth() + 1 );
  462. while ( it.hasNext() )
  463. {
  464. Exclusion value = (Exclusion) it.next();
  465. Element el;
  466. if ( elIt != null && elIt.hasNext() )
  467. {
  468. el = (Element) elIt.next();
  469. if ( !elIt.hasNext() )
  470. elIt = null;
  471. }
  472. else
  473. {
  474. el = factory.element( childTag, element.getNamespace() );
  475. insertAtPreferredLocation( element, el, innerCount );
  476. }
  477. updateExclusion( value, childTag, innerCount, el );
  478. innerCount.increaseCount();
  479. }
  480. if ( elIt != null )
  481. {
  482. while ( elIt.hasNext() )
  483. {
  484. elIt.next();
  485. elIt.remove();
  486. }
  487. }
  488. }
  489. } // -- void iterateExclusion(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  490. /**
  491. * Method iterateExtension
  492. *
  493. * @param counter
  494. * @param childTag
  495. * @param parentTag
  496. * @param list
  497. * @param parent
  498. */
  499. protected void iterateExtension( Counter counter, Element parent, java.util.Collection list,
  500. java.lang.String parentTag, java.lang.String childTag )
  501. {
  502. boolean shouldExist = list != null && list.size() > 0;
  503. Element element = updateElement( counter, parent, parentTag, shouldExist );
  504. if ( shouldExist )
  505. {
  506. Iterator it = list.iterator();
  507. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  508. if ( !elIt.hasNext() )
  509. elIt = null;
  510. Counter innerCount = new Counter( counter.getDepth() + 1 );
  511. while ( it.hasNext() )
  512. {
  513. Extension value = (Extension) it.next();
  514. Element el;
  515. if ( elIt != null && elIt.hasNext() )
  516. {
  517. el = (Element) elIt.next();
  518. if ( !elIt.hasNext() )
  519. elIt = null;
  520. }
  521. else
  522. {
  523. el = factory.element( childTag, element.getNamespace() );
  524. insertAtPreferredLocation( element, el, innerCount );
  525. }
  526. updateExtension( value, childTag, innerCount, el );
  527. innerCount.increaseCount();
  528. }
  529. if ( elIt != null )
  530. {
  531. while ( elIt.hasNext() )
  532. {
  533. elIt.next();
  534. elIt.remove();
  535. }
  536. }
  537. }
  538. } // -- void iterateExtension(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  539. /**
  540. * Method iterateLicense
  541. *
  542. * @param counter
  543. * @param childTag
  544. * @param parentTag
  545. * @param list
  546. * @param parent
  547. */
  548. protected void iterateLicense( Counter counter, Element parent, java.util.Collection list,
  549. java.lang.String parentTag, java.lang.String childTag )
  550. {
  551. boolean shouldExist = list != null && list.size() > 0;
  552. Element element = updateElement( counter, parent, parentTag, shouldExist );
  553. if ( shouldExist )
  554. {
  555. Iterator it = list.iterator();
  556. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  557. if ( !elIt.hasNext() )
  558. elIt = null;
  559. Counter innerCount = new Counter( counter.getDepth() + 1 );
  560. while ( it.hasNext() )
  561. {
  562. License value = (License) it.next();
  563. Element el;
  564. if ( elIt != null && elIt.hasNext() )
  565. {
  566. el = (Element) elIt.next();
  567. if ( !elIt.hasNext() )
  568. elIt = null;
  569. }
  570. else
  571. {
  572. el = factory.element( childTag, element.getNamespace() );
  573. insertAtPreferredLocation( element, el, innerCount );
  574. }
  575. updateLicense( value, childTag, innerCount, el );
  576. innerCount.increaseCount();
  577. }
  578. if ( elIt != null )
  579. {
  580. while ( elIt.hasNext() )
  581. {
  582. elIt.next();
  583. elIt.remove();
  584. }
  585. }
  586. }
  587. } // -- void iterateLicense(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  588. /**
  589. * Method iterateMailingList
  590. *
  591. * @param counter
  592. * @param childTag
  593. * @param parentTag
  594. * @param list
  595. * @param parent
  596. */
  597. protected void iterateMailingList( Counter counter, Element parent, java.util.Collection list,
  598. java.lang.String parentTag, java.lang.String childTag )
  599. {
  600. boolean shouldExist = list != null && list.size() > 0;
  601. Element element = updateElement( counter, parent, parentTag, shouldExist );
  602. if ( shouldExist )
  603. {
  604. Iterator it = list.iterator();
  605. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  606. if ( !elIt.hasNext() )
  607. elIt = null;
  608. Counter innerCount = new Counter( counter.getDepth() + 1 );
  609. while ( it.hasNext() )
  610. {
  611. MailingList value = (MailingList) it.next();
  612. Element el;
  613. if ( elIt != null && elIt.hasNext() )
  614. {
  615. el = (Element) elIt.next();
  616. if ( !elIt.hasNext() )
  617. elIt = null;
  618. }
  619. else
  620. {
  621. el = factory.element( childTag, element.getNamespace() );
  622. insertAtPreferredLocation( element, el, innerCount );
  623. }
  624. updateMailingList( value, childTag, innerCount, el );
  625. innerCount.increaseCount();
  626. }
  627. if ( elIt != null )
  628. {
  629. while ( elIt.hasNext() )
  630. {
  631. elIt.next();
  632. elIt.remove();
  633. }
  634. }
  635. }
  636. } // -- void iterateMailingList(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  637. /**
  638. * Method iterateNotifier
  639. *
  640. * @param counter
  641. * @param childTag
  642. * @param parentTag
  643. * @param list
  644. * @param parent
  645. */
  646. protected void iterateNotifier( Counter counter, Element parent, java.util.Collection list,
  647. java.lang.String parentTag, java.lang.String childTag )
  648. {
  649. boolean shouldExist = list != null && list.size() > 0;
  650. Element element = updateElement( counter, parent, parentTag, shouldExist );
  651. if ( shouldExist )
  652. {
  653. Iterator it = list.iterator();
  654. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  655. if ( !elIt.hasNext() )
  656. elIt = null;
  657. Counter innerCount = new Counter( counter.getDepth() + 1 );
  658. while ( it.hasNext() )
  659. {
  660. Notifier value = (Notifier) it.next();
  661. Element el;
  662. if ( elIt != null && elIt.hasNext() )
  663. {
  664. el = (Element) elIt.next();
  665. if ( !elIt.hasNext() )
  666. elIt = null;
  667. }
  668. else
  669. {
  670. el = factory.element( childTag, element.getNamespace() );
  671. insertAtPreferredLocation( element, el, innerCount );
  672. }
  673. updateNotifier( value, childTag, innerCount, el );
  674. innerCount.increaseCount();
  675. }
  676. if ( elIt != null )
  677. {
  678. while ( elIt.hasNext() )
  679. {
  680. elIt.next();
  681. elIt.remove();
  682. }
  683. }
  684. }
  685. } // -- void iterateNotifier(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  686. /**
  687. * Method iteratePlugin
  688. *
  689. * @param counter
  690. * @param childTag
  691. * @param parentTag
  692. * @param list
  693. * @param parent
  694. */
  695. protected void iteratePlugin( Counter counter, Element parent, java.util.Collection list,
  696. java.lang.String parentTag, java.lang.String childTag )
  697. {
  698. boolean shouldExist = list != null && list.size() > 0;
  699. Element element = updateElement( counter, parent, parentTag, shouldExist );
  700. if ( shouldExist )
  701. {
  702. Iterator it = list.iterator();
  703. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  704. if ( !elIt.hasNext() )
  705. elIt = null;
  706. Counter innerCount = new Counter( counter.getDepth() + 1 );
  707. while ( it.hasNext() )
  708. {
  709. Plugin value = (Plugin) it.next();
  710. Element el;
  711. if ( elIt != null && elIt.hasNext() )
  712. {
  713. el = (Element) elIt.next();
  714. if ( !elIt.hasNext() )
  715. elIt = null;
  716. }
  717. else
  718. {
  719. el = factory.element( childTag, element.getNamespace() );
  720. insertAtPreferredLocation( element, el, innerCount );
  721. }
  722. updatePlugin( value, childTag, innerCount, el );
  723. innerCount.increaseCount();
  724. }
  725. if ( elIt != null )
  726. {
  727. while ( elIt.hasNext() )
  728. {
  729. elIt.next();
  730. elIt.remove();
  731. }
  732. }
  733. }
  734. } // -- void iteratePlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  735. /**
  736. * Method iteratePluginExecution
  737. *
  738. * @param counter
  739. * @param childTag
  740. * @param parentTag
  741. * @param list
  742. * @param parent
  743. */
  744. protected void iteratePluginExecution( Counter counter, Element parent, java.util.Collection list,
  745. java.lang.String parentTag, java.lang.String childTag )
  746. {
  747. boolean shouldExist = list != null && list.size() > 0;
  748. Element element = updateElement( counter, parent, parentTag, shouldExist );
  749. if ( shouldExist )
  750. {
  751. Iterator it = list.iterator();
  752. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  753. if ( !elIt.hasNext() )
  754. elIt = null;
  755. Counter innerCount = new Counter( counter.getDepth() + 1 );
  756. while ( it.hasNext() )
  757. {
  758. PluginExecution value = (PluginExecution) it.next();
  759. Element el;
  760. if ( elIt != null && elIt.hasNext() )
  761. {
  762. el = (Element) elIt.next();
  763. if ( !elIt.hasNext() )
  764. elIt = null;
  765. }
  766. else
  767. {
  768. el = factory.element( childTag, element.getNamespace() );
  769. insertAtPreferredLocation( element, el, innerCount );
  770. }
  771. updatePluginExecution( value, childTag, innerCount, el );
  772. innerCount.increaseCount();
  773. }
  774. if ( elIt != null )
  775. {
  776. while ( elIt.hasNext() )
  777. {
  778. elIt.next();
  779. elIt.remove();
  780. }
  781. }
  782. }
  783. } // -- void iteratePluginExecution(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  784. /**
  785. * Method iterateProfile
  786. *
  787. * @param counter
  788. * @param childTag
  789. * @param parentTag
  790. * @param list
  791. * @param parent
  792. */
  793. protected void iterateProfile( Counter counter, Element parent, java.util.Collection list,
  794. java.lang.String parentTag, java.lang.String childTag )
  795. {
  796. boolean shouldExist = list != null && list.size() > 0;
  797. Element element = updateElement( counter, parent, parentTag, shouldExist );
  798. if ( shouldExist )
  799. {
  800. Iterator it = list.iterator();
  801. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  802. if ( !elIt.hasNext() )
  803. elIt = null;
  804. Counter innerCount = new Counter( counter.getDepth() + 1 );
  805. while ( it.hasNext() )
  806. {
  807. Profile value = (Profile) it.next();
  808. Element el;
  809. if ( elIt != null && elIt.hasNext() )
  810. {
  811. el = (Element) elIt.next();
  812. if ( !elIt.hasNext() )
  813. elIt = null;
  814. }
  815. else
  816. {
  817. el = factory.element( childTag, element.getNamespace() );
  818. insertAtPreferredLocation( element, el, innerCount );
  819. }
  820. updateProfile( value, childTag, innerCount, el );
  821. innerCount.increaseCount();
  822. }
  823. if ( elIt != null )
  824. {
  825. while ( elIt.hasNext() )
  826. {
  827. elIt.next();
  828. elIt.remove();
  829. }
  830. }
  831. }
  832. } // -- void iterateProfile(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  833. /**
  834. * Method iterateReportPlugin
  835. *
  836. * @param counter
  837. * @param childTag
  838. * @param parentTag
  839. * @param list
  840. * @param parent
  841. */
  842. protected void iterateReportPlugin( Counter counter, Element parent, java.util.Collection list,
  843. java.lang.String parentTag, java.lang.String childTag )
  844. {
  845. boolean shouldExist = list != null && list.size() > 0;
  846. Element element = updateElement( counter, parent, parentTag, shouldExist );
  847. if ( shouldExist )
  848. {
  849. Iterator it = list.iterator();
  850. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  851. if ( !elIt.hasNext() )
  852. elIt = null;
  853. Counter innerCount = new Counter( counter.getDepth() + 1 );
  854. while ( it.hasNext() )
  855. {
  856. ReportPlugin value = (ReportPlugin) it.next();
  857. Element el;
  858. if ( elIt != null && elIt.hasNext() )
  859. {
  860. el = (Element) elIt.next();
  861. if ( !elIt.hasNext() )
  862. elIt = null;
  863. }
  864. else
  865. {
  866. el = factory.element( childTag, element.getNamespace() );
  867. insertAtPreferredLocation( element, el, innerCount );
  868. }
  869. updateReportPlugin( value, childTag, innerCount, el );
  870. innerCount.increaseCount();
  871. }
  872. if ( elIt != null )
  873. {
  874. while ( elIt.hasNext() )
  875. {
  876. elIt.next();
  877. elIt.remove();
  878. }
  879. }
  880. }
  881. } // -- void iterateReportPlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  882. /**
  883. * Method iterateReportSet
  884. *
  885. * @param counter
  886. * @param childTag
  887. * @param parentTag
  888. * @param list
  889. * @param parent
  890. */
  891. protected void iterateReportSet( Counter counter, Element parent, java.util.Collection list,
  892. java.lang.String parentTag, java.lang.String childTag )
  893. {
  894. boolean shouldExist = list != null && list.size() > 0;
  895. Element element = updateElement( counter, parent, parentTag, shouldExist );
  896. if ( shouldExist )
  897. {
  898. Iterator it = list.iterator();
  899. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  900. if ( !elIt.hasNext() )
  901. elIt = null;
  902. Counter innerCount = new Counter( counter.getDepth() + 1 );
  903. while ( it.hasNext() )
  904. {
  905. ReportSet value = (ReportSet) it.next();
  906. Element el;
  907. if ( elIt != null && elIt.hasNext() )
  908. {
  909. el = (Element) elIt.next();
  910. if ( !elIt.hasNext() )
  911. elIt = null;
  912. }
  913. else
  914. {
  915. el = factory.element( childTag, element.getNamespace() );
  916. insertAtPreferredLocation( element, el, innerCount );
  917. }
  918. updateReportSet( value, childTag, innerCount, el );
  919. innerCount.increaseCount();
  920. }
  921. if ( elIt != null )
  922. {
  923. while ( elIt.hasNext() )
  924. {
  925. elIt.next();
  926. elIt.remove();
  927. }
  928. }
  929. }
  930. } // -- void iterateReportSet(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  931. /**
  932. * Method iterateRepository
  933. *
  934. * @param counter
  935. * @param childTag
  936. * @param parentTag
  937. * @param list
  938. * @param parent
  939. */
  940. protected void iterateRepository( Counter counter, Element parent, java.util.Collection list,
  941. java.lang.String parentTag, java.lang.String childTag )
  942. {
  943. boolean shouldExist = list != null && list.size() > 0;
  944. Element element = updateElement( counter, parent, parentTag, shouldExist );
  945. if ( shouldExist )
  946. {
  947. Iterator it = list.iterator();
  948. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  949. if ( !elIt.hasNext() )
  950. elIt = null;
  951. Counter innerCount = new Counter( counter.getDepth() + 1 );
  952. while ( it.hasNext() )
  953. {
  954. Repository value = (Repository) it.next();
  955. Element el;
  956. if ( elIt != null && elIt.hasNext() )
  957. {
  958. el = (Element) elIt.next();
  959. if ( !elIt.hasNext() )
  960. elIt = null;
  961. }
  962. else
  963. {
  964. el = factory.element( childTag, element.getNamespace() );
  965. insertAtPreferredLocation( element, el, innerCount );
  966. }
  967. updateRepository( value, childTag, innerCount, el );
  968. innerCount.increaseCount();
  969. }
  970. if ( elIt != null )
  971. {
  972. while ( elIt.hasNext() )
  973. {
  974. elIt.next();
  975. elIt.remove();
  976. }
  977. }
  978. }
  979. } // -- void iterateRepository(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  980. /**
  981. * Method iterateResource
  982. *
  983. * @param counter
  984. * @param childTag
  985. * @param parentTag
  986. * @param list
  987. * @param parent
  988. */
  989. protected void iterateResource( Counter counter, Element parent, java.util.Collection list,
  990. java.lang.String parentTag, java.lang.String childTag )
  991. {
  992. boolean shouldExist = list != null && list.size() > 0;
  993. Element element = updateElement( counter, parent, parentTag, shouldExist );
  994. if ( shouldExist )
  995. {
  996. Iterator it = list.iterator();
  997. Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
  998. if ( !elIt.hasNext() )
  999. elIt = null;
  1000. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1001. while ( it.hasNext() )
  1002. {
  1003. Resource value = (Resource) it.next();
  1004. Element el;
  1005. if ( elIt != null && elIt.hasNext() )
  1006. {
  1007. el = (Element) elIt.next();
  1008. if ( !elIt.hasNext() )
  1009. elIt = null;
  1010. }
  1011. else
  1012. {
  1013. el = factory.element( childTag, element.getNamespace() );
  1014. insertAtPreferredLocation( element, el, innerCount );
  1015. }
  1016. updateResource( value, childTag, innerCount, el );
  1017. innerCount.increaseCount();
  1018. }
  1019. if ( elIt != null )
  1020. {
  1021. while ( elIt.hasNext() )
  1022. {
  1023. elIt.next();
  1024. elIt.remove();
  1025. }
  1026. }
  1027. }
  1028. } // -- void iterateResource(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
  1029. /**
  1030. * Method replaceXpp3DOM
  1031. *
  1032. * @param parent
  1033. * @param counter
  1034. * @param parentDom
  1035. */
  1036. protected void replaceXpp3DOM( Element parent, Xpp3Dom parentDom, Counter counter )
  1037. {
  1038. if ( parentDom.getChildCount() > 0 )
  1039. {
  1040. Xpp3Dom[] childs = parentDom.getChildren();
  1041. Collection domChilds = new ArrayList();
  1042. for ( int i = 0; i < childs.length; i++ )
  1043. {
  1044. domChilds.add( childs[i] );
  1045. }
  1046. // int domIndex = 0;
  1047. ListIterator it = parent.getChildren().listIterator();
  1048. while ( it.hasNext() )
  1049. {
  1050. Element elem = (Element) it.next();
  1051. Iterator it2 = domChilds.iterator();
  1052. Xpp3Dom corrDom = null;
  1053. while ( it2.hasNext() )
  1054. {
  1055. Xpp3Dom dm = (Xpp3Dom) it2.next();
  1056. if ( dm.getName().equals( elem.getName() ) )
  1057. {
  1058. corrDom = dm;
  1059. break;
  1060. }
  1061. }
  1062. if ( corrDom != null )
  1063. {
  1064. domChilds.remove( corrDom );
  1065. replaceXpp3DOM( elem, corrDom, new Counter( counter.getDepth() + 1 ) );
  1066. counter.increaseCount();
  1067. }
  1068. else
  1069. {
  1070. parent.removeContent( elem );
  1071. }
  1072. }
  1073. Iterator it2 = domChilds.iterator();
  1074. while ( it2.hasNext() )
  1075. {
  1076. Xpp3Dom dm = (Xpp3Dom) it2.next();
  1077. Element elem = factory.element( dm.getName(), parent.getNamespace() );
  1078. insertAtPreferredLocation( parent, elem, counter );
  1079. counter.increaseCount();
  1080. replaceXpp3DOM( elem, dm, new Counter( counter.getDepth() + 1 ) );
  1081. }
  1082. }
  1083. else if ( parentDom.getValue() != null )
  1084. {
  1085. parent.setText( parentDom.getValue() );
  1086. }
  1087. } // -- void replaceXpp3DOM(Element, Xpp3Dom, Counter)
  1088. /**
  1089. * Method updateActivation
  1090. *
  1091. * @param value
  1092. * @param element
  1093. * @param counter
  1094. * @param xmlTag
  1095. */
  1096. /*
  1097. * protected void updateActivation(Activation value, String xmlTag, Counter counter, Element element) { boolean
  1098. * shouldExist = value != null; Element root = updateElement(counter, element, xmlTag, shouldExist); if
  1099. * (shouldExist) { Counter innerCount = new Counter(counter.getDepth() + 1); findAndReplaceSimpleElement(innerCount,
  1100. * root, "activeByDefault", !value.isActiveByDefault() ? null : String.valueOf( value.isActiveByDefault() ),
  1101. * "false"); findAndReplaceSimpleElement(innerCount, root, "jdk", value.getJdk(), null); updateActivationOS(
  1102. * value.getOs(), "os", innerCount, root); updateActivationProperty( value.getProperty(), "property", innerCount,
  1103. * root); updateActivationFile( value.getFile(), "file", innerCount, root); updateActivationCustom(
  1104. * value.getCustom(), "custom", innerCount, root); } } //-- void updateActivation(Activation, String, Counter,
  1105. * Element)
  1106. */
  1107. /**
  1108. * Method updateActivationCustom
  1109. *
  1110. * @param value
  1111. * @param element
  1112. * @param counter
  1113. * @param xmlTag
  1114. */
  1115. /*
  1116. * protected void updateActivationCustom(ActivationCustom value, String xmlTag, Counter counter, Element element) {
  1117. * boolean shouldExist = value != null; Element root = updateElement(counter, element, xmlTag, shouldExist); if
  1118. * (shouldExist) { Counter innerCount = new Counter(counter.getDepth() + 1); findAndReplaceXpp3DOM(innerCount, root,
  1119. * "configuration", (Xpp3Dom)value.getConfiguration()); findAndReplaceSimpleElement(innerCount, root, "type",
  1120. * value.getType(), null); } } //-- void updateActivationCustom(ActivationCustom, String, Counter, Element)
  1121. */
  1122. /**
  1123. * Method updateActivationFile
  1124. *
  1125. * @param value
  1126. * @param element
  1127. * @param counter
  1128. * @param xmlTag
  1129. */
  1130. protected void updateActivationFile( ActivationFile value, String xmlTag, Counter counter, Element element )
  1131. {
  1132. boolean shouldExist = value != null;
  1133. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1134. if ( shouldExist )
  1135. {
  1136. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1137. findAndReplaceSimpleElement( innerCount, root, "missing", value.getMissing(), null );
  1138. findAndReplaceSimpleElement( innerCount, root, "exists", value.getExists(), null );
  1139. }
  1140. } // -- void updateActivationFile(ActivationFile, String, Counter, Element)
  1141. /**
  1142. * Method updateActivationOS
  1143. *
  1144. * @param value
  1145. * @param element
  1146. * @param counter
  1147. * @param xmlTag
  1148. */
  1149. protected void updateActivationOS( ActivationOS value, String xmlTag, Counter counter, Element element )
  1150. {
  1151. boolean shouldExist = value != null;
  1152. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1153. if ( shouldExist )
  1154. {
  1155. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1156. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  1157. findAndReplaceSimpleElement( innerCount, root, "family", value.getFamily(), null );
  1158. findAndReplaceSimpleElement( innerCount, root, "arch", value.getArch(), null );
  1159. findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
  1160. }
  1161. } // -- void updateActivationOS(ActivationOS, String, Counter, Element)
  1162. /**
  1163. * Method updateActivationProperty
  1164. *
  1165. * @param value
  1166. * @param element
  1167. * @param counter
  1168. * @param xmlTag
  1169. */
  1170. protected void updateActivationProperty( ActivationProperty value, String xmlTag, Counter counter, Element element )
  1171. {
  1172. boolean shouldExist = value != null;
  1173. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1174. if ( shouldExist )
  1175. {
  1176. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1177. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  1178. findAndReplaceSimpleElement( innerCount, root, "value", value.getValue(), null );
  1179. }
  1180. } // -- void updateActivationProperty(ActivationProperty, String, Counter, Element)
  1181. /**
  1182. * Method updateBuild
  1183. *
  1184. * @param value
  1185. * @param element
  1186. * @param counter
  1187. * @param xmlTag
  1188. */
  1189. protected void updateBuild( Build value, String xmlTag, Counter counter, Element element )
  1190. {
  1191. boolean shouldExist = value != null;
  1192. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1193. if ( shouldExist )
  1194. {
  1195. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1196. findAndReplaceSimpleElement( innerCount, root, "sourceDirectory", value.getSourceDirectory(), null );
  1197. findAndReplaceSimpleElement( innerCount, root, "scriptSourceDirectory", value.getScriptSourceDirectory(),
  1198. null );
  1199. findAndReplaceSimpleElement( innerCount, root, "testSourceDirectory", value.getTestSourceDirectory(), null );
  1200. findAndReplaceSimpleElement( innerCount, root, "outputDirectory", value.getOutputDirectory(), null );
  1201. findAndReplaceSimpleElement( innerCount, root, "testOutputDirectory", value.getTestOutputDirectory(), null );
  1202. iterateExtension( innerCount, root, value.getExtensions(), "extensions", "extension" );
  1203. findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
  1204. iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
  1205. iterateResource( innerCount, root, value.getTestResources(), "testResources", "testResource" );
  1206. findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
  1207. findAndReplaceSimpleElement( innerCount, root, "finalName", value.getFinalName(), null );
  1208. findAndReplaceSimpleLists( innerCount, root, value.getFilters(), "filters", "filter" );
  1209. updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
  1210. iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
  1211. }
  1212. } // -- void updateBuild(Build, String, Counter, Element)
  1213. /**
  1214. * Method updateBuildBase
  1215. *
  1216. * @param value
  1217. * @param element
  1218. * @param counter
  1219. * @param xmlTag
  1220. */
  1221. protected void updateBuildBase( BuildBase value, String xmlTag, Counter counter, Element element )
  1222. {
  1223. boolean shouldExist = value != null;
  1224. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1225. if ( shouldExist )
  1226. {
  1227. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1228. findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
  1229. iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
  1230. iterateResource( innerCount, root, value.getTestResources(), "testResources", "testResource" );
  1231. findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
  1232. findAndReplaceSimpleElement( innerCount, root, "finalName", value.getFinalName(), null );
  1233. findAndReplaceSimpleLists( innerCount, root, value.getFilters(), "filters", "filter" );
  1234. updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
  1235. iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
  1236. }
  1237. } // -- void updateBuildBase(BuildBase, String, Counter, Element)
  1238. /**
  1239. * Method updateCiManagement
  1240. *
  1241. * @param value
  1242. * @param element
  1243. * @param counter
  1244. * @param xmlTag
  1245. */
  1246. protected void updateCiManagement( CiManagement value, String xmlTag, Counter counter, Element element )
  1247. {
  1248. boolean shouldExist = value != null;
  1249. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1250. if ( shouldExist )
  1251. {
  1252. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1253. findAndReplaceSimpleElement( innerCount, root, "system", value.getSystem(), null );
  1254. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  1255. iterateNotifier( innerCount, root, value.getNotifiers(), "notifiers", "notifier" );
  1256. }
  1257. } // -- void updateCiManagement(CiManagement, String, Counter, Element)
  1258. /**
  1259. * Method updateConfigurationContainer
  1260. *
  1261. * @param value
  1262. * @param element
  1263. * @param counter
  1264. * @param xmlTag
  1265. */
  1266. protected void updateConfigurationContainer( ConfigurationContainer value, String xmlTag, Counter counter,
  1267. Element element )
  1268. {
  1269. boolean shouldExist = value != null;
  1270. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1271. if ( shouldExist )
  1272. {
  1273. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1274. findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
  1275. findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
  1276. }
  1277. } // -- void updateConfigurationContainer(ConfigurationContainer, String, Counter, Element)
  1278. /**
  1279. * Method updateContributor
  1280. *
  1281. * @param value
  1282. * @param element
  1283. * @param counter
  1284. * @param xmlTag
  1285. */
  1286. protected void updateContributor( Contributor value, String xmlTag, Counter counter, Element element )
  1287. {
  1288. Element root = element;
  1289. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1290. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  1291. findAndReplaceSimpleElement( innerCount, root, "email", value.getEmail(), null );
  1292. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  1293. findAndReplaceSimpleElement( innerCount, root, "organization", value.getOrganization(), null );
  1294. findAndReplaceSimpleElement( innerCount, root, "organizationUrl", value.getOrganizationUrl(), null );
  1295. findAndReplaceSimpleLists( innerCount, root, value.getRoles(), "roles", "role" );
  1296. findAndReplaceSimpleElement( innerCount, root, "timezone", value.getTimezone(), null );
  1297. findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
  1298. } // -- void updateContributor(Contributor, String, Counter, Element)
  1299. /**
  1300. * Method updateDependency
  1301. *
  1302. * @param value
  1303. * @param element
  1304. * @param counter
  1305. * @param xmlTag
  1306. */
  1307. protected void updateDependency( Dependency value, String xmlTag, Counter counter, Element element )
  1308. {
  1309. Element root = element;
  1310. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1311. findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
  1312. findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
  1313. findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
  1314. findAndReplaceSimpleElement( innerCount, root, "type", value.getType(), "jar" );
  1315. findAndReplaceSimpleElement( innerCount, root, "classifier", value.getClassifier(), null );
  1316. findAndReplaceSimpleElement( innerCount, root, "scope", value.getScope(), null );
  1317. findAndReplaceSimpleElement( innerCount, root, "systemPath", value.getSystemPath(), null );
  1318. iterateExclusion( innerCount, root, value.getExclusions(), "exclusions", "exclusion" );
  1319. findAndReplaceSimpleElement( innerCount, root, "optional", !value.isOptional() ? null
  1320. : String.valueOf( value.isOptional() ), "false" );
  1321. } // -- void updateDependency(Dependency, String, Counter, Element)
  1322. /**
  1323. * Method updateDependencyManagement
  1324. *
  1325. * @param value
  1326. * @param element
  1327. * @param counter
  1328. * @param xmlTag
  1329. */
  1330. protected void updateDependencyManagement( DependencyManagement value, String xmlTag, Counter counter,
  1331. Element element )
  1332. {
  1333. boolean shouldExist = value != null;
  1334. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1335. if ( shouldExist )
  1336. {
  1337. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1338. iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
  1339. }
  1340. } // -- void updateDependencyManagement(DependencyManagement, String, Counter, Element)
  1341. /**
  1342. * Method updateDeploymentRepository
  1343. *
  1344. * @param value
  1345. * @param element
  1346. * @param counter
  1347. * @param xmlTag
  1348. */
  1349. protected void updateDeploymentRepository( DeploymentRepository value, String xmlTag, Counter counter,
  1350. Element element )
  1351. {
  1352. boolean shouldExist = value != null;
  1353. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1354. if ( shouldExist )
  1355. {
  1356. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1357. findAndReplaceSimpleElement( innerCount, root, "uniqueVersion", value.isUniqueVersion() ? null
  1358. : String.valueOf( value.isUniqueVersion() ), "true" );
  1359. findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
  1360. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  1361. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  1362. findAndReplaceSimpleElement( innerCount, root, "layout", value.getLayout(), "default" );
  1363. }
  1364. } // -- void updateDeploymentRepository(DeploymentRepository, String, Counter, Element)
  1365. /**
  1366. * Method updateDeveloper
  1367. *
  1368. * @param value
  1369. * @param element
  1370. * @param counter
  1371. * @param xmlTag
  1372. */
  1373. protected void updateDeveloper( Developer value, String xmlTag, Counter counter, Element element )
  1374. {
  1375. Element root = element;
  1376. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1377. findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
  1378. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  1379. findAndReplaceSimpleElement( innerCount, root, "email", value.getEmail(), null );
  1380. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  1381. findAndReplaceSimpleElement( innerCount, root, "organization", value.getOrganization(), null );
  1382. findAndReplaceSimpleElement( innerCount, root, "organizationUrl", value.getOrganizationUrl(), null );
  1383. findAndReplaceSimpleLists( innerCount, root, value.getRoles(), "roles", "role" );
  1384. findAndReplaceSimpleElement( innerCount, root, "timezone", value.getTimezone(), null );
  1385. findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
  1386. } // -- void updateDeveloper(Developer, String, Counter, Element)
  1387. /**
  1388. * Method updateDistributionManagement
  1389. *
  1390. * @param value
  1391. * @param element
  1392. * @param counter
  1393. * @param xmlTag
  1394. */
  1395. protected void updateDistributionManagement( DistributionManagement value, String xmlTag, Counter counter,
  1396. Element element )
  1397. {
  1398. boolean shouldExist = value != null;
  1399. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1400. if ( shouldExist )
  1401. {
  1402. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1403. updateDeploymentRepository( value.getRepository(), "repository", innerCount, root );
  1404. updateDeploymentRepository( value.getSnapshotRepository(), "snapshotRepository", innerCount, root );
  1405. updateSite( value.getSite(), "site", innerCount, root );
  1406. findAndReplaceSimpleElement( innerCount, root, "downloadUrl", value.getDownloadUrl(), null );
  1407. updateRelocation( value.getRelocation(), "relocation", innerCount, root );
  1408. findAndReplaceSimpleElement( innerCount, root, "status", value.getStatus(), null );
  1409. }
  1410. } // -- void updateDistributionManagement(DistributionManagement, String, Counter, Element)
  1411. /**
  1412. * Method updateElement
  1413. *
  1414. * @param counter
  1415. * @param shouldExist
  1416. * @param name
  1417. * @param parent
  1418. */
  1419. protected Element updateElement( Counter counter, Element parent, String name, boolean shouldExist )
  1420. {
  1421. Element element = parent.getChild( name, parent.getNamespace() );
  1422. if ( element != null && shouldExist )
  1423. {
  1424. counter.increaseCount();
  1425. }
  1426. if ( element == null && shouldExist )
  1427. {
  1428. element = factory.element( name, parent.getNamespace() );
  1429. insertAtPreferredLocation( parent, element, counter );
  1430. counter.increaseCount();
  1431. }
  1432. if ( !shouldExist && element != null )
  1433. {
  1434. int index = parent.indexOf( element );
  1435. if ( index > 0 )
  1436. {
  1437. Content previous = parent.getContent( index - 1 );
  1438. if ( previous instanceof Text )
  1439. {
  1440. Text txt = (Text) previous;
  1441. if ( txt.getTextTrim().length() == 0 )
  1442. {
  1443. parent.removeContent( txt );
  1444. }
  1445. }
  1446. }
  1447. parent.removeContent( element );
  1448. }
  1449. return element;
  1450. } // -- Element updateElement(Counter, Element, String, boolean)
  1451. /**
  1452. * Method updateExclusion
  1453. *
  1454. * @param value
  1455. * @param element
  1456. * @param counter
  1457. * @param xmlTag
  1458. */
  1459. protected void updateExclusion( Exclusion value, String xmlTag, Counter counter, Element element )
  1460. {
  1461. Element root = element;
  1462. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1463. findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
  1464. findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
  1465. } // -- void updateExclusion(Exclusion, String, Counter, Element)
  1466. /**
  1467. * Method updateExtension
  1468. *
  1469. * @param value
  1470. * @param element
  1471. * @param counter
  1472. * @param xmlTag
  1473. */
  1474. protected void updateExtension( Extension value, String xmlTag, Counter counter, Element element )
  1475. {
  1476. Element root = element;
  1477. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1478. findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
  1479. findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
  1480. findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
  1481. } // -- void updateExtension(Extension, String, Counter, Element)
  1482. /**
  1483. * Method updateFileSet
  1484. *
  1485. * @param value
  1486. * @param element
  1487. * @param counter
  1488. * @param xmlTag
  1489. */
  1490. protected void updateFileSet( FileSet value, String xmlTag, Counter counter, Element element )
  1491. {
  1492. boolean shouldExist = value != null;
  1493. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1494. if ( shouldExist )
  1495. {
  1496. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1497. findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
  1498. findAndReplaceSimpleLists( innerCount, root, value.getIncludes(), "includes", "include" );
  1499. findAndReplaceSimpleLists( innerCount, root, value.getExcludes(), "excludes", "exclude" );
  1500. }
  1501. } // -- void updateFileSet(FileSet, String, Counter, Element)
  1502. /**
  1503. * Method updateIssueManagement
  1504. *
  1505. * @param value
  1506. * @param element
  1507. * @param counter
  1508. * @param xmlTag
  1509. */
  1510. protected void updateIssueManagement( IssueManagement value, String xmlTag, Counter counter, Element element )
  1511. {
  1512. boolean shouldExist = value != null;
  1513. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1514. if ( shouldExist )
  1515. {
  1516. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1517. findAndReplaceSimpleElement( innerCount, root, "system", value.getSystem(), null );
  1518. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  1519. }
  1520. } // -- void updateIssueManagement(IssueManagement, String, Counter, Element)
  1521. /**
  1522. * Method updateLicense
  1523. *
  1524. * @param value
  1525. * @param element
  1526. * @param counter
  1527. * @param xmlTag
  1528. */
  1529. protected void updateLicense( License value, String xmlTag, Counter counter, Element element )
  1530. {
  1531. Element root = element;
  1532. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1533. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  1534. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  1535. findAndReplaceSimpleElement( innerCount, root, "distribution", value.getDistribution(), null );
  1536. findAndReplaceSimpleElement( innerCount, root, "comments", value.getComments(), null );
  1537. } // -- void updateLicense(License, String, Counter, Element)
  1538. /**
  1539. * Method updateMailingList
  1540. *
  1541. * @param value
  1542. * @param element
  1543. * @param counter
  1544. * @param xmlTag
  1545. */
  1546. protected void updateMailingList( MailingList value, String xmlTag, Counter counter, Element element )
  1547. {
  1548. Element root = element;
  1549. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1550. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  1551. findAndReplaceSimpleElement( innerCount, root, "subscribe", value.getSubscribe(), null );
  1552. findAndReplaceSimpleElement( innerCount, root, "unsubscribe", value.getUnsubscribe(), null );
  1553. findAndReplaceSimpleElement( innerCount, root, "post", value.getPost(), null );
  1554. findAndReplaceSimpleElement( innerCount, root, "archive", value.getArchive(), null );
  1555. findAndReplaceSimpleLists( innerCount, root, value.getOtherArchives(), "otherArchives", "otherArchive" );
  1556. } // -- void updateMailingList(MailingList, String, Counter, Element)
  1557. /**
  1558. * Method updateModel
  1559. *
  1560. * @param value
  1561. * @param element
  1562. * @param counter
  1563. * @param xmlTag
  1564. */
  1565. protected void updateModel( Model value, String xmlTag, Counter counter, Element element )
  1566. {
  1567. Element root = element;
  1568. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1569. updateParent( value.getParent(), "parent", innerCount, root );
  1570. findAndReplaceSimpleElement( innerCount, root, "modelVersion", value.getModelVersion(), null );
  1571. findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
  1572. findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
  1573. findAndReplaceSimpleElement( innerCount, root, "packaging", value.getPackaging(), "jar" );
  1574. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  1575. findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
  1576. findAndReplaceSimpleElement( innerCount, root, "description", value.getDescription(), null );
  1577. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  1578. updatePrerequisites( value.getPrerequisites(), "prerequisites", innerCount, root );
  1579. updateIssueManagement( value.getIssueManagement(), "issueManagement", innerCount, root );
  1580. updateCiManagement( value.getCiManagement(), "ciManagement", innerCount, root );
  1581. findAndReplaceSimpleElement( innerCount, root, "inceptionYear", value.getInceptionYear(), null );
  1582. iterateMailingList( innerCount, root, value.getMailingLists(), "mailingLists", "mailingList" );
  1583. iterateDeveloper( innerCount, root, value.getDevelopers(), "developers", "developer" );
  1584. iterateContributor( innerCount, root, value.getContributors(), "contributors", "contributor" );
  1585. iterateLicense( innerCount, root, value.getLicenses(), "licenses", "license" );
  1586. updateScm( value.getScm(), "scm", innerCount, root );
  1587. updateOrganization( value.getOrganization(), "organization", innerCount, root );
  1588. updateBuild( value.getBuild(), "build", innerCount, root );
  1589. iterateProfile( innerCount, root, value.getProfiles(), "profiles", "profile" );
  1590. findAndReplaceSimpleLists( innerCount, root, value.getModules(), "testmodules", "module" );
  1591. iterateRepository( innerCount, root, value.getRepositories(), "repositories", "repository" );
  1592. iterateRepository( innerCount, root, value.getPluginRepositories(), "pluginRepositories", "pluginRepository" );
  1593. iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
  1594. findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
  1595. updateReporting( value.getReporting(), "reporting", innerCount, root );
  1596. updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
  1597. updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root );
  1598. findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
  1599. } // -- void updateModel(Model, String, Counter, Element)
  1600. /**
  1601. * Method updateModelBase
  1602. *
  1603. * @param value
  1604. * @param element
  1605. * @param counter
  1606. * @param xmlTag
  1607. */
  1608. protected void updateModelBase( ModelBase value, String xmlTag, Counter counter, Element element )
  1609. {
  1610. boolean shouldExist = value != null;
  1611. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1612. if ( shouldExist )
  1613. {
  1614. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1615. findAndReplaceSimpleLists( innerCount, root, value.getModules(), "testmodules", "module" );
  1616. iterateRepository( innerCount, root, value.getRepositories(), "repositories", "repository" );
  1617. iterateRepository( innerCount, root, value.getPluginRepositories(), "pluginRepositories",
  1618. "pluginRepository" );
  1619. iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
  1620. findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
  1621. updateReporting( value.getReporting(), "reporting", innerCount, root );
  1622. updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
  1623. updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root );
  1624. findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
  1625. }
  1626. } // -- void updateModelBase(ModelBase, String, Counter, Element)
  1627. /**
  1628. * Method updateNotifier
  1629. *
  1630. * @param value
  1631. * @param element
  1632. * @param counter
  1633. * @param xmlTag
  1634. */
  1635. protected void updateNotifier( Notifier value, String xmlTag, Counter counter, Element element )
  1636. {
  1637. Element root = element;
  1638. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1639. findAndReplaceSimpleElement( innerCount, root, "type", value.getType(), "mail" );
  1640. findAndReplaceSimpleElement( innerCount, root, "sendOnError", value.isSendOnError() ? null
  1641. : String.valueOf( value.isSendOnError() ), "true" );
  1642. findAndReplaceSimpleElement( innerCount, root, "sendOnFailure", value.isSendOnFailure() ? null
  1643. : String.valueOf( value.isSendOnFailure() ), "true" );
  1644. findAndReplaceSimpleElement( innerCount, root, "sendOnSuccess", value.isSendOnSuccess() ? null
  1645. : String.valueOf( value.isSendOnSuccess() ), "true" );
  1646. findAndReplaceSimpleElement( innerCount, root, "sendOnWarning", value.isSendOnWarning() ? null
  1647. : String.valueOf( value.isSendOnWarning() ), "true" );
  1648. findAndReplaceSimpleElement( innerCount, root, "address", value.getAddress(), null );
  1649. findAndReplaceProperties( innerCount, root, "configuration", value.getConfiguration() );
  1650. } // -- void updateNotifier(Notifier, String, Counter, Element)
  1651. /**
  1652. * Method updateOrganization
  1653. *
  1654. * @param value
  1655. * @param element
  1656. * @param counter
  1657. * @param xmlTag
  1658. */
  1659. protected void updateOrganization( Organization value, String xmlTag, Counter counter, Element element )
  1660. {
  1661. boolean shouldExist = value != null;
  1662. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1663. if ( shouldExist )
  1664. {
  1665. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1666. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  1667. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  1668. }
  1669. } // -- void updateOrganization(Organization, String, Counter, Element)
  1670. /**
  1671. * Method updateParent
  1672. *
  1673. * @param value
  1674. * @param element
  1675. * @param counter
  1676. * @param xmlTag
  1677. */
  1678. protected void updateParent( Parent value, String xmlTag, Counter counter, Element element )
  1679. {
  1680. boolean shouldExist = value != null;
  1681. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1682. if ( shouldExist )
  1683. {
  1684. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1685. findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
  1686. findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
  1687. findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
  1688. findAndReplaceSimpleElement( innerCount, root, "relativePath", value.getRelativePath(), "../pom.xml" );
  1689. }
  1690. } // -- void updateParent(Parent, String, Counter, Element)
  1691. /**
  1692. * Method updatePatternSet
  1693. *
  1694. * @param value
  1695. * @param element
  1696. * @param counter
  1697. * @param xmlTag
  1698. */
  1699. protected void updatePatternSet( PatternSet value, String xmlTag, Counter counter, Element element )
  1700. {
  1701. boolean shouldExist = value != null;
  1702. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1703. if ( shouldExist )
  1704. {
  1705. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1706. findAndReplaceSimpleLists( innerCount, root, value.getIncludes(), "includes", "include" );
  1707. findAndReplaceSimpleLists( innerCount, root, value.getExcludes(), "excludes", "exclude" );
  1708. }
  1709. } // -- void updatePatternSet(PatternSet, String, Counter, Element)
  1710. /**
  1711. * Method updatePlugin
  1712. *
  1713. * @param value
  1714. * @param element
  1715. * @param counter
  1716. * @param xmlTag
  1717. */
  1718. protected void updatePlugin( Plugin value, String xmlTag, Counter counter, Element element )
  1719. {
  1720. Element root = element;
  1721. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1722. findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins" );
  1723. findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
  1724. findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
  1725. findAndReplaceSimpleElement( innerCount, root, "extensions", !value.isExtensions() ? null
  1726. : String.valueOf( value.isExtensions() ), "false" );
  1727. iteratePluginExecution( innerCount, root, value.getExecutions(), "executions", "execution" );
  1728. iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
  1729. findAndReplaceXpp3DOM( innerCount, root, "goals", (Xpp3Dom) value.getGoals() );
  1730. findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
  1731. findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
  1732. } // -- void updatePlugin(Plugin, String, Counter, Element)
  1733. /**
  1734. * Method updatePluginConfiguration
  1735. *
  1736. * @param value
  1737. * @param element
  1738. * @param counter
  1739. * @param xmlTag
  1740. */
  1741. protected void updatePluginConfiguration( PluginConfiguration value, String xmlTag, Counter counter, Element element )
  1742. {
  1743. boolean shouldExist = value != null;
  1744. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1745. if ( shouldExist )
  1746. {
  1747. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1748. updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
  1749. iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
  1750. }
  1751. } // -- void updatePluginConfiguration(PluginConfiguration, String, Counter, Element)
  1752. /**
  1753. * Method updatePluginContainer
  1754. *
  1755. * @param value
  1756. * @param element
  1757. * @param counter
  1758. * @param xmlTag
  1759. */
  1760. protected void updatePluginContainer( PluginContainer value, String xmlTag, Counter counter, Element element )
  1761. {
  1762. boolean shouldExist = value != null;
  1763. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1764. if ( shouldExist )
  1765. {
  1766. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1767. iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
  1768. }
  1769. } // -- void updatePluginContainer(PluginContainer, String, Counter, Element)
  1770. /**
  1771. * Method updatePluginExecution
  1772. *
  1773. * @param value
  1774. * @param element
  1775. * @param counter
  1776. * @param xmlTag
  1777. */
  1778. protected void updatePluginExecution( PluginExecution value, String xmlTag, Counter counter, Element element )
  1779. {
  1780. Element root = element;
  1781. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1782. findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), "default" );
  1783. findAndReplaceSimpleElement( innerCount, root, "phase", value.getPhase(), null );
  1784. findAndReplaceSimpleLists( innerCount, root, value.getGoals(), "goals", "goal" );
  1785. findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
  1786. findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
  1787. } // -- void updatePluginExecution(PluginExecution, String, Counter, Element)
  1788. /**
  1789. * Method updatePluginManagement
  1790. *
  1791. * @param value
  1792. * @param element
  1793. * @param counter
  1794. * @param xmlTag
  1795. */
  1796. protected void updatePluginManagement( PluginManagement value, String xmlTag, Counter counter, Element element )
  1797. {
  1798. boolean shouldExist = value != null;
  1799. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1800. if ( shouldExist )
  1801. {
  1802. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1803. iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
  1804. }
  1805. } // -- void updatePluginManagement(PluginManagement, String, Counter, Element)
  1806. /**
  1807. * Method updatePrerequisites
  1808. *
  1809. * @param value
  1810. * @param element
  1811. * @param counter
  1812. * @param xmlTag
  1813. */
  1814. protected void updatePrerequisites( Prerequisites value, String xmlTag, Counter counter, Element element )
  1815. {
  1816. boolean shouldExist = value != null;
  1817. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1818. if ( shouldExist )
  1819. {
  1820. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1821. findAndReplaceSimpleElement( innerCount, root, "maven", value.getMaven(), "2.0" );
  1822. }
  1823. } // -- void updatePrerequisites(Prerequisites, String, Counter, Element)
  1824. /**
  1825. * Method updateProfile
  1826. *
  1827. * @param value
  1828. * @param element
  1829. * @param counter
  1830. * @param xmlTag
  1831. */
  1832. protected void updateProfile( Profile value, String xmlTag, Counter counter, Element element )
  1833. {
  1834. Element root = element;
  1835. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1836. findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), "default" );
  1837. // updateActivation( value.getActivation(), "activation", innerCount, root);
  1838. updateBuildBase( value.getBuild(), "build", innerCount, root );
  1839. findAndReplaceSimpleLists( innerCount, root, value.getModules(), "testmodules", "module" );
  1840. iterateRepository( innerCount, root, value.getRepositories(), "repositories", "repository" );
  1841. iterateRepository( innerCount, root, value.getPluginRepositories(), "pluginRepositories", "pluginRepository" );
  1842. iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
  1843. findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
  1844. updateReporting( value.getReporting(), "reporting", innerCount, root );
  1845. updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
  1846. updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root );
  1847. findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
  1848. } // -- void updateProfile(Profile, String, Counter, Element)
  1849. /**
  1850. * Method updateRelocation
  1851. *
  1852. * @param value
  1853. * @param element
  1854. * @param counter
  1855. * @param xmlTag
  1856. */
  1857. protected void updateRelocation( Relocation value, String xmlTag, Counter counter, Element element )
  1858. {
  1859. boolean shouldExist = value != null;
  1860. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1861. if ( shouldExist )
  1862. {
  1863. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1864. findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
  1865. findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
  1866. findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
  1867. findAndReplaceSimpleElement( innerCount, root, "message", value.getMessage(), null );
  1868. }
  1869. } // -- void updateRelocation(Relocation, String, Counter, Element)
  1870. /**
  1871. * Method updateReportPlugin
  1872. *
  1873. * @param value
  1874. * @param element
  1875. * @param counter
  1876. * @param xmlTag
  1877. */
  1878. protected void updateReportPlugin( ReportPlugin value, String xmlTag, Counter counter, Element element )
  1879. {
  1880. Element root = element;
  1881. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1882. findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins" );
  1883. findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
  1884. findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
  1885. findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
  1886. findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
  1887. iterateReportSet( innerCount, root, value.getReportSets(), "reportSets", "reportSet" );
  1888. } // -- void updateReportPlugin(ReportPlugin, String, Counter, Element)
  1889. /**
  1890. * Method updateReportSet
  1891. *
  1892. * @param value
  1893. * @param element
  1894. * @param counter
  1895. * @param xmlTag
  1896. */
  1897. protected void updateReportSet( ReportSet value, String xmlTag, Counter counter, Element element )
  1898. {
  1899. Element root = element;
  1900. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1901. findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), "default" );
  1902. findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
  1903. findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
  1904. findAndReplaceSimpleLists( innerCount, root, value.getReports(), "reports", "report" );
  1905. } // -- void updateReportSet(ReportSet, String, Counter, Element)
  1906. /**
  1907. * Method updateReporting
  1908. *
  1909. * @param value
  1910. * @param element
  1911. * @param counter
  1912. * @param xmlTag
  1913. */
  1914. protected void updateReporting( Reporting value, String xmlTag, Counter counter, Element element )
  1915. {
  1916. boolean shouldExist = value != null;
  1917. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1918. if ( shouldExist )
  1919. {
  1920. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1921. findAndReplaceSimpleElement( innerCount, root, "excludeDefaults", !value.isExcludeDefaults() ? null
  1922. : String.valueOf( value.isExcludeDefaults() ), "false" );
  1923. findAndReplaceSimpleElement( innerCount, root, "outputDirectory", value.getOutputDirectory(), null );
  1924. iterateReportPlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
  1925. }
  1926. } // -- void updateReporting(Reporting, String, Counter, Element)
  1927. /**
  1928. * Method updateRepository
  1929. *
  1930. * @param value
  1931. * @param element
  1932. * @param counter
  1933. * @param xmlTag
  1934. */
  1935. protected void updateRepository( Repository value, String xmlTag, Counter counter, Element element )
  1936. {
  1937. Element root = element;
  1938. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1939. updateRepositoryPolicy( value.getReleases(), "releases", innerCount, root );
  1940. updateRepositoryPolicy( value.getSnapshots(), "snapshots", innerCount, root );
  1941. findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
  1942. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  1943. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  1944. findAndReplaceSimpleElement( innerCount, root, "layout", value.getLayout(), "default" );
  1945. } // -- void updateRepository(Repository, String, Counter, Element)
  1946. /**
  1947. * Method updateRepositoryBase
  1948. *
  1949. * @param value
  1950. * @param element
  1951. * @param counter
  1952. * @param xmlTag
  1953. */
  1954. protected void updateRepositoryBase( RepositoryBase value, String xmlTag, Counter counter, Element element )
  1955. {
  1956. boolean shouldExist = value != null;
  1957. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1958. if ( shouldExist )
  1959. {
  1960. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1961. findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
  1962. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  1963. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  1964. findAndReplaceSimpleElement( innerCount, root, "layout", value.getLayout(), "default" );
  1965. }
  1966. } // -- void updateRepositoryBase(RepositoryBase, String, Counter, Element)
  1967. /**
  1968. * Method updateRepositoryPolicy
  1969. *
  1970. * @param value
  1971. * @param element
  1972. * @param counter
  1973. * @param xmlTag
  1974. */
  1975. protected void updateRepositoryPolicy( RepositoryPolicy value, String xmlTag, Counter counter, Element element )
  1976. {
  1977. boolean shouldExist = value != null;
  1978. Element root = updateElement( counter, element, xmlTag, shouldExist );
  1979. if ( shouldExist )
  1980. {
  1981. Counter innerCount = new Counter( counter.getDepth() + 1 );
  1982. findAndReplaceSimpleElement( innerCount, root, "enabled", value.isEnabled() ? null
  1983. : String.valueOf( value.isEnabled() ), "true" );
  1984. findAndReplaceSimpleElement( innerCount, root, "updatePolicy", value.getUpdatePolicy(), null );
  1985. findAndReplaceSimpleElement( innerCount, root, "checksumPolicy", value.getChecksumPolicy(), null );
  1986. }
  1987. } // -- void updateRepositoryPolicy(RepositoryPolicy, String, Counter, Element)
  1988. /**
  1989. * Method updateResource
  1990. *
  1991. * @param value
  1992. * @param element
  1993. * @param counter
  1994. * @param xmlTag
  1995. */
  1996. protected void updateResource( Resource value, String xmlTag, Counter counter, Element element )
  1997. {
  1998. Element root = element;
  1999. Counter innerCount = new Counter( counter.getDepth() + 1 );
  2000. findAndReplaceSimpleElement( innerCount, root, "targetPath", value.getTargetPath(), null );
  2001. findAndReplaceSimpleElement( innerCount, root, "filtering", !value.isFiltering() ? null
  2002. : String.valueOf( value.isFiltering() ), "false" );
  2003. findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
  2004. findAndReplaceSimpleLists( innerCount, root, value.getIncludes(), "includes", "include" );
  2005. findAndReplaceSimpleLists( innerCount, root, value.getExcludes(), "excludes", "exclude" );
  2006. } // -- void updateResource(Resource, String, Counter, Element)
  2007. /**
  2008. * Method updateScm
  2009. *
  2010. * @param value
  2011. * @param element
  2012. * @param counter
  2013. * @param xmlTag
  2014. */
  2015. protected void updateScm( Scm value, String xmlTag, Counter counter, Element element )
  2016. {
  2017. boolean shouldExist = value != null;
  2018. Element root = updateElement( counter, element, xmlTag, shouldExist );
  2019. if ( shouldExist )
  2020. {
  2021. Counter innerCount = new Counter( counter.getDepth() + 1 );
  2022. findAndReplaceSimpleElement( innerCount, root, "connection", value.getConnection(), null );
  2023. findAndReplaceSimpleElement( innerCount, root, "developerConnection", value.getDeveloperConnection(), null );
  2024. findAndReplaceSimpleElement( innerCount, root, "tag", value.getTag(), "HEAD" );
  2025. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  2026. }
  2027. } // -- void updateScm(Scm, String, Counter, Element)
  2028. /**
  2029. * Method updateSite
  2030. *
  2031. * @param value
  2032. * @param element
  2033. * @param counter
  2034. * @param xmlTag
  2035. */
  2036. protected void updateSite( Site value, String xmlTag, Counter counter, Element element )
  2037. {
  2038. boolean shouldExist = value != null;
  2039. Element root = updateElement( counter, element, xmlTag, shouldExist );
  2040. if ( shouldExist )
  2041. {
  2042. Counter innerCount = new Counter( counter.getDepth() + 1 );
  2043. findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
  2044. findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
  2045. findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
  2046. }
  2047. } // -- void updateSite(Site, String, Counter, Element)
  2048. /**
  2049. * Method write
  2050. *
  2051. * @deprecated
  2052. * @param project
  2053. * @param stream
  2054. * @param document
  2055. */
  2056. public void write( Model project, Document document, OutputStream stream )
  2057. throws java.io.IOException
  2058. {
  2059. updateModel( project, "project", new Counter( 0 ), document.getRootElement() );
  2060. XMLOutputter outputter = new XMLOutputter();
  2061. Format format = Format.getPrettyFormat();
  2062. format.setIndent( " " ).setLineSeparator( System.getProperty( "line.separator" ) );
  2063. outputter.setFormat( format );
  2064. outputter.output( document, stream );
  2065. } // -- void write(Model, Document, OutputStream)
  2066. /**
  2067. * Method write
  2068. *
  2069. * @param project
  2070. * @param writer
  2071. * @param document
  2072. */
  2073. public void write( Model project, Document document, OutputStreamWriter writer )
  2074. throws java.io.IOException
  2075. {
  2076. Format format = Format.getRawFormat();
  2077. format.setEncoding( writer.getEncoding() ).setLineSeparator( System.getProperty( "line.separator" ) );
  2078. write( project, document, writer, format );
  2079. } // -- void write(Model, Document, OutputStreamWriter)
  2080. /**
  2081. * Method write
  2082. *
  2083. * @param project
  2084. * @param jdomFormat
  2085. * @param writer
  2086. * @param document
  2087. */
  2088. public void write( Model project, Document document, Writer writer, Format jdomFormat )
  2089. throws java.io.IOException
  2090. {
  2091. updateModel( project, "project", new Counter( 0 ), document.getRootElement() );
  2092. XMLOutputter outputter = new XMLOutputter();
  2093. outputter.setFormat( jdomFormat );
  2094. outputter.output( document, writer );
  2095. } // -- void write(Model, Document, Writer, Format)
  2096. // -----------------/
  2097. // - Inner Classes -/
  2098. // -----------------/
  2099. /**
  2100. * Class Counter.
  2101. *
  2102. * @version $Revision: 944825 $ $Date: 2010-05-16 06:15:38 -0700 (Sun, 16 May 2010) $
  2103. */
  2104. public class Counter
  2105. {
  2106. // --------------------------/
  2107. // - Class/Member Variables -/
  2108. // --------------------------/
  2109. /**
  2110. * Field currentIndex
  2111. */
  2112. private int currentIndex = 0;
  2113. /**
  2114. * Field level
  2115. */
  2116. private int level;
  2117. // ----------------/
  2118. // - Constructors -/
  2119. // ----------------/
  2120. public Counter( int depthLevel )
  2121. {
  2122. level = depthLevel;
  2123. } // -- org.apache.maven.model.io.jdom.Counter(int)
  2124. // -----------/
  2125. // - Methods -/
  2126. // -----------/
  2127. /**
  2128. * Method getCurrentIndex
  2129. */
  2130. public int getCurrentIndex()
  2131. {
  2132. return currentIndex;
  2133. } // -- int getCurrentIndex()
  2134. /**
  2135. * Method getDepth
  2136. */
  2137. public int getDepth()
  2138. {
  2139. return level;
  2140. } // -- int getDepth()
  2141. /**
  2142. * Method increaseCount
  2143. */
  2144. public void increaseCount()
  2145. {
  2146. currentIndex = currentIndex + 1;
  2147. } // -- void increaseCount()
  2148. }
  2149. }