geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r354993 - in /geronimo/gbuild/trunk: gbuild-agent-application/src/conf/ gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ gbuild-agent/src/main/resources/META-INF/plexus/
Date Thu, 08 Dec 2005 05:22:55 GMT
Author: dblevins
Date: Wed Dec  7 21:21:47 2005
New Revision: 354993

URL: http://svn.apache.org/viewcvs?rev=354993&view=rev
Log:
Wrote an extension to gzip build output and send it with the results
Wrote another extension to log build output if the build was a failure.

Added:
    geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildOutputExtension.java
    geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/LogFailedBuildsExtension.java
Modified:
    geronimo/gbuild/trunk/gbuild-agent-application/src/conf/application.xml
    geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ReportActivityExtension.java
    geronimo/gbuild/trunk/gbuild-agent/src/main/resources/META-INF/plexus/components.xml

Modified: geronimo/gbuild/trunk/gbuild-agent-application/src/conf/application.xml
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent-application/src/conf/application.xml?rev=354993&r1=354992&r2=354993&view=diff
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent-application/src/conf/application.xml (original)
+++ geronimo/gbuild/trunk/gbuild-agent-application/src/conf/application.xml Wed Dec  7 21:21:47
2005
@@ -152,7 +152,7 @@
       <implementation>org.apache.geronimo.gbuild.agent.WriteIncludeFileExtension</implementation>
       <configuration>
         <include-pattern>^include.*</include-pattern>
-        <results-directory>results</results-directory>
+        <results-directory>${plexus.home}/results</results-directory>
         <date-format>yyyy-MM</date-format>
         <file-name-template>{date}/{project.name}/{project.version}/{build.name}-{build.id}.properties</file-name-template>
       </configuration>

Added: geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildOutputExtension.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildOutputExtension.java?rev=354993&view=auto
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildOutputExtension.java
(added)
+++ geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildOutputExtension.java
Wed Dec  7 21:21:47 2005
@@ -0,0 +1,99 @@
+/**
+ *
+ * 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.ConfigurationException;
+import org.apache.maven.continuum.configuration.ConfigurationService;
+import org.apache.maven.continuum.core.action.AbstractContinuumAction;
+import org.apache.maven.continuum.model.project.BuildResult;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.store.ContinuumStore;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BuildOutputExtension extends AbstractLogEnabled implements BuildAgentExtension
{
+
+    /**
+     * @plexus.requirement
+     */
+    private ConfigurationService configurationService;
+
+    /**
+     * @plexus.requirement
+     */
+    private ContinuumStore store;
+
+    public void preProcess(Map build) {
+    }
+
+    public void postProcess(Map build, Map results) {
+        File file = null;
+        try {
+            int projectId = AbstractContinuumAction.getProjectId(build);
+
+            Project project = store.getProject(projectId);
+
+            BuildResult buildResult = store.getBuildResult(project.getLatestBuildId());
+
+            file = configurationService.getBuildOutputFile(buildResult.getId(), projectId);
+
+        } catch (ContinuumStoreException e) {
+
+            getLogger().error("Unable to retrieve info from the ContinuumStore.", e);
+
+            return;
+
+        } catch (ConfigurationException e) {
+
+            getLogger().error("Unable to get the build output file from the configuration
service.", e);
+
+            return;
+        }
+
+        if (!file.exists()) {
+
+            getLogger().warn("File to include doesn't exist: " + file.getAbsolutePath());
+
+            return;
+        }
+
+        try {
+
+            getLogger().debug("Reading " + file.getAbsolutePath());
+
+            byte[] bytes = GZipUtils.fileRead(file);
+
+            getLogger().debug("Including " + bytes.length + " - " + file.getAbsolutePath());
+
+            results.put("build.output-file.gz", bytes);
+
+        }
+        catch (IOException e) {
+            getLogger().warn("Error reading file to include: " + file.getAbsolutePath(),
e);
+        }
+
+
+    }
+
+}

Added: geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/LogFailedBuildsExtension.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/LogFailedBuildsExtension.java?rev=354993&view=auto
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/LogFailedBuildsExtension.java
(added)
+++ geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/LogFailedBuildsExtension.java
Wed Dec  7 21:21:47 2005
@@ -0,0 +1,127 @@
+/**
+ *
+ * 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.core.action.AbstractContinuumAction;
+import org.apache.maven.continuum.model.project.BuildResult;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.store.ContinuumStore;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LogFailedBuildsExtension extends AbstractContinuumAgentAction implements BuildResultsExtension,
Startable {
+
+    /**
+     * @plexus.configuration
+     */
+    private String fileNameTemplate;
+    private StringTemplate template;
+
+    /**
+     * @plexus.configuration
+     */
+    private String resultsDirectory;
+    private File directory;
+
+    /**
+     * @plexus.configuration
+     */
+    private String dateFormat;
+    private SimpleDateFormat dateFormatter;
+
+
+    public void start() throws StartingException {
+        template = new StringTemplate(fileNameTemplate);
+        directory = new File(resultsDirectory);
+        directory.mkdirs();
+
+        if (!directory.exists()) {
+            throw new IllegalStateException("File specified does not exist. " + directory.getAbsolutePath());
+        }
+
+        if (!directory.isDirectory()) {
+            throw new IllegalStateException("File specified is not a directory. " + directory.getAbsolutePath());
+        }
+
+        if (!directory.canWrite()) {
+            throw new IllegalStateException("Directory specified is not writable. " + directory.getAbsolutePath());
+        }
+
+        getLogger().info("Include files will be written to " + directory.getAbsolutePath());
+        dateFormatter = new SimpleDateFormat(dateFormat);
+    }
+
+    public void stop() throws StoppingException {
+    }
+
+    public void execute(Map context) throws Exception {
+        ContinuumStore store = AbstractContinuumAgentAction.getContinuumStore(context);
+
+        int projectId = AbstractContinuumAction.getProjectId(context);
+
+        Project project = store.getProject(projectId);
+
+        BuildResult buildResult = store.getBuildResult(project.getLatestBuildId());
+
+        int exitCode = buildResult.getExitCode();
+
+        if (exitCode == 0) {
+            return;
+        }
+
+        byte[] bytes = (byte[]) context.get("build.output-file.gz");
+
+        if (bytes == null) {
+
+            getLogger().debug("No build output to write.");
+
+            return;
+        }
+
+
+        Map map = new HashMap();
+
+        map.putAll(context);
+
+        map.put("date", dateFormatter.format(new Date()));
+
+        String fileName = template.apply(map);
+
+        File file = new File(directory, fileName);
+
+        File parent = file.getParentFile();
+
+        parent.mkdirs();
+
+        try {
+            GZipUtils.fileWrite(file, bytes);
+        } catch (IOException e) {
+            getLogger().error("Could not write to file " + file.getAbsolutePath(), e);
+        }
+    }
+}

Modified: geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ReportActivityExtension.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ReportActivityExtension.java?rev=354993&r1=354992&r2=354993&view=diff
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ReportActivityExtension.java
(original)
+++ geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ReportActivityExtension.java
Wed Dec  7 21:21:47 2005
@@ -18,7 +18,9 @@
 
 import org.apache.maven.continuum.core.action.AbstractContinuumAction;
 import org.apache.maven.continuum.model.project.BuildResult;
+import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.store.ContinuumStore;
+import org.apache.maven.continuum.store.ContinuumStoreException;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
 import java.util.Map;
@@ -47,7 +49,14 @@
 
         int projectId = AbstractContinuumAction.getProjectId(build);
 
-        BuildResult buildResult = store.getLatestBuildResultForProject(projectId);
+        BuildResult buildResult = null;
+        try {
+            Project project = store.getProject(projectId);
+
+            buildResult = store.getBuildResult(project.getLatestBuildId());
+        } catch (ContinuumStoreException e) {
+            getLogger().error("Unable to read data from ContinuumStore.", e);
+        }
 
         long minutes = (buildResult.getEndTime() - buildResult.getStartTime()) / 60000;
 

Modified: geronimo/gbuild/trunk/gbuild-agent/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent/src/main/resources/META-INF/plexus/components.xml?rev=354993&r1=354992&r2=354993&view=diff
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent/src/main/resources/META-INF/plexus/components.xml (original)
+++ geronimo/gbuild/trunk/gbuild-agent/src/main/resources/META-INF/plexus/components.xml Wed
Dec  7 21:21:47 2005
@@ -221,6 +221,9 @@
       <implementation>org.apache.geronimo.gbuild.agent.ReportActivityExtension</implementation>
       <requirements>
         <requirement>
+          <role>org.apache.maven.continuum.store.ContinuumStore</role>
+        </requirement>
+        <requirement>
           <role>org.apache.geronimo.gbuild.agent.BuildActivityNotifier</role>
         </requirement>
       </requirements>
@@ -237,6 +240,33 @@
       </requirements>
       <configuration>
         <regex>.*geronimo-tck.*</regex>
+      </configuration>
+    </component>
+
+    <component>
+      <role>org.apache.geronimo.gbuild.agent.BuildAgentExtension</role>
+      <role-hint>build-output</role-hint>
+      <implementation>org.apache.geronimo.gbuild.agent.BuildOutputExtension</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.continuum.configuration.ConfigurationService</role>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.continuum.store.ContinuumStore</role>
+        </requirement>
+      </requirements>
+      <configuration>
+      </configuration>
+    </component>
+
+    <component>
+      <role>org.apache.geronimo.gbuild.agent.BuildResultsExtension</role>
+      <role-hint>log-failed-build-file</role-hint>
+      <implementation>org.apache.geronimo.gbuild.agent.LogFailedBuildsExtension</implementation>
+      <configuration>
+        <results-directory>${plexus.home}/failed</results-directory>
+        <date-format>yyyy-MM-dd-HHmm</date-format>
+        <file-name-template>{project.name}-{project.version}/{date}-{build.name}-{build.id}.txt</file-name-template>
       </configuration>
     </component>
 



Mime
View raw message