1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 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(final File file) {
44
45 if (file == null) {
46 throw new IllegalArgumentException("Argument [file] should not be null");
47 }
48 if (file.isDirectory()) {
49 throw new IllegalArgumentException("Argument [file] should not be a directory");
50 }
51
52
53 XJavaDoc xJavaDoc = new XJavaDoc();
54 SourceSet fileSourceSet = new FileSourceSet(file);
55 xJavaDoc.addSourceSet(fileSourceSet);
56
57
58 XClass xClass = xJavaDoc.getXClass(fileSourceSet.getQualifiedName(0));
59
60
61 if (xClass == null) {
62 throw new IllegalStateException(
63 "xjavadoc.XClass.getXClass(String qualifiedName) has returned a null value. Check version of xjavadoc used");
64 }
65
66
67 XDoc xDoc = xClass.getDoc();
68 if (xDoc != null) {
69 List authorTags = xDoc.getTags(AUTHOR_TAG_NAME);
70 if (authorTags != null && authorTags.size() > 0) {
71 String[] authors = new String[authorTags.size()];
72 for (int i = 0; i < authorTags.size(); i++) {
73 authors[i] = ((XTag) authorTags.get(i)).getValue();
74 }
75 return authors;
76 }
77 }
78
79
80 return new String[0];
81 }
82 }