Skip to content

Commit 723640e

Browse files
committed
437430 jettyXml not consistent between jetty:run and jetty:run-forked
1 parent 4896672 commit 723640e

File tree

3 files changed

+53
-30
lines changed

3 files changed

+53
-30
lines changed

jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.net.URLClassLoader;
2828
import java.util.ArrayList;
2929
import java.util.Arrays;
30+
import java.util.Collections;
3031
import java.util.Enumeration;
3132
import java.util.Iterator;
3233
import java.util.List;
@@ -449,7 +450,7 @@ public void finishConfigurationBeforeStart() throws Exception
449450

450451

451452

452-
453+
453454
/**
454455
* @throws Exception
455456
*/
@@ -458,28 +459,7 @@ public void applyJettyXml() throws Exception
458459
if (getJettyXmlFiles() == null)
459460
return;
460461

461-
XmlConfiguration last = null;
462-
for ( File xmlFile : getJettyXmlFiles() )
463-
{
464-
getLog().info( "Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath() );
465-
XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(xmlFile));
466-
467-
//chain ids from one config file to another
468-
if (last == null)
469-
xmlConfiguration.getIdMap().put("Server", this.server);
470-
else
471-
xmlConfiguration.getIdMap().putAll(last.getIdMap());
472-
473-
//Set the system properties each time in case the config file set a new one
474-
Enumeration<?> ensysprop = System.getProperties().propertyNames();
475-
while (ensysprop.hasMoreElements())
476-
{
477-
String name = (String)ensysprop.nextElement();
478-
xmlConfiguration.getProperties().put(name,System.getProperty(name));
479-
}
480-
last = xmlConfiguration;
481-
xmlConfiguration.configure();
482-
}
462+
this.server.applyXmlConfigurations(getJettyXmlFiles());
483463
}
484464

485465

jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyServer.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
package org.eclipse.jetty.maven.plugin;
2020

2121

22+
import java.io.File;
23+
import java.util.Collections;
24+
import java.util.Enumeration;
25+
import java.util.List;
26+
import java.util.Map;
27+
2228
import org.eclipse.jetty.server.Handler;
2329
import org.eclipse.jetty.server.RequestLog;
2430
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
@@ -27,6 +33,8 @@
2733
import org.eclipse.jetty.server.handler.RequestLogHandler;
2834
import org.eclipse.jetty.util.resource.Resource;
2935
import org.eclipse.jetty.webapp.WebAppContext;
36+
import org.eclipse.jetty.xml.XmlConfiguration;
37+
3038

3139
/**
3240
* JettyServer
@@ -109,4 +117,43 @@ public void configureHandlers () throws Exception
109117
}
110118
}
111119
}
120+
121+
/**
122+
* Apply xml files to server startup, passing in ourselves as the
123+
* "Server" instance.
124+
*
125+
* @param files
126+
* @throws Exception
127+
*/
128+
public void applyXmlConfigurations (List<File> files)
129+
throws Exception
130+
{
131+
if (files == null || files.isEmpty())
132+
return;
133+
134+
Map<String,Object> lastMap = Collections.singletonMap("Server", (Object)this);
135+
136+
for ( File xmlFile : files )
137+
{
138+
if (PluginLog.getLog() != null)
139+
PluginLog.getLog().info( "Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath() );
140+
141+
142+
XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(xmlFile));
143+
144+
//chain ids from one config file to another
145+
if (lastMap != null)
146+
xmlConfiguration.getIdMap().putAll(lastMap);
147+
148+
//Set the system properties each time in case the config file set a new one
149+
Enumeration<?> ensysprop = System.getProperties().propertyNames();
150+
while (ensysprop.hasMoreElements())
151+
{
152+
String name = (String)ensysprop.nextElement();
153+
xmlConfiguration.getProperties().put(name,System.getProperty(name));
154+
}
155+
xmlConfiguration.configure();
156+
lastMap = xmlConfiguration.getIdMap();
157+
}
158+
}
112159
}

jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Starter.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.InputStream;
2424
import java.net.URL;
2525
import java.util.ArrayList;
26+
import java.util.Collections;
2627
import java.util.Enumeration;
2728
import java.util.HashSet;
2829
import java.util.Iterator;
@@ -415,19 +416,14 @@ public void communicateStartupResult (Exception e)
415416

416417

417418
/**
419+
* Apply any jetty xml files given
418420
* @throws Exception
419421
*/
420422
public void applyJettyXml() throws Exception
421423
{
422424
if (jettyXmls == null)
423425
return;
424-
425-
for ( File xmlFile : jettyXmls )
426-
{
427-
LOG.info( "Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath() );
428-
XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(xmlFile));
429-
xmlConfiguration.configure(this.server);
430-
}
426+
this.server.applyXmlConfigurations(jettyXmls);
431427
}
432428

433429

0 commit comments

Comments
 (0)