Coverage Report - fr.paris.lutece.plugins.releaser.service.WorkflowReleaseContextService
 
Classes in this File Line Coverage Branch Coverage Complexity
WorkflowReleaseContextService
12 %
32/253
3 %
2/64
2,905
 
 1  
 package fr.paris.lutece.plugins.releaser.service;
 2  
 
 3  
 import java.io.File;
 4  
 import java.io.IOException;
 5  
 import java.util.ArrayList;
 6  
 import java.util.HashMap;
 7  
 import java.util.Iterator;
 8  
 import java.util.List;
 9  
 import java.util.Locale;
 10  
 import java.util.concurrent.ExecutorService;
 11  
 import java.util.concurrent.Executors;
 12  
 
 13  
 import javax.servlet.http.HttpServletRequest;
 14  
 
 15  
 import org.apache.commons.collections.CollectionUtils;
 16  
 import org.apache.commons.lang.StringUtils;
 17  
 import org.eclipse.jgit.api.Git;
 18  
 import org.eclipse.jgit.api.MergeResult;
 19  
 import org.eclipse.jgit.api.ResetCommand.ResetType;
 20  
 import org.eclipse.jgit.api.errors.GitAPIException;
 21  
 import org.eclipse.jgit.api.errors.InvalidRemoteException;
 22  
 import org.eclipse.jgit.api.errors.TransportException;
 23  
 import org.eclipse.jgit.internal.storage.file.FileRepository;
 24  
 import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
 25  
 
 26  
 import fr.paris.lutece.plugins.releaser.business.Component;
 27  
 import fr.paris.lutece.plugins.releaser.business.WorkflowReleaseContext;
 28  
 import fr.paris.lutece.plugins.releaser.util.CommandResult;
 29  
 import fr.paris.lutece.plugins.releaser.util.ConstanteUtils;
 30  
 import fr.paris.lutece.plugins.releaser.util.MapperJsonUtil;
 31  
 import fr.paris.lutece.plugins.releaser.util.PluginUtils;
 32  
 import fr.paris.lutece.plugins.releaser.util.ReleaserUtils;
 33  
 import fr.paris.lutece.plugins.releaser.util.file.FileUtils;
 34  
 import fr.paris.lutece.plugins.releaser.util.github.GitUtils;
 35  
 import fr.paris.lutece.portal.business.user.AdminUser;
 36  
 import fr.paris.lutece.portal.service.datastore.DatastoreService;
 37  
 import fr.paris.lutece.portal.service.i18n.I18nService;
 38  
 import fr.paris.lutece.portal.service.spring.SpringContextService;
 39  
 import fr.paris.lutece.portal.service.util.AppException;
 40  
 import fr.paris.lutece.portal.service.util.AppLogService;
 41  
 import fr.paris.lutece.portal.service.util.AppPropertiesService;
 42  
 import fr.paris.lutece.util.ReferenceItem;
 43  
 import fr.paris.lutece.util.ReferenceList;
 44  
 
 45  1
 public class WorkflowReleaseContextService implements IWorkflowReleaseContextService
 46  
 {
 47  
 
 48  
     private static IWorkflowReleaseContextService _singleton;
 49  1
     private HashMap<Integer, WorkflowReleaseContext> _mapWorkflowReleaseContext = new HashMap<Integer, WorkflowReleaseContext>( );
 50  
     private ExecutorService _executor;
 51  
     private  IMavenPrepareUpdateRemoteRepository  _svnMavenPrepareUpadteRepo ;
 52  
     private  IMavenPrepareUpdateRemoteRepository  _gitMavenPrepareUpadteRepo;
 53  
     
 54  
 
 55  
     /*
 56  
      * (non-Javadoc)
 57  
      * 
 58  
      * @see fr.paris.lutece.plugins.releaser.service.IWorkflowReleaseContextService#addWorkflowDeploySiteContext(fr.paris.lutece.plugins.releaser.business.
 59  
      * WorkflowReleaseContext)
 60  
      */
 61  
     @Override
 62  
     public synchronized int addWorkflowReleaseContext( WorkflowReleaseContext context )
 63  
     {
 64  0
         int nIdKey = Integer.parseInt( DatastoreService.getDataValue( ConstanteUtils.CONSTANTE_MAX_RELEASE_CONTEXT_KEY, "0" ) ) + 1;
 65  
         // stored key in database
 66  0
         DatastoreService.setDataValue( ConstanteUtils.CONSTANTE_MAX_RELEASE_CONTEXT_KEY, Integer.toString( nIdKey ) );
 67  0
         context.setId( nIdKey );
 68  0
         _mapWorkflowReleaseContext.put( nIdKey, context );
 69  
 
 70  0
         return nIdKey;
 71  
     }
 72  
 
 73  
     /*
 74  
      * (non-Javadoc)
 75  
      * 
 76  
      * @see fr.paris.lutece.plugins.releaser.service.IWorkflowReleaseContextService#getWorkflowDeploySiteContext(int)
 77  
      */
 78  
     @Override
 79  
     public WorkflowReleaseContext getWorkflowReleaseContext( int nIdContext )
 80  
     {
 81  0
         return _mapWorkflowReleaseContext.get( nIdContext );
 82  
     }
 83  
 
 84  
     public synchronized void saveWorkflowReleaseContext( WorkflowReleaseContext context )
 85  
     {
 86  
         try
 87  
         {
 88  0
             String strJsonContext = MapperJsonUtil.getJson( context );
 89  0
             DatastoreService.setDataValue( ReleaserUtils.getWorklowContextDataKey( context.getComponent( ) != null ? context.getComponent( ).getArtifactId( )
 90  0
                     : context.getSite( ).getArtifactId( ), context.getId( ) ), strJsonContext );
 91  
 
 92  
         }
 93  0
         catch( IOException e )
 94  
         {
 95  0
             AppLogService.error( "error during save context json", e );
 96  0
         }
 97  0
     }
 98  
 
 99  
     public WorkflowReleaseContext getWorkflowReleaseContextHistory( int nIdContext, String strArtifactId )
 100  
     {
 101  0
         WorkflowReleaseContext context = null;
 102  
         try
 103  
         {
 104  
 
 105  0
             String strJsonContext = DatastoreService.getDataValue( ReleaserUtils.getWorklowContextDataKey( strArtifactId, nIdContext ), null );
 106  0
             context = MapperJsonUtil.parse( strJsonContext, WorkflowReleaseContext.class );
 107  
 
 108  
         }
 109  0
         catch( IOException e )
 110  
         {
 111  0
             AppLogService.error( "error during get context in the datastore", e );
 112  0
         }
 113  0
         return context;
 114  
 
 115  
     }
 116  
 
 117  
     public List<WorkflowReleaseContext> getListWorkflowReleaseContextHistory( String strArtifactId )
 118  
     {
 119  0
         WorkflowReleaseContext context = null;
 120  0
         List<WorkflowReleaseContext> listContext = new ArrayList<WorkflowReleaseContext>( );
 121  
 
 122  
         try
 123  
         {
 124  
 
 125  0
             ReferenceList refListContextHistory = DatastoreService.getDataByPrefix( ConstanteUtils.CONSTANTE_RELEASE_CONTEXT_PREFIX + strArtifactId );
 126  0
             if ( !CollectionUtils.isEmpty( refListContextHistory ) )
 127  
             {
 128  0
                 for ( Iterator iterator = refListContextHistory.iterator( ); iterator.hasNext( ); )
 129  
                 {
 130  
                     
 131  
                     
 132  0
                     ReferenceItem referenceItem = (ReferenceItem) iterator.next( );
 133  
                     
 134  
                     //return only the reference item associated to the artifact id
 135  0
                     if(referenceItem.getCode( ).startsWith( ConstanteUtils.CONSTANTE_RELEASE_CONTEXT_PREFIX + strArtifactId+"_"  ))
 136  
                     {
 137  0
                         context = MapperJsonUtil.parse( referenceItem.getName( ), WorkflowReleaseContext.class );
 138  0
                         if ( context != null )
 139  
                         {
 140  0
                             listContext.add( context );
 141  
                         }
 142  
                     }
 143  0
                 }
 144  
             }
 145  
         }
 146  0
         catch( IOException e )
 147  
         {
 148  0
             AppLogService.error( "error during get context in the datastore", e );
 149  0
         }
 150  0
         return listContext;
 151  
 
 152  
     }
 153  
 
 154  
     public int getIdWorkflow( WorkflowReleaseContext context )
 155  
     {
 156  0
         int nIdWorkflow = ConstanteUtils.CONSTANTE_ID_NULL;
 157  
 
 158  0
         if ( context.isLuteceSite( ) )
 159  
         {
 160  0
             nIdWorkflow = AppPropertiesService.getPropertyInt( ConstanteUtils.PROPERTY_ID_WORKFLOW_LUTECE_SITE, ConstanteUtils.CONSTANTE_ID_NULL );
 161  
 
 162  
         }
 163  
         else
 164  
         {
 165  
 
 166  0
             if ( ComponentService.getService( ).isGitComponent( context.getComponent( ) ) )
 167  
             {
 168  0
                 nIdWorkflow = AppPropertiesService.getPropertyInt( ConstanteUtils.PROPERTY_ID_WORKFLOW_GIT_COMPONENT, ConstanteUtils.CONSTANTE_ID_NULL );
 169  
             }
 170  
             else
 171  
             {
 172  0
                 nIdWorkflow = AppPropertiesService.getPropertyInt( ConstanteUtils.PROPERTY_ID_WORKFLOW_SVN_COMPONENT, ConstanteUtils.CONSTANTE_ID_NULL );
 173  
             }
 174  
         }
 175  
 
 176  0
         return nIdWorkflow;
 177  
     }
 178  
 
 179  
     public static IWorkflowReleaseContextService getService( )
 180  
     {
 181  1
         if ( _singleton == null )
 182  
         {
 183  
 
 184  1
             _singleton = SpringContextService.getBean( ConstanteUtils.BEAN_WORKFLOW_RELEASE_CONTEXT_SERVICE );
 185  1
             _singleton.init( );
 186  
         }
 187  
 
 188  1
         return _singleton;
 189  
     }
 190  
 
 191  
     public void gitCloneRepository( WorkflowReleaseContext context, Locale locale )
 192  
     {
 193  1
         Git git = null;
 194  
         // FileRepository fLocalRepo = null;
 195  1
         CommandResult commandResult = context.getCommandResult( );
 196  1
         ReleaserUtils.logStartAction( context, " Clone Repository" );
 197  1
         Component component = context.getComponent( );
 198  1
         String strComponentName = ReleaserUtils.getGitComponentName( component.getScmDeveloperConnection( ) );
 199  1
         String strLocalComponentPath = ReleaserUtils.getLocalComponentPath( strComponentName );
 200  
 
 201  1
         File file = new File( strLocalComponentPath );
 202  
 
 203  1
         if ( file.exists( ) )
 204  
         {
 205  
 
 206  0
             commandResult.getLog( ).append( "Local repository " + strComponentName + " exist\nCleaning Local folder...\n" );
 207  0
             if ( !FileUtils.delete( file, commandResult.getLog( ) ) )
 208  
             {
 209  0
                 commandResult.setError( commandResult.getLog( ).toString( ) );
 210  
 
 211  
             }
 212  0
             commandResult.getLog( ).append( "Local repository has been cleaned\n" );
 213  
         }
 214  
 
 215  1
         commandResult.getLog( ).append( "Cloning repository ...\n" );
 216  
         try
 217  
         {
 218  
 
 219  
             // PROGRESS 5%
 220  1
             commandResult.setProgressValue( commandResult.getProgressValue( ) + 5 );
 221  1
             git = GitUtils.cloneRepo( strLocalComponentPath, component.getScmDeveloperConnection( ), commandResult, context.getReleaserUser( ).getGithubComponentAccountLogin( ) );
 222  
             // fLocalRepo = new FileRepository( strLocalComponentPath + "/.git" );
 223  
             // git = new Git( fLocalRepo );
 224  1
             GitUtils.createLocalBranch( git, GitUtils.DEVELOP_BRANCH, commandResult );
 225  1
             GitUtils.createLocalBranch( git, GitUtils.MASTER_BRANCH, commandResult );
 226  1
             context.setRefBranchDev( GitUtils.getRefBranch( git, GitUtils.DEVELOP_BRANCH, commandResult ) );
 227  1
             context.setRefBranchRelease( GitUtils.getRefBranch( git, GitUtils.MASTER_BRANCH, commandResult ) );
 228  
             
 229  
             
 230  
             //String ref = git.getRepository( ).findRef( GitUtils.MASTER_BRANCH ).getName( ); 
 231  
 //            git.reset( ).setRef( ref  ).setMode( ResetType.HARD ).call( );
 232  
 //            git.push( )
 233  
 //            .setCredentialsProvider( new UsernamePasswordCredentialsProvider( context.getReleaserUser( ).getGithubComponentAccountLogin( ), context.getReleaserUser( ).getGithubComponentAccountPassword( ) ) ).setRe
 234  
 //            .call( );
 235  1
             commandResult.getLog( ).append( "the repository has been successfully cloned.\n" );
 236  1
             commandResult.getLog( ).append( "Checkout branch \"" + GitUtils.DEVELOP_BRANCH + "\" ...\n" );
 237  1
             GitUtils.checkoutRepoBranch( git, GitUtils.DEVELOP_BRANCH, commandResult );
 238  
             // PROGRESS 10%
 239  1
             commandResult.setProgressValue( commandResult.getProgressValue( ) + 5 );
 240  
             
 241  
         
 242  1
             if(ComponentService.getService( ).isErrorSnapshotComponentInformations( component,ReleaserUtils.getLocalComponentPomPath( strComponentName ) ))
 243  
             {
 244  0
                 ReleaserUtils.addTechnicalError( commandResult,"The cloned component does not match the release informations");
 245  
                 
 246  
             }
 247  
 
 248  
         }
 249  
       
 250  
         finally
 251  
         {
 252  1
             if ( git != null )
 253  
             {
 254  
 
 255  1
                 git.close( );
 256  
 
 257  
             }
 258  
         }
 259  
 
 260  0
         commandResult.getLog( ).append( "Checkout branch develop successfull\n" );
 261  
 
 262  0
         ReleaserUtils.logEndAction( context, " Clone Repository" );
 263  
 
 264  0
     }
 265  
 
 266  
     public void gitMerge( WorkflowReleaseContext context, Locale locale )
 267  
     {
 268  
 
 269  0
         FileRepository fLocalRepo = null;
 270  0
         CommandResult commandResult = context.getCommandResult( );
 271  0
         Component component = context.getComponent( );
 272  0
         ReleaserUtils.logStartAction( context, " Merge DEVELOP/MASTER" );
 273  0
         String strComponentName = ReleaserUtils.getGitComponentName( component.getScmDeveloperConnection( ) );
 274  0
         String strLocalComponentPath = ReleaserUtils.getLocalComponentPath( strComponentName );
 275  0
         Git git = null;
 276  
         try
 277  
         {
 278  
 
 279  0
             fLocalRepo = new FileRepository( strLocalComponentPath + "/.git" );
 280  0
             git = new Git( fLocalRepo );
 281  0
             commandResult.getLog( ).append( "Checking if local repository " + strComponentName + " exist\n" );
 282  0
             if ( !fLocalRepo.getDirectory( ).exists( ) )
 283  
             {
 284  
 
 285  0
                 ReleaserUtils.addTechnicalError( commandResult, "the local repository does not exist" );
 286  
 
 287  
             }
 288  
             else
 289  
             {
 290  0
                 commandResult.getLog( ).append( "Checkout branch \"" + GitUtils.MASTER_BRANCH + "\" ...\n" );
 291  0
                 GitUtils.checkoutRepoBranch( git, GitUtils.MASTER_BRANCH, commandResult );
 292  0
                 commandResult.getLog( ).append( "Checkout successfull\n" );
 293  
                 // PROGRESS 15%
 294  0
                 commandResult.setProgressValue( commandResult.getProgressValue( ) + 5 );
 295  
 
 296  0
                 commandResult.getLog( ).append( "Going to merge '" + GitUtils.DEVELOP_BRANCH + "' branch on 'master' branch...\n" );
 297  0
                 MergeResult mergeResult = GitUtils.mergeRepoBranch( git, GitUtils.DEVELOP_BRANCH );
 298  0
                 if ( mergeResult.getMergeStatus( ).equals( MergeResult.MergeStatus.CHECKOUT_CONFLICT )
 299  0
                         || mergeResult.getMergeStatus( ).equals( MergeResult.MergeStatus.CONFLICTING )
 300  0
                         || mergeResult.getMergeStatus( ).equals( MergeResult.MergeStatus.FAILED )
 301  0
                         || mergeResult.getMergeStatus( ).equals( MergeResult.MergeStatus.NOT_SUPPORTED ) )
 302  
                 {
 303  0
                     ReleaserUtils.addTechnicalError( commandResult, "An error appear during merge operation, the status of merge result is: "
 304  0
                             + mergeResult.getMergeStatus( ).toString( ) + "\nPlease merge manually before releasing." );
 305  
 
 306  
                 }
 307  
                 else
 308  
                 {
 309  0
                     git.push( )
 310  0
                             .setCredentialsProvider( new UsernamePasswordCredentialsProvider( context.getReleaserUser( ).getGithubComponentAccountLogin( ), context.getReleaserUser( ).getGithubComponentAccountPassword( ) ) )
 311  0
                             .call( );
 312  0
                     commandResult.getLog( ).append( mergeResult.getMergeStatus( ) );
 313  
                 }
 314  0
                 ReleaserUtils.logEndAction( context, " Merge DEVELOP/MASTER" );
 315  
                 // PROGRESS 25%
 316  0
                 commandResult.setProgressValue( commandResult.getProgressValue( ) + 10 );
 317  
 
 318  
             }
 319  
 
 320  
         }
 321  0
         catch( InvalidRemoteException e )
 322  
         {
 323  
 
 324  0
             ReleaserUtils.addTechnicalError( commandResult, e.getMessage( ), e );
 325  
 
 326  
         }
 327  0
         catch( TransportException e )
 328  
         {
 329  0
             ReleaserUtils.addTechnicalError( commandResult, e.getMessage( ), e );
 330  
 
 331  
         }
 332  0
         catch( IOException e )
 333  
         {
 334  0
             ReleaserUtils.addTechnicalError( commandResult, e.getMessage( ), e );
 335  
         }
 336  0
         catch( GitAPIException e )
 337  
         {
 338  0
             ReleaserUtils.addTechnicalError( commandResult, e.getMessage( ), e );
 339  
         }
 340  
         finally
 341  
         {
 342  
 
 343  0
             if ( fLocalRepo != null )
 344  
             {
 345  
 
 346  0
                 fLocalRepo.close( );
 347  
 
 348  
             }
 349  0
             if ( git != null )
 350  
             {
 351  
 
 352  0
                 git.close( );
 353  
 
 354  
             }
 355  
 
 356  
         }
 357  0
     }
 358  
 
 359  
     public void rollBackReleasePrepareGit( WorkflowReleaseContext context, Locale locale )
 360  
     {
 361  
        
 362  0
         String strComponentName = ReleaserUtils.getGitComponentName( context.getComponent( ).getScmDeveloperConnection( ) );
 363  0
         _gitMavenPrepareUpadteRepo.rollbackRelease( ReleaserUtils.getLocalComponentPath( strComponentName) , context, locale );
 364  
             
 365  0
     }
 366  
     
 367  
     public void releasePrepareGit( WorkflowReleaseContext context, Locale locale )
 368  
     {
 369  0
         String strComponentName = ReleaserUtils.getGitComponentName( context.getComponent( ).getScmDeveloperConnection( ) );
 370  
         
 371  
         try
 372  
         {
 373  0
         realeasePrepare(strComponentName, context.getReleaserUser( ).getGithubComponentAccountLogin( ),context.getReleaserUser( ).getGithubComponentAccountPassword( ),_gitMavenPrepareUpadteRepo,
 374  
                 context, locale );
 375  
         
 376  0
         }catch(AppException ex)
 377  
         {
 378  0
             _gitMavenPrepareUpadteRepo.rollbackRelease( ReleaserUtils.getLocalComponentPath( strComponentName) , context, locale );
 379  
             
 380  0
         }
 381  
 
 382  0
     }
 383  
 
 384  
     public void releasePerformGit( WorkflowReleaseContext context, Locale locale )
 385  
     {
 386  
 
 387  0
         CommandResult commandResult = context.getCommandResult( );
 388  0
         Component component = context.getComponent( );
 389  
 
 390  0
         ReleaserUtils.logStartAction( context, " Release Perform" );
 391  
 
 392  0
         String strComponentName = ReleaserUtils.getGitComponentName( component.getScmDeveloperConnection( ) );
 393  0
         String strLocalComponentPomPath = ReleaserUtils.getLocalComponentPomPath( strComponentName );
 394  
 
 395  
         // PROGRESS 75%
 396  0
         commandResult.setProgressValue( commandResult.getProgressValue( ) + 10 );
 397  
 
 398  0
         MavenService.getService( ).mvnReleasePerform( strLocalComponentPomPath, context.getReleaserUser( ).getGithubComponentAccountLogin( ), context.getReleaserUser( ).getGithubComponentAccountPassword( ), commandResult );
 399  
 
 400  0
         ReleaserUtils.logEndAction( context, " Release Perform" );
 401  0
     }
 402  
 
 403  
     public void checkoutSite( WorkflowReleaseContext context, Locale locale )
 404  
     {
 405  0
         CommandResult commandResult = context.getCommandResult( );
 406  
 
 407  0
         ReleaserUtils.logStartAction( context, " checkout Site" );
 408  
 
 409  0
         SvnService.getService( ).doSvnCheckoutSite( context.getSite( ), context.getReleaserUser( ).getSvnSiteAccountLogin( ), context.getReleaserUser( ).getSvnSiteAccountPassword( ), context.getCommandResult( ) );
 410  
         // PROGRESS 30%
 411  0
         commandResult.setProgressValue( commandResult.getProgressValue( ) + 30 );
 412  
 
 413  0
         ReleaserUtils.logEndAction( context, " checkout Site" );
 414  
 
 415  0
     }
 416  
 
 417  
     public void checkoutComponent( WorkflowReleaseContext context, Locale locale )
 418  
     {
 419  0
         CommandResult commandResult = context.getCommandResult( );
 420  
 
 421  0
         ReleaserUtils.logStartAction( context, " Checkout Svn Component " );
 422  0
         String strComponentName = context.getComponent( ).getArtifactId( );
 423  0
         String strLocalComponentPath = ReleaserUtils.getLocalComponentPath( strComponentName );
 424  
 
 425  0
         File file = new File( strLocalComponentPath );
 426  
 
 427  0
         if ( file.exists( ) )
 428  
         {
 429  
 
 430  0
             commandResult.getLog( ).append( "Local SVN Component " + strComponentName + " exist\nCleaning Local folder...\n" );
 431  0
             if ( !FileUtils.delete( file, commandResult.getLog( ) ) )
 432  
             {
 433  0
                 commandResult.setError( commandResult.getLog( ).toString( ) );
 434  
 
 435  
             }
 436  0
             commandResult.getLog( ).append( "Local SVN Component has been cleaned\n" );
 437  
         }
 438  
         // PROGRESS 5%
 439  0
         commandResult.setProgressValue( commandResult.getProgressValue( ) + 5 );
 440  
 
 441  0
         commandResult.getLog( ).append( "Checkout SVN Component ...\n" );
 442  0
         SvnService.getService( ).doSvnCheckoutComponent( context.getComponent( ), context.getReleaserUser( ).getSvnComponentAccountLogin( ), context.getReleaserUser( ).getSvnComponentAccountPassword( ),
 443  0
                 context.getCommandResult( ) );
 444  
         // PROGRESS 10%
 445  0
         commandResult.setProgressValue( commandResult.getProgressValue( ) + 5 );
 446  
         
 447  0
         if(ComponentService.getService( ).isErrorSnapshotComponentInformations( context.getComponent( ) ,ReleaserUtils.getLocalComponentPomPath( strComponentName )))
 448  
         {
 449  0
             ReleaserUtils.addTechnicalError( commandResult,"The checkout component does not match the release informations");
 450  
          }
 451  
 
 452  0
         ReleaserUtils.logEndAction( context, "Checkout Svn Component " );
 453  
 
 454  0
     }
 455  
 
 456  
     public void releaseSite( WorkflowReleaseContext context, Locale locale )
 457  
     {
 458  0
         CommandResult commandResult = context.getCommandResult( );
 459  
 
 460  0
         ReleaserUtils.logStartAction( context, " Release Site" );
 461  
 
 462  0
         context.getCommandResult( ).getLog( ).append( "Starting Action Release Site...\n" );
 463  0
         SvnService.getService( ).doReleaseSite( context.getSite( ), context.getReleaserUser( ).getSvnSiteAccountLogin( ), context.getReleaserUser( ).getSvnSiteAccountPassword( ), context.getCommandResult( ) );
 464  
 
 465  0
         ReleaserUtils.logEndAction( context, " Release Site" );
 466  
 
 467  0
     }
 468  
 
 469  
     public void releasePrepareSvn( WorkflowReleaseContext context, Locale locale )
 470  
     {
 471  0
         String strComponentName = context.getComponent( ).getArtifactId( );
 472  
         
 473  
         
 474  0
      realeasePrepare(strComponentName,context.getReleaserUser( ).getSvnComponentAccountLogin( ),context.getReleaserUser( ).getSvnComponentAccountPassword( ), _svnMavenPrepareUpadteRepo,
 475  
                 context, locale );
 476  
 
 477  0
     }
 478  
 
 479  
     public void releasePerformSvn( WorkflowReleaseContext context, Locale locale )
 480  
     {
 481  0
         CommandResult commandResult = context.getCommandResult( );
 482  
        
 483  0
         ReleaserUtils.logStartAction( context, " Release Perform" );
 484  
 
 485  0
         String strComponentName = context.getComponent( ).getArtifactId( );
 486  0
         String strLocalComponentPomPath = ReleaserUtils.getLocalComponentPomPath( strComponentName );
 487  
 
 488  
 
 489  
         // PROGRESS 75%
 490  0
         commandResult.setProgressValue( commandResult.getProgressValue( ) + 10 );
 491  
 
 492  0
         MavenService.getService( ).mvnReleasePerform( strLocalComponentPomPath, context.getReleaserUser( ).getSvnComponentAccountLogin( ), context.getReleaserUser( ).getSvnComponentAccountPassword( ), commandResult );
 493  
 
 494  0
         ReleaserUtils.logEndAction( context, " Release Perform" );
 495  0
     }
 496  
 
 497  
     public void sendTweet( WorkflowReleaseContext context, Locale locale )
 498  
     {
 499  
 
 500  0
         CommandResult commandResult = context.getCommandResult( );
 501  0
         Component component = context.getComponent( );
 502  
 
 503  0
         ReleaserUtils.logStartAction( context, " send Tweet" );
 504  
 
 505  0
         String strComponentName = ReleaserUtils.getGitComponentName( component.getScmDeveloperConnection( ) );
 506  0
         String strComponentReleaseVersion = component.getTargetVersion( );
 507  
 
 508  0
         Object [ ] messageAgrs = {
 509  
                 strComponentName, strComponentReleaseVersion
 510  
         };
 511  
 
 512  0
         String strTweetMessage = I18nService.getLocalizedString( ConstanteUtils.I18_TWITTER_MESSAGE, messageAgrs, locale );
 513  
 
 514  0
         TwitterService.getService( ).sendTweet( strTweetMessage, commandResult );
 515  
 
 516  0
         ReleaserUtils.logEndAction( context, " send Tweet" );
 517  
 
 518  0
     }
 519  
 
 520  
     public void startWorkflowReleaseContext( WorkflowReleaseContext context, int nIdWorkflow, Locale locale, HttpServletRequest request, AdminUser user )
 521  
     {
 522  0
         _executor.execute( new ReleaseComponentTask( nIdWorkflow, context, request, user, locale ) );
 523  0
     }
 524  
 
 525  
     public void init( )
 526  
     {
 527  
 
 528  1
         _executor = Executors.newFixedThreadPool( AppPropertiesService.getPropertyInt( ConstanteUtils.PROPERTY_THREAD_RELEASE_POOL_MAX_SIZE, 10 ) );
 529  1
         _svnMavenPrepareUpadteRepo =SpringContextService.getBean( ConstanteUtils.BEAN_SVN_MAVEN_PREPARE_UPDATE_REMOTE_REPOSITORY );
 530  1
          _gitMavenPrepareUpadteRepo =SpringContextService.getBean( ConstanteUtils.BEAN_GIT_MAVEN_PREPARE_UPDATE_REMOTE_REPOSITORY );
 531  
         
 532  
 
 533  1
     }
 534  
 
 535  
     private void realeasePrepare( String strComponentName,String strUserLogin,String strUserPassword,IMavenPrepareUpdateRemoteRepository mavenPrepareUpdateRepo, WorkflowReleaseContext context, Locale locale )
 536  
     {
 537  
 
 538  0
         CommandResult commandResult = context.getCommandResult( );
 539  0
         Component component = context.getComponent( );
 540  0
         String strLocalComponentPath = ReleaserUtils.getLocalComponentPath( strComponentName );
 541  0
         String strLocalComponentPomPath = ReleaserUtils.getLocalComponentPomPath( strComponentName );
 542  
 
 543  0
         String strComponentReleaseVersion = component.getTargetVersion( );
 544  0
         String strComponentReleaseTagName = component.getArtifactId( ) + "-" + component.getTargetVersion( );
 545  0
         String strComponentReleaseNewDeveloppmentVersion = component.getNextSnapshotVersion( );
 546  
 
 547  0
         ReleaserUtils.logStartAction( context, " Release Prepare" );
 548  
 
 549  0
         if ( PluginUtils.isCore( strComponentName ) )
 550  
         {
 551  
             // update core xml
 552  0
             String strCoreXMLPath = PluginUtils.getCoreXMLFile( strLocalComponentPath );
 553  
 
 554  0
             if ( StringUtils.isNotBlank( strCoreXMLPath ) )
 555  
             {
 556  0
                 commandResult.getLog( ).append( "Updating Core XML " + strComponentName + " to " + strComponentReleaseVersion + "\n" );
 557  
 
 558  
                 
 559  0
                 PluginUtils.updatePluginXMLVersion( strLocalComponentPath, strComponentReleaseVersion, commandResult );
 560  
                 // Commit Plugin xml modification version
 561  0
                 mavenPrepareUpdateRepo.updateDevelopBranch( strLocalComponentPath,context, locale, "[site-release] Update core version to " + strComponentReleaseVersion );
 562  0
                 commandResult.getLog( ).append( "Core XML updated to " + strComponentReleaseVersion + "\n" );
 563  
                 // PROGRESS 30%
 564  0
                 commandResult.setProgressValue( commandResult.getProgressValue( ) + 5 );
 565  
 
 566  
             }
 567  
 
 568  
             // update appinfo.java
 569  0
             String strAppInfoFilePath = PluginUtils.getAppInfoFile( strLocalComponentPath, PluginUtils.CORE_PLUGIN_NAME1 );
 570  0
             if ( StringUtils.isBlank( strAppInfoFilePath ) )
 571  
             {
 572  0
                 strAppInfoFilePath = PluginUtils.getAppInfoFile( strLocalComponentPath, PluginUtils.CORE_PLUGIN_NAME2 );
 573  
             }
 574  0
             if ( StringUtils.isNotBlank( strAppInfoFilePath ) )
 575  
             {
 576  0
                 PluginUtils.updateAppInfoFile( strAppInfoFilePath, strComponentReleaseVersion, commandResult );
 577  0
                 mavenPrepareUpdateRepo.updateDevelopBranch( strAppInfoFilePath,context, locale, "[site-release] Update AppInfo.java version" );
 578  
 
 579  
             }
 580  
             else
 581  
             {
 582  0
                 commandResult.getLog( ).append( "No AppInfo file found..." );
 583  
             }
 584  
 
 585  0
         }
 586  
         else
 587  
         {
 588  0
             String [ ] pluginNames = PluginUtils.getPluginXMLFile( strLocalComponentPath );
 589  0
             for ( String pluginXMLPath : pluginNames )
 590  
             {
 591  0
                 commandResult.getLog( ).append( "Updating plugin XML " + strComponentName + " to " + strComponentReleaseVersion + "\n" );
 592  0
                 PluginUtils.updatePluginXMLVersion( pluginXMLPath, strComponentReleaseVersion, commandResult );
 593  0
                 mavenPrepareUpdateRepo.updateDevelopBranch(pluginXMLPath, context, locale, "[site-release] Update plugin version to " + strComponentReleaseVersion + " for "
 594  
                         + strComponentName );
 595  
 
 596  0
                 commandResult.getLog( ).append( "Plugin XML updated to " + strComponentReleaseVersion + "\n" );
 597  
                 // PROGRESS 30%
 598  0
                 commandResult.setProgressValue( commandResult.getProgressValue( ) + 5 );
 599  
 
 600  
             }
 601  
         }
 602  
 
 603  
        
 604  
        
 605  
         
 606  0
         MavenService.getService( ).mvnReleasePrepare( strLocalComponentPomPath, strComponentReleaseVersion, strComponentReleaseTagName,
 607  
                 strComponentReleaseNewDeveloppmentVersion, strUserLogin, strUserPassword, commandResult );
 608  
         // Merge Master
 609  0
         mavenPrepareUpdateRepo.updateReleaseBranch( strLocalComponentPomPath,context, locale );
 610  
         // PROGRESS 50%
 611  0
         commandResult.setProgressValue( commandResult.getProgressValue( ) + 20 );
 612  
 
 613  
         // Modify plugin version on develop
 614  0
         if ( PluginUtils.isCore( strComponentName ) )
 615  
         {
 616  
             // update core xml
 617  0
             String strCoreXMLPath = PluginUtils.getCoreXMLFile( strLocalComponentPath );
 618  
 
 619  0
             if ( StringUtils.isNotBlank( strCoreXMLPath ) )
 620  
             {
 621  0
                 commandResult.getLog( ).append( "Updating Core XML " + strComponentName + " to " + strComponentReleaseNewDeveloppmentVersion + "\n" );
 622  
 
 623  0
                 PluginUtils.updatePluginXMLVersion( strLocalComponentPath, strComponentReleaseNewDeveloppmentVersion, commandResult );
 624  
                 // Commit Plugin xml modification version
 625  0
                 mavenPrepareUpdateRepo.updateDevelopBranch(strLocalComponentPath,  context, locale, "[site-release] Update core version to "
 626  
                         + strComponentReleaseNewDeveloppmentVersion );
 627  
             }
 628  
 
 629  
             // update appinfo.java
 630  0
             String strAppInfoFilePath = PluginUtils.getAppInfoFile( strLocalComponentPath, PluginUtils.CORE_PLUGIN_NAME1 );
 631  0
             if ( StringUtils.isBlank( strAppInfoFilePath ) )
 632  
             {
 633  0
                 strAppInfoFilePath = PluginUtils.getAppInfoFile( strLocalComponentPath, PluginUtils.CORE_PLUGIN_NAME2 );
 634  
             }
 635  0
             if ( StringUtils.isNotBlank( strAppInfoFilePath ) )
 636  
             {
 637  0
                 mavenPrepareUpdateRepo.updateDevelopBranch(strAppInfoFilePath, context, locale, "[site-release] Update AppInfo.java version" );
 638  
 
 639  
             }
 640  
             else
 641  
             {
 642  0
                 commandResult.getLog( ).append( "No AppInfo file found..." );
 643  
             }
 644  
 
 645  0
         }
 646  
         else
 647  
         {
 648  0
             String [ ] pluginNames = PluginUtils.getPluginXMLFile( strLocalComponentPath );
 649  0
             for ( String pluginXMLPath : pluginNames )
 650  
             {
 651  0
                 commandResult.getLog( ).append( "Updating plugin XML " + strComponentName + " to " + strComponentReleaseNewDeveloppmentVersion + "\n" );
 652  0
                 PluginUtils.updatePluginXMLVersion( pluginXMLPath, strComponentReleaseNewDeveloppmentVersion, commandResult );
 653  
                 // Commit Plugin xml modification version
 654  0
                 mavenPrepareUpdateRepo.updateDevelopBranch( pluginXMLPath,context, locale, "[site-release] Update plugin version to "
 655  
                         + strComponentReleaseNewDeveloppmentVersion + " for " + strComponentName );
 656  
 
 657  0
                 commandResult.getLog( ).append( "Plugin XML updated to " + strComponentReleaseNewDeveloppmentVersion + "\n" );
 658  
             }
 659  
         }
 660  
         // PROGRESS 65%
 661  0
         commandResult.setProgressValue( commandResult.getProgressValue( ) + 15 );
 662  
         
 663  0
         ReleaserUtils.logEndAction( context, " Release Prepare" );
 664  
 
 665  0
     }
 666  
 
 667  
 }