| 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 java.util.ArrayList; |
| 23 | |
import java.util.Collections; |
| 24 | |
import java.util.Comparator; |
| 25 | |
import java.util.Iterator; |
| 26 | |
import java.util.List; |
| 27 | |
import java.util.Locale; |
| 28 | |
|
| 29 | |
import org.apache.maven.artifact.Artifact; |
| 30 | |
import org.apache.maven.artifact.factory.ArtifactFactory; |
| 31 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
| 32 | |
import org.apache.maven.artifact.versioning.VersionRange; |
| 33 | |
import org.apache.maven.doxia.sink.Sink; |
| 34 | |
import org.apache.maven.model.Plugin; |
| 35 | |
import org.apache.maven.plugin.logging.Log; |
| 36 | |
import org.apache.maven.project.MavenProject; |
| 37 | |
import org.apache.maven.project.MavenProjectBuilder; |
| 38 | |
import org.apache.maven.project.ProjectBuildingException; |
| 39 | |
import org.codehaus.plexus.i18n.I18N; |
| 40 | |
import org.codehaus.plexus.util.StringUtils; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | 1 | public class PluginManagementReport |
| 52 | |
extends AbstractProjectInfoReport |
| 53 | |
{ |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
private MavenProjectBuilder mavenProjectBuilder; |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
private ArtifactFactory artifactFactory; |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
public void executeReport( Locale locale ) |
| 78 | |
{ |
| 79 | 1 | PluginManagementRenderer r = new PluginManagementRenderer( getLog(), getSink(), locale, i18n, project |
| 80 | |
.getPluginManagement().getPlugins(), project, mavenProjectBuilder, artifactFactory, localRepository ); |
| 81 | 1 | r.render(); |
| 82 | 1 | } |
| 83 | |
|
| 84 | |
|
| 85 | |
public String getOutputName() |
| 86 | |
{ |
| 87 | 2 | return "plugin-management"; |
| 88 | |
} |
| 89 | |
|
| 90 | |
protected String getI18Nsection() |
| 91 | |
{ |
| 92 | 1 | return "pluginManagement"; |
| 93 | |
} |
| 94 | |
|
| 95 | |
|
| 96 | |
public boolean canGenerateReport() |
| 97 | |
{ |
| 98 | 2 | return project.getPluginManagement() != null && project.getPluginManagement().getPlugins() != null |
| 99 | |
&& !project.getPluginManagement().getPlugins().isEmpty(); |
| 100 | |
} |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | 1 | protected static class PluginManagementRenderer |
| 112 | |
extends AbstractProjectInfoRenderer |
| 113 | |
{ |
| 114 | |
private final Log log; |
| 115 | |
|
| 116 | |
private final List pluginManagement; |
| 117 | |
|
| 118 | |
private final MavenProject project; |
| 119 | |
|
| 120 | |
private final MavenProjectBuilder mavenProjectBuilder; |
| 121 | |
|
| 122 | |
private final ArtifactFactory artifactFactory; |
| 123 | |
|
| 124 | |
private final ArtifactRepository localRepository; |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
public PluginManagementRenderer( Log log, Sink sink, Locale locale, I18N i18n, List plugins, |
| 138 | |
MavenProject project, MavenProjectBuilder mavenProjectBuilder, |
| 139 | |
ArtifactFactory artifactFactory, ArtifactRepository localRepository ) |
| 140 | |
{ |
| 141 | 1 | super( sink, i18n, locale ); |
| 142 | |
|
| 143 | 1 | this.log = log; |
| 144 | |
|
| 145 | 1 | this.pluginManagement = plugins; |
| 146 | |
|
| 147 | 1 | this.project = project; |
| 148 | |
|
| 149 | 1 | this.mavenProjectBuilder = mavenProjectBuilder; |
| 150 | |
|
| 151 | 1 | this.artifactFactory = artifactFactory; |
| 152 | |
|
| 153 | 1 | this.localRepository = localRepository; |
| 154 | 1 | } |
| 155 | |
|
| 156 | |
protected String getI18Nsection() |
| 157 | |
{ |
| 158 | 2 | return "pluginManagement"; |
| 159 | |
} |
| 160 | |
|
| 161 | |
|
| 162 | |
public void renderBody() |
| 163 | |
{ |
| 164 | |
|
| 165 | 1 | renderSectionPluginManagement(); |
| 166 | 1 | } |
| 167 | |
|
| 168 | |
private void renderSectionPluginManagement() |
| 169 | |
{ |
| 170 | 1 | String[] tableHeader = getPluginTableHeader(); |
| 171 | |
|
| 172 | 1 | startSection( getTitle() ); |
| 173 | |
|
| 174 | |
|
| 175 | 1 | Collections.sort( pluginManagement, getPluginComparator() ); |
| 176 | |
|
| 177 | 1 | startTable(); |
| 178 | 1 | tableHeader( tableHeader ); |
| 179 | |
|
| 180 | 1 | for ( Iterator iterator = pluginManagement.iterator(); iterator.hasNext(); ) |
| 181 | |
{ |
| 182 | 2 | Plugin plugin = (Plugin) iterator.next(); |
| 183 | |
VersionRange versionRange; |
| 184 | 2 | if ( StringUtils.isEmpty( plugin.getVersion() ) ) |
| 185 | |
{ |
| 186 | 1 | versionRange = VersionRange.createFromVersion( Artifact.RELEASE_VERSION ); |
| 187 | |
} |
| 188 | |
else |
| 189 | |
{ |
| 190 | 1 | versionRange = VersionRange.createFromVersion( plugin.getVersion() ); |
| 191 | |
} |
| 192 | |
|
| 193 | 2 | Artifact pluginArtifact = artifactFactory.createParentArtifact( plugin.getGroupId(), plugin |
| 194 | |
.getArtifactId(), versionRange.toString() ); |
| 195 | 2 | List artifactRepositories = project.getPluginArtifactRepositories(); |
| 196 | 2 | if ( artifactRepositories == null ) |
| 197 | |
{ |
| 198 | 2 | artifactRepositories = new ArrayList(); |
| 199 | |
} |
| 200 | |
try |
| 201 | |
{ |
| 202 | 2 | MavenProject pluginProject = mavenProjectBuilder.buildFromRepository( pluginArtifact, |
| 203 | |
artifactRepositories, |
| 204 | |
localRepository ); |
| 205 | 2 | tableRow( getPluginRow( pluginProject.getGroupId(), pluginProject.getArtifactId(), pluginProject |
| 206 | |
.getVersion(), pluginProject.getUrl() ) ); |
| 207 | |
} |
| 208 | 0 | catch ( ProjectBuildingException e ) |
| 209 | |
{ |
| 210 | 0 | log.info( "Could not build project for: " + plugin.getArtifactId() + ":" + e.getMessage(), e ); |
| 211 | 0 | tableRow( getPluginRow( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), null ) ); |
| 212 | 2 | } |
| 213 | |
|
| 214 | 2 | } |
| 215 | 1 | endTable(); |
| 216 | |
|
| 217 | 1 | endSection(); |
| 218 | 1 | } |
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
private String[] getPluginTableHeader() |
| 225 | |
{ |
| 226 | |
|
| 227 | 1 | String groupId = getI18nString( "dependencyManagement", "column.groupId" ); |
| 228 | 1 | String artifactId = getI18nString( "dependencyManagement", "column.artifactId" ); |
| 229 | 1 | String version = getI18nString( "dependencyManagement", "column.version" ); |
| 230 | 1 | return new String[] { groupId, artifactId, version }; |
| 231 | |
} |
| 232 | |
|
| 233 | |
private String[] getPluginRow( String groupId, String artifactId, String version, String link ) |
| 234 | |
{ |
| 235 | 2 | artifactId = ProjectInfoReportUtils.getArtifactIdCell( artifactId, link ); |
| 236 | 2 | return new String[] { groupId, artifactId, version }; |
| 237 | |
} |
| 238 | |
|
| 239 | |
private Comparator getPluginComparator() |
| 240 | |
{ |
| 241 | 1 | return new Comparator() |
| 242 | 1 | { |
| 243 | |
|
| 244 | |
public int compare( Object o1, Object o2 ) |
| 245 | |
{ |
| 246 | 1 | Plugin a1 = (Plugin) o1; |
| 247 | 1 | Plugin a2 = (Plugin) o2; |
| 248 | |
|
| 249 | 1 | int result = a1.getGroupId().compareTo( a2.getGroupId() ); |
| 250 | 1 | if ( result == 0 ) |
| 251 | |
{ |
| 252 | 1 | result = a1.getArtifactId().compareTo( a2.getArtifactId() ); |
| 253 | |
} |
| 254 | 1 | return result; |
| 255 | |
} |
| 256 | |
}; |
| 257 | |
} |
| 258 | |
} |
| 259 | |
} |