View Javadoc

1   package org.apache.maven.usability;
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.plugin.PluginConfigurationException;
23  import org.apache.maven.plugin.PluginParameterException;
24  import org.apache.maven.usability.diagnostics.DiagnosisUtils;
25  import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
26  import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
27  
28  public class PluginConfigurationDiagnoser
29      implements ErrorDiagnoser
30  {
31      public boolean canDiagnose( Throwable error )
32      {
33          return DiagnosisUtils.containsInCausality( error, PluginConfigurationException.class );
34      }
35  
36      public String diagnose( Throwable error )
37      {
38          PluginConfigurationException pce =
39              (PluginConfigurationException) DiagnosisUtils.getFromCausality( error, PluginConfigurationException.class );
40  
41          if ( pce instanceof PluginParameterException )
42          {
43              PluginParameterException exception = (PluginParameterException) pce;
44  
45              return exception.buildDiagnosticMessage();
46          }
47          else if ( DiagnosisUtils.containsInCausality( pce, ComponentConfigurationException.class ) )
48          {
49              ComponentConfigurationException cce = (ComponentConfigurationException) DiagnosisUtils.getFromCausality(
50                  pce, ComponentConfigurationException.class );
51  
52              return pce.buildConfigurationDiagnosticMessage( cce );
53          }
54          else
55          {
56              return pce.getMessage();
57          }
58      }
59  }