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 org.apache.maven.continuum.model.project.Project;
23  import org.apache.maven.continuum.model.project.ProjectGroup;
24  
25  import java.util.ArrayList;
26  import java.util.Arrays;
27  import java.util.HashMap;
28  import java.util.List;
29  import java.util.Map;
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 1372260 2012-08-13 04:29:09Z brett $
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 =
70          "add.project.missing.notifier.configuration.error";
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      private Project rootProject;
97  
98      public void addProject( Project project )
99      {
100         projects.add( project );
101     }
102 
103     public void addProjectGroup( ProjectGroup projectGroup )
104     {
105         projectGroups.add( projectGroup );
106     }
107 
108     public void addProject( Project project, String executorId )
109     {
110         project.setExecutorId( executorId );
111 
112         projects.add( project );
113     }
114 
115     public List<Project> getProjects()
116     {
117         return projects;
118     }
119 
120     public List<ProjectGroup> getProjectGroups()
121     {
122         return projectGroups;
123     }
124 
125     /**
126      * Add a warning that happened during adding the project to Continuum.
127      *
128      * @param warningKey warning id (so it can be internationalized later)
129      * @deprecated Use {@link #addError(String)} instead
130      */
131     public void addWarning( String warningKey )
132     {
133         addError( warningKey );
134     }
135 
136     /**
137      * Add an error that happened during adding the project to Continuum.
138      *
139      * @param errorKey error id (so it can be internationalized later)
140      */
141     public void addError( String errorKey )
142     {
143         errors.put( errorKey, "" );
144     }
145 
146     /**
147      * Add an error that happened during adding the project to Continuum.
148      *
149      * @param errorKey error id (so it can be internationalized later)
150      */
151     public void addError( String errorKey, Object param )
152     {
153         errors.put( errorKey, param == null ? "" : param.toString() );
154     }
155 
156     /**
157      * Add an error that happened during adding the project to Continuum.
158      *
159      * @param errorKey error id (so it can be internationalized later)
160      */
161     public void addError( String errorKey, Object params[] )
162     {
163         if ( params != null )
164         {
165             errors.put( errorKey, Arrays.asList( params ).toString() );
166         }
167     }
168 
169     /**
170      * Get the warnings that happened during adding the project to Continuum.
171      * There is an entry with the warning key (so it can be internationalized later) for each warning.
172      *
173      * @return {@link List} &lt; {@link String} >
174      * @deprecated Use {@link #getErrors()} instead
175      */
176     public List<String> getWarnings()
177     {
178         return getErrors();
179     }
180 
181     /**
182      * Get the errors that happened during adding the project to Continuum.
183      * There is an entry with the error key (so it can be internationalized later) for each error.
184      *
185      * @return {@link List} &lt; {@link String} >
186      */
187     public List<String> getErrors()
188     {
189         return new ArrayList<String>( errors.keySet() );
190     }
191 
192     public Map<String, String> getErrorsWithCause()
193     {
194         return errors;
195     }
196 
197     /**
198      * Quick check to see if there are any errors.
199      *
200      * @return boolean indicating if there are any errors.
201      */
202     public boolean hasErrors()
203     {
204         return ( errors != null ) && ( !errors.isEmpty() );
205     }
206 
207     /**
208      * Returns a string representation of the errors.
209      *
210      * @return a string representation of the errors.
211      */
212     public String getErrorsAsString()
213     {
214         if ( !hasErrors() )
215         {
216             return null;
217         }
218 
219         StringBuilder message = new StringBuilder();
220         for ( String key : errors.keySet() )
221         {
222             message.append( errors.get( key ) );
223             message.append( LS );
224         }
225         return message.toString();
226     }
227 
228     public Project getRootProject()
229     {
230         return rootProject;
231     }
232 
233     public void setRootProject( Project rootProject )
234     {
235         this.rootProject = rootProject;
236     }
237 }