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.releaser.service; |
35 | |
|
36 | |
import java.io.File; |
37 | |
import java.util.ArrayList; |
38 | |
import java.util.List; |
39 | |
|
40 | |
import org.apache.commons.lang.StringUtils; |
41 | |
import org.apache.maven.shared.invoker.DefaultInvocationRequest; |
42 | |
import org.apache.maven.shared.invoker.DefaultInvoker; |
43 | |
import org.apache.maven.shared.invoker.InvocationOutputHandler; |
44 | |
import org.apache.maven.shared.invoker.InvocationRequest; |
45 | |
import org.apache.maven.shared.invoker.InvocationResult; |
46 | |
import org.apache.maven.shared.invoker.Invoker; |
47 | |
|
48 | |
import fr.paris.lutece.plugins.releaser.util.CommandResult; |
49 | |
import fr.paris.lutece.plugins.releaser.util.ConstanteUtils; |
50 | |
import fr.paris.lutece.plugins.releaser.util.ReleaserUtils; |
51 | |
import fr.paris.lutece.plugins.releaser.util.maven.MavenGoals; |
52 | |
import fr.paris.lutece.plugins.releaser.util.maven.MavenUtils; |
53 | |
import fr.paris.lutece.plugins.releaser.util.svn.SvnUser; |
54 | |
import fr.paris.lutece.portal.service.spring.SpringContextService; |
55 | |
import fr.paris.lutece.portal.service.util.AppPropertiesService; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public class MavenService implements IMavenService |
63 | |
{ |
64 | |
|
65 | |
private Invoker _invoker; |
66 | |
private static IMavenService _instance; |
67 | |
|
68 | |
|
69 | |
private MavenService( ) |
70 | 1 | { |
71 | |
|
72 | 1 | } |
73 | |
|
74 | |
public static IMavenService getService() |
75 | |
{ |
76 | 0 | if(_instance==null) |
77 | |
{ |
78 | 0 | _instance=SpringContextService.getBean(ConstanteUtils.BEAN_MAVEN_SERVICE ); |
79 | 0 | _instance.init( ); |
80 | |
} |
81 | |
|
82 | 0 | return _instance; |
83 | |
|
84 | |
} |
85 | |
|
86 | |
public void init( ) |
87 | |
{ |
88 | 0 | _invoker = new DefaultInvoker( ); |
89 | 0 | _invoker.setMavenHome( new File( AppPropertiesService.getProperty( ConstanteUtils.PROPERTY_MAVEN_HOME_PATH ) ) ); |
90 | 0 | _invoker.setLocalRepositoryDirectory( new File( AppPropertiesService.getProperty( ConstanteUtils.PROPERTY_MAVEN_LOCAL_REPOSITORY ) ) ); |
91 | |
|
92 | 0 | } |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
public void mvnSiteAssembly( String strSiteName, String strTagName, String strMavenProfile, SvnUser user, CommandResult commandResult ) |
101 | |
{ |
102 | 0 | String strSiteLocalBasePath = ReleaserUtils.getLocalSitePath( strSiteName ); |
103 | |
|
104 | 0 | List<String> listGoals = MavenGoals.LUTECE_SITE_ASSEMBLY.asList( ); |
105 | 0 | List<String> listGoalsProfile = new ArrayList<String>( ); |
106 | 0 | listGoalsProfile.addAll( listGoals ); |
107 | 0 | listGoalsProfile.add( "-P " + strMavenProfile ); |
108 | 0 | listGoalsProfile.add( "-U" ); |
109 | |
|
110 | 0 | } |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
private InvocationResult mvnExecute( String strPathPom, List<String> goals, CommandResult commandResult ) |
145 | |
{ |
146 | 0 | InvocationRequest request = new DefaultInvocationRequest( ); |
147 | 0 | request.setPomFile( new File( strPathPom ) ); |
148 | 0 | request.setGoals( goals ); |
149 | 0 | String strProxyHost=AppPropertiesService.getProperty( ConstanteUtils.PROPERTY_PROXY_HOST ); |
150 | 0 | String strProxyPort=AppPropertiesService.getProperty( ConstanteUtils.PROPERTY_PROXY_PORT ); |
151 | |
|
152 | 0 | if(!StringUtils.isEmpty( strProxyHost ) && !StringUtils.isEmpty( strProxyPort )) |
153 | |
{ |
154 | 0 | request.setMavenOpts( "-Dhttps.proxyHost="+strProxyHost+" -Dhttps.proxyPort="+strProxyPort+" -Dhttp.proxyHost="+strProxyHost+" -Dhttp.proxyPort="+strProxyPort); |
155 | |
} |
156 | 0 | InvocationResult invocationResult = null; |
157 | |
try |
158 | |
{ |
159 | 0 | final StringBuffer sbLog = commandResult.getLog( ); |
160 | |
|
161 | |
|
162 | 0 | _invoker.setOutputHandler( new InvocationOutputHandler( ) |
163 | 0 | { |
164 | |
public void consumeLine( String strLine ) |
165 | |
{ |
166 | 0 | sbLog.append( strLine + "\n" ); |
167 | 0 | } |
168 | |
} ); |
169 | |
|
170 | 0 | invocationResult = _invoker.execute( request ); |
171 | |
|
172 | 0 | return invocationResult; |
173 | |
|
174 | |
} |
175 | 0 | catch( Exception e ) |
176 | |
{ |
177 | |
|
178 | 0 | ReleaserUtils.addTechnicalError( commandResult, commandResult.getLog( ).toString( ), e ); |
179 | |
} |
180 | |
|
181 | 0 | return invocationResult; |
182 | |
} |
183 | |
|
184 | |
public String mvnReleasePerform( String strPathPom,String strUsername, String strPassword, CommandResult commandResult ) |
185 | |
{ |
186 | 0 | InvocationResult invocationResult = mvnExecute( strPathPom, MavenGoals.RELEASE_PERFORM.asList( ), commandResult ); |
187 | 0 | int nStatus = invocationResult.getExitCode( ); |
188 | |
|
189 | 0 | if ( nStatus != 0 ) |
190 | |
{ |
191 | 0 | ReleaserUtils.addTechnicalError( commandResult, "Error during Release Perform exit code is: " + nStatus ); |
192 | |
} |
193 | |
|
194 | 0 | return ""; |
195 | |
} |
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
public String mvnReleasePrepare( String strPathPom, String strReleaseVersion, String strTag, String strDevelopmentVersion, String strUsername, |
214 | |
String strPassword, CommandResult commandResult ) |
215 | |
{ |
216 | 0 | List<String> listGoals = MavenUtils.createReleasePrepare( strReleaseVersion, strTag, strDevelopmentVersion, strUsername, strPassword ); |
217 | |
|
218 | 0 | InvocationResult invocationResult = mvnExecute( strPathPom, listGoals, commandResult ); |
219 | |
|
220 | 0 | int nStatus = invocationResult.getExitCode( ); |
221 | |
|
222 | 0 | if ( nStatus != 0 ) |
223 | |
{ |
224 | 0 | ReleaserUtils.addTechnicalError( commandResult, "Error during Release Prepare exit code is: " + nStatus ); |
225 | |
} |
226 | |
|
227 | 0 | return ""; |
228 | |
} |
229 | |
|
230 | |
} |