View Javadoc
1   /*
2    * Copyright (c) 2002-2021, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.releaser.service;
35  
36  import java.io.IOException;
37  import java.sql.Timestamp;
38  import java.util.ArrayList;
39  import java.util.HashMap;
40  import java.util.HashSet;
41  import java.util.List;
42  import java.util.Locale;
43  import java.util.concurrent.ExecutorService;
44  import java.util.concurrent.Executors;
45  
46  import javax.servlet.http.HttpServletRequest;
47  import javax.xml.bind.JAXBException;
48  
49  import org.apache.commons.collections.CollectionUtils;
50  import org.apache.commons.lang3.StringUtils;
51  import org.eclipse.jgit.api.Git;
52  import org.eclipse.jgit.api.MergeResult;
53  import org.eclipse.jgit.api.errors.GitAPIException;
54  import org.eclipse.jgit.api.errors.InvalidRemoteException;
55  import org.eclipse.jgit.api.errors.TransportException;
56  import org.eclipse.jgit.internal.storage.file.FileRepository;
57  import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
58  
59  import fr.paris.lutece.plugins.releaser.business.Component;
60  import fr.paris.lutece.plugins.releaser.business.RepositoryType;
61  import fr.paris.lutece.plugins.releaser.business.WorkflowContextHistory;
62  import fr.paris.lutece.plugins.releaser.business.WorkflowContextHistoryHome;
63  import fr.paris.lutece.plugins.releaser.business.WorkflowReleaseContext;
64  import fr.paris.lutece.plugins.releaser.util.CVSFactoryService;
65  import fr.paris.lutece.plugins.releaser.util.CommandResult;
66  import fr.paris.lutece.plugins.releaser.util.ConstanteUtils;
67  import fr.paris.lutece.plugins.releaser.util.IVCSResourceService;
68  import fr.paris.lutece.plugins.releaser.util.MapperJsonUtil;
69  import fr.paris.lutece.plugins.releaser.util.PluginUtils;
70  import fr.paris.lutece.plugins.releaser.util.ReleaserUtils;
71  import fr.paris.lutece.plugins.releaser.util.github.GitUtils;
72  import fr.paris.lutece.plugins.releaser.util.pom.PomUpdater;
73  import fr.paris.lutece.portal.business.user.AdminUser;
74  import fr.paris.lutece.portal.service.spring.SpringContextService;
75  import fr.paris.lutece.portal.service.util.AppException;
76  import fr.paris.lutece.portal.service.util.AppLogService;
77  import fr.paris.lutece.portal.service.util.AppPropertiesService;
78  
79  // TODO: Auto-generated Javadoc
80  /**
81   * The Class WorkflowReleaseContextService.
82   */
83  public class WorkflowReleaseContextService implements IWorkflowReleaseContextService
84  {
85  
86      /** The singleton. */
87      private static IWorkflowReleaseContextService _singleton;
88  
89      /** The map workflow release context. */
90      private HashMap<Integer, WorkflowReleaseContext> _mapWorkflowReleaseContext = new HashMap<Integer, WorkflowReleaseContext>( );
91  
92      /** The executor. */
93      private ExecutorService _executor;
94  
95      /** The release in progress. */
96      private HashSet<String> _releaseInProgress = new HashSet<String>( );
97  
98      /**
99       * Adds the workflow release context.
100      *
101      * @param context
102      *            the context
103      * @return the int
104      */
105     /*
106      * (non-Javadoc)
107      * 
108      * @see fr.paris.lutece.plugins.releaser.service.IWorkflowReleaseContextService#addWorkflowDeploySiteContext(fr.paris.lutece.plugins.releaser.business.
109      * WorkflowReleaseContext)
110      */
111     @Override
112     public synchronized int addWorkflowReleaseContext( WorkflowReleaseContext context )
113     {
114 
115         try
116         {
117             String strJsonContext = MapperJsonUtil.getJson( context );
118             // clean PWD in log before save in history
119             String strJsonContextClean = ReleaserUtils.cleanPWDInLog( strJsonContext );
120 
121             WorkflowContextHistory/WorkflowContextHistory.html#WorkflowContextHistory">WorkflowContextHistory wfHistory = new WorkflowContextHistory( );
122             wfHistory.setArtifactId( context.getComponent( ) != null ? context.getComponent( ).getArtifactId( ) : context.getSite( ).getArtifactId( ) );
123             wfHistory.setData( strJsonContextClean );
124             WorkflowContextHistoryHome.create( wfHistory );
125             context.setId( wfHistory.getId( ) );
126             _mapWorkflowReleaseContext.put( context.getId( ), context );
127         }
128         catch( IOException e )
129         {
130             AppLogService.error( "error during add workkflow context context json", e );
131         }
132 
133         return context.getId( );
134     }
135 
136     /**
137      * Gets the workflow release context.
138      *
139      * @param nIdContext
140      *            the n id context
141      * @return the workflow release context
142      */
143     /*
144      * (non-Javadoc)
145      * 
146      * @see fr.paris.lutece.plugins.releaser.service.IWorkflowReleaseContextService#getWorkflowDeploySiteContext(int)
147      */
148     @Override
149     public WorkflowReleaseContext getWorkflowReleaseContext( int nIdContext )
150     {
151         return _mapWorkflowReleaseContext.get( nIdContext );
152     }
153 
154     /**
155      * Save workflow release context.
156      *
157      * @param context
158      *            the context
159      */
160     public synchronized void saveWorkflowReleaseContext( WorkflowReleaseContext context )
161     {
162         try
163         {
164             String strJsonContext = MapperJsonUtil.getJson( context );
165             // clean PWD in log before save in history
166             String strJsonContextClean = ReleaserUtils.cleanPWDInLog( strJsonContext );
167 
168             WorkflowContextHistory wfHistory = WorkflowContextHistoryHome.findByPrimaryKey( context.getId( ) );
169 
170             if ( wfHistory != null )
171             {
172                 if ( context.getCommandResult( ) != null && context.getCommandResult( ).getDateBegin( ) != null )
173                 {
174                     wfHistory.setDateBegin( new Timestamp( context.getCommandResult( ).getDateBegin( ).getTime( ) ) );
175                 }
176                 if ( context.getCommandResult( ) != null && context.getCommandResult( ).getDateEnd( ) != null )
177                 {
178                     wfHistory.setDateEnd( new Timestamp( context.getCommandResult( ).getDateEnd( ).getTime( ) ) );
179                 }
180                 wfHistory.setData( strJsonContextClean );
181                 WorkflowContextHistoryHome.update( wfHistory );
182             }
183             else
184             {
185                 wfHistory = new WorkflowContextHistory( );
186 
187                 wfHistory.setArtifactId( context.getComponent( ) != null ? context.getComponent( ).getArtifactId( ) : context.getSite( ).getArtifactId( ) );
188                 wfHistory.setData( strJsonContextClean );
189                 WorkflowContextHistoryHome.create( wfHistory );
190                 context.setId( wfHistory.getId( ) );
191             }
192 
193         }
194         catch( IOException e )
195         {
196             AppLogService.error( "error during save context json", e );
197         }
198     }
199 
200     /**
201      * Gets the workflow release context history.
202      *
203      * @param nIdContext
204      *            the n id context
205      * @return the workflow release context history
206      */
207     public WorkflowReleaseContext getWorkflowReleaseContextHistory( int nIdContext )
208     {
209         WorkflowReleaseContext context = null;
210         try
211         {
212 
213             WorkflowContextHistory wfHistory = WorkflowContextHistoryHome.findByPrimaryKey( nIdContext );
214             context = MapperJsonUtil.parse( wfHistory.getData( ), WorkflowReleaseContext.class );
215 
216         }
217         catch( IOException e )
218         {
219             AppLogService.error( "error during get context in the datastore", e );
220         }
221         return context;
222 
223     }
224 
225     /**
226      * Gets the list workflow release context history.
227      *
228      * @param strArtifactId
229      *            the str artifact id
230      * @return the list workflow release context history
231      */
232     public List<WorkflowReleaseContext> getListWorkflowReleaseContextHistory( String strArtifactId )
233     {
234         WorkflowReleaseContext context = null;
235         List<WorkflowReleaseContext> listContext = new ArrayList<WorkflowReleaseContext>( );
236 
237         try
238         {
239 
240             List<WorkflowContextHistory> listWfContextHistory = WorkflowContextHistoryHome.getWorkflowDeployContextsListByArtifactId( strArtifactId );
241             if ( !CollectionUtils.isEmpty( listWfContextHistory ) )
242             {
243 
244                 for ( WorkflowContextHistory wfHistory : listWfContextHistory )
245                 {
246                     context = MapperJsonUtil.parse( wfHistory.getData( ), WorkflowReleaseContext.class );
247                     if ( context != null )
248                     {
249                         listContext.add( context );
250                     }
251                 }
252 
253             }
254         }
255         catch( IOException e )
256         {
257             AppLogService.error( "error for parsing json workflow context", e );
258         }
259         return listContext;
260 
261     }
262 
263     /**
264      * Gets the id workflow.
265      *
266      * @param context
267      *            the context
268      * @return the id workflow
269      */
270     public int getIdWorkflow( WorkflowReleaseContext context )
271     {
272         int nIdWorkflow = ConstanteUtils.CONSTANTE_ID_NULL;
273 
274         if ( context.isLuteceSite( ) )
275         {
276             nIdWorkflow = AppPropertiesService.getPropertyInt( ConstanteUtils.PROPERTY_ID_WORKFLOW_LUTECE_SITE, ConstanteUtils.CONSTANTE_ID_NULL );
277 
278         }
279         else
280         {
281 
282             nIdWorkflow = AppPropertiesService.getPropertyInt( ConstanteUtils.PROPERTY_ID_WORKFLOW_COMPONENT, ConstanteUtils.CONSTANTE_ID_NULL );
283         }
284 
285         return nIdWorkflow;
286     }
287 
288     /**
289      * Gets the service.
290      *
291      * @return the service
292      */
293     public static IWorkflowReleaseContextService getService( )
294     {
295         if ( _singleton == null )
296         {
297 
298             _singleton = SpringContextService.getBean( ConstanteUtils.BEAN_WORKFLOW_RELEASE_CONTEXT_SERVICE );
299             _singleton.init( );
300         }
301 
302         return _singleton;
303     }
304 
305     /**
306      * Merge develop master.
307      *
308      * @param context
309      *            the context
310      * @param locale
311      *            the locale
312      */
313     public void mergeDevelopMaster( WorkflowReleaseContext context, Locale locale )
314     {
315 
316         if ( !context.getReleaserResource( ).getRepoType( ).equals( RepositoryType.SVN )
317                 && ReleaserUtils.getBranchReleaseFrom( context ).equals( GitUtils.DEFAULT_RELEASE_BRANCH ) )
318         {
319 
320             FileRepository fLocalRepo = null;
321             CommandResult commandResult = context.getCommandResult( );
322             String strLogin = context.getReleaserUser( ).getCredential( context.getReleaserResource( ).getRepoType( ) ).getLogin( );
323             String strPassword = context.getReleaserUser( ).getCredential( context.getReleaserResource( ).getRepoType( ) ).getPassword( );
324 
325             ReleaserUtils.logStartAction( context, " Merge DEVELOP/MASTER" );
326 
327             String strLocalComponentPath = ReleaserUtils.getLocalPath( context );
328             Git git = null;
329             try
330             {
331 
332                 fLocalRepo = new FileRepository( strLocalComponentPath + "/.git" );
333                 git = new Git( fLocalRepo );
334                 commandResult.getLog( ).append( "Checking if local repository " + strLocalComponentPath + " exist\n" );
335                 if ( !fLocalRepo.getDirectory( ).exists( ) )
336                 {
337 
338                     ReleaserUtils.addTechnicalError( commandResult, "the local repository does not exist" );
339 
340                 }
341                 else
342                 {
343                     commandResult.getLog( ).append( "Checkout branch \"" + GitUtils.MASTER_BRANCH + "\" ...\n" );
344                     GitUtils.checkoutRepoBranch( git, GitUtils.MASTER_BRANCH, commandResult );
345                     commandResult.getLog( ).append( "Checkout successfull\n" );
346                     // PROGRESS 15%
347                     commandResult.setProgressValue( commandResult.getProgressValue( ) + 5 );
348 
349                     commandResult.getLog( ).append( "Going to merge '" + GitUtils.DEFAULT_RELEASE_BRANCH + "' branch on 'master' branch...\n" );
350                     MergeResult mergeResult = GitUtils.mergeRepoBranch( git, GitUtils.DEFAULT_RELEASE_BRANCH );
351                     if ( mergeResult.getMergeStatus( ).equals( MergeResult.MergeStatus.CHECKOUT_CONFLICT )
352                             || mergeResult.getMergeStatus( ).equals( MergeResult.MergeStatus.CONFLICTING )
353                             || mergeResult.getMergeStatus( ).equals( MergeResult.MergeStatus.FAILED )
354                             || mergeResult.getMergeStatus( ).equals( MergeResult.MergeStatus.NOT_SUPPORTED ) )
355                     {
356                         ReleaserUtils.addTechnicalError( commandResult, "An error appear during merge operation, the status of merge result is: "
357                                 + mergeResult.getMergeStatus( ).toString( ) + "\nPlease merge manually before releasing." );
358 
359                     }
360                     else
361                     {
362                         git.push( ).setCredentialsProvider( new UsernamePasswordCredentialsProvider( strLogin, strPassword ) ).call( );
363                         commandResult.getLog( ).append( mergeResult.getMergeStatus( ) );
364                     }
365                     ReleaserUtils.logEndAction( context, " Merge DEVELOP/MASTER" );
366                     // BACK to Branch DEVELOP after merge
367                     GitUtils.checkoutRepoBranch( git, GitUtils.DEFAULT_RELEASE_BRANCH, commandResult );
368                     // PROGRESS 25%
369                     commandResult.setProgressValue( commandResult.getProgressValue( ) + 10 );
370 
371                 }
372 
373             }
374             catch( InvalidRemoteException e )
375             {
376 
377                 ReleaserUtils.addTechnicalError( commandResult, e.getMessage( ), e );
378 
379             }
380             catch( TransportException e )
381             {
382                 ReleaserUtils.addTechnicalError( commandResult, e.getMessage( ), e );
383 
384             }
385             catch( IOException e )
386             {
387                 ReleaserUtils.addTechnicalError( commandResult, e.getMessage( ), e );
388             }
389             catch( GitAPIException e )
390             {
391                 ReleaserUtils.addTechnicalError( commandResult, e.getMessage( ), e );
392             }
393             finally
394             {
395 
396                 if ( fLocalRepo != null )
397                 {
398 
399                     fLocalRepo.close( );
400 
401                 }
402                 if ( git != null )
403                 {
404 
405                     git.close( );
406 
407                 }
408 
409             }
410         }
411     }
412 
413     /**
414      * Release prepare component.
415      *
416      * @param context
417      *            the context
418      * @param locale
419      *            the locale
420      */
421     public void releasePrepareComponent( WorkflowReleaseContext context, Locale locale )
422     {
423         String strComponentName = context.getComponent( ).getName( );
424         String strLogin = context.getReleaserUser( ).getCredential( context.getReleaserResource( ).getRepoType( ) ).getLogin( );
425         String strPassword = context.getReleaserUser( ).getCredential( context.getReleaserResource( ).getRepoType( ) ).getPassword( );
426         IVCSResourceService cvsService = CVSFactoryService.getService( context.getComponent( ).getRepoType( ) );
427 
428         try
429         {
430             CommandResult commandResult = context.getCommandResult( );
431             Component component = context.getComponent( );
432 
433             // Checkout branch release from before prepare
434             cvsService.checkoutBranch( context, component.getBranchReleaseFrom( ), locale );
435 
436             String strLocalComponentPath = ReleaserUtils.getLocalPath( context );
437             String strLocalComponentPomPath = ReleaserUtils.getLocalPomPath( context );
438 
439             String strComponentReleaseVersion = component.getTargetVersion( );
440 
441             String strComponentReleaseTagName = null;
442             if ( component.getBranchReleaseFrom( ).equals( GitUtils.DEFAULT_RELEASE_BRANCH ) )
443             {
444                 strComponentReleaseTagName = component.getArtifactId( ) + "-" + component.getTargetVersion( );
445             }
446             else
447             {
448                 strComponentReleaseTagName = component.getArtifactId( ) + "-" + component.getTargetVersion( ) + "-" + component.getBranchReleaseFrom( );
449             }
450 
451             String strComponentReleaseNewDeveloppmentVersion = component.getNextSnapshotVersion( );
452 
453             ReleaserUtils.logStartAction( context, " Release Prepare" );
454 
455             if ( PluginUtils.isCore( strComponentName ) )
456             {
457                 // update core xml
458                 String strCoreXMLPath = PluginUtils.getCoreXMLFile( strLocalComponentPath );
459 
460                 if ( StringUtils.isNotBlank( strCoreXMLPath ) )
461                 {
462                     commandResult.getLog( ).append( "Updating Core XML " + strComponentName + " to " + strComponentReleaseVersion + "\n" );
463 
464                     PluginUtils.updatePluginXMLVersion( strCoreXMLPath, strComponentReleaseVersion, commandResult );
465                     // Commit Plugin xml modification version
466                     cvsService.updateBranch( context, component.getBranchReleaseFrom( ), locale,
467                             "[site-release] Update core version to " + strComponentReleaseVersion );
468                     commandResult.getLog( ).append( "Core XML updated to " + strComponentReleaseVersion + "\n" );
469                     // PROGRESS 30%
470                     commandResult.setProgressValue( commandResult.getProgressValue( ) + 5 );
471 
472                 }
473 
474                 // update appinfo.java
475                 String strAppInfoFilePath = PluginUtils.getAppInfoFile( strLocalComponentPath );
476 
477                 if ( StringUtils.isNotBlank( strAppInfoFilePath ) )
478                 {
479                     PluginUtils.updateAppInfoFile( strAppInfoFilePath, strComponentReleaseVersion, commandResult );
480                     cvsService.updateBranch( context, component.getBranchReleaseFrom( ), locale, "[site-release] Update AppInfo.java version" );
481 
482                 }
483                 else
484                 {
485                     commandResult.getLog( ).append( "No AppInfo file found..." );
486                 }
487 
488             }
489             else
490             {
491                 String [ ] pluginNames = PluginUtils.getPluginXMLFile( strLocalComponentPath );
492                 for ( String pluginXMLPath : pluginNames )
493                 {
494                     commandResult.getLog( ).append( "Updating plugin XML " + strComponentName + " to " + strComponentReleaseVersion + "\n" );
495                     PluginUtils.updatePluginXMLVersion( pluginXMLPath, strComponentReleaseVersion, commandResult );
496                     cvsService.updateBranch( context, component.getBranchReleaseFrom( ), locale,
497                             "[site-release] Update plugin version to " + strComponentReleaseVersion + " for " + strComponentName );
498 
499                     commandResult.getLog( ).append( "Plugin XML updated to " + strComponentReleaseVersion + "\n" );
500                     // PROGRESS 30%
501                     commandResult.setProgressValue( commandResult.getProgressValue( ) + 5 );
502 
503                 }
504             }
505 
506             MavenService.getService( ).mvnReleasePrepare( strLocalComponentPomPath, strComponentReleaseVersion, strComponentReleaseTagName,
507                     strComponentReleaseNewDeveloppmentVersion, strLogin, strPassword, commandResult );
508 
509             // Merge Master if release from develop branch
510             if ( component.getBranchReleaseFrom( ).equals( GitUtils.DEFAULT_RELEASE_BRANCH ) )
511             {
512                 cvsService.updateMasterBranch( context, locale );
513             }
514 
515             // Checkout branch after prepare
516             cvsService.checkoutBranch( context, component.getBranchReleaseFrom( ), locale );
517 
518             // PROGRESS 50%
519             commandResult.setProgressValue( commandResult.getProgressValue( ) + 20 );
520 
521             // Modify plugin version on released branch
522             if ( PluginUtils.isCore( strComponentName ) )
523             {
524                 // update core xml
525                 String strCoreXMLPath = PluginUtils.getCoreXMLFile( strLocalComponentPath );
526 
527                 if ( StringUtils.isNotBlank( strCoreXMLPath ) )
528                 {
529                     commandResult.getLog( ).append( "Updating Core XML " + strComponentName + " to " + strComponentReleaseNewDeveloppmentVersion + "\n" );
530 
531                     PluginUtils.updatePluginXMLVersion( strCoreXMLPath, strComponentReleaseNewDeveloppmentVersion, commandResult );
532 
533                     // Commit Plugin xml modification version
534                     cvsService.updateBranch( context, component.getBranchReleaseFrom( ), locale,
535                             "[site-release] Update core version to " + strComponentReleaseNewDeveloppmentVersion );
536                 }
537 
538                 // update appinfo.java
539                 String strAppInfoFilePath = PluginUtils.getAppInfoFile( strLocalComponentPath );
540 
541                 if ( StringUtils.isNotBlank( strAppInfoFilePath ) )
542                 {
543                     PluginUtils.updateAppInfoFile( strAppInfoFilePath, strComponentReleaseNewDeveloppmentVersion, commandResult );
544                     cvsService.updateBranch( context, component.getBranchReleaseFrom( ), locale, "[site-release] Update AppInfo.java version" );
545                 }
546                 else
547                 {
548                     commandResult.getLog( ).append( "No AppInfo file found..." );
549                 }
550 
551             }
552             else
553             {
554                 String [ ] pluginNames = PluginUtils.getPluginXMLFile( strLocalComponentPath );
555                 for ( String pluginXMLPath : pluginNames )
556                 {
557                     commandResult.getLog( ).append( "Updating plugin XML " + strComponentName + " to " + strComponentReleaseNewDeveloppmentVersion + "\n" );
558                     PluginUtils.updatePluginXMLVersion( pluginXMLPath, strComponentReleaseNewDeveloppmentVersion, commandResult );
559                     // Commit Plugin xml modification version
560                     cvsService.updateBranch( context, component.getBranchReleaseFrom( ), locale,
561                             "[site-release] Update plugin version to " + strComponentReleaseNewDeveloppmentVersion + " for " + strComponentName );
562 
563                     commandResult.getLog( ).append( "Plugin XML updated to " + strComponentReleaseNewDeveloppmentVersion + "\n" );
564                 }
565             }
566             // PROGRESS 65%
567             commandResult.setProgressValue( commandResult.getProgressValue( ) + 15 );
568 
569             ReleaserUtils.logEndAction( context, " Release Prepare" );
570 
571         }
572         catch( AppException ex )
573         {
574 
575             cvsService.rollbackRelease( context, locale );
576             throw ex;
577         }
578 
579     }
580 
581     /**
582      * Release perform component.
583      *
584      * @param context
585      *            the context
586      * @param locale
587      *            the locale
588      */
589     public void releasePerformComponent( WorkflowReleaseContext context, Locale locale )
590     {
591 
592         CommandResult commandResult = context.getCommandResult( );
593         String strLogin = context.getReleaserUser( ).getCredential( context.getReleaserResource( ).getRepoType( ) ).getLogin( );
594         String strPassword = context.getReleaserUser( ).getCredential( context.getReleaserResource( ).getRepoType( ) ).getPassword( );
595         IVCSResourceService cvsService = CVSFactoryService.getService( context.getComponent( ).getRepoType( ) );
596 
597         ReleaserUtils.logStartAction( context, " Release Perform" );
598 
599         String strLocalComponentPath = ReleaserUtils.getLocalPath( context );
600 
601         // PROGRESS 75%
602         commandResult.setProgressValue( commandResult.getProgressValue( ) + 10 );
603 
604         try
605         {
606         	
607 
608         		MavenService.getService( ).mvnReleasePerform( strLocalComponentPath, strLogin, strPassword, commandResult,context.getComponent().getRepoType( ).equals(RepositoryType.GITLAB) );
609         		
610         		
611 
612         }
613         catch( AppException ex )
614         {
615             cvsService.rollbackRelease( context, locale );
616             throw ex;
617         }
618         ReleaserUtils.logEndAction( context, " Release Perform" );
619     }
620 
621     /**
622      * Checkout repository.
623      *
624      * @param context
625      *            the context
626      * @param locale
627      *            the locale
628      */
629     public void checkoutRepository( WorkflowReleaseContext context, Locale locale )
630     {
631         CommandResult commandResult = context.getCommandResult( );
632         String strLogin = context.getReleaserUser( ).getCredential( context.getReleaserResource( ).getRepoType( ) ).getLogin( );
633         String strPassword = context.getReleaserUser( ).getCredential( context.getReleaserResource( ).getRepoType( ) ).getPassword( );
634 
635         ReleaserUtils.logStartAction( context, " checkout resource" );
636         CVSFactoryService.getService( context.getReleaserResource( ).getRepoType( ) ).doCheckoutRepository( context, strLogin, strPassword );
637         // PROGRESS 30%
638         commandResult.setProgressValue( commandResult.getProgressValue( ) + 30 );
639 
640         ReleaserUtils.logEndAction( context, " checkout resource" );
641 
642     }
643 
644     /**
645      * Release prepare site.
646      *
647      * @param context
648      *            the context
649      * @param locale
650      *            the locale
651      */
652     public void releasePrepareSite( WorkflowReleaseContext context, Locale locale )
653     {
654 
655         IVCSResourceService cvsService = CVSFactoryService.getService( context.getSite( ).getRepoType( ) );
656         String strLogin = context.getReleaserUser( ).getCredential( context.getSite( ).getRepoType( ) ).getLogin( );
657         String strPassword = context.getReleaserUser( ).getCredential( context.getSite( ).getRepoType( ) ).getPassword( );
658         String strSitePomLocalBasePath = ReleaserUtils.getLocalPomPath( context );
659 
660         CommandResult commandResult = context.getCommandResult( );
661         String componentTyeName = context.getSite( ).isTheme( ) ? "Theme " : "Site";
662 
663         ReleaserUtils.logStartAction( context, " Release perpare " + componentTyeName );
664 
665         commandResult.getLog( ).append( "Starting Action Release " + componentTyeName + "...\n" );
666 
667         commandResult.getLog( ).append( "Preparing release " + componentTyeName + "\n" );
668         commandResult.getLog( ).append( "Updating pom version to " + context.getSite( ).getNextReleaseVersion( ) + "...\n" );
669         commandResult.getLog( ).append( "Updating dependency version ...\n" );
670         try
671         {
672             PomUpdater.updateSiteBeforeTag( context.getSite( ), ReleaserUtils.getLocalPomPath( context ) );
673             cvsService.updateDevelopBranch( context, locale, "[site-release] update pom before tag" );
674 
675             // PROGRESS 30%
676             commandResult.setProgressValue( commandResult.getProgressValue( ) + 30 );
677 
678             commandResult.getLog( ).append( "Pom updated\n" );
679             commandResult.getLog( ).append( "Release prepare " + componentTyeName + " " + context.getSite( ).getNextReleaseVersion( ) + "...\n" );
680 
681             MavenService.getService( ).mvnReleasePrepare( strSitePomLocalBasePath, context.getSite( ).getNextReleaseVersion( ),
682                     context.getSite( ).getArtifactId( ) + "-" + context.getSite( ).getNextReleaseVersion( ), context.getSite( ).getNextSnapshotVersion( ),
683                     strLogin, strPassword, commandResult );
684 
685             commandResult.getLog( ).append( "End Release prepare " + componentTyeName + " " + context.getSite( ).getNextReleaseVersion( ) + "...\n" );
686 
687             // Merge Master
688             cvsService.updateMasterBranch( context, locale );
689             // checkout/pull develop branch after prepare
690             cvsService.checkoutDevelopBranch( context, locale );
691 
692             // PROGRESS 20%
693             commandResult.setProgressValue( commandResult.getProgressValue( ) + 20 );
694 
695             commandResult.getLog( ).append( "Updating pom after release prepare \n" );
696 
697             PomUpdater.updateSiteAfterTag( context.getSite( ), ReleaserUtils.getLocalPomPath( context ) );
698             cvsService.updateDevelopBranch( context, locale, "[site-release] update Updating pom to next development" );
699             commandResult.getLog( ).append( "Pom updated\n" );
700 
701         }
702 
703         catch( JAXBException e )
704         {
705             ReleaserUtils.addTechnicalError( commandResult, "error during update pom", e );
706         }
707         catch( AppException ex )
708         {
709 
710             cvsService.rollbackRelease( context, locale );
711             throw ex;
712         }
713 
714         ReleaserUtils.logEndAction( context, " Release prepare " + componentTyeName );
715 
716     }
717 
718     /**
719      * Send tweet.
720      *
721      * @param context
722      *            the context
723      * @param locale
724      *            the locale
725      */
726     public void sendTweet( WorkflowReleaseContext context, Locale locale )
727     {
728 
729         CommandResult commandResult = context.getCommandResult( );
730 
731         ReleaserUtils.logStartAction( context, " send Tweet" );
732 
733         TwitterService.getService( ).sendTweet( context.getComponent( ).getTweetMessage( ), commandResult );
734 
735         ReleaserUtils.logEndAction( context, " send Tweet" );
736 
737     }
738 
739     /**
740      * Update jira versions.
741      *
742      * @param context
743      *            the context
744      * @param locale
745      *            the locale
746      */
747     public void updateJiraVersions( WorkflowReleaseContext context, Locale locale )
748     {
749 
750         CommandResult commandResult = context.getCommandResult( );
751 
752         ReleaserUtils.logStartAction( context, " Update Jira Versions" );
753 
754         JiraComponentService.getService( ).updateComponentVersions( context.getComponent( ), commandResult );
755 
756         ReleaserUtils.logEndAction( context, " Update Jira Versions" );
757 
758     }
759 
760     /**
761      * Start workflow release context.
762      *
763      * @param context
764      *            the context
765      * @param nIdWorkflow
766      *            the n id workflow
767      * @param locale
768      *            the locale
769      * @param request
770      *            the request
771      * @param user
772      *            the user
773      */
774     public void startWorkflowReleaseContext( WorkflowReleaseContext context, int nIdWorkflow, Locale locale, HttpServletRequest request, AdminUser user )
775     {
776         _executor.execute( new ReleaseComponentTask( nIdWorkflow, context, request, user, locale ) );
777     }
778 
779     /**
780      * Inits the.
781      */
782     public void init( )
783     {
784 
785         _executor = Executors.newFixedThreadPool( AppPropertiesService.getPropertyInt( ConstanteUtils.PROPERTY_THREAD_RELEASE_POOL_MAX_SIZE, 5 ) );
786 
787     }
788 
789     /**
790      * Start release in progress.
791      *
792      * @param strArtifactId
793      *            the str artifact id
794      */
795     public void startReleaseInProgress( String strArtifactId )
796     {
797 
798         _releaseInProgress.add( strArtifactId );
799     }
800 
801     /**
802      * Stop release in progress.
803      *
804      * @param strArtifactId
805      *            the str artifact id
806      */
807     public void stopReleaseInProgress( String strArtifactId )
808     {
809 
810         _releaseInProgress.remove( strArtifactId );
811     }
812 
813     /**
814      * Checks if is release in progress.
815      *
816      * @param strArtifactId
817      *            the str artifact id
818      * @return true, if is release in progress
819      */
820     public boolean isReleaseInProgress( String strArtifactId )
821     {
822 
823         return _releaseInProgress.contains( strArtifactId );
824     }
825 
826     /**
827      * Release perform site.
828      *
829      * @param context
830      *            the context
831      * @param locale
832      *            the locale
833      */
834     @Override
835     public void releasePerformSite( WorkflowReleaseContext context, Locale locale )
836     {
837         CommandResult commandResult = context.getCommandResult( );
838         String strLogin = context.getReleaserUser( ).getCredential( context.getReleaserResource( ).getRepoType( ) ).getLogin( );
839         String strPassword = context.getReleaserUser( ).getCredential( context.getReleaserResource( ).getRepoType( ) ).getPassword( );
840         IVCSResourceService cvsService = CVSFactoryService.getService( context.getReleaserResource( ).getRepoType( ) );
841 
842         if ( context.getSite( ).isTheme( ) )
843         {
844             ReleaserUtils.logStartAction( context, " Release Perform" );
845 
846             String strLocalComponentPath = ReleaserUtils.getLocalPath( context );
847 
848             // PROGRESS 75%
849             commandResult.setProgressValue( commandResult.getProgressValue( ) + 10 );
850 
851             try
852             {
853 
854                 MavenService.getService( ).mvnReleasePerform( strLocalComponentPath, strLogin, strPassword, commandResult,true );
855 
856             }
857             catch( AppException ex )
858             {
859                 cvsService.rollbackRelease( context, locale );
860                 throw ex;
861             }
862             ReleaserUtils.logEndAction( context, " Release Perform" );
863         }
864         else
865         {
866             commandResult.getLog( ).append( "No release Perform for Site" );
867         }
868     }
869 
870 }