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_SCM_COMMENT_PREFIX = "scm-comment-prefix";
42  
43      public static final String KEY_AUTO_VERSION_SUBMODULES = "auto-version-submodules";
44  
45      public static final String KEY_ADD_SCHEMA = "add-schema";
46  
47      public static final String KEY_PROJECT = "project";
48  
49      public static final String KEY_PROFILE = "profile";
50  
51      public static final String KEY_PROPERTIES = "properties";
52  
53      public static final String KEY_RELEASE_VERSION = "releaseVersion";
54  
55      public static final String KEY_DEVELOPMENT_VERSION = "developmentVersion";
56  
57      public static final String KEY_PROJECT_ID = "project-id";
58  
59      public static final String KEY_GROUP_ID = "group-id";
60  
61      public static final String KEY_ARTIFACT_ID = "artifact-id";
62  
63      public static final String KEY_SCM_URL = "scm-url";
64  
65      public static final String KEY_LOCAL_REPOSITORY = "local-repository";
66  
67      public static final String KEY_USE_EDIT_MODE = "use-edit-mode";
68  
69      public static final String KEY_ENVIRONMENTS = "environments";
70  
71      public static final String KEY_START_TIME = "start-time";
72  
73      public static final String KEY_END_TIME = "end-time";
74  
75      public static final String KEY_RELEASE_RESULT_CODE = "release-result-code";
76  
77      public static final String KEY_RELEASE_OUTPUT = "release-output";
78  
79      public static final String KEY_RELEASE_STATE = "state";
80  
81      public static final String KEY_RELEASE_PHASES = "release-phases";
82  
83      public static final String KEY_COMPLETED_RELEASE_PHASES = "completed-release-phases";
84  
85      public static final String KEY_RELEASE_IN_PROGRESS = "release-in-progress";
86  
87      public static final String KEY_RELEASE_ERROR = "release-error";
88  
89      public static final String KEY_USE_RELEASE_PROFILE = "use-release-profile";
90  
91      public static final String KEY_GOALS = "goals";
92  
93      public static final String KEY_RELEASE_ID = "release-id";
94  
95      public static final String KEY_LOCAL_REPOSITORY_NAME = "repo-name";
96  
97      public static final String KEY_LOCAL_REPOSITORY_LAYOUT = "repo-layout";
98  
99      public static final String KEY_RELEASE_GOAL = "release-goal";
100 
101     public static final String KEY_BUILD_AGENT_URL = "build-agent-url";
102 
103     public static String getScmTag( Map<String, Object> context, String defaultValue )
104     {
105         return getString( context, KEY_SCM_TAG, defaultValue );
106     }
107 
108     public static String getScmTagBase( Map<String, Object> context, String defaultValue )
109     {
110         return getString( context, KEY_SCM_TAGBASE, defaultValue );
111     }
112 
113     public static String getArguments( Map<String, Object> context, String defaultValue )
114     {
115         return getString( context, KEY_ARGUMENTS, defaultValue );
116     }
117 
118     public static String getPrepareGoals( Map<String, Object> context, String defaultValue )
119     {
120         return getString( context, KEY_PREPARE_GOALS, defaultValue );
121     }
122 
123     public static String getScmCommentPrefix( Map<String, Object> context, String defaultValue )
124     {
125         return getString( context, KEY_SCM_COMMENT_PREFIX, defaultValue );
126     }
127 
128     public static Boolean getAutoVersionSubmodules( Map<String, Object> context, boolean defaultValue )
129     {
130         return getBoolean( context, KEY_AUTO_VERSION_SUBMODULES, defaultValue );
131     }
132 
133     public static Boolean getAddSchema( Map<String, Object> context, boolean defaultValue )
134     {
135         return getBoolean( context, KEY_ADD_SCHEMA, defaultValue );
136     }
137 
138     public static Long getStartTime( Map<String, Object> context )
139     {
140         return new Long( getString( context, KEY_START_TIME ) );
141     }
142 
143     public static Long getEndTime( Map<String, Object> context )
144     {
145         return new Long( getString( context, KEY_END_TIME ) );
146     }
147 
148     public static int getReleaseResultCode( Map<String, Object> context )
149     {
150         return getInteger( context, KEY_RELEASE_RESULT_CODE );
151     }
152 
153     public static String getReleaseOutput( Map<String, Object> context )
154     {
155         return getString( context, KEY_RELEASE_OUTPUT );
156     }
157 
158     public static int getReleaseState( Map<String, Object> context )
159     {
160         return getInteger( context, KEY_RELEASE_STATE );
161     }
162 
163     public static List getReleasePhases( Map<String, Object> context )
164     {
165         return getList( context, KEY_RELEASE_PHASES, new ArrayList() );
166     }
167 
168     public static List getCompletedReleasePhases( Map<String, Object> context )
169     {
170         return getList( context, KEY_COMPLETED_RELEASE_PHASES, new ArrayList() );
171     }
172 
173     public static String getReleaseInProgress( Map<String, Object> context )
174     {
175         return getString( context, KEY_RELEASE_IN_PROGRESS, "" );
176     }
177 
178     public static String getReleaseError( Map<String, Object> context )
179     {
180         return getString( context, KEY_RELEASE_ERROR, null );
181     }
182 
183     public static boolean getUseReleaseProfile( Map<String, Object> context, boolean defaultValue )
184     {
185         return getBoolean( context, KEY_USE_RELEASE_PROFILE, defaultValue );
186     }
187 
188     public static String getGoals( Map<String, Object> context, String defaultValue )
189     {
190         return getString( context, KEY_GOALS, defaultValue );
191     }
192 
193     public static String getReleaseId( Map<String, Object> context )
194     {
195         return getString( context, KEY_RELEASE_ID );
196     }
197 
198     public static String getReleaseGoal( Map<String, Object> context )
199     {
200         return getString( context, KEY_RELEASE_GOAL );
201     }
202 
203     public static String getBuildAgentUrl( Map<String, Object> context )
204     {
205         return getString( context, KEY_BUILD_AGENT_URL );
206     }
207 
208     public static int getProjectId( Map<String, Object> context )
209     {
210         return getInteger( context, KEY_PROJECT_ID );
211     }
212 
213     // ----------------------------------------------------------------------
214     //
215     // ----------------------------------------------------------------------
216 
217     public static Integer getInteger( Map<String, Object> context, String key )
218     {
219         return (Integer) getObject( context, key );
220     }
221 
222     public static Integer getInteger( Map<String, Object> context, String key, Object defaultValue )
223     {
224         return (Integer) getObject( context, key, defaultValue );
225     }
226 
227     public static String getString( Map<String, Object> context, String key )
228     {
229         return (String) getObject( context, key );
230     }
231 
232     public static String getString( Map<String, Object> context, String key, String defaultValue )
233     {
234         return (String) getObject( context, key, defaultValue );
235     }
236 
237     public static boolean getBoolean( Map<String, Object> context, String key )
238     {
239         return (Boolean) getObject( context, key );
240     }
241 
242     public static boolean getBoolean( Map<String, Object> context, String key, boolean defaultValue )
243     {
244         return (Boolean) getObject( context, key, defaultValue );
245     }
246 
247     public static List getList( Map<String, Object> context, String key, Object defaultValue )
248     {
249         Object obj = getObject( context, key, defaultValue );
250 
251         if ( obj == null )
252         {
253             return null;
254         }
255         else
256         {
257             List<Object> list = new ArrayList<Object>();
258 
259             if ( obj instanceof Object[] )
260             {
261                 Object[] objA = (Object[]) obj;
262 
263                 list.addAll( Arrays.asList( objA ) );
264             }
265             else
266             {
267                 list = (List<Object>) obj;
268             }
269 
270             return list;
271         }
272     }
273 
274     protected static Object getObject( Map<String, Object> context, String key )
275     {
276         if ( !context.containsKey( key ) )
277         {
278             throw new RuntimeException( "Missing key '" + key + "'." );
279         }
280 
281         Object value = context.get( key );
282 
283         if ( value == null )
284         {
285             throw new RuntimeException( "Missing value for key '" + key + "'." );
286         }
287 
288         return value;
289     }
290 
291     protected static Object getObject( Map<String, Object> context, String key, Object defaultValue )
292     {
293         Object value = context.get( key );
294 
295         if ( value == null )
296         {
297             return defaultValue;
298         }
299 
300         return value;
301     }
302 }