View Javadoc

1   package org.apache.maven.continuum.project.builder;
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.HashMap;
25  import java.util.List;
26  import java.util.Map;
27  
28  import org.apache.maven.continuum.model.project.Project;
29  import org.apache.maven.continuum.model.project.ProjectGroup;
30  
31  /**
32   * Holder for results of adding projects to Continuum. Contains added projects, project groups
33   * and errors that happened during the add.
34   *
35   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
36   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
37   * @version $Id: ContinuumProjectBuildingResult.java 777411 2009-05-22 07:13:37Z ctan $
38   */
39  public class ContinuumProjectBuildingResult
40  {
41      public static final String ERROR_MALFORMED_URL = "add.project.malformed.url.error";
42  
43      public static final String ERROR_UNKNOWN_HOST = "add.project.unknown.host.error";
44  
45      public static final String ERROR_CONNECT = "add.project.connect.error";
46  
47      public static final String ERROR_XML_PARSE = "add.project.xml.parse.error";
48  
49      public static final String ERROR_EXTEND = "add.project.extend.error";
50  
51      public static final String ERROR_MISSING_GROUPID = "add.project.missing.groupid.error";
52  
53      public static final String ERROR_MISSING_ARTIFACTID = "add.project.missing.artifactid.error";
54  
55      public static final String ERROR_POM_NOT_FOUND = "add.project.missing.pom.error";
56  
57      public static final String ERROR_MISSING_VERSION = "add.project.missing.version.error";
58  
59      public static final String ERROR_MISSING_NAME = "add.project.missing.name.error";
60  
61      public static final String ERROR_MISSING_REPOSITORY = "add.project.missing.repository.error";
62  
63      public static final String ERROR_MISSING_SCM = "add.project.missing.scm.error";
64  
65      public static final String ERROR_MISSING_SCM_CONNECTION = "add.project.missing.scm.connection.error";
66  
67      public static final String ERROR_MISSING_NOTIFIER_TYPE = "add.project.missing.notifier.type.error";
68  
69      public static final String ERROR_MISSING_NOTIFIER_CONFIGURATION = "add.project.missing.notifier.configuration.error"
70          ;
71  
72      public static final String ERROR_METADATA_TRANSFER = "add.project.metadata.transfer.error";
73  
74      public static final String ERROR_VALIDATION = "add.project.validation.error";
75  
76      public static final String ERROR_UNAUTHORIZED = "add.project.unauthorized.error";
77  
78      public static final String ERROR_PROTOCOL_NOT_ALLOWED = "add.project.validation.protocol.not_allowed";
79  
80      public static final String ERROR_ARTIFACT_NOT_FOUND = "add.project.artifact.not.found.error";
81  
82      public static final String ERROR_PROJECT_BUILDING = "add.project.project.building.error";
83  
84      public static final String ERROR_UNKNOWN = "add.project.unknown.error";
85  
86      public static final String ERROR_DUPLICATE_PROJECTS = "add.project.duplicate.error";
87  
88      private final List<Project> projects = new ArrayList<Project>();
89  
90      private final List<ProjectGroup> projectGroups = new ArrayList<ProjectGroup>();
91  
92      private final Map<String, String> errors = new HashMap<String, String>();
93  
94      private static final String LS = System.getProperty( "line.separator" );
95  
96      public void addProject( Project project )
97      {
98          projects.add( project );
99      }
100 
101     public void addProjectGroup( ProjectGroup projectGroup )
102     {
103         projectGroups.add( projectGroup );
104     }
105 
106     public void addProject( Project project, String executorId )
107     {
108         project.setExecutorId( executorId );
109 
110         projects.add( project );
111     }
112 
113     public List<Project> getProjects()
114     {
115         return projects;
116     }
117 
118     public List<ProjectGroup> getProjectGroups()
119     {
120         return projectGroups;
121     }
122 
123     /**
124      * Add a warning that happened during adding the project to Continuum.
125      *
126      * @param warningKey warning id (so it can be internationalized later)
127      * @deprecated Use {@link #addError(String)} instead
128      */
129     public void addWarning( String warningKey )
130     {
131         addError( warningKey );
132     }
133 
134     /**
135      * Add an error that happened during adding the project to Continuum.
136      *
137      * @param errorKey error id (so it can be internationalized later)
138      */
139     public void addError( String errorKey )
140     {
141         errors.put( errorKey, "" );
142     }
143 
144     /**
145      * Add an error that happened during adding the project to Continuum.
146      *
147      * @param errorKey error id (so it can be internationalized later)
148      */
149     public void addError( String errorKey, Object param )
150     {
151         errors.put( errorKey, param == null ? "" : param.toString() );
152     }
153 
154     /**
155      * Add an error that happened during adding the project to Continuum.
156      *
157      * @param errorKey error id (so it can be internationalized later)
158      */
159     public void addError( String errorKey, Object params[] )
160     {
161         if ( params != null )
162         {
163             errors.put( errorKey, Arrays.asList( params ).toString() );
164         }
165     }
166 
167     /**
168      * Get the warnings that happened during adding the project to Continuum.
169      * There is an entry with the warning key (so it can be internationalized later) for each warning.
170      *
171      * @return {@link List} &lt; {@link String} >
172      * @deprecated Use {@link #getErrors()} instead
173      */
174     public List<String> getWarnings()
175     {
176         return getErrors();
177     }
178 
179     /**
180      * Get the errors that happened during adding the project to Continuum.
181      * There is an entry with the error key (so it can be internationalized later) for each error.
182      *
183      * @return {@link List} &lt; {@link String} >
184      */
185     public List<String> getErrors()
186     {
187         return new ArrayList<String>( errors.keySet() );
188     }
189 
190     public Map<String, String> getErrorsWithCause()
191     {
192         return errors;
193     }
194 
195     /**
196      * Quick check to see if there are any errors.
197      *
198      * @return boolean indicating if there are any errors.
199      */
200     public boolean hasErrors()
201     {
202         return ( errors != null ) && ( !errors.isEmpty() );
203     }
204 
205     /**
206      * Returns a string representation of the errors.
207      *
208      * @return a string representation of the errors.
209      */
210     public String getErrorsAsString()
211     {
212         if ( !hasErrors() )
213         {
214             return null;
215         }
216 
217         StringBuilder message = new StringBuilder();
218         for ( String key : errors.keySet() )
219         {
220             message.append( errors.get( key ) );
221             message.append( LS );
222         }
223         return message.toString();
224     }
225 }