View Javadoc

1   package org.apache.continuum.release.distributed;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Arrays;
24  import java.util.List;
25  import java.util.Map;
26  
27  public class DistributedReleaseUtil
28  {
29      public static final String KEY_SCM_TAG = "scm-tag";
30  
31      public static final String KEY_SCM_TAGBASE = "scm-tagbase";
32  
33      public static final String KEY_SCM_USERNAME = "scm-username";
34  
35      public static final String KEY_SCM_PASSWORD = "scm-password";
36  
37      public static final String KEY_ARGUMENTS = "arguments";
38  
39      public static final String KEY_PREPARE_GOALS = "preparation-goals";
40  
41      public static final String KEY_PERFORM_GOALS = "perform-goals";
42  
43      public static final String KEY_SCM_COMMENT_PREFIX = "scm-comment-prefix";
44  
45      public static final String KEY_AUTO_VERSION_SUBMODULES = "auto-version-submodules";
46  
47      public static final String KEY_ADD_SCHEMA = "add-schema";
48  
49      public static final String KEY_PROJECT = "project";
50  
51      public static final String KEY_PROFILE = "profile";
52  
53      public static final String KEY_PROPERTIES = "properties";
54  
55      public static final String KEY_RELEASE_VERSION = "releaseVersion";
56  
57      public static final String KEY_DEVELOPMENT_VERSION = "developmentVersion";
58  
59      public static final String KEY_PROJECT_ID = "project-id";
60  
61      public static final String KEY_GROUP_ID = "group-id";
62  
63      public static final String KEY_ARTIFACT_ID = "artifact-id";
64  
65      public static final String KEY_SCM_URL = "scm-url";
66  
67      public static final String KEY_LOCAL_REPOSITORY = "local-repository";
68  
69      public static final String KEY_USE_EDIT_MODE = "use-edit-mode";
70  
71      public static final String KEY_ENVIRONMENTS = "environments";
72  
73      public static final String KEY_START_TIME = "start-time";
74  
75      public static final String KEY_END_TIME = "end-time";
76  
77      public static final String KEY_RELEASE_RESULT_CODE = "release-result-code";
78  
79      public static final String KEY_RELEASE_OUTPUT = "release-output";
80  
81      public static final String KEY_RELEASE_STATE = "state";
82  
83      public static final String KEY_RELEASE_PHASES = "release-phases";
84  
85      public static final String KEY_COMPLETED_RELEASE_PHASES = "completed-release-phases";
86  
87      public static final String KEY_RELEASE_IN_PROGRESS = "release-in-progress";
88  
89      public static final String KEY_RELEASE_ERROR = "release-error";
90  
91      public static final String KEY_USE_RELEASE_PROFILE = "use-release-profile";
92  
93      public static final String KEY_GOALS = "goals";
94  
95      public static final String KEY_RELEASE_ID = "release-id";
96  
97      public static final String KEY_LOCAL_REPOSITORY_NAME = "repo-name";
98  
99      public static final String KEY_LOCAL_REPOSITORY_LAYOUT = "repo-layout";
100 
101     public static final String KEY_RELEASE_GOAL = "release-goal";
102 
103     public static final String KEY_BUILD_AGENT_URL = "build-agent-url";
104 
105     public static final String KEY_USERNAME = "username";
106 
107     public static String getScmTag( Map<String, Object> context, String defaultValue )
108     {
109         return getString( context, KEY_SCM_TAG, defaultValue );
110     }
111 
112     public static String getScmTagBase( Map<String, Object> context, String defaultValue )
113     {
114         return getString( context, KEY_SCM_TAGBASE, defaultValue );
115     }
116 
117     public static String getArguments( Map<String, Object> context, String defaultValue )
118     {
119         return getString( context, KEY_ARGUMENTS, defaultValue );
120     }
121 
122     public static String getPrepareGoals( Map<String, Object> context, String defaultValue )
123     {
124         return getString( context, KEY_PREPARE_GOALS, defaultValue );
125     }
126 
127     public static String getPerformGoals( Map<String, Object> context, String defaultValue )
128     {
129         return getString( context, KEY_PERFORM_GOALS, defaultValue );
130     }
131 
132     public static String getScmCommentPrefix( Map<String, Object> context, String defaultValue )
133     {
134         return getString( context, KEY_SCM_COMMENT_PREFIX, defaultValue );
135     }
136 
137     public static Boolean getAutoVersionSubmodules( Map<String, Object> context, boolean defaultValue )
138     {
139         return getBoolean( context, KEY_AUTO_VERSION_SUBMODULES, defaultValue );
140     }
141 
142     public static Boolean getAddSchema( Map<String, Object> context, boolean defaultValue )
143     {
144         return getBoolean( context, KEY_ADD_SCHEMA, defaultValue );
145     }
146 
147     public static Long getStartTime( Map<String, Object> context )
148     {
149         return new Long( getString( context, KEY_START_TIME ) );
150     }
151 
152     public static Long getEndTime( Map<String, Object> context )
153     {
154         return new Long( getString( context, KEY_END_TIME ) );
155     }
156 
157     public static int getReleaseResultCode( Map<String, Object> context )
158     {
159         return getInteger( context, KEY_RELEASE_RESULT_CODE );
160     }
161 
162     public static String getReleaseOutput( Map<String, Object> context )
163     {
164         return getString( context, KEY_RELEASE_OUTPUT );
165     }
166 
167     public static int getReleaseState( Map<String, Object> context )
168     {
169         return getInteger( context, KEY_RELEASE_STATE );
170     }
171 
172     public static List getReleasePhases( Map<String, Object> context )
173     {
174         return getList( context, KEY_RELEASE_PHASES, new ArrayList() );
175     }
176 
177     public static List getCompletedReleasePhases( Map<String, Object> context )
178     {
179         return getList( context, KEY_COMPLETED_RELEASE_PHASES, new ArrayList() );
180     }
181 
182     public static String getReleaseInProgress( Map<String, Object> context )
183     {
184         return getString( context, KEY_RELEASE_IN_PROGRESS, "" );
185     }
186 
187     public static String getReleaseError( Map<String, Object> context )
188     {
189         return getString( context, KEY_RELEASE_ERROR, null );
190     }
191 
192     public static boolean getUseReleaseProfile( Map<String, Object> context, boolean defaultValue )
193     {
194         return getBoolean( context, KEY_USE_RELEASE_PROFILE, defaultValue );
195     }
196 
197     public static String getGoals( Map<String, Object> context, String defaultValue )
198     {
199         return getString( context, KEY_GOALS, defaultValue );
200     }
201 
202     public static String getReleaseId( Map<String, Object> context )
203     {
204         return getString( context, KEY_RELEASE_ID );
205     }
206 
207     public static String getReleaseGoal( Map<String, Object> context )
208     {
209         return getString( context, KEY_RELEASE_GOAL );
210     }
211 
212     public static String getBuildAgentUrl( Map<String, Object> context )
213     {
214         return getString( context, KEY_BUILD_AGENT_URL );
215     }
216 
217     public static int getProjectId( Map<String, Object> context )
218     {
219         return getInteger( context, KEY_PROJECT_ID );
220     }
221 
222     public static String getUsername( Map<String, Object> context )
223     {
224         return getString( context, KEY_USERNAME, "" );
225     }
226 
227     // ----------------------------------------------------------------------
228     //
229     // ----------------------------------------------------------------------
230 
231     public static Integer getInteger( Map<String, Object> context, String key )
232     {
233         return (Integer) getObject( context, key );
234     }
235 
236     public static Integer getInteger( Map<String, Object> context, String key, Object defaultValue )
237     {
238         return (Integer) getObject( context, key, defaultValue );
239     }
240 
241     public static String getString( Map<String, Object> context, String key )
242     {
243         return (String) getObject( context, key );
244     }
245 
246     public static String getString( Map<String, Object> context, String key, String defaultValue )
247     {
248         return (String) getObject( context, key, defaultValue );
249     }
250 
251     public static boolean getBoolean( Map<String, Object> context, String key )
252     {
253         return (Boolean) getObject( context, key );
254     }
255 
256     public static boolean getBoolean( Map<String, Object> context, String key, boolean defaultValue )
257     {
258         return (Boolean) getObject( context, key, defaultValue );
259     }
260 
261     public static List getList( Map<String, Object> context, String key, Object defaultValue )
262     {
263         Object obj = getObject( context, key, defaultValue );
264 
265         if ( obj == null )
266         {
267             return null;
268         }
269         else
270         {
271             List<Object> list = new ArrayList<Object>();
272 
273             if ( obj instanceof Object[] )
274             {
275                 Object[] objA = (Object[]) obj;
276 
277                 list.addAll( Arrays.asList( objA ) );
278             }
279             else
280             {
281                 list = (List<Object>) obj;
282             }
283 
284             return list;
285         }
286     }
287 
288     protected static Object getObject( Map<String, Object> context, String key )
289     {
290         if ( !context.containsKey( key ) )
291         {
292             throw new RuntimeException( "Missing key '" + key + "'." );
293         }
294 
295         Object value = context.get( key );
296 
297         if ( value == null )
298         {
299             throw new RuntimeException( "Missing value for key '" + key + "'." );
300         }
301 
302         return value;
303     }
304 
305     protected static Object getObject( Map<String, Object> context, String key, Object defaultValue )
306     {
307         Object value = context.get( key );
308 
309         if ( value == null )
310         {
311             return defaultValue;
312         }
313 
314         return value;
315     }
316 }