View Javadoc

1   package org.codehaus.mojo.macker;
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.MojoExecutionException;
23  import org.apache.maven.plugin.MojoFailureException;
24  
25  import java.io.File;
26  import java.io.IOException;
27  
28  import net.innig.macker.event.ListenerException;
29  import net.innig.macker.event.MackerIsMadException;
30  import net.innig.macker.rule.RuleSeverity;
31  import net.innig.macker.rule.RulesException;
32  import net.innig.macker.structure.ClassParseException;
33  
34  /**
35   * Delegator to the Macker tool.
36   */
37  public class LinkedMacker
38      implements Macker
39  {
40      private final net.innig.macker.Macker macker = new net.innig.macker.Macker();
41  
42      public void addClass( File clazz )
43          throws IOException, MojoExecutionException
44      {
45          try
46          {
47              macker.addClass( clazz );
48          }
49          catch ( ClassParseException ex )
50          {
51              throw new MojoExecutionException( "Macker problem parsing a class: " + ex.getMessage(), ex );
52          }
53      }
54  
55      public void addRulesFile( File rule )
56          throws IOException, MojoExecutionException
57      {
58          try
59          {
60              macker.addRulesFile( rule );
61          }
62          catch ( RulesException ex )
63          {
64              throw new MojoExecutionException( "Macker rules are not properly defined: " + ex.getMessage(), ex );
65          }
66      }
67  
68      public void check()
69          throws MojoExecutionException, MojoFailureException
70      {
71          try
72          {
73              macker.check();
74          }
75          catch ( MackerIsMadException ex )
76          {
77              throw new MojoFailureException( "MackerIsMadException during Macker execution: " + ex.getMessage() );
78          }
79          catch ( RulesException ex )
80          {
81              throw new MojoExecutionException( "Macker rules are not properly defined: " + ex.getMessage(), ex );
82          }
83          catch ( ListenerException ex )
84          {
85              throw new MojoExecutionException( "Error during Macker execution: " + ex.getMessage(), ex );
86          }
87      }
88  
89      public void setAngerThreshold( String anger )
90      {
91          macker.setAngerThreshold( RuleSeverity.fromName( anger ) );
92      }
93  
94      public void setPrintMaxMessages( int maxMsg )
95      {
96          macker.setPrintMaxMessages( maxMsg );
97      }
98  
99      public void setPrintThreshold( String print )
100     {
101         macker.setPrintThreshold( RuleSeverity.fromName( print ) );
102     }
103 
104     public void setVariable( String name, String value )
105     {
106         macker.setVariable( name, value );
107     }
108 
109     public void setVerbose( boolean verbose )
110     {
111         macker.setVerbose( verbose );
112     }
113 
114     public void setXmlReportFile( File report )
115     {
116         macker.setXmlReportFile( report );
117     }
118 
119 }