View Javadoc
1   package org.apache.maven.project;
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.io.File;
23  import java.util.List;
24  
25  /**
26   * @author Jason van Zyl
27   */
28  public class ProjectBuildingException
29      extends Exception
30  {
31      private final String projectId;
32  
33      private File pomFile;
34  
35      private List<ProjectBuildingResult> results;
36  
37      public ProjectBuildingException( String projectId, String message, Throwable cause )
38      {
39          super( createMessage( message, projectId, null ), cause );
40          this.projectId = projectId;
41      }
42  
43      /**
44       * @param projectId
45       * @param message
46       * @param pomFile   pom file location
47       */
48      public ProjectBuildingException( String projectId, String message, File pomFile )
49      {
50          super( createMessage( message, projectId, pomFile ) );
51          this.projectId = projectId;
52          this.pomFile = pomFile;
53      }
54  
55      /**
56       * @param projectId
57       * @param message
58       * @param pomFile   pom file location
59       * @param cause
60       */
61      protected ProjectBuildingException( String projectId, String message, File pomFile, Throwable cause )
62      {
63          super( createMessage( message, projectId, pomFile ), cause );
64          this.projectId = projectId;
65          this.pomFile = pomFile;
66      }
67  
68      public ProjectBuildingException( List<ProjectBuildingResult> results )
69      {
70          super( "Some problems were encountered while processing the POMs" );
71          this.projectId = "";
72          this.results = results;
73      }
74  
75      public File getPomFile()
76      {
77          return pomFile;
78      }
79  
80      /**
81       * @deprecated use {@link #getPomFile()}
82       */
83      public String getPomLocation()
84      {
85          if ( getPomFile() != null )
86          {
87              return getPomFile().getAbsolutePath();
88          }
89          else
90          {
91              return "null";
92          }
93      }
94  
95      public String getProjectId()
96      {
97          return projectId;
98      }
99  
100     public List<ProjectBuildingResult> getResults()
101     {
102         return results;
103     }
104 
105     private static String createMessage( String message, String projectId, File pomFile )
106     {
107         StringBuilder buffer = new StringBuilder( 256 );
108         buffer.append( message );
109         buffer.append( " for project " ).append( projectId );
110         if ( pomFile != null )
111         {
112             buffer.append( " at " ).append( pomFile.getAbsolutePath() );
113         }
114         return buffer.toString();
115     }
116 
117 }