You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ge...@apache.org on 2010/08/05 15:05:23 UTC
svn commit: r982597 - in
/geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server:
ServerOverride.java StartServerMojo.java
Author: genspring
Date: Thu Aug 5 13:05:23 2010
New Revision: 982597
URL: http://svn.apache.org/viewvc?rev=982597&view=rev
Log:
GERONIMO-5504 Add "overrides" and "overriDir" parameters to geronimo-maven-plugin start-server goal, patch from Viola.
Added:
geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/ServerOverride.java (with props)
Modified:
geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/StartServerMojo.java
Added: geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/ServerOverride.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/ServerOverride.java?rev=982597&view=auto
==============================================================================
--- geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/ServerOverride.java (added)
+++ geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/ServerOverride.java Thu Aug 5 13:05:23 2010
@@ -0,0 +1,46 @@
+package org.apache.geronimo.mavenplugins.geronimo.server;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.geronimo.system.configuration.AttributesXmlUtil;
+import org.apache.geronimo.system.plugin.model.AttributesType;
+import org.xml.sax.SAXException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServerOverride {
+
+ /**
+ * server these overides apply to
+ * @parameter
+ */
+ private String server;
+
+ /**
+ * file containing overrides
+ * @parameter
+ */
+ private String overrides;
+
+ public String getServer() {
+ return server;
+ }
+
+ public AttributesType getOverrides(File base) throws IOException, JAXBException, ParserConfigurationException, SAXException, XMLStreamException {
+ File file = new File(base, overrides);
+ FileReader input = new FileReader(file);
+ try {
+ return AttributesXmlUtil.loadAttributes(input);
+ } finally {
+ input.close();
+ }
+
+ }
+}
Propchange: geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/ServerOverride.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/StartServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/StartServerMojo.java?rev=982597&r1=982596&r2=982597&view=diff
==============================================================================
--- geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/StartServerMojo.java (original)
+++ geronimo/server/branches/2.2/framework/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/StartServerMojo.java Thu Aug 5 13:05:23 2010
@@ -20,7 +20,9 @@
package org.apache.geronimo.mavenplugins.geronimo.server;
import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Map;
@@ -31,13 +33,24 @@ import java.util.StringTokenizer;
import java.util.List;
import java.util.ArrayList;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.tools.ant.taskdefs.Java;
import org.codehaus.mojo.pluginsupport.util.ObjectHolder;
+import org.apache.geronimo.kernel.repository.Artifact;
+
import org.apache.geronimo.mavenplugins.geronimo.ServerProxy;
+import org.apache.geronimo.system.configuration.LocalAttributeManager;
+import org.apache.geronimo.system.configuration.PluginAttributeStore;
+import org.apache.geronimo.system.plugin.model.AttributesType;
+import org.apache.geronimo.system.plugin.model.ModuleType;
+
+import org.apache.geronimo.system.plugin.ServerInstanceData;
+import org.apache.geronimo.system.serverinfo.BasicServerInfo;
+import org.apache.geronimo.system.serverinfo.ServerInfo;
import org.codehaus.plexus.util.FileUtils;
@@ -153,6 +166,17 @@ public class StartServerMojo
* @parameter
*/
private String[] startModules = null;
+
+ /**
+ * @parameter expression="${project.build.directory}/classes/var/config/overrides"
+ * @required
+ */
+ private File overridesDir;
+
+ /**
+ * @parameter
+ */
+ private List<ServerOverride> overrides;
private Timer timer = new Timer(true);
@@ -167,6 +191,28 @@ public class StartServerMojo
throw new MojoExecutionException("Missing pre-installed assembly directory: " + geronimoHome);
}
}
+ //Add overrides , so users can customize config.xml before start server.
+ if (overrides != null) {
+ ServerInstanceData serverInstance = new ServerInstanceData();
+ serverInstance.setConfigFile("var/config/config.xml");
+ serverInstance.setName("default");
+ serverInstance.setConfigSubstitutionsFile("var/config/config-substitutions.properties");
+ serverInstance.setConfigSubstitutionsPrefix("org.apache.geronimo.config.substitution.");
+ serverInstance.setArtifactAliasesFile("var/config/artifact_aliases.properties");
+
+ try {
+ if (overrides != null) {
+ for (ServerOverride overrideItem : this.overrides) {
+ AttributesType attributes = overrideItem
+ .getOverrides(overridesDir);
+ mergeOverrides(serverInstance,attributes);
+ }
+ }
+ } catch (Exception e) {
+ throw new MojoExecutionException(
+ "Could not merge overrides", e);
+ }
+ }
log.info("Starting Geronimo server...");
@@ -459,4 +505,25 @@ public class StartServerMojo
protected String getFullClassName() {
return this.getClass().getName();
}
+
+ public void mergeOverrides(ServerInstanceData serverInstance, AttributesType overrides) throws Exception {
+
+ if (serverInstance == null) {
+ throw new NullPointerException("No such server: " + serverInstance.getName());
+ }
+ ServerInfo serverInfo = new BasicServerInfo(geronimoHome.getAbsolutePath(), false);
+
+ PluginAttributeStore attributeStore = new LocalAttributeManager(serverInstance.getConfigFile(), serverInstance.getConfigSubstitutionsFile(),
+ serverInstance.getConfigSubstitutionsPrefix(),
+ false,
+ serverInfo);
+ for (ModuleType module : overrides.getModule()) {
+ Artifact artifact = Artifact.create(module.getName());
+ attributeStore.setModuleGBeans(artifact, module.getGbean(), module.isLoad(), module.getCondition());
+ attributeStore.save();
+ }
+ if (overrides.getConfiguration().size() > 0) {
+ throw new UnsupportedOperationException("Use modules, not configurations");
+ }
+ }
}