1 package org.apache.maven.report.projectinfo;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.doxia.sink.Sink;
23 import org.apache.maven.plugins.annotations.Mojo;
24 import org.apache.maven.plugins.annotations.Parameter;
25 import org.apache.maven.reporting.MavenReportException;
26 import org.codehaus.plexus.i18n.I18N;
27
28 import java.util.Formatter;
29 import java.util.Locale;
30
31
32
33
34
35
36
37
38 @Mojo( name = "dependency-info" )
39 public final class DependencyInformationReport
40 extends AbstractProjectInfoReport
41 {
42
43 private static final String DEPENDENCY_INFO = "dependency-info";
44
45 private static final String JAR_PACKAGING = "jar";
46
47
48
49 @Parameter( defaultValue = "${project.groupId}", required = true )
50 protected String groupId;
51
52
53
54 @Parameter( defaultValue = "${project.artifactId}", required = true )
55 protected String artifactId;
56
57
58
59 @Parameter( defaultValue = "${project.version}", required = true )
60 protected String version;
61
62
63
64 @Parameter( defaultValue = "${project.packaging}", required = true )
65 protected String packaging;
66
67
68
69
70
71
72
73
74 public String getOutputName()
75 {
76 return DEPENDENCY_INFO;
77 }
78
79
80
81
82 @Override
83 protected String getI18Nsection()
84 {
85 return DEPENDENCY_INFO;
86 }
87
88
89
90
91 @Override
92 protected void executeReport( Locale locale )
93 throws MavenReportException
94 {
95 new DependencyInformationRenderer( getSink(), getI18N( locale ), locale, groupId, artifactId, version,
96 packaging ).render();
97 }
98
99
100
101
102
103 private static final class DependencyInformationRenderer
104 extends AbstractProjectInfoRenderer
105 {
106
107 private final String groupId;
108
109 private final String artifactId;
110
111 private final String version;
112
113 private final String packaging;
114
115 public DependencyInformationRenderer( Sink sink, I18N i18n, Locale locale, String groupId, String artifactId,
116 String version, String packaging )
117 {
118 super( sink, i18n, locale );
119 this.groupId = groupId;
120 this.artifactId = artifactId;
121 this.version = version;
122 this.packaging = packaging;
123 }
124
125
126
127
128 @Override
129 protected String getI18Nsection()
130 {
131 return DEPENDENCY_INFO;
132 }
133
134
135
136
137 @Override
138 protected void renderBody()
139 {
140 startSection( getTitle() );
141
142 Formatter mavenDependency =
143 new Formatter().format( "<dependency>%n" ).format( " <groupId>%s</groupId>%n", groupId ).format(
144 " <artifactId>%s</artifactId>%n", artifactId ).format( " <version>%s</version>%n", version );
145
146 if ( !JAR_PACKAGING.equals( packaging ) )
147 {
148 mavenDependency = mavenDependency.format( " <type>%s</type>%n", packaging );
149 }
150
151 renderDependencyInfo( "Apache Maven", mavenDependency.format( "</dependency>" ) );
152
153 renderDependencyInfo( "Apache Buildr",
154 new Formatter().format( "'%s:%s:%s:%s'", groupId, artifactId, packaging, version ) );
155
156 renderDependencyInfo( "Apache Ant",
157 new Formatter().format( "<dependency org=\"%s\" name=\"%s\" rev=\"%s\">%n", groupId,
158 artifactId, version ).format(
159 " <artifact name=\"%s\" type=\"%s\" />%n", artifactId, packaging ).format(
160 "</dependency>" ) );
161
162 renderDependencyInfo( "Groovy Grape", new Formatter().format( "@Grapes(%n" ).format(
163 "@Grab(group='%s', module='%s', version='%s')%n", groupId, artifactId, version ).format( ")" ) );
164
165 renderDependencyInfo( "Grails",
166 new Formatter().format( "compile '%s:%s:%s'", groupId, artifactId, version ) );
167
168
169
170 Formatter leiningenDependency = new Formatter().format( "[%s", groupId );
171
172 if ( !groupId.equals( artifactId ) )
173 {
174 leiningenDependency.format( "/%s", artifactId );
175 }
176
177 leiningenDependency.format( " \"%s\"]", version );
178
179 renderDependencyInfo( "Leiningen", leiningenDependency );
180
181
182
183 renderDependencyInfo( "SBT", new Formatter().format( "libraryDependencies += \"%s\" %%%% \"%s\" %% \"%s\"",
184 groupId, artifactId, version ) );
185
186 endSection();
187 }
188
189 private void renderDependencyInfo( String name, Formatter formatter )
190 {
191 startSection( name );
192 verbatimText( formatter.toString() );
193 endSection();
194 }
195
196 }
197
198 }