Author: jmcconnell
Date: Wed Oct 18 19:34:07 2006
New Revision: 465451
URL: http://svn.apache.org/viewvc?view=rev&rev=465451
Log:
added some project group notifier methods and a test case
Modified:
maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java
maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java
Modified: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java?view=diff&rev=465451&r1=465450&r2=465451
==============================================================================
--- maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java (original)
+++ maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java Wed Oct 18 19:34:07 2006
@@ -16,11 +16,6 @@
* limitations under the License.
*/
-import java.io.File;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
import org.apache.maven.continuum.configuration.ConfigurationService;
import org.apache.maven.continuum.execution.ContinuumBuildExecutor;
import org.apache.maven.continuum.model.project.BuildDefinition;
@@ -32,10 +27,15 @@
import org.apache.maven.continuum.model.system.ContinuumUser;
import org.apache.maven.continuum.model.system.UserGroup;
import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
-import org.apache.maven.continuum.security.ContinuumSecurity;
import org.apache.maven.continuum.release.ContinuumReleaseManager;
+import org.apache.maven.continuum.security.ContinuumSecurity;
import org.codehaus.plexus.util.dag.CycleDetectedException;
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
/**
* @author Jason van Zyl
* @author Trygve Laugstøl
@@ -197,6 +197,15 @@
void updateProject( Project project )
throws ContinuumException;
+ Project getProjectWithCheckoutResult( int projectId )
+ throws ContinuumException;
+
+ Project getProjectWithAllDetails( int projectId )
+ throws ContinuumException;
+
+ Project getProjectWithBuilds( int projectId )
+ throws ContinuumException;
+
// ----------------------------------------------------------------------
// Notification
// ----------------------------------------------------------------------
@@ -204,28 +213,25 @@
ProjectNotifier getNotifier( int projectId, int notifierId )
throws ContinuumException;
- ProjectNotifier updateNotifier( int projectId, int notifierId, Map configuration )
+ ProjectNotifier getGroupNotifier( int projectGroupId, int notifierId )
throws ContinuumException;
ProjectNotifier updateNotifier( int projectId, ProjectNotifier notifier )
throws ContinuumException;
- ProjectNotifier addNotifier( int projectId, ProjectNotifier notifier )
+ ProjectNotifier updateGroupNotifier( int projectGroupId, ProjectNotifier notifier )
throws ContinuumException;
- ProjectNotifier addNotifier( int projectId, String notifierType, Map configuration )
- throws ContinuumException;
-
- void removeNotifier( int projectId, int notifierId )
+ ProjectNotifier addNotifier( int projectId, ProjectNotifier notifier )
throws ContinuumException;
- Project getProjectWithCheckoutResult( int projectId )
+ ProjectNotifier addGroupNotifier( int projectGroupId, ProjectNotifier notifier )
throws ContinuumException;
- Project getProjectWithAllDetails( int projectId )
+ void removeNotifier( int projectId, int notifierId )
throws ContinuumException;
- Project getProjectWithBuilds( int projectId )
+ void removeGroupNotifier( int projectGroupId, int notifierId )
throws ContinuumException;
// ----------------------------------------------------------------------
Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?view=diff&rev=465451&r1=465450&r2=465451
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java Wed Oct 18 19:34:07 2006
@@ -1099,7 +1099,6 @@
// This whole section needs a scrub but will need to be dealt with generally
// when we add schedules and profiles to the mix.
-
public ProjectNotifier getNotifier( int projectId, int notifierId )
throws ContinuumException
{
@@ -1122,6 +1121,28 @@
return notifier;
}
+ public ProjectNotifier getGroupNotifier( int projectGroupId, int notifierId )
+ throws ContinuumException
+ {
+ ProjectGroup projectGroup = getProjectGroup( projectGroupId );
+
+ List notifiers = projectGroup.getNotifiers();
+
+ ProjectNotifier notifier = null;
+
+ for ( Iterator i = notifiers.iterator(); i.hasNext(); )
+ {
+ notifier = (ProjectNotifier) i.next();
+
+ if ( notifier.getId() == notifierId )
+ {
+ break;
+ }
+ }
+
+ return notifier;
+ }
+
public ProjectNotifier updateNotifier( int projectId, ProjectNotifier notifier )
throws ContinuumException
{
@@ -1137,6 +1158,29 @@
return addNotifier( projectId, notifier );
}
+ public ProjectNotifier updateGroupNotifier( int projectGroupId, ProjectNotifier notifier )
+ throws ContinuumException
+ {
+ ProjectGroup projectGroup = getProjectGroup( projectGroupId );
+
+ ProjectNotifier notif = getGroupNotifier( projectGroupId, notifier.getId() );
+
+ // I remove notifier then add it instead of update it due to a ClassCastException in jpox
+ projectGroup.removeNotifier( notif );
+
+ try
+ {
+ store.updateProjectGroup( projectGroup );
+ }
+ catch ( ContinuumStoreException cse )
+ {
+ throw new ContinuumException( "Unable to update project group.", cse );
+ }
+
+ return addGroupNotifier( projectGroupId, notifier );
+ }
+
+ /*
public ProjectNotifier updateNotifier( int projectId, int notifierId, Map configuration )
throws ContinuumException
{
@@ -1180,7 +1224,7 @@
return notifierProperties;
}
-
+ */
public ProjectNotifier addNotifier( int projectId, ProjectNotifier notifier )
throws ContinuumException
{
@@ -1209,6 +1253,41 @@
return notif;
}
+ public ProjectNotifier addGroupNotifier( int projectGroupId, ProjectNotifier notifier )
+ throws ContinuumException
+ {
+ ProjectNotifier notif = new ProjectNotifier();
+
+ notif.setSendOnSuccess( notifier.isSendOnSuccess() );
+
+ notif.setSendOnFailure( notifier.isSendOnFailure() );
+
+ notif.setSendOnError( notifier.isSendOnError() );
+
+ notif.setSendOnWarning( notifier.isSendOnWarning() );
+
+ notif.setConfiguration( notifier.getConfiguration() );
+
+ notif.setType( notifier.getType() );
+
+ notif.setFrom( ProjectNotifier.FROM_USER );
+
+ ProjectGroup projectGroup = getProjectGroup( projectGroupId );
+
+ projectGroup.addNotifier( notif );
+ try
+ {
+ store.updateProjectGroup( projectGroup );
+ }
+ catch ( ContinuumStoreException cse )
+ {
+ throw new ContinuumException( "unable to add notifier to project group", cse );
+ }
+
+ return notif;
+ }
+
+ /*
public ProjectNotifier addNotifier( int projectId, String notifierType, Map configuration )
throws ContinuumException
{
@@ -1242,7 +1321,7 @@
return addNotifier( projectId, notifier );
}
-
+ */
public void removeNotifier( int projectId, int notifierId )
throws ContinuumException
{
@@ -1263,6 +1342,37 @@
project.removeNotifier( n );
updateProject( project );
+ }
+ }
+ }
+
+ public void removeGroupNotifier( int projectGroupId, int notifierId )
+ throws ContinuumException
+ {
+ ProjectGroup projectGroup = getProjectGroup( projectGroupId );
+
+ ProjectNotifier n = getGroupNotifier( projectGroupId, notifierId );
+
+ if ( n != null )
+ {
+ if ( n.isFromProject() )
+ {
+ n.setEnabled( false );
+
+ storeNotifier( n );
+ }
+ else
+ {
+ projectGroup.removeNotifier( n );
+
+ try
+ {
+ store.updateProjectGroup( projectGroup );
+ }
+ catch ( ContinuumStoreException cse )
+ {
+ throw new ContinuumException( "Unable to remove notifer from project group.", cse );
+ }
}
}
}
Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java?view=diff&rev=465451&r1=465450&r2=465451
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java Wed Oct 18 19:34:07 2006
@@ -79,7 +79,7 @@
* 1) project groups have default build definitions
* 2) if project has default build definition, that overrides project group definition
* 3) changing parent default build definition does not effect project if it has a default declared
- * 4) project groups much have a default build definition
+ * 4) project groups must have a default build definition
*
* @param buildDefinition
* @param projectGroup
Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java?view=diff&rev=465451&r1=465450&r2=465451
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java (original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java Wed Oct 18 19:34:07 2006
@@ -16,20 +16,21 @@
* limitations under the License.
*/
+import org.apache.maven.continuum.initialization.DefaultContinuumInitializer;
+import org.apache.maven.continuum.model.project.BuildDefinition;
import org.apache.maven.continuum.model.project.Project;
import org.apache.maven.continuum.model.project.ProjectGroup;
-import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.ProjectNotifier;
import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
-import org.apache.maven.continuum.initialization.DefaultContinuumInitializer;
import org.codehaus.plexus.taskqueue.TaskQueue;
import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor;
import java.io.File;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Collection;
/**
* @author Trygve Laugstøl
@@ -251,6 +252,57 @@
projectGroupList = continuum.getAllProjectGroupsWithProjects();
assertEquals( "Remove project group failed", projectGroupsBefore, projectGroupList.size() );
+ }
+
+
+ /**
+ * test the logic for notifiers
+ *
+ * @throws Exception
+ */
+ public void testProjectAndGroupNotifiers()
+ throws Exception
+ {
+ Continuum continuum = (Continuum) lookup( Continuum.ROLE );
+
+ Collection projectGroupList = continuum.getAllProjectGroupsWithProjects();
+
+ int projectGroupsBefore = projectGroupList.size();
+
+ assertEquals( 1, projectGroupsBefore );
+
+ String url = getTestFile( "src/test-projects/project1/pom.xml" ).toURL().toExternalForm();
+
+ ContinuumProjectBuildingResult result = continuum.addMavenTwoProject( url );
+
+ assertNotNull( result );
+
+ assertEquals( 1, result.getProjectGroups().size() );
+
+ ProjectGroup projectGroup = (ProjectGroup) result.getProjectGroups().get( 0 );
+
+ continuum.addGroupNotifier( projectGroup.getId(), new ProjectNotifier() );
+ continuum.addGroupNotifier( projectGroup.getId(), new ProjectNotifier() );
+
+ for ( Iterator i = projectGroup.getProjects().iterator(); i.hasNext(); )
+ {
+ Project p = (Project)i.next();
+ continuum.addNotifier( p.getId(), new ProjectNotifier() );
+ }
+
+ projectGroup = continuum.getProjectGroup( projectGroup.getId() );
+
+
+ assertEquals( 2, projectGroup.getNotifiers().size() );
+
+
+ for ( Iterator i = projectGroup.getProjects().iterator(); i.hasNext(); )
+ {
+ Project p = (Project)i.next();
+ // this is 2 right now, the notifier in the pom is placed in each notifier right now
+ assertEquals( 2, p.getNotifiers().size() );
+
+ }
}
public void testExecuteAction()