29
29
import java .util .Arrays ;
30
30
import java .util .HashMap ;
31
31
import java .util .HashSet ;
32
+ import java .util .Optional ;
32
33
import java .util .Set ;
33
34
import java .util .Map ;
34
35
import java .util .Properties ;
43
44
import javax .xml .xpath .XPathExpressionException ;
44
45
import javax .xml .xpath .XPathFactory ;
45
46
47
+ import io .openliberty .tools .common .plugins .util .PluginExecutionException ;
46
48
import org .apache .commons .io .comparator .NameFileComparator ;
47
49
import org .w3c .dom .Document ;
48
50
import org .w3c .dom .Element ;
@@ -72,6 +74,8 @@ public class ServerConfigDocument {
72
74
private Properties defaultProps ;
73
75
private Map <String , File > libertyDirectoryPropertyToFile = null ;
74
76
77
+ Optional <String > springBootAppNodeLocation =Optional .empty ();
78
+
75
79
private static final XPathExpression XPATH_SERVER_APPLICATION ;
76
80
private static final XPathExpression XPATH_SERVER_WEB_APPLICATION ;
77
81
private static final XPathExpression XPATH_SERVER_SPRINGBOOT_APPLICATION ;
@@ -135,7 +139,7 @@ public File getServerXML() {
135
139
* @param originalServerXMLFile
136
140
* @param libertyDirPropertyFiles
137
141
*/
138
- public ServerConfigDocument (CommonLoggerI log , File originalServerXMLFile , Map <String , File > libertyDirPropertyFiles ) {
142
+ public ServerConfigDocument (CommonLoggerI log , File originalServerXMLFile , Map <String , File > libertyDirPropertyFiles ) throws PluginExecutionException {
139
143
this .log = log ;
140
144
if (libertyDirPropertyFiles != null ) {
141
145
libertyDirectoryPropertyToFile = new HashMap <String , File >(libertyDirPropertyFiles );
@@ -157,7 +161,7 @@ public ServerConfigDocument(CommonLoggerI log, File originalServerXMLFile, Map<S
157
161
158
162
// LCLS constructor
159
163
// TODO: populate libertyDirectoryPropertyToFile with workspace information
160
- public ServerConfigDocument (CommonLoggerI log ) {
164
+ public ServerConfigDocument (CommonLoggerI log ) throws PluginExecutionException {
161
165
this (log , null , null );
162
166
}
163
167
@@ -227,7 +231,7 @@ private DocumentBuilder getDocumentBuilder() {
227
231
// c. ${server.config.dir}/configDropins/overrides/
228
232
// 7. variables declared on the command line
229
233
*/
230
- public void initializeAppsLocation () {
234
+ public void initializeAppsLocation () throws PluginExecutionException {
231
235
try {
232
236
// 1. Need to parse variables in the server.xml for default values before trying to
233
237
// find the include files in case one of the variables is used in the location.
@@ -265,6 +269,9 @@ public void initializeAppsLocation() {
265
269
parseConfigDropinsDir ();
266
270
267
271
} catch (Exception e ) {
272
+ if (e instanceof PluginExecutionException ){
273
+ throw (PluginExecutionException )e ;
274
+ }
268
275
e .printStackTrace ();
269
276
}
270
277
}
@@ -484,15 +491,19 @@ public String findNameForLocation(String location) {
484
491
return appName ;
485
492
}
486
493
487
- private void parseApplication (Document doc , XPathExpression expression ) throws XPathExpressionException {
494
+ private void parseApplication (Document doc , XPathExpression expression ) throws XPathExpressionException , PluginExecutionException {
488
495
489
496
NodeList nodeList = (NodeList ) expression .evaluate (doc , XPathConstants .NODESET );
490
-
497
+ if (expression .equals (XPATH_SERVER_SPRINGBOOT_APPLICATION ) && nodeList .getLength ()>1 ){
498
+ throw new PluginExecutionException ("Multiple <springBootApplication/> nodes found in Liberty Config server.xml. Please specify only one" );
499
+ }
491
500
for (int i = 0 ; i < nodeList .getLength (); i ++) {
492
501
String nodeValue = nodeList .item (i ).getAttributes ().getNamedItem ("location" ).getNodeValue ();
493
-
494
502
// add unique values only
495
503
if (!nodeValue .isEmpty ()) {
504
+ if (expression .equals (XPATH_SERVER_SPRINGBOOT_APPLICATION )){
505
+ springBootAppNodeLocation = Optional .of (nodeValue );
506
+ }
496
507
String resolved = VariableUtility .resolveVariables (log , nodeValue , null , getProperties (), getDefaultProperties (), getLibertyDirPropertyFiles ());
497
508
if (resolved == null ) {
498
509
// location could not be resolved, log message and add location as is
@@ -508,7 +519,7 @@ private void parseApplication(Document doc, XPathExpression expression) throws X
508
519
}
509
520
}
510
521
511
- private void parseInclude (Document doc ) throws XPathExpressionException , IOException , SAXException {
522
+ private void parseInclude (Document doc ) throws XPathExpressionException , IOException , SAXException , PluginExecutionException {
512
523
// parse include document in source server xml
513
524
NodeList nodeList = (NodeList ) XPATH_SERVER_INCLUDE .evaluate (doc , XPathConstants .NODESET );
514
525
@@ -539,7 +550,7 @@ private void parseInclude(Document doc) throws XPathExpressionException, IOExcep
539
550
}
540
551
}
541
552
542
- private void parseConfigDropinsDir () throws XPathExpressionException , IOException , SAXException {
553
+ private void parseConfigDropinsDir () throws XPathExpressionException , IOException , SAXException , PluginExecutionException {
543
554
File configDropins = getConfigDropinsDir ();
544
555
545
556
if (configDropins == null || !configDropins .exists ()) {
@@ -557,7 +568,7 @@ private void parseConfigDropinsDir() throws XPathExpressionException, IOExceptio
557
568
}
558
569
}
559
570
560
- private void parseDropinsFiles (File [] files ) throws XPathExpressionException , IOException , SAXException {
571
+ private void parseDropinsFiles (File [] files ) throws XPathExpressionException , IOException , SAXException , PluginExecutionException {
561
572
Arrays .sort (files , NameFileComparator .NAME_INSENSITIVE_COMPARATOR );
562
573
for (File file : files ) {
563
574
if (file .isFile ()) {
@@ -566,7 +577,7 @@ private void parseDropinsFiles(File[] files) throws XPathExpressionException, IO
566
577
}
567
578
}
568
579
569
- private void parseDropinsFile (File file ) throws IOException , XPathExpressionException , SAXException {
580
+ private void parseDropinsFile (File file ) throws IOException , XPathExpressionException , SAXException , PluginExecutionException {
570
581
// get input XML Document
571
582
Document doc = parseDocument (file );
572
583
if (doc != null ) {
@@ -906,4 +917,13 @@ public File getOriginalServerXMLFile() {
906
917
public void setOriginalServerXMLFile (File originalServerXMLFile ) {
907
918
this .originalServerXMLFile = originalServerXMLFile ;
908
919
}
920
+
921
+ public Optional <String > getSpringBootAppNodeLocation () {
922
+ return springBootAppNodeLocation ;
923
+ }
924
+
925
+ public void setSpringBootAppNodeLocation (Optional <String > springBootAppNodeLocation ) {
926
+ this .springBootAppNodeLocation = springBootAppNodeLocation ;
927
+ }
928
+
909
929
}
0 commit comments