59
59
import org .apache .maven .model .License ;
60
60
import org .apache .maven .model .MailingList ;
61
61
import org .apache .maven .model .Model ;
62
- import org .apache .maven .model .ModelBase ;
63
62
import org .apache .maven .model .Notifier ;
64
63
import org .apache .maven .model .Organization ;
65
64
import org .apache .maven .model .Parent ;
@@ -127,7 +126,7 @@ public MavenJDOMWriter() {
127
126
*/
128
127
@ Deprecated
129
128
public void write (Model project , Document document , OutputStream stream ) throws java .io .IOException {
130
- updateModel (project , "project" , new Counter (0 ), document .getRootElement ());
129
+ updateModel (project , new Counter (0 ), document .getRootElement ());
131
130
132
131
XMLOutputter outputter = new XMLOutputter ();
133
132
outputter .setFormat (Format .getPrettyFormat ().setIndent (" " ).setLineSeparator (LS ));
@@ -155,7 +154,7 @@ public void write(Model project, Document document, OutputStreamWriter writer) t
155
154
* @param document
156
155
*/
157
156
public void write (Model project , Document document , Writer writer , Format jdomFormat ) throws java .io .IOException {
158
- updateModel (project , "project" , new Counter (0 ), document .getRootElement ());
157
+ updateModel (project , new Counter (0 ), document .getRootElement ());
159
158
160
159
XMLOutputter outputter = new XMLOutputter ();
161
160
outputter .setFormat (jdomFormat );
@@ -174,7 +173,7 @@ public void write(Model project, Document document, Writer writer, Format jdomFo
174
173
* @param name
175
174
* @param parent
176
175
*/
177
- protected Element findAndReplaceProperties (Counter counter , Element parent , String name , Map props ) {
176
+ protected void findAndReplaceProperties (Counter counter , Element parent , String name , Map props ) {
178
177
boolean shouldExist = (props != null ) && !props .isEmpty ();
179
178
Element element = updateElement (counter , parent , name , shouldExist );
180
179
if (shouldExist ) {
@@ -195,7 +194,6 @@ protected Element findAndReplaceProperties(Counter counter, Element parent, Stri
195
194
}
196
195
}
197
196
}
198
- return element ;
199
197
} // -- Element findAndReplaceProperties(Counter, Element, String, Map)
200
198
201
199
/**
@@ -207,13 +205,13 @@ protected Element findAndReplaceProperties(Counter counter, Element parent, Stri
207
205
* @param name
208
206
* @param parent
209
207
*/
210
- protected Element findAndReplaceSimpleElement (
208
+ protected void findAndReplaceSimpleElement (
211
209
Counter counter , Element parent , String name , String text , String defaultValue ) {
212
210
if ((defaultValue != null ) && (text != null ) && defaultValue .equals (text )) {
213
211
Element element = parent .getChild (name , parent .getNamespace ());
214
212
// if exist and is default value or if doesn't exist.. just keep the way it is..
215
213
if (((element != null ) && defaultValue .equals (element .getText ())) || (element == null )) {
216
- return element ;
214
+ return ;
217
215
}
218
216
}
219
217
@@ -222,7 +220,6 @@ protected Element findAndReplaceSimpleElement(
222
220
if (shouldExist ) {
223
221
element .setText (text );
224
222
}
225
- return element ;
226
223
} // -- Element findAndReplaceSimpleElement(Counter, Element, String, String, String)
227
224
228
225
/**
@@ -234,7 +231,7 @@ protected Element findAndReplaceSimpleElement(
234
231
* @param list
235
232
* @param parent
236
233
*/
237
- protected Element findAndReplaceSimpleLists (
234
+ protected void findAndReplaceSimpleLists (
238
235
Counter counter , Element parent , Collection list , String parentName , String childName ) {
239
236
boolean shouldExist = (list != null ) && (list .size () > 0 );
240
237
Element element = updateElement (counter , parent , parentName , shouldExist );
@@ -269,7 +266,6 @@ protected Element findAndReplaceSimpleLists(
269
266
}
270
267
}
271
268
}
272
- return element ;
273
269
} // -- Element findAndReplaceSimpleLists(Counter, Element, Collection, String, String)
274
270
275
271
/**
@@ -280,13 +276,12 @@ protected Element findAndReplaceSimpleLists(
280
276
* @param name
281
277
* @param parent
282
278
*/
283
- protected Element findAndReplaceXpp3DOM (Counter counter , Element parent , String name , Xpp3Dom dom ) {
279
+ protected void findAndReplaceXpp3DOM (Counter counter , Element parent , String name , Xpp3Dom dom ) {
284
280
boolean shouldExist = (dom != null ) && ((dom .getChildCount () > 0 ) || (dom .getValue () != null ));
285
281
Element element = updateElement (counter , parent , name , shouldExist );
286
282
if (shouldExist ) {
287
283
replaceXpp3DOM (element , dom , new Counter (counter .getDepth () + 1 ));
288
284
}
289
- return element ;
290
285
} // -- Element findAndReplaceXpp3DOM(Counter, Element, String, Xpp3Dom)
291
286
292
287
/**
@@ -1022,7 +1017,7 @@ protected void iterateResource(
1022
1017
el = factory .element (childTag , element .getNamespace ());
1023
1018
insertAtPreferredLocation (element , el , innerCount );
1024
1019
}
1025
- updateResource (value , childTag , innerCount , el );
1020
+ updateResource (value , innerCount , el );
1026
1021
innerCount .increaseCount ();
1027
1022
}
1028
1023
if (elIt != null ) {
@@ -1540,9 +1535,8 @@ protected void updateMailingList(MailingList value, String xmlTag, Counter count
1540
1535
* @param value
1541
1536
* @param element
1542
1537
* @param counter
1543
- * @param xmlTag
1544
1538
*/
1545
- protected void updateModel (Model value , String xmlTag , Counter counter , Element element ) {
1539
+ protected void updateModel (Model value , Counter counter , Element element ) {
1546
1540
Element root = element ;
1547
1541
Counter innerCount = new Counter (counter .getDepth () + 1 );
1548
1542
updateParent (value .getParent (), "parent" , innerCount , root );
@@ -1570,39 +1564,13 @@ protected void updateModel(Model value, String xmlTag, Counter counter, Element
1570
1564
iterateRepository (innerCount , root , value .getRepositories (), "repositories" , "repository" );
1571
1565
iterateRepository (innerCount , root , value .getPluginRepositories (), "pluginRepositories" , "pluginRepository" );
1572
1566
iterateDependency (innerCount , root , value .getDependencies (), "dependencies" , "dependency" );
1573
- findAndReplaceXpp3DOM (innerCount , root , "reports" , (Xpp3Dom ) value . getReports ( ));
1567
+ findAndReplaceXpp3DOM (innerCount , root , "reports" , (Xpp3Dom ) safeGetReports ( value ));
1574
1568
updateReporting (value .getReporting (), "reporting" , innerCount , root );
1575
1569
updateDependencyManagement (value .getDependencyManagement (), "dependencyManagement" , innerCount , root );
1576
1570
updateDistributionManagement (value .getDistributionManagement (), "distributionManagement" , innerCount , root );
1577
1571
findAndReplaceProperties (innerCount , root , "properties" , value .getProperties ());
1578
1572
} // -- void updateModel(Model, String, Counter, Element)
1579
1573
1580
- /**
1581
- * Method updateModelBase.
1582
- *
1583
- * @param value
1584
- * @param element
1585
- * @param counter
1586
- * @param xmlTag
1587
- */
1588
- protected void updateModelBase (ModelBase value , String xmlTag , Counter counter , Element element ) {
1589
- boolean shouldExist = value != null ;
1590
- Element root = updateElement (counter , element , xmlTag , shouldExist );
1591
- if (shouldExist ) {
1592
- Counter innerCount = new Counter (counter .getDepth () + 1 );
1593
- findAndReplaceSimpleLists (innerCount , root , value .getModules (), "modules" , "module" );
1594
- iterateRepository (innerCount , root , value .getRepositories (), "repositories" , "repository" );
1595
- iterateRepository (
1596
- innerCount , root , value .getPluginRepositories (), "pluginRepositories" , "pluginRepository" );
1597
- iterateDependency (innerCount , root , value .getDependencies (), "dependencies" , "dependency" );
1598
- findAndReplaceXpp3DOM (innerCount , root , "reports" , (Xpp3Dom ) value .getReports ());
1599
- updateReporting (value .getReporting (), "reporting" , innerCount , root );
1600
- updateDependencyManagement (value .getDependencyManagement (), "dependencyManagement" , innerCount , root );
1601
- updateDistributionManagement (value .getDistributionManagement (), "distributionManagement" , innerCount , root );
1602
- findAndReplaceProperties (innerCount , root , "properties" , value .getProperties ());
1603
- }
1604
- } // -- void updateModelBase(ModelBase, String, Counter, Element)
1605
-
1606
1574
/**
1607
1575
* Method updateNotifier.
1608
1576
*
@@ -1721,11 +1689,29 @@ protected void updatePlugin(Plugin value, String xmlTag, Counter counter, Elemen
1721
1689
"false" );
1722
1690
iteratePluginExecution (innerCount , root , value .getExecutions (), "executions" , "execution" );
1723
1691
iterateDependency (innerCount , root , value .getDependencies (), "dependencies" , "dependency" );
1724
- findAndReplaceXpp3DOM (innerCount , root , "goals" , (Xpp3Dom ) value . getGoals ( ));
1692
+ findAndReplaceXpp3DOM (innerCount , root , "goals" , (Xpp3Dom ) safeGetGoals ( value ));
1725
1693
findAndReplaceSimpleElement (innerCount , root , "inherited" , value .getInherited (), null );
1726
1694
findAndReplaceXpp3DOM (innerCount , root , "configuration" , (Xpp3Dom ) value .getConfiguration ());
1727
1695
} // -- void updatePlugin(Plugin, String, Counter, Element)
1728
1696
1697
+ // Workaround for Maven 4 dropped methods
1698
+
1699
+ private Object safeGetGoals (Plugin plugin ) {
1700
+ try {
1701
+ return plugin .getGoals ();
1702
+ } catch (NoSuchMethodError e ) {
1703
+ return null ;
1704
+ }
1705
+ }
1706
+
1707
+ private Object safeGetReports (Model model ) {
1708
+ try {
1709
+ return model .getReports ();
1710
+ } catch (NoSuchMethodError e ) {
1711
+ return null ;
1712
+ }
1713
+ }
1714
+
1729
1715
/**
1730
1716
* Method updatePluginConfiguration.
1731
1717
*
@@ -1988,9 +1974,8 @@ protected void updateRepositoryPolicy(RepositoryPolicy value, String xmlTag, Cou
1988
1974
* @param value
1989
1975
* @param element
1990
1976
* @param counter
1991
- * @param xmlTag
1992
1977
*/
1993
- protected void updateResource (Resource value , String xmlTag , Counter counter , Element element ) {
1978
+ protected void updateResource (Resource value , Counter counter , Element element ) {
1994
1979
Element root = element ;
1995
1980
Counter innerCount = new Counter (counter .getDepth () + 1 );
1996
1981
findAndReplaceSimpleElement (innerCount , root , "targetPath" , value .getTargetPath (), null );
0 commit comments