maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r1608018 - in /maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle: CheckstyleReportGenerator.java IconTool.java
Date Sat, 05 Jul 2014 14:13:12 GMT
Author: hboutemy
Date: Sat Jul  5 14:13:12 2014
New Revision: 1608018

URL: http://svn.apache.org/r1608018
Log:
refactoring: extracted IconTool to deal with info/warning/error icons in reports

Added:
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/IconTool.java
  (with props)
Modified:
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java?rev=1608018&r1=1608017&r2=1608018&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java
(original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java
Sat Jul  5 14:13:12 2014
@@ -75,6 +75,8 @@ public class CheckstyleReportGenerator
 
     private List<String> treeWalkerNames = Collections.singletonList( "TreeWalker"
);
 
+    private final IconTool iconTool;
+
     public CheckstyleReportGenerator( Sink sink, ResourceBundle bundle, File basedir, SiteTool
siteTool )
     {
         this.bundle = bundle;
@@ -89,6 +91,7 @@ public class CheckstyleReportGenerator
         this.enableSeveritySummary = true;
         this.enableFilesSummary = true;
         this.enableRSS = true;
+        this.iconTool = new IconTool( sink, bundle );
     }
 
     public Log getLog()
@@ -188,43 +191,6 @@ public class CheckstyleReportGenerator
         sink.section1_();
     }
 
-    private void iconSeverity( String level )
-    {
-        if ( SeverityLevel.INFO.getName().equalsIgnoreCase( level ) )
-        {
-            iconInfo();
-        }
-        else if ( SeverityLevel.WARNING.getName().equalsIgnoreCase( level ) )
-        {
-            iconWarning();
-        }
-        else if ( SeverityLevel.ERROR.getName().equalsIgnoreCase( level ) )
-        {
-            iconError();
-        }
-    }
-
-    private void iconInfo()
-    {
-        sink.figure();
-        sink.figureGraphics( "images/icon_info_sml.gif" );
-        sink.figure_();
-    }
-
-    private void iconWarning()
-    {
-        sink.figure();
-        sink.figureGraphics( "images/icon_warning_sml.gif" );
-        sink.figure_();
-    }
-
-    private void iconError()
-    {
-        sink.figure();
-        sink.figureGraphics( "images/icon_error_sml.gif" );
-        sink.figure_();
-    }
-
     /**
      * Get the value of the specified attribute from the Checkstyle configuration.
      * If parentConfigurations is non-null and non-empty, the parent
@@ -464,22 +430,7 @@ public class CheckstyleReportGenerator
         // Grab the severity from the rule configuration, this time use error as default
value
         // Also pass along all parent configurations, so that we can try to find the severity
there
         configSeverity = getConfigAttribute( checkerConfig, parentConfigurations, "severity",
"error" );
-        iconSeverity( configSeverity );
-        sink.nonBreakingSpace();
-
-        if ( SeverityLevel.INFO.getName().equalsIgnoreCase( configSeverity ) )
-        {
-            sink.text( bundle.getString( "report.checkstyle.info" ) );
-        }
-        else if ( SeverityLevel.WARNING.getName().equalsIgnoreCase( configSeverity ) )
-        {
-            sink.text( bundle.getString( "report.checkstyle.warning" ) );
-        }
-        else if ( SeverityLevel.ERROR.getName().equalsIgnoreCase( configSeverity ) )
-        {
-            sink.text( bundle.getString( "report.checkstyle.error" ) );
-        }
-
+        iconTool.iconSeverity( configSeverity, IconTool.TEXT_SIMPLE );
         sink.tableCell_();
 
         sink.tableRow_();
@@ -588,21 +539,15 @@ public class CheckstyleReportGenerator
         sink.tableHeaderCell_();
 
         sink.tableHeaderCell();
-        iconInfo();
-        sink.nonBreakingSpace();
-        sink.text( bundle.getString( "report.checkstyle.infos" ) );
+        iconTool.iconInfo( IconTool.TEXT_TITLE );
         sink.tableHeaderCell_();
 
         sink.tableHeaderCell();
-        iconWarning();
-        sink.nonBreakingSpace();
-        sink.text( bundle.getString( "report.checkstyle.warnings" ) );
+        iconTool.iconWarning( IconTool.TEXT_TITLE );
         sink.tableHeaderCell_();
 
         sink.tableHeaderCell();
-        iconError();
-        sink.nonBreakingSpace();
-        sink.text( bundle.getString( "report.checkstyle.errors" ) );
+        iconTool.iconError( IconTool.TEXT_TITLE );
         sink.tableHeaderCell_();
         sink.tableRow_();
 
@@ -640,19 +585,13 @@ public class CheckstyleReportGenerator
         sink.text( bundle.getString( "report.checkstyle.file" ) );
         sink.tableHeaderCell_();
         sink.tableHeaderCell();
-        iconInfo();
-        sink.nonBreakingSpace();
-        sink.text( bundle.getString( "report.checkstyle.infos.abbrev" ) );
+        iconTool.iconInfo( IconTool.TEXT_ABBREV );
         sink.tableHeaderCell_();
         sink.tableHeaderCell();
-        iconWarning();
-        sink.nonBreakingSpace();
-        sink.text( bundle.getString( "report.checkstyle.warnings.abbrev" ) );
+        iconTool.iconWarning( IconTool.TEXT_ABBREV );
         sink.tableHeaderCell_();
         sink.tableHeaderCell();
-        iconError();
-        sink.nonBreakingSpace();
-        sink.text( bundle.getString( "report.checkstyle.errors.abbrev" ) );
+        iconTool.iconError( IconTool.TEXT_ABBREV );
         sink.tableHeaderCell_();
         sink.tableRow_();
 
@@ -765,19 +704,13 @@ public class CheckstyleReportGenerator
             switch( level )
             {
             case INFO:
-                iconInfo();
-                sink.nonBreakingSpace();
-                sink.text( bundle.getString( "report.checkstyle.info" ) );
+                iconTool.iconInfo( IconTool.TEXT_SIMPLE );
                 break;
             case WARNING:
-                iconWarning();
-                sink.nonBreakingSpace();
-                sink.text( bundle.getString( "report.checkstyle.warning" ) );
+                iconTool.iconWarning( IconTool.TEXT_SIMPLE );
                 break;
             case ERROR:
-                iconError();
-                sink.nonBreakingSpace();
-                sink.text( bundle.getString( "report.checkstyle.error" ) );
+                iconTool.iconError( IconTool.TEXT_SIMPLE );
                 break;
             default:
                 break;

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/IconTool.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/IconTool.java?rev=1608018&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/IconTool.java
(added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/IconTool.java
Sat Jul  5 14:13:12 2014
@@ -0,0 +1,117 @@
+package org.apache.maven.plugin.checkstyle;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ResourceBundle;
+
+import org.apache.maven.doxia.sink.Sink;
+
+/**
+ * A little tool to deal with info/warning/error icons in Checkstyle reports, with eventual
text.
+ *
+ * @since 2.13
+ */
+public class IconTool
+{
+    public final static String INFO = "info";
+
+    public final static String WARNING = "warning";
+
+    public final static String ERROR = "error";
+
+    public final static int NO_TEXT = 0;
+    public final static int TEXT_SIMPLE = 1;
+    public final static int TEXT_TITLE = 2;
+    public final static int TEXT_ABBREV = 3;
+
+    private final Sink sink;
+
+    private final ResourceBundle bundle;
+
+    public IconTool( Sink sink, ResourceBundle bundle )
+    {
+        this.sink = sink;
+        this.bundle = bundle;
+    }
+
+    public void iconSeverity( String level )
+    {
+        sink.figure();
+        sink.figureGraphics( "images/icon_" + level + "_sml.gif" );
+        sink.figure_();
+    }
+
+    public void iconSeverity( String level, int textType )
+    {
+        sink.figure();
+        sink.figureGraphics( "images/icon_" + level + "_sml.gif" );
+        sink.figure_();
+
+        if ( textType > 0 )
+        {
+            sink.nonBreakingSpace();
+
+            sink.text( bundle.getString( "report.checkstyle." + level + suffix( textType
) ) );
+        }
+    }
+
+    public void iconInfo()
+    {
+        iconSeverity( INFO );
+    }
+
+    public void iconInfo( int textType )
+    {
+        iconSeverity( INFO, textType );
+    }
+
+    public void iconWarning()
+    {
+        iconSeverity( WARNING );
+    }
+
+    public void iconWarning( int textType )
+    {
+        iconSeverity( WARNING, textType );
+    }
+
+    public void iconError()
+    {
+        iconSeverity( ERROR );
+    }
+
+    public void iconError( int textType )
+    {
+        iconSeverity( ERROR, textType );
+    }
+
+    private String suffix( int textType )
+    {
+        switch ( textType )
+        {
+            case TEXT_TITLE:
+                return "s";
+            case TEXT_ABBREV:
+                return "s.abbrev";
+            default:
+                return "";
+        }
+    }
+}

Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/IconTool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/IconTool.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/IconTool.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message