| 1 |
package org.apache.maven.report.projectinfo;
|
| 2 |
|
| 3 |
/*
|
| 4 |
* Copyright 2004-2005 The Apache Software Foundation.
|
| 5 |
*
|
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
* you may not use this file except in compliance with the License.
|
| 8 |
* You may obtain a copy of the License at
|
| 9 |
*
|
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
*
|
| 12 |
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
* See the License for the specific language governing permissions and
|
| 16 |
* limitations under the License.
|
| 17 |
*/
|
| 18 |
|
| 19 |
import org.apache.maven.model.Contributor;
|
| 20 |
import org.apache.maven.model.Developer;
|
| 21 |
import org.apache.maven.model.Model;
|
| 22 |
import org.apache.maven.project.MavenProject;
|
| 23 |
import org.apache.maven.reporting.AbstractMavenReport;
|
| 24 |
import org.apache.maven.reporting.AbstractMavenReportRenderer;
|
| 25 |
import org.codehaus.doxia.sink.Sink;
|
| 26 |
import org.codehaus.doxia.site.renderer.SiteRenderer;
|
| 27 |
import org.codehaus.plexus.i18n.I18N;
|
| 28 |
import org.codehaus.plexus.util.StringUtils;
|
| 29 |
|
| 30 |
import java.util.Iterator;
|
| 31 |
import java.util.List;
|
| 32 |
import java.util.Locale;
|
| 33 |
import java.util.Properties;
|
| 34 |
|
| 35 |
/**
|
| 36 |
* Generates the Project Team report.
|
| 37 |
*
|
| 38 |
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
|
| 39 |
* @version $Id$
|
| 40 |
* @goal project-team
|
| 41 |
*/
|
| 42 |
public class TeamListReport
|
| 43 |
extends AbstractMavenReport
|
| 44 |
{
|
| 45 |
/**
|
| 46 |
* Report output directory.
|
| 47 |
*
|
| 48 |
* @parameter expression="${project.reporting.outputDirectory}"
|
| 49 |
* @required
|
| 50 |
*/
|
| 51 |
private String outputDirectory;
|
| 52 |
|
| 53 |
/**
|
| 54 |
* Doxia Site Renderer.
|
| 55 |
*
|
| 56 |
* @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
|
| 57 |
* @required
|
| 58 |
* @readonly
|
| 59 |
*/
|
| 60 |
private SiteRenderer siteRenderer;
|
| 61 |
|
| 62 |
/**
|
| 63 |
* The Maven Project.
|
| 64 |
*
|
| 65 |
* @parameter expression="${project}"
|
| 66 |
* @required
|
| 67 |
* @readonly
|
| 68 |
*/
|
| 69 |
private MavenProject project;
|
| 70 |
|
| 71 |
/**
|
| 72 |
* Internationalization.
|
| 73 |
*
|
| 74 |
* @component
|
| 75 |
*/
|
| 76 |
private I18N i18n;
|
| 77 |
|
| 78 |
/**
|
| 79 |
* @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
|
| 80 |
*/
|
| 81 |
public String getName( Locale locale )
|
| 82 |
{
|
| 83 |
return i18n.getString( "project-info-report", locale, "report.team-list.name" );
|
| 84 |
}
|
| 85 |
|
| 86 |
/**
|
| 87 |
* @see org.apache.maven.reporting.MavenReport#getCategoryName()
|
| 88 |
*/
|
| 89 |
public String getCategoryName()
|
| 90 |
{
|
| 91 |
return CATEGORY_PROJECT_INFORMATION;
|
| 92 |
}
|
| 93 |
|
| 94 |
/**
|
| 95 |
* @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale)
|
| 96 |
*/
|
| 97 |
public String getDescription( Locale locale )
|
| 98 |
{
|
| 99 |
return i18n.getString( "project-info-report", locale, "report.team-list.description" );
|
| 100 |
}
|
| 101 |
|
| 102 |
/**
|
| 103 |
* @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory()
|
| 104 |
*/
|
| 105 |
protected String getOutputDirectory()
|
| 106 |
{
|
| 107 |
return outputDirectory;
|
| 108 |
}
|
| 109 |
|
| 110 |
/**
|
| 111 |
* @see org.apache.maven.reporting.AbstractMavenReport#getProject()
|
| 112 |
*/
|
| 113 |
protected MavenProject getProject()
|
| 114 |
{
|
| 115 |
return project;
|
| 116 |
}
|
| 117 |
|
| 118 |
/**
|
| 119 |
* @see org.apache.maven.reporting.AbstractMavenReport#getSiteRenderer()
|
| 120 |
*/
|
| 121 |
protected SiteRenderer getSiteRenderer()
|
| 122 |
{
|
| 123 |
return siteRenderer;
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
| 127 |
* @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
|
| 128 |
*/
|
| 129 |
public void executeReport( Locale locale )
|
| 130 |
{
|
| 131 |
TeamListRenderer r = new TeamListRenderer( getSink(), getProject().getModel(), i18n, locale );
|
| 132 |
|
| 133 |
r.render();
|
| 134 |
}
|
| 135 |
|
| 136 |
/**
|
| 137 |
* @see org.apache.maven.reporting.MavenReport#getOutputName()
|
| 138 |
*/
|
| 139 |
public String getOutputName()
|
| 140 |
{
|
| 141 |
return "team-list";
|
| 142 |
}
|
| 143 |
|
| 144 |
static class TeamListRenderer
|
| 145 |
extends AbstractMavenReportRenderer
|
| 146 |
{
|
| 147 |
private Model model;
|
| 148 |
|
| 149 |
private I18N i18n;
|
| 150 |
|
| 151 |
private Locale locale;
|
| 152 |
|
| 153 |
public TeamListRenderer( Sink sink, Model model, I18N i18n, Locale locale )
|
| 154 |
{
|
| 155 |
super( sink );
|
| 156 |
|
| 157 |
this.model = model;
|
| 158 |
|
| 159 |
this.i18n = i18n;
|
| 160 |
|
| 161 |
this.locale = locale;
|
| 162 |
}
|
| 163 |
|
| 164 |
/**
|
| 165 |
* @see org.apache.maven.reporting.MavenReportRenderer#getTitle()
|
| 166 |
*/
|
| 167 |
public String getTitle()
|
| 168 |
{
|
| 169 |
return i18n.getString( "project-info-report", locale, "report.team-list.title" );
|
| 170 |
}
|
| 171 |
|
| 172 |
/**
|
| 173 |
* @see org.apache.maven.reporting.AbstractMavenReportRenderer#renderBody()
|
| 174 |
*/
|
| 175 |
public void renderBody()
|
| 176 |
{
|
| 177 |
startSection( i18n.getString( "project-info-report", locale, "report.team-list.intro.title" ) );
|
| 178 |
|
| 179 |
// To handle JS
|
| 180 |
StringBuffer javascript = new StringBuffer( "function offsetDate(id, offset) {\n" )
|
| 181 |
.append( " var now = new Date();\n" )
|
| 182 |
.append( " var nowTime = now.getTime();\n" )
|
| 183 |
.append( " var localOffset = now.getTimezoneOffset();\n" )
|
| 184 |
.append(
|
| 185 |
" var developerTime = nowTime + ( offset * 60 * 60 * 1000 ) + ( localOffset * 60 * 1000 );\n" )
|
| 186 |
.append( " var developerDate = new Date(developerTime);\n" ).append( "\n" )
|
| 187 |
.append( " document.getElementById(id).innerHTML = developerDate;\n" ).append( "}\n" )
|
| 188 |
.append( "\n" )
|
| 189 |
.append( "function init(){\n" );
|
| 190 |
|
| 191 |
// Intoduction
|
| 192 |
paragraph( i18n.getString( "project-info-report", locale, "report.team-list.intro.description1" ) );
|
| 193 |
paragraph( i18n.getString( "project-info-report", locale, "report.team-list.intro.description2" ) );
|
| 194 |
|
| 195 |
// Developer section
|
| 196 |
List developers = model.getDevelopers();
|
| 197 |
|
| 198 |
startSection( i18n.getString( "project-info-report", locale, "report.team-list.developers.title" ) );
|
| 199 |
|
| 200 |
if ( ( developers == null ) || ( developers.isEmpty() ) )
|
| 201 |
{
|
| 202 |
paragraph( i18n.getString( "project-info-report", locale, "report.team-list.nodeveloper" ) );
|
| 203 |
}
|
| 204 |
else
|
| 205 |
{
|
| 206 |
paragraph( i18n.getString( "project-info-report", locale, "report.team-list.developers.intro" ) );
|
| 207 |
|
| 208 |
startTable();
|
| 209 |
|
| 210 |
String id = i18n.getString( "project-info-report", locale, "report.team-list.developers.id" );
|
| 211 |
String name = i18n.getString( "project-info-report", locale, "report.team-list.developers.name" );
|
| 212 |
String email = i18n.getString( "project-info-report", locale, "report.team-list.developers.email" );
|
| 213 |
String url = i18n.getString( "project-info-report", locale, "report.team-list.developers.url" );
|
| 214 |
String organization = i18n.getString( "project-info-report", locale, "report.team-list.developers.organization" );
|
| 215 |
String organizationUrl = i18n.getString( "project-info-report", locale, "report.team-list.developers.organizationurl" );
|
| 216 |
String roles = i18n.getString( "project-info-report", locale, "report.team-list.developers.roles" );
|
| 217 |
String timeZone = i18n.getString( "project-info-report", locale, "report.team-list.developers.timezone" );
|
| 218 |
String actualTime = i18n.getString( "project-info-report", locale, "report.team-list.developers.actualtime" );
|
| 219 |
String properties = i18n.getString( "project-info-report", locale, "report.team-list.developers.properties" );
|
| 220 |
|
| 221 |
tableHeader( new String[]{id, name, email, url, organization, organizationUrl, roles, timeZone,
|
| 222 |
actualTime, properties} );
|
| 223 |
|
| 224 |
// To handle JS
|
| 225 |
int developersRows = 0;
|
| 226 |
for ( Iterator i = developers.iterator(); i.hasNext(); )
|
| 227 |
{
|
| 228 |
Developer developer = (Developer) i.next();
|
| 229 |
|
| 230 |
// To handle JS
|
| 231 |
sink.tableRow();
|
| 232 |
|
| 233 |
tableCell( developer.getId() );
|
| 234 |
|
| 235 |
tableCell( developer.getName() );
|
| 236 |
|
| 237 |
tableCell( createLinkPatternedText( developer.getEmail(), developer.getEmail() ) );
|
| 238 |
|
| 239 |
tableCell( createLinkPatternedText( developer.getUrl(), developer.getUrl() ) );
|
| 240 |
|
| 241 |
tableCell( developer.getOrganization() );
|
| 242 |
|
| 243 |
tableCell(
|
| 244 |
createLinkPatternedText( developer.getOrganizationUrl(), developer.getOrganizationUrl() ) );
|
| 245 |
|
| 246 |
if ( developer.getRoles() != null )
|
| 247 |
{
|
| 248 |
// Comma separated roles
|
| 249 |
tableCell( StringUtils.join( developer.getRoles().toArray( new String[0] ), ", " ) );
|
| 250 |
}
|
| 251 |
else
|
| 252 |
{
|
| 253 |
tableCell( null );
|
| 254 |
}
|
| 255 |
|
| 256 |
tableCell( developer.getTimezone() );
|
| 257 |
|
| 258 |
// To handle JS
|
| 259 |
sink.tableCell();
|
| 260 |
sink.rawText( "<span id=\"developer-" + developersRows + "\">" );
|
| 261 |
text( developer.getTimezone() );
|
| 262 |
if ( !StringUtils.isEmpty( developer.getTimezone() ) )
|
| 263 |
{
|
| 264 |
javascript.append( " offsetDate('developer-" + developersRows + "', '" );
|
| 265 |
javascript.append( developer.getTimezone() );
|
| 266 |
javascript.append( "');\n" );
|
| 267 |
}
|
| 268 |
sink.rawText( "</span>" );
|
| 269 |
sink.tableCell_();
|
| 270 |
|
| 271 |
Properties props = developer.getProperties();
|
| 272 |
if ( props != null )
|
| 273 |
{
|
| 274 |
tableCell( propertiesToString( props ) );
|
| 275 |
}
|
| 276 |
else
|
| 277 |
{
|
| 278 |
tableCell( null );
|
| 279 |
}
|
| 280 |
|
| 281 |
sink.tableRow_();
|
| 282 |
|
| 283 |
developersRows++;
|
| 284 |
}
|
| 285 |
|
| 286 |
endTable();
|
| 287 |
}
|
| 288 |
|
| 289 |
endSection();
|
| 290 |
|
| 291 |
// contributors section
|
| 292 |
List contributors = model.getContributors();
|
| 293 |
|
| 294 |
startSection( i18n.getString( "project-info-report", locale, "report.team-list.contributors.title" ) );
|
| 295 |
|
| 296 |
if ( ( contributors == null ) || ( contributors.isEmpty() ) )
|
| 297 |
{
|
| 298 |
paragraph( i18n.getString( "project-info-report", locale, "report.team-list.nocontributor" ) );
|
| 299 |
}
|
| 300 |
else
|
| 301 |
{
|
| 302 |
paragraph( i18n.getString( "project-info-report", locale, "report.team-list.contributors.intro" ) );
|
| 303 |
|
| 304 |
startTable();
|
| 305 |
|
| 306 |
String name = i18n.getString( "project-info-report", locale, "report.team-list.contributors.name" );
|
| 307 |
String email = i18n.getString( "project-info-report", locale, "report.team-list.contributors.email" );
|
| 308 |
String url = i18n.getString( "project-info-report", locale, "report.team-list.contributors.url" );
|
| 309 |
String organization = i18n.getString( "project-info-report", locale, "report.team-list.contributors.organization" );
|
| 310 |
String organizationUrl = i18n.getString( "project-info-report", locale, "report.team-list.contributors.organizationurl" );
|
| 311 |
String roles = i18n.getString( "project-info-report", locale, "report.team-list.contributors.roles" );
|
| 312 |
String timeZone = i18n.getString( "project-info-report", locale, "report.team-list.contributors.timezone" );
|
| 313 |
String actualTime = i18n.getString( "project-info-report", locale, "report.team-list.contributors.actualtime" );
|
| 314 |
String properties = i18n.getString( "project-info-report", locale, "report.team-list.contributors.properties" );
|
| 315 |
|
| 316 |
tableHeader( new String[]{name, email, url, organization, organizationUrl, roles, timeZone, actualTime,
|
| 317 |
properties} );
|
| 318 |
|
| 319 |
// To handle JS
|
| 320 |
int contributorsRows = 0;
|
| 321 |
for ( Iterator i = contributors.iterator(); i.hasNext(); )
|
| 322 |
{
|
| 323 |
Contributor contributor = (Contributor) i.next();
|
| 324 |
|
| 325 |
sink.tableRow();
|
| 326 |
|
| 327 |
tableCell( contributor.getName() );
|
| 328 |
|
| 329 |
tableCell( createLinkPatternedText( contributor.getEmail(), contributor.getEmail() ) );
|
| 330 |
|
| 331 |
tableCell( createLinkPatternedText( contributor.getUrl(), contributor.getUrl() ) );
|
| 332 |
|
| 333 |
tableCell( contributor.getOrganization() );
|
| 334 |
|
| 335 |
tableCell( createLinkPatternedText( contributor.getOrganizationUrl(), contributor
|
| 336 |
.getOrganizationUrl() ) );
|
| 337 |
|
| 338 |
if ( contributor.getRoles() != null )
|
| 339 |
{
|
| 340 |
// Comma separated roles
|
| 341 |
tableCell( StringUtils.join( contributor.getRoles().toArray( new String[0] ), ", " ) );
|
| 342 |
}
|
| 343 |
else
|
| 344 |
{
|
| 345 |
tableCell( null );
|
| 346 |
}
|
| 347 |
|
| 348 |
tableCell( contributor.getTimezone() );
|
| 349 |
|
| 350 |
// To handle JS
|
| 351 |
sink.tableCell();
|
| 352 |
sink.rawText( "<span id=\"contributor-" + contributorsRows + "\">" );
|
| 353 |
text( contributor.getTimezone() );
|
| 354 |
if ( !StringUtils.isEmpty( contributor.getTimezone() ) )
|
| 355 |
{
|
| 356 |
javascript.append( " offsetDate('contributor-" + contributorsRows + "', '" );
|
| 357 |
javascript.append( contributor.getTimezone() );
|
| 358 |
javascript.append( "');\n" );
|
| 359 |
}
|
| 360 |
sink.rawText( "</span>" );
|
| 361 |
sink.tableCell_();
|
| 362 |
|
| 363 |
Properties props = contributor.getProperties();
|
| 364 |
if ( props != null )
|
| 365 |
{
|
| 366 |
tableCell( propertiesToString( props ) );
|
| 367 |
}
|
| 368 |
else
|
| 369 |
{
|
| 370 |
tableCell( null );
|
| 371 |
}
|
| 372 |
|
| 373 |
sink.tableRow_();
|
| 374 |
|
| 375 |
contributorsRows++;
|
| 376 |
}
|
| 377 |
|
| 378 |
endTable();
|
| 379 |
}
|
| 380 |
|
| 381 |
endSection();
|
| 382 |
|
| 383 |
endSection();
|
| 384 |
|
| 385 |
// To handle JS
|
| 386 |
javascript.append( "}\n" ).append( "\n" ).append( "window.onLoad = init();\n" );
|
| 387 |
javaScript( javascript.toString() );
|
| 388 |
}
|
| 389 |
}
|
| 390 |
} |