/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

Large files are truncated click here to view the full file

  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