Save This Page
Home » maven-mailetdocs-plugin-0.1-src » org.apache.james.mailet » [javadoc | source]
    1   /****************************************************************
    2    * Licensed to the Apache Software Foundation (ASF) under one   *
    3    * or more contributor license agreements.  See the NOTICE file *
    4    * distributed with this work for additional information        *
    5    * regarding copyright ownership.  The ASF licenses this file   *
    6    * to you under the Apache License, Version 2.0 (the            *
    7    * "License"); you may not use this file except in compliance   *
    8    * with the License.  You may obtain a copy of the License at   *
    9    *                                                              *
   10    *   http://www.apache.org/licenses/LICENSE-2.0                 *
   11    *                                                              *
   12    * Unless required by applicable law or agreed to in writing,   *
   13    * software distributed under the License is distributed on an  *
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
   15    * KIND, either express or implied.  See the License for the    *
   16    * specific language governing permissions and limitations      *
   17    * under the License.                                           *
   18    ****************************************************************/
   19   
   20   package org.apache.james.mailet;
   21   
   22   import org.apache.commons.collections.CollectionUtils;
   23   import org.apache.commons.collections.Predicate;
   24   import org.apache.maven.doxia.siterenderer.Renderer;
   25   import org.apache.maven.project.MavenProject;
   26   import org.apache.maven.reporting.AbstractMavenReport;
   27   import org.apache.maven.reporting.MavenReportException;
   28   
   29   import java.io.File;
   30   import java.util.Collections;
   31   import java.util.Comparator;
   32   import java.util.List;
   33   import java.util.Locale;
   34   
   35   /**
   36    * <p>Generates catalog and reports on mailets and matchers.</p>
   37    * <h4>Notes</h4>
   38    * <ul>
   39    * <li>Should only used as a report.</li>
   40    * <li>Mailets are instantiated during report production. </li>
   41    * </ul>
   42    * @goal mailetdocs
   43    * @since 0.1
   44    * @requiresDependencyResolution compile
   45    */
   46   public class MailetdocsMojo extends AbstractMavenReport {
   47   
   48       /**
   49        * <i>Maven Internal</i>: The Doxia Site Renderer.
   50        * 
   51        * @component
   52        */
   53       private Renderer siteRenderer;
   54   
   55       /**
   56        * <i>Maven Internal</i>: The Project descriptor.
   57        * 
   58        * @parameter expression="${project}"
   59        * @required
   60        * @readonly
   61        */
   62       private MavenProject project;
   63   
   64       /**
   65        * The output directory.
   66        * 
   67        * @parameter expression="${project.reporting.outputDirectory}"
   68        * @required
   69        * @since 0.1
   70        */
   71       private File outputDirectory;
   72   
   73       /**
   74        * Extracts only a given type from a list.
   75        */
   76       private static final class TypePredicate implements Predicate {
   77           private int type;
   78   
   79           public TypePredicate(int typeMatcher) {
   80               this.type = typeMatcher;
   81           }
   82   
   83           public boolean evaluate(Object arg0) {
   84               return ((MailetMatcherDescriptor) arg0).getType() == type;
   85           }
   86       }
   87   
   88       protected void executeReport(Locale locale) throws MavenReportException {
   89   
   90           List descriptors = new DefaultDescriptorsExtractor().extractDescriptors(project, getLog());
   91   
   92           Collections.sort(descriptors, new Comparator() {
   93   
   94               public int compare(Object arg0, Object arg1) {
   95                   return ((MailetMatcherDescriptor) arg0).getName().compareTo(
   96                           ((MailetMatcherDescriptor) arg1).getName());
   97               }
   98   
   99           });
  100   
  101           getLog().info("Executing Mailets/Matchers Report");
  102   
  103           getSink().head();
  104           getSink().title();
  105           getSink().text("Mailet and Matchers Reference");
  106           getSink().title_();
  107           getSink().head_();
  108   
  109           getSink().body();
  110   
  111           List matchers = (List) CollectionUtils.select(descriptors,
  112                   new TypePredicate(MailetMatcherDescriptor.TYPE_MATCHER));
  113           List mailets = (List) CollectionUtils.select(descriptors,
  114                   new TypePredicate(MailetMatcherDescriptor.TYPE_MAILET));
  115           
  116           getSink().section1();
  117           getSink().sectionTitle1();
  118           getSink().text("Mailets and Matchers Reference");
  119           getSink().sectionTitle1_();
  120           getSink().section1_();
  121           
  122           if (matchers.size() > 0 && mailets.size() > 0) {
  123               getSink().table();
  124               getSink().tableRow();
  125               getSink().tableCell();
  126           }
  127           if (matchers.size() > 0) {
  128               outputDescriptorIndex(matchers, "Matchers");
  129           }
  130           if (matchers.size() > 0 && mailets.size() > 0) {
  131               getSink().tableCell_();
  132               getSink().tableCell();
  133           }
  134           if (mailets.size() > 0) {
  135               outputDescriptorIndex(mailets, "Mailets");
  136           }
  137           if (matchers.size() > 0 && mailets.size() > 0) {
  138               getSink().tableCell_();
  139               getSink().tableRow_();
  140               getSink().table_();
  141           }
  142   
  143           if (matchers.size() > 0) {
  144               outputDescriptorList(matchers, "Matchers");
  145           }
  146           if (mailets.size() > 0) {
  147               outputDescriptorList(mailets, "Mailets");
  148           }
  149   
  150           getSink().body_();
  151   
  152           getSink().flush();
  153           getSink().close();
  154   
  155           /*
  156            * for (Iterator i = getProject().getCompileSourceRoots().iterator();
  157            * i.hasNext(); ) { String folder = (String) i.next(); DirectoryScanner
  158            * ds = new DirectoryScanner(); ds.setBasedir(folder);
  159            * ds.addDefaultExcludes(); ds.setIncludes(new
  160            * String[]{"**"+"/"+"*.java"}); ds.scan(); for (int k = 0; k <
  161            * ds.getIncludedFiles().length; k++) { getLog().info("include:
  162            * "+ds.getIncludedFiles()[k]); } }
  163            */
  164   
  165       }
  166   
  167       private void outputDescriptorIndex(List descriptors, String title) {
  168           getSink().section2();
  169           getSink().sectionTitle2();
  170           getSink().text(title);
  171           getSink().sectionTitle2_();
  172   
  173           getSink().list();
  174           for (int i = 0; i < descriptors.size(); i++) {
  175               getSink().listItem();
  176               getSink().link("#"+((MailetMatcherDescriptor) descriptors.get(i)).getName());
  177               getSink().text(
  178                       ((MailetMatcherDescriptor) descriptors.get(i)).getName());
  179               getSink().link_();
  180               getSink().listItem_();
  181           }
  182           getSink().list_();
  183   
  184           getSink().section2_();
  185       }
  186   
  187       private void outputDescriptorList(List descriptors, String title) {
  188           getSink().section1();
  189           getSink().sectionTitle1();
  190           getSink().text(title);
  191           getSink().sectionTitle1_();
  192   
  193           for (int i = 0; i < descriptors.size(); i++) {
  194               getSink().section2();
  195   
  196               getSink().sectionTitle2();
  197               getSink().anchor(((MailetMatcherDescriptor) descriptors.get(i)).getName());
  198               getSink().text(
  199                       ((MailetMatcherDescriptor) descriptors.get(i)).getName());
  200               getSink().anchor_();
  201               getSink().sectionTitle2_();
  202   
  203               if (((MailetMatcherDescriptor) descriptors.get(i)).getInfo() != null) {
  204                 getSink().paragraph();
  205   	            if (((MailetMatcherDescriptor) descriptors.get(i)).getType() == MailetMatcherDescriptor.TYPE_MAILET) {
  206   	                getSink().text("Mailet Info: ");
  207   	            } else if (((MailetMatcherDescriptor) descriptors.get(i)).getType() == MailetMatcherDescriptor.TYPE_MATCHER) {
  208   	                getSink().text("Matcher Info: ");
  209   	            } else {
  210   	                getSink().text("Info: ");
  211   	            }
  212   	            getSink().bold();
  213   	            getSink().text(
  214   	                    ((MailetMatcherDescriptor) descriptors.get(i)).getInfo());
  215   	            getSink().bold_();
  216   	            getSink().lineBreak();
  217   	            getSink().paragraph_();
  218               }
  219   
  220               getSink().paragraph();
  221               getSink().rawText(
  222                       ((MailetMatcherDescriptor) descriptors.get(i))
  223                               .getClassDocs());
  224               getSink().paragraph_();
  225   
  226               getSink().section2_();
  227   
  228           }
  229   
  230           getSink().section1_();
  231       }
  232   
  233       protected String getOutputDirectory() {
  234           return outputDirectory.getAbsolutePath();
  235       }
  236   
  237       /**
  238        * @return Returns the siteRenderer.
  239        */
  240       public Renderer getSiteRenderer() {
  241           return siteRenderer;
  242       }
  243   
  244       protected MavenProject getProject() {
  245           return project;
  246       }
  247   
  248       public String getDescription(Locale arg0) {
  249           return "Documentation about bundled mailets";
  250       }
  251   
  252       public String getName(Locale arg0) {
  253           return "Mailet Reference";
  254       }
  255   
  256       public String getOutputName() {
  257           return "mailet-report";
  258       }
  259   
  260       /**
  261        * @param siteRenderer
  262        *                The siteRenderer to set.
  263        */
  264       public void setSiteRenderer(Renderer siteRenderer) {
  265           this.siteRenderer = siteRenderer;
  266       }
  267   
  268       /**
  269        * For testing purpose only.
  270        * 
  271        * @param project
  272        *                The project to set.
  273        */
  274       public void setProject(MavenProject project) {
  275           this.project = project;
  276       }
  277   
  278   }

Save This Page
Home » maven-mailetdocs-plugin-0.1-src » org.apache.james.mailet » [javadoc | source]