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 JAR_PACKAGING = "jar";
44
45
46
47 @Parameter( defaultValue = "${project.groupId}", required = true )
48 protected String groupId;
49
50
51
52 @Parameter( defaultValue = "${project.artifactId}", required = true )
53 protected String artifactId;
54
55
56
57 @Parameter( defaultValue = "${project.version}", required = true )
58 protected String version;
59
60
61
62 @Parameter( defaultValue = "${project.packaging}", required = true )
63 protected String packaging;
64
65
66
67
68
69
70
71
72 public String getOutputName()
73 {
74 return "dependency-info";
75 }
76
77
78
79
80 @Override
81 protected String getI18Nsection()
82 {
83 return "dependency-info";
84 }
85
86
87
88
89 @Override
90 protected void executeReport( Locale locale )
91 throws MavenReportException
92 {
93 new DependencyInformationRenderer( getSink(), getI18N( locale ), locale, groupId, artifactId, version,
94 packaging ).render();
95 }
96
97
98
99
100
101 private static final class DependencyInformationRenderer
102 extends AbstractProjectInfoRenderer
103 {
104
105 private final String groupId;
106
107 private final String artifactId;
108
109 private final String version;
110
111 private final String packaging;
112
113 public DependencyInformationRenderer( Sink sink, I18N i18n, Locale locale, String groupId, String artifactId,
114 String version, String packaging )
115 {
116 super( sink, i18n, locale );
117 this.groupId = groupId;
118 this.artifactId = artifactId;
119 this.version = version;
120 this.packaging = packaging;
121 }
122
123
124
125
126 @Override
127 protected String getI18Nsection()
128 {
129 return "dependency-info";
130 }
131
132
133
134
135 @Override
136 protected void renderBody()
137 {
138 startSection( getTitle() );
139
140 Formatter mavenDependency =
141 new Formatter().format( "<dependency>%n" ).format( " <groupId>%s</groupId>%n", groupId ).format(
142 " <artifactId>%s</artifactId>%n", artifactId ).format( " <version>%s</version>%n", version );
143
144 if ( !JAR_PACKAGING.equals( packaging ) )
145 {
146 mavenDependency = mavenDependency.format( " <type>%s</type>%n", packaging );
147 }
148
149 renderDependencyInfo( "Apache Maven", mavenDependency.format( "</dependency>" ) );
150
151 renderDependencyInfo( "Apache Buildr",
152 new Formatter().format( "'%s:%s:%s:%s'", groupId, artifactId, packaging, version ) );
153
154 renderDependencyInfo( "Apache Ivy",
155 new Formatter().format( "<dependency org=\"%s\" name=\"%s\" rev=\"%s\">%n", groupId,
156 artifactId, version ).format(
157 " <artifact name=\"%s\" type=\"%s\" />%n", artifactId, packaging ).format(
158 "</dependency>" ) );
159
160 renderDependencyInfo( "Groovy Grape", new Formatter().format( "@Grapes(%n" ).format(
161 "@Grab(group='%s', module='%s', version='%s')%n", groupId, artifactId, version ).format( ")" ) );
162
163 renderDependencyInfo( "Gradle/Grails",
164 new Formatter().format( "compile '%s:%s:%s'", groupId, artifactId, version ) );
165
166 renderDependencyInfo( "Scala SBT", new Formatter().format(
167 "libraryDependencies += \"%s\" %% \"%s\" %% \"%s\"", groupId, artifactId, version ) );
168
169
170
171 Formatter leiningenDependency = new Formatter().format( "[%s", groupId );
172
173 if ( !groupId.equals( artifactId ) )
174 {
175 leiningenDependency.format( "/%s", artifactId );
176 }
177
178 leiningenDependency.format( " \"%s\"]", version );
179
180 renderDependencyInfo( "Leiningen", leiningenDependency );
181
182 endSection();
183 }
184
185 private void renderDependencyInfo( String name, Formatter formatter )
186 {
187 startSection( name );
188 verbatimText( formatter.toString() );
189 endSection();
190 }
191
192 }
193
194 }