You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by db...@apache.org on 2005/11/15 03:05:56 UTC
svn commit: r344290 - in /geronimo/gbuild/trunk/src/main:
java/org/apache/geronimo/gbuild/agent/ resources/META-INF/plexus/
Author: dblevins
Date: Mon Nov 14 18:05:52 2005
New Revision: 344290
URL: http://svn.apache.org/viewcvs?rev=344290&view=rev
Log:
Added the ability to arbitrarily extend the agent to do environment specific processing before and after each build.
Added:
geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentException.java
geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentExtention.java
geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentExtentionManager.java
geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/DefaultBuildAgentExtentionManager.java
geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/FileIncludeExtention.java
geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/NoSuchBuildAgentExtentionException.java
Modified:
geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java
geronimo/gbuild/trunk/src/main/resources/META-INF/plexus/components.xml
Added: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentException.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentException.java?rev=344290&view=auto
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentException.java (added)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentException.java Mon Nov 14 18:05:52 2005
@@ -0,0 +1,28 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.gbuild.agent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BuildAgentException extends Exception {
+
+ public BuildAgentException(String s, Exception e) {
+ super(s, e);
+ }
+
+}
Added: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentExtention.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentExtention.java?rev=344290&view=auto
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentExtention.java (added)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentExtention.java Mon Nov 14 18:05:52 2005
@@ -0,0 +1,32 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.gbuild.agent;
+
+import java.util.Map;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface BuildAgentExtention {
+
+ String ROLE = BuildAgentExtention.class.getName();
+
+ public void preProcess(Map build);
+
+ public void postProcess(Map build, Map results);
+
+}
Added: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentExtentionManager.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentExtentionManager.java?rev=344290&view=auto
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentExtentionManager.java (added)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/BuildAgentExtentionManager.java Mon Nov 14 18:05:52 2005
@@ -0,0 +1,34 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.gbuild.agent;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface BuildAgentExtentionManager {
+
+ String ROLE = BuildAgentExtentionManager.class.getName();
+
+ BuildAgentExtention getBuildAgentExtention(String id) throws NoSuchBuildAgentExtentionException;
+
+ void postProcess(Map build, HashMap results);
+
+ void preProcess(Map build);
+}
Modified: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java?rev=344290&r1=344289&r2=344290&view=diff
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java (original)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java Mon Nov 14 18:05:52 2005
@@ -21,6 +21,7 @@
import org.apache.maven.continuum.store.ContinuumStore;
import org.apache.maven.continuum.configuration.ConfigurationService;
import org.apache.maven.continuum.configuration.ConfigurationLoadingException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
@@ -38,11 +39,12 @@
import java.io.File;
import java.util.Map;
import java.util.HashMap;
+import java.util.Iterator;
/**
* @version $Rev$ $Date$
*/
-public class ContinuumBuildAgent implements BuildAgent, ExceptionListener {
+public class ContinuumBuildAgent extends AbstractLogEnabled implements BuildAgent, ExceptionListener {
// ----------------------------------------------------------------------
// Keys for the values that can be in the context
@@ -67,6 +69,11 @@
/**
* @plexus.requirement
*/
+ private BuildAgentExtentionManager extentionManager;
+
+ /**
+ * @plexus.requirement
+ */
private BuildController controller;
/**
@@ -113,14 +120,22 @@
public void run() {
try {
+ getLogger().info("Continuum Build Agent starting.");
+ getLogger().info("coordinatorUrl "+coordinatorUrl);
+ getLogger().info("buildTaskQueue "+buildTaskQueue);
+ getLogger().info("buildResultsTopic "+buildResultsTopic);
+ getLogger().info("workingDirectory "+workingDirectory);
+ getLogger().info("buildOutputDirectory "+buildOutputDirectory);
+ getLogger().info("adminAddress "+adminAddress);
+ getLogger().info("contributor "+contributor);
+
run = true;
Connection connection = null;
try {
connection = createConnection(coordinatorUrl);
} catch (Throwable e) {
- System.out.println("Could not create connection to: "+coordinatorUrl);
- e.printStackTrace();
+ getLogger().error("Could not create connection to: "+coordinatorUrl, e);
return;
}
@@ -131,6 +146,8 @@
MessageProducer resultsProducer = createTopicProducer(session, buildResultsTopic);
+ getLogger().info("Continuum Build Agent started and waiting for work.");
+
while (run) {
// Wait for a message
Message message = buildConsumer.receive(1000);
@@ -141,54 +158,64 @@
} else if (message instanceof ObjectMessage) {
- ObjectMessage objectMessage = (ObjectMessage) message;
+ try {
+ getLogger().info("Message Received "+ message.getJMSMessageID() +" on "+ connection.getClientID()+":"+buildTaskQueue);
- Map mapMessage = (Map) objectMessage.getObject();
+ ObjectMessage objectMessage = (ObjectMessage) message;
- ContinuumStore store = getContinuumStore(mapMessage);
+ Map buildTask = getMap(objectMessage, message);
- ThreadContextContinuumStore.setStore(store);
+ ContinuumStore store = getContinuumStore(buildTask);
- init();
+ ThreadContextContinuumStore.setStore(store);
- int projectId = getProjectId(mapMessage);
+ init();
- int buildDefinitionId = getBuildDefinitionId(mapMessage);
+ int projectId = getProjectId(buildTask);
- int trigger = getTrigger(mapMessage);
+ int buildDefinitionId = getBuildDefinitionId(buildTask);
- build(projectId, buildDefinitionId, trigger);
+ int trigger = getTrigger(buildTask);
- HashMap results = new HashMap();
+ extentionManager.preProcess(buildTask);
- setStore(results, store);
+ build(projectId, buildDefinitionId, trigger);
- setProjectId(results, projectId);
+ HashMap results = new HashMap();
- setBuildDefinitionId(results, buildDefinitionId);
+ setStore(results, store);
- setTrigger(results, trigger);
+ setProjectId(results, projectId);
- setSystemProperty(results, "os.version");
+ setBuildDefinitionId(results, buildDefinitionId);
- setSystemProperty(results, "os.name");
+ setTrigger(results, trigger);
- setSystemProperty(results, "java.version");
+ setSystemProperty(results, "os.version");
- setSystemProperty(results, "java.vendor");
+ setSystemProperty(results, "os.name");
- setHostInformation(results);
+ setSystemProperty(results, "java.version");
- setContributor(results);
+ setSystemProperty(results, "java.vendor");
- setAdminAddress(results);
+ setHostInformation(results);
- ObjectMessage resultMessage = session.createObjectMessage(results);
+ setContributor(results);
- resultsProducer.send(resultMessage);
+ setAdminAddress(results);
+
+ extentionManager.postProcess(buildTask, results);
+
+ ObjectMessage resultMessage = session.createObjectMessage(results);
+
+ resultsProducer.send(resultMessage);
+ } catch (Exception e) {
+ getLogger().error("Failed Processing message "+message.getJMSMessageID());
+ }
} else {
- System.out.println("Incorect message type: " + message.getClass().getName());
+ getLogger().warn("Agent received incorrect message type: "+message.getClass().getName());
}
}
@@ -196,9 +223,15 @@
session.close();
connection.close();
} catch (Exception e) {
- System.out.println("Caught: " + e);
- e.printStackTrace();
- System.out.println("ContinuumBuildAgent.run");
+ getLogger().error("Agent failed.", e);
+ }
+ }
+
+ private Map getMap(ObjectMessage objectMessage, Message message) throws JMSException, BuildAgentException {
+ try {
+ return (Map) objectMessage.getObject();
+ } catch (Exception e) {
+ throw new BuildAgentException("Message.getObject failed on "+ message.getJMSMessageID(), e);
}
}
Added: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/DefaultBuildAgentExtentionManager.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/DefaultBuildAgentExtentionManager.java?rev=344290&view=auto
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/DefaultBuildAgentExtentionManager.java (added)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/DefaultBuildAgentExtentionManager.java Mon Nov 14 18:05:52 2005
@@ -0,0 +1,93 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.gbuild.agent;
+
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DefaultBuildAgentExtentionManager extends AbstractLogEnabled implements BuildAgentExtentionManager {
+
+ /**
+ * @plexus.requirement
+ */
+ private Map extentions;
+
+ public BuildAgentExtention getBuildAgentExtention(String id) throws NoSuchBuildAgentExtentionException {
+
+ BuildAgentExtention agentExtention = (BuildAgentExtention) extentions.get(id);
+
+ if (agentExtention == null){
+ throw new NoSuchBuildAgentExtentionException(id);
+ }
+ return agentExtention;
+ }
+
+ public void postProcess(Map build, HashMap results) {
+
+ for (Iterator iterator = extentions.entrySet().iterator(); iterator.hasNext();) {
+
+ Map.Entry entry = (Map.Entry) iterator.next();
+
+ String name = (String) entry.getKey();
+
+ BuildAgentExtention extention = (BuildAgentExtention) entry.getValue();
+
+ getLogger().info("Executing extention "+name +" post process");
+
+ try {
+
+ extention.postProcess(build, results);
+
+ } catch (Exception e) {
+
+ getLogger().warn("Extention Failed: "+name, e);
+
+ }
+ }
+ }
+
+ public void preProcess(Map build) {
+
+ for (Iterator iterator = extentions.entrySet().iterator(); iterator.hasNext();) {
+
+ Map.Entry entry = (Map.Entry) iterator.next();
+
+ String name = (String) entry.getKey();
+
+ BuildAgentExtention extention = (BuildAgentExtention) entry.getValue();
+
+ getLogger().info("Executing extention "+name +" pre process");
+
+ try {
+
+ extention.preProcess(build);
+
+ } catch (Exception e) {
+
+ getLogger().warn("Extention Failed: "+name, e);
+
+ }
+ }
+ }
+
+}
Added: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/FileIncludeExtention.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/FileIncludeExtention.java?rev=344290&view=auto
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/FileIncludeExtention.java (added)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/FileIncludeExtention.java Mon Nov 14 18:05:52 2005
@@ -0,0 +1,83 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.gbuild.agent;
+
+import org.apache.maven.continuum.configuration.ConfigurationService;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class FileIncludeExtention extends AbstractLogEnabled implements BuildAgentExtention {
+
+ /**
+ * @plexus.requirement
+ */
+ private ConfigurationService configurationService;
+
+ /**
+ * @plexus.configuration
+ */
+ private String fileNameKey;
+
+
+ public void preProcess(Map build) {
+ }
+
+ // TODO: Maybe allow for the file contents to be compressed
+ public void postProcess(Map build, Map results) {
+
+ getLogger().debug("Looking for " + fileNameKey);
+
+ String fileName = (String) build.get(fileNameKey);
+
+ if (fileName == null) {
+ return;
+ }
+
+ getLogger().info("Found entry " + fileNameKey + " = " + fileName);
+
+ File workingDirectory = configurationService.getWorkingDirectory();
+
+ File file = new File(workingDirectory, fileName);
+
+ if (!file.exists()) {
+
+ getLogger().warn("File to include doesn't exist: " + file.getAbsolutePath());
+
+ return;
+ }
+
+ try {
+
+ String content = FileUtils.fileRead(file.getAbsolutePath());
+
+ results.put(fileNameKey, content);
+
+ }
+ catch (IOException e) {
+ getLogger().warn("Error reading file to include: " + file.getAbsolutePath(), e);
+ }
+ }
+
+
+}
Added: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/NoSuchBuildAgentExtentionException.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/NoSuchBuildAgentExtentionException.java?rev=344290&view=auto
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/NoSuchBuildAgentExtentionException.java (added)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/NoSuchBuildAgentExtentionException.java Mon Nov 14 18:05:52 2005
@@ -0,0 +1,28 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.gbuild.agent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NoSuchBuildAgentExtentionException extends Exception {
+
+ public NoSuchBuildAgentExtentionException(String id) {
+ super(id);
+ }
+
+}
Modified: geronimo/gbuild/trunk/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/resources/META-INF/plexus/components.xml?rev=344290&r1=344289&r2=344290&view=diff
==============================================================================
--- geronimo/gbuild/trunk/src/main/resources/META-INF/plexus/components.xml (original)
+++ geronimo/gbuild/trunk/src/main/resources/META-INF/plexus/components.xml Mon Nov 14 18:05:52 2005
@@ -37,17 +37,6 @@
</component>
<component>
- <role>org.apache.geronimo.gbuild.agent.BuildAgentExtentionManager</role>
- <implementation>org.apache.geronimo.gbuild.agent.DefaultBuildAgentExtentionManager</implementation>
- <requirements>
- <requirement>
- <role>org.apache.geronimo.gbuild.agent.BuildAgentExtention</role>
- <field-name>extentions</field-name>
- </requirement>
- </requirements>
- </component>
-
- <component>
<role>org.codehaus.plexus.action.Action</role>
<role-hint>execute-builder</role-hint>
<implementation>org.apache.geronimo.gbuild.agent.ExecuteDistributedBuilderContinuumAction</implementation>
@@ -79,6 +68,30 @@
<implementation>org.apache.geronimo.gbuild.agent.MockContinuumNotificationDispatcher</implementation>
</component>
+ <component>
+ <role>org.apache.geronimo.gbuild.agent.BuildAgentExtentionManager</role>
+ <implementation>org.apache.geronimo.gbuild.agent.DefaultBuildAgentExtentionManager</implementation>
+ <requirements>
+ <requirement>
+ <role>org.apache.geronimo.gbuild.agent.BuildAgentExtention</role>
+ <field-name>extentions</field-name>
+ </requirement>
+ </requirements>
+ </component>
+
+ <component>
+ <role>org.apache.geronimo.gbuild.agent.BuildAgentExtention</role>
+ <role-hint>work-properties</role-hint>
+ <implementation>org.apache.geronimo.gbuild.agent.FileIncludeExtention</implementation>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.continuum.configuration.ConfigurationService</role>
+ </requirement>
+ </requirements>
+ <configuration>
+ <file-name-key>work-properties</file-name-key>
+ </configuration>
+ </component>
</components>
</component-set>