You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by ws...@apache.org on 2009/07/02 21:21:44 UTC

svn commit: r790715 - /continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-client/src/main/java/org/apache/maven/continuum/xmlrpc/client/BuildResultsPurge.java

Author: wsmoak
Date: Thu Jul  2 19:21:44 2009
New Revision: 790715

URL: http://svn.apache.org/viewvc?rev=790715&view=rev
Log:
[CONTINUUM-1696] Add a utility class as a workaround to purge old build results from the database until it is possible through the scheduled purge.

Added:
    continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-client/src/main/java/org/apache/maven/continuum/xmlrpc/client/BuildResultsPurge.java

Added: continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-client/src/main/java/org/apache/maven/continuum/xmlrpc/client/BuildResultsPurge.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-client/src/main/java/org/apache/maven/continuum/xmlrpc/client/BuildResultsPurge.java?rev=790715&view=auto
==============================================================================
--- continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-client/src/main/java/org/apache/maven/continuum/xmlrpc/client/BuildResultsPurge.java (added)
+++ continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-client/src/main/java/org/apache/maven/continuum/xmlrpc/client/BuildResultsPurge.java Thu Jul  2 19:21:44 2009
@@ -0,0 +1,89 @@
+package org.apache.maven.continuum.xmlrpc.client;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import java.net.URL;
+import java.util.List;
+import java.util.Date;
+
+import org.apache.maven.continuum.xmlrpc.project.*;
+
+/**
+ * Utility class to purge old build results.
+ * <p/>
+ * The easiest way to use it is to change the exec plugin config in the pom to execute this class instead of
+ * SampleClient, change RETENTION_DAYS if desired, and type 'mvn clean install exec:exec'
+ */
+public class BuildResultsPurge {
+
+    private static ContinuumXmlRpcClient client;
+
+    private static long RETENTION_DAYS = 60;
+
+    private static long DAY_IN_MILLISECONDS = 24 * 60 * 60 * 1000;
+
+    public static void main(String[] args)
+            throws Exception {
+
+        client = new ContinuumXmlRpcClient(new URL(args[0]), args[1], args[2]);
+
+        long today = new Date().getTime();
+
+        System.out.println("Today is " + new Date(today));
+
+        long purgeDate = today - (RETENTION_DAYS * DAY_IN_MILLISECONDS);
+        //long purgeDate = today - 1000;  // 1 second ago (for testing)
+
+        System.out.println("Purging build results older than " + new Date(purgeDate));
+
+        List<ProjectGroupSummary> groups = client.getAllProjectGroups();
+
+        for (ProjectGroupSummary group : groups) {
+
+            System.out.println("Project Group [" + group.getId() + "] " + group.getName());
+
+            List<ProjectSummary> projects = client.getProjects(group.getId());
+
+            for (ProjectSummary project : projects) {
+
+
+                System.out.println(" Project [" + project.getId() + "] " + project.getName());
+
+                List<BuildResultSummary> results = client.getBuildResultsForProject(project.getId());
+
+                for (BuildResultSummary brs : results) {
+
+                    BuildResult br = client.getBuildResult(project.getId(), brs.getId());
+
+                    System.out.print("  Build Result [" + br.getId() + "] ended " + new Date(br.getEndTime()));
+
+                    if (br.getEndTime() > 0 && br.getEndTime() < purgeDate) {
+
+                        client.removeBuildResult(br);
+                        System.out.println(" ...removed.");
+                    } else {
+                        System.out.println(" ...retained.");
+                    }
+                }
+            }
+
+        }
+    }
+}