continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r584870 - in /maven/continuum/trunk: continuum-api/src/main/java/org/apache/maven/continuum/store/ continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/ continuum-store/src/main/java/org/apache/ma...
Date Mon, 15 Oct 2007 19:39:57 GMT
Author: evenisse
Date: Mon Oct 15 12:39:56 2007
New Revision: 584870

URL: http://svn.apache.org/viewvc?rev=584870&view=rev
Log:
[CONTINUUM-1516] Fix getPreviousBuild method when the project use more than one build definition.
Now getPreviousBuild look only at build results based on the same build definition

Modified:
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
    maven/continuum/trunk/continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/AbstractContinuumNotifier.java
    maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java

Modified: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java?rev=584870&r1=584869&r2=584870&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
(original)
+++ maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
Mon Oct 15 12:39:56 2007
@@ -311,6 +311,8 @@
 
     List<BuildResult> getBuildResultByBuildNumber( int projectId, int buildNumber );
 
+    List<BuildResult> getBuildResultsByBuildDefinition( int projectId, int buildDefinitionId
);
+
     Map getBuildResultsInSuccess();
 
     Map getBuildResultsInSuccessByProjectGroupId( int projectGroupId );

Modified: maven/continuum/trunk/continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/AbstractContinuumNotifier.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/AbstractContinuumNotifier.java?rev=584870&r1=584869&r2=584870&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/AbstractContinuumNotifier.java
(original)
+++ maven/continuum/trunk/continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/AbstractContinuumNotifier.java
Mon Oct 15 12:39:56 2007
@@ -185,34 +185,60 @@
     protected BuildResult getPreviousBuild( Project project, BuildDefinition buildDef, BuildResult
currentBuild )
         throws NotificationException
     {
+        List<BuildResult> builds;
         try
         {
-            // TODO: prefer to remove this and get them up front
-            if ( project.getId() > 0 )
+            if ( buildDef != null )
             {
-                project = store.getProjectWithBuilds( project.getId() );
+                builds = store.getBuildResultsByBuildDefinition( project.getId(), buildDef.getId()
);
+
+                if ( builds.size() < 2 )
+                {
+                    return null;
+                }
+                //builds are sorted in descending way
+                BuildResult build = builds.get( 0 );
+                if ( currentBuild != null && build.getId() != currentBuild.getId()
)
+                {
+                    throw new NotificationException(
+                        "INTERNAL ERROR: The current build wasn't the first in the build
list. " + "Current build: '" +
+                            currentBuild.getId() + "', " + "first build: '" + build.getId()
+ "'." );
+                }
+                else
+                {
+                    return builds.get( 1 );
+                }
             }
-        }
-        catch ( ContinuumStoreException e )
-        {
-            throw new NotificationException( "Unable to obtain project builds", e );
-        }
-        List builds = project.getBuildResults();
+            else
+            {
+                //Normally, it isn't possible, buildDef should be != null
+                if ( project.getId() > 0 )
+                {
+                    project = store.getProjectWithBuilds( project.getId() );
+                }
+                builds = project.getBuildResults();
 
-        if ( builds.size() < 2 )
-        {
-            return null;
-        }
+                if ( builds.size() < 2 )
+                {
+                    return null;
+                }
+
+                BuildResult build = builds.get( builds.size() - 1 );
 
-        BuildResult build = (BuildResult) builds.get( builds.size() - 1 );
+                if ( currentBuild != null && build.getId() != currentBuild.getId()
)
+                {
+                    throw new NotificationException(
+                        "INTERNAL ERROR: The current build wasn't the first in the build
list. " + "Current build: '" +
+                            currentBuild.getId() + "', " + "first build: '" + build.getId()
+ "'." );
+                }
 
-        if ( currentBuild != null && build.getId() != currentBuild.getId() )
+                return builds.get( builds.size() - 2 );
+            }
+        }
+        catch ( ContinuumStoreException e )
         {
-            throw new NotificationException( "INTERNAL ERROR: The current build wasn't the
first in the build list. " +
-                "Current build: '" + currentBuild.getId() + "', " + "first build: '" + build.getId()
+ "'." );
+            throw new NotificationException( "Unable to obtain project builds", e );
         }
-
-        return (BuildResult) builds.get( builds.size() - 2 );
     }
 
 }

Modified: maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java?rev=584870&r1=584869&r2=584870&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
(original)
+++ maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
Mon Oct 15 12:39:56 2007
@@ -103,7 +103,7 @@
     private static final String PROJECT_DEPENDENCIES_FETCH_GROUP = "project-dependencies";
 
     private static final String PROJECTGROUP_PROJECTS_FETCH_GROUP = "projectgroup-projects";
-    
+
     private static final String BUILD_TEMPLATE_BUILD_DEFINITIONS = "build-template-build-definitions";
 
     // ----------------------------------------------------------------------
@@ -620,7 +620,7 @@
     // ------------------------------------------------------
     //  BuildDefinition
     // ------------------------------------------------------    
-    
+
     public BuildDefinition getDefaultBuildDefinition( int projectId )
         throws ContinuumStoreException, ContinuumObjectNotFoundException
     {
@@ -760,7 +760,7 @@
         return null;
     }
 
-    
+
     public List<BuildDefinitionTemplate> getContinuumBuildDefinitionTemplates()
         throws ContinuumStoreException
     {
@@ -786,9 +786,9 @@
 
             rollback( tx );
         }
-    }    
-    
-    
+    }
+
+
     public BuildDefinitionTemplate getContinuumBuildDefinitionTemplateWithType( String type
)
         throws ContinuumStoreException
     {
@@ -894,8 +894,7 @@
 
         return buildDefinition;
     }
-    
-    
+
 
     public BuildDefinition addBuildDefinition( BuildDefinition buildDefinition )
         throws ContinuumStoreException
@@ -903,12 +902,11 @@
         return (BuildDefinition) addObject( buildDefinition );
     }
 
-    
     // ------------------------------------------------------
     //  BuildDefinitionTemplate
     // ------------------------------------------------------      
-    
-    
+
+
     public BuildDefinitionTemplate addBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate
)
         throws ContinuumStoreException
     {
@@ -924,7 +922,8 @@
     public BuildDefinitionTemplate getBuildDefinitionTemplate( int id )
         throws ContinuumStoreException, ContinuumObjectNotFoundException
     {
-        return (BuildDefinitionTemplate) getObjectById( BuildDefinitionTemplate.class, id,
BUILD_TEMPLATE_BUILD_DEFINITIONS );
+        return (BuildDefinitionTemplate) getObjectById( BuildDefinitionTemplate.class, id,
+                                                        BUILD_TEMPLATE_BUILD_DEFINITIONS
);
     }
 
     public void removeBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate
)
@@ -968,7 +967,7 @@
             rollback( tx );
         }
     }
-    
+
     public List<BuildDefinitionTemplate> getBuildDefinitionTemplatesWithType( String
type )
         throws ContinuumStoreException
     {
@@ -997,8 +996,8 @@
             rollback( tx );
         }
     }
-    
-    
+
+
     private Object makePersistent( PersistenceManager pm, Object object, boolean detach )
     {
         return PlexusJdoUtils.makePersistent( pm, object, detach );
@@ -1107,11 +1106,12 @@
     // todo get this natively supported in the store
     public List<Project> getProjectsWithDependenciesByGroupId( int projectGroupId )
     {
-        List<Project> allProjects = getAllObjectsDetached( Project.class, "name ascending",
PROJECT_DEPENDENCIES_FETCH_GROUP );
+        List<Project> allProjects =
+            getAllObjectsDetached( Project.class, "name ascending", PROJECT_DEPENDENCIES_FETCH_GROUP
);
 
         List<Project> groupProjects = new ArrayList<Project>();
 
-        for ( Project project:allProjects )
+        for ( Project project : allProjects )
         {
             if ( project.getProjectGroup().getId() == projectGroupId )
             {
@@ -1520,6 +1520,41 @@
             List result = (List) query.execute( new Integer( projectId ), new Integer( buildNumber
) );
 
             result = (List) pm.detachCopyAll( result );
+
+            tx.commit();
+
+            return result;
+        }
+        finally
+        {
+            rollback( tx );
+        }
+    }
+
+    public List<BuildResult> getBuildResultsByBuildDefinition( int projectId, int buildDefinitionId
)
+    {
+        PersistenceManager pm = getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( BuildResult.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.declareParameters( "int projectId, int buildDefinitionId" );
+
+            query.setFilter( "this.project.id == projectId && this.buildDefinition.id
== buildDefinitionId" );
+
+            query.setOrdering( "this.id descending" );
+
+            List<BuildResult> result =
+                (List<BuildResult>) query.execute( new Integer( projectId ), new Integer(
buildDefinitionId ) );
+
+            result = (List<BuildResult>) pm.detachCopyAll( result );
 
             tx.commit();
 



Mime
View raw message