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 | 0 | 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 | 0 | return DEPENDENCY_INFO; |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
@Override |
83 | |
protected String getI18Nsection() |
84 | |
{ |
85 | 0 | return DEPENDENCY_INFO; |
86 | |
} |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
@Override |
92 | |
protected void executeReport( Locale locale ) |
93 | |
throws MavenReportException |
94 | |
{ |
95 | 0 | new DependencyInformationRenderer( getSink(), getI18N( locale ), locale, groupId, artifactId, version, |
96 | |
packaging ).render(); |
97 | 0 | } |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | 0 | 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 | 0 | super( sink, i18n, locale ); |
119 | 0 | this.groupId = groupId; |
120 | 0 | this.artifactId = artifactId; |
121 | 0 | this.version = version; |
122 | 0 | this.packaging = packaging; |
123 | 0 | } |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
@Override |
129 | |
protected String getI18Nsection() |
130 | |
{ |
131 | 0 | return DEPENDENCY_INFO; |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
@Override |
138 | |
protected void renderBody() |
139 | |
{ |
140 | 0 | startSection( getTitle() ); |
141 | |
|
142 | 0 | 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 | 0 | if ( !JAR_PACKAGING.equals( packaging ) ) |
147 | |
{ |
148 | 0 | mavenDependency = mavenDependency.format( " <type>%s</type>%n", packaging ); |
149 | |
} |
150 | |
|
151 | 0 | renderDependencyInfo( "Apache Maven", mavenDependency.format( "</dependency>" ) ); |
152 | |
|
153 | 0 | renderDependencyInfo( "Apache Buildr", |
154 | |
new Formatter().format( "'%s:%s:%s:%s'", groupId, artifactId, packaging, version ) ); |
155 | |
|
156 | 0 | 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 | 0 | renderDependencyInfo( "Groovy Grape", new Formatter().format( "@Grapes(%n" ).format( |
163 | |
"@Grab(group='%s', module='%s', version='%s')%n", groupId, artifactId, version ).format( ")" ) ); |
164 | |
|
165 | 0 | renderDependencyInfo( "Grails", |
166 | |
new Formatter().format( "compile '%s:%s:%s'", groupId, artifactId, version ) ); |
167 | |
|
168 | |
|
169 | |
|
170 | 0 | Formatter leiningenDependency = new Formatter().format( "[%s", groupId ); |
171 | |
|
172 | 0 | if ( !groupId.equals( artifactId ) ) |
173 | |
{ |
174 | 0 | leiningenDependency.format( "/%s", artifactId ); |
175 | |
} |
176 | |
|
177 | 0 | leiningenDependency.format( " \"%s\"]", version ); |
178 | |
|
179 | 0 | renderDependencyInfo( "Leiningen", leiningenDependency ); |
180 | |
|
181 | |
|
182 | |
|
183 | 0 | renderDependencyInfo( "SBT", new Formatter().format( "libraryDependencies += \"%s\" %%%% \"%s\" %% \"%s\"", |
184 | |
groupId, artifactId, version ) ); |
185 | |
|
186 | 0 | endSection(); |
187 | 0 | } |
188 | |
|
189 | |
private void renderDependencyInfo( String name, Formatter formatter ) |
190 | |
{ |
191 | 0 | startSection( name ); |
192 | 0 | verbatimText( formatter.toString() ); |
193 | 0 | endSection(); |
194 | 0 | } |
195 | |
|
196 | |
} |
197 | |
|
198 | |
} |