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