1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.deployment.service.vcs;
35
36 import fr.paris.lutece.plugins.deployment.business.CommandResult;
37 import fr.paris.lutece.plugins.deployment.business.vcs.GitUser;
38 import fr.paris.lutece.plugins.deployment.util.ConstanteUtils;
39 import fr.paris.lutece.plugins.deployment.util.DeploymentUtils;
40 import fr.paris.lutece.plugins.deployment.util.FileUtil;
41 import fr.paris.lutece.plugins.deployment.util.vcs.GitUtils;
42 import fr.paris.lutece.portal.service.util.AppPropertiesService;
43 import fr.paris.lutece.util.ReferenceItem;
44 import fr.paris.lutece.util.ReferenceList;
45 import java.util.Collection;
46 import java.util.List;
47 import java.util.regex.Matcher;
48 import java.util.regex.Pattern;
49 import org.apache.commons.lang3.StringUtils;
50 import org.eclipse.jgit.api.Git;
51
52 public class AbstractGitService implements IVCSService<GitUser>
53 {
54
55 @Override
56 public void init( )
57 {
58 throw new UnsupportedOperationException( "Not supported yet." );
59 }
60
61 @Override
62 public ReferenceList getTagsSite( String strUrlSite, GitUser user, String strSiteName )
63 {
64 String strClonePath = DeploymentUtils.getPathCheckoutSite( strSiteName );
65 CommandResult commandResult = new CommandResult( );
66 DeploymentUtils.startCommandResult( commandResult );
67 Git git = GitUtils.cloneOrReturnGit( strClonePath, strUrlSite, commandResult, user, null, null );
68 Collection<String> listTagName = GitUtils.getTagNameList( git );
69
70 ReferenceList refList = new ReferenceList( );
71 for ( String strTagName : listTagName )
72 {
73 ReferenceItem item = new ReferenceItem( );
74 item.setName( strTagName );
75 item.setCode( strTagName );
76 refList.add( item );
77 }
78 DeploymentUtils.stopCommandResult( commandResult );
79 return refList;
80 }
81
82 @Override
83 public String doCheckoutSite( String strSiteName, String strUrl, GitUser user, CommandResult commandResult, String strBranch, String strTagName )
84 {
85 String strClonePath = DeploymentUtils.getPathCheckoutSite( strSiteName );
86 GitUtils.cloneOrReturnGit( strClonePath, strUrl, commandResult, user, strBranch, strTagName );
87
88 return StringUtils.EMPTY;
89 }
90
91 @Override
92 public ReferenceList getUpgradesFiles( String strSiteName, String strUrlSite, GitUser user )
93 {
94 CommandResult commandResult = new CommandResult( );
95 DeploymentUtils.startCommandResult( commandResult );
96 ReferenceList upgradeResults = new ReferenceList( );
97
98 doCheckoutSite( strSiteName, strUrlSite, user, commandResult, ConstanteUtils.CONSTANTE_BRANCH_DEVELOP, null );
99
100 List<String> listUpgradeFiles = FileUtil.list( DeploymentUtils.getPathUpgradeFiles( DeploymentUtils.getPathCheckoutSite( strSiteName ) ), "sql" );
101
102 for ( String upgradeFile : listUpgradeFiles )
103 {
104 upgradeResults.addItem( upgradeFile, upgradeFile );
105 }
106
107 DeploymentUtils.stopCommandResult( commandResult );
108
109 return upgradeResults;
110
111 }
112
113 @Override
114 public String getArtifactId( String strPathRepo )
115 {
116 String strRegexExtractArtifact = AppPropertiesService.getProperty( ConstanteUtils.REGEX_GIT_EXTRACT_ARTIFACT_FROM_URL );
117 Pattern r = Pattern.compile( strRegexExtractArtifact );
118 String strArtifactId = null;
119
120 Matcher m = r.matcher( strPathRepo );
121 if ( m.find( ) )
122 {
123 strArtifactId = m.group( 2 );
124 }
125 return strArtifactId;
126 }
127
128 @Override
129 public boolean isPrivate( )
130 {
131 return true;
132 }
133
134 @Override
135 public void checkAuthentication( String strRepoUrl, GitUser user )
136 {
137 }
138 }