Coverage report

  %line %branch
org.apache.maven.author.resolver.JavadocAuthorResolver
95% 
94% 

 1  
 /*
 2  
  * Copyright 2006 Eric Ballet Baz
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.maven.author.resolver;
 18  
 
 19  
 import java.io.File;
 20  
 import java.util.List;
 21  
 
 22  
 import xjavadoc.SourceSet;
 23  
 import xjavadoc.XClass;
 24  
 import xjavadoc.XDoc;
 25  
 import xjavadoc.XJavaDoc;
 26  
 import xjavadoc.XTag;
 27  
 import xjavadoc.filesystem.FileSourceSet;
 28  
 
 29  
 /**
 30  
  * AuthorResolver based on javadoc.
 31  
  * This resolver uses author's javadoc tags to resolve the author(s).
 32  
  *
 33  
  * @author Eric Ballet Baz
 34  
  */
 35  10
 public class JavadocAuthorResolver implements AuthorResolver {
 36  
 
 37  
     /** Javadoc tag used to declare the author(s) of a file. */
 38  
     private static final String AUTHOR_TAG_NAME = "author";
 39  
 
 40  
     /**
 41  
      * @see org.apache.maven.author.resolver.AuthorResolver#resolveAuthors(java.io.File)
 42  
      */
 43  
     public final String[] resolveAuthors(class="keyword">final File file) {
 44  
         // Check argument
 45  11
         if (file == null) {
 46  1
             throw new IllegalArgumentException("Argument [file] should not be null");
 47  
         }
 48  10
         if (file.isDirectory()) {
 49  1
             throw new IllegalArgumentException("Argument [file] should not be a directory");
 50  
         }
 51  
 
 52  
         // Prepare resources used to inspect the javadoc of this file
 53  9
         XJavaDoc xJavaDoc = new XJavaDoc();
 54  9
         SourceSet fileSourceSet = new FileSourceSet(file);
 55  9
         xJavaDoc.addSourceSet(fileSourceSet);
 56  
 
 57  
         // Find values of author's javadoc tags for this file
 58  9
         XClass xClass = xJavaDoc.getXClass(fileSourceSet.getQualifiedName(0));
 59  
 
 60  
         // This should never happen
 61  9
         if (xClass == null) {
 62  0
             throw new IllegalStateException(
 63  
                 "xjavadoc.XClass.getXClass(String qualifiedName) has returned a null value. Check version of xjavadoc used");
 64  
         }
 65  
 
 66  
         // Inspect javadoc to resolver authors
 67  9
         XDoc xDoc = xClass.getDoc();
 68  9
         if (xDoc != null) {
 69  9
             List authorTags = xDoc.getTags(AUTHOR_TAG_NAME);
 70  9
             if (authorTags != null && authorTags.size() > 0) {
 71  6
                 String[] authors = new String[authorTags.size()];
 72  18
                 for (int i = 0; i < authorTags.size(); i++) {
 73  12
                     authors[i] = ((XTag) authorTags.get(i)).getValue();
 74  
                 }
 75  6
                 return authors;
 76  
             }
 77  
         }
 78  
 
 79  
         // No author has been found
 80  3
         return new String[0];
 81  
     }
 82  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.