private static @CheckForNull <T> T getReportPluginPropertyImpl(@NonNull MavenProject prj, @NonNull String groupId, @NonNull String artifactId, @NonNull ConfigurationBuilder<T> builder, @NullAllowed String report) { T toRet = null; for (ReportPlugin plug : getEffectiveReportPlugins(prj)) { if (artifactId.equals(plug.getArtifactId()) && groupId.equals(plug.getGroupId())) { if (plug.getReportSets() != null) { for (ReportSet exe : plug.getReportSets()) { if (exe.getReports().contains(report)) { toRet = builder.build((Xpp3Dom)exe.getConfiguration(), DUMMY_EVALUATOR); if (toRet != null) { break; } } } } if (toRet == null) { toRet = builder.build((Xpp3Dom)plug.getConfiguration(), DUMMY_EVALUATOR); } } } return toRet; }
private void writeReporting(Reporting reporting, String tagName, XmlSerializer serializer) throws java.io.IOException { serializer.startTag(NAMESPACE, tagName); flush(serializer); StringBuffer b = b(serializer); int start = b.length(); if (reporting.getExcludeDefaults() != null) { writeValue(serializer, "excludeDefaults", reporting.getExcludeDefaults(), reporting); } if (reporting.getOutputDirectory() != null) { writeValue(serializer, "outputDirectory", reporting.getOutputDirectory(), reporting); } if ((reporting.getPlugins() != null) && (reporting.getPlugins().size() > 0)) { serializer.startTag(NAMESPACE, "plugins"); for (Iterator iter = reporting.getPlugins().iterator(); iter.hasNext();) { ReportPlugin o = (ReportPlugin) iter.next(); writeReportPlugin(o, "plugin", serializer); } serializer.endTag(NAMESPACE, "plugins"); } serializer.endTag(NAMESPACE, tagName).flush(); logLocation(reporting, "", start, b.length()); }
private void visitProfileReporting( ModelVisitor visitor, Reporting reporting ) { List<ReportPlugin> plugins = reporting.getPlugins(); if ( plugins != null ) { ListIterator<ReportPlugin> pluginIterator = plugins.listIterator(); while ( pluginIterator.hasNext() ) { ReportPlugin plugin = pluginIterator.next(); visitor.visitProfileReportingPlugin( plugin ); visitProfileReportingPlugin( visitor, plugin ); plugin = visitor.replaceProfileReportingPlugin( plugin ); if ( plugin == null ) pluginIterator.remove(); else pluginIterator.set( plugin ); } } }
private void visitProfileReportingPlugin( ModelVisitor visitor, ReportPlugin reportPlugin ) { List<ReportSet> reportSets = reportPlugin.getReportSets(); if ( reportSets != null ) { ListIterator<ReportSet> reportSetIterator = reportSets.listIterator(); while ( reportSetIterator.hasNext() ) { ReportSet reportSet = reportSetIterator.next(); visitor.visitProfileReportingPluginReportSet( reportSet ); visitProfileReportingPluginReportSet( visitor, reportSet ); reportSet = visitor.replaceProfileReportingPluginReportSet( reportSet ); if ( reportSet == null ) reportSetIterator.remove(); else reportSetIterator.set( reportSet ); } } }
private void visitReporting( ModelVisitor visitor, Reporting reporting ) { List<ReportPlugin> plugins = reporting.getPlugins(); if ( plugins != null ) { ListIterator<ReportPlugin> pluginIterator = plugins.listIterator(); while ( pluginIterator.hasNext() ) { ReportPlugin plugin = pluginIterator.next(); visitor.visitReportingPlugin( plugin ); visitReportingPlugin( visitor, plugin ); plugin = visitor.replaceReportingPlugin( plugin ); if ( plugin == null ) pluginIterator.remove(); else pluginIterator.set( plugin ); } } }
private void visitReportingPlugin( ModelVisitor visitor, ReportPlugin reportPlugin ) { List<ReportSet> reportSets = reportPlugin.getReportSets(); if ( reportSets != null ) { ListIterator<ReportSet> reportSetIterator = reportSets.listIterator(); while ( reportSetIterator.hasNext() ) { ReportSet reportSet = reportSetIterator.next(); visitor.visitReportingPluginReportSet( reportSet ); visitReportingPluginReportSet( visitor, reportSet ); reportSet = visitor.replaceReportingPluginReportSet( reportSet ); if ( reportSet == null ) reportSetIterator.remove(); else reportSetIterator.set( reportSet ); } } }
public void expandPluginConfiguration( Model model, ModelBuildingRequest request, ModelProblemCollector problems ) { Reporting reporting = model.getReporting(); if ( reporting != null ) { for ( ReportPlugin reportPlugin : reporting.getPlugins() ) { Xpp3Dom parentDom = (Xpp3Dom) reportPlugin.getConfiguration(); if ( parentDom != null ) { for ( ReportSet execution : reportPlugin.getReportSets() ) { Xpp3Dom childDom = (Xpp3Dom) execution.getConfiguration(); childDom = Xpp3Dom.mergeXpp3Dom( childDom, new Xpp3Dom( parentDom ) ); execution.setConfiguration( childDom ); } } } } }
/** * Like {@link #getPluginVersion} but for report plugins. * @since 2.32 */ public static @CheckForNull String getReportPluginVersion(@NonNull MavenProject prj, @NonNull String groupId, @NonNull String artifactId) { for (ReportPlugin plug : getEffectiveReportPlugins(prj)) { if (groupId.equals(plug.getGroupId()) && artifactId.equals(plug.getArtifactId())) { return plug.getVersion(); } } return null; }
/** * Should handle both deprecated 2.x-style report section, and 3.x-style Site Plugin config. * https://jira.codehaus.org/browse/MSITE-484 and https://jira.codehaus.org/browse/MSITE-443 if and when implemented may require updates. */ private static @NonNull Iterable<ReportPlugin> getEffectiveReportPlugins(@NonNull MavenProject prj) { List<ReportPlugin> plugins = new ArrayList<ReportPlugin>(); for (Plugin plug : prj.getBuildPlugins()) { if (Constants.GROUP_APACHE_PLUGINS.equals(plug.getGroupId()) && Constants.PLUGIN_SITE.equals(plug.getArtifactId())) { Xpp3Dom cfg = (Xpp3Dom) plug.getConfiguration(); // MNG-4862 if (cfg == null) { continue; } Xpp3Dom reportPlugins = cfg.getChild("reportPlugins"); if (reportPlugins == null) { continue; } for (Xpp3Dom plugin : reportPlugins.getChildren("plugin")) { ReportPlugin p = new ReportPlugin(); Xpp3Dom groupId = plugin.getChild("groupId"); if (groupId != null) { p.setGroupId(groupId.getValue()); } Xpp3Dom artifactId = plugin.getChild("artifactId"); if (artifactId != null) { p.setArtifactId(artifactId.getValue()); } Xpp3Dom version = plugin.getChild("version"); if (version != null) { p.setVersion(version.getValue()); } p.setConfiguration(plugin.getChild("configuration")); // XXX reportSets // maven-site-plugin does not appear to apply defaults from plugin.xml (unlike 2.x?) plugins.add(p); } } } @SuppressWarnings("deprecation") List<ReportPlugin> m2Plugins = prj.getReportPlugins(); plugins.addAll(m2Plugins); return plugins; }
static boolean definesCheckStyle(MavenProject prj) { for (ReportPlugin plug : prj.getReportPlugins()) { if (Constants.GROUP_APACHE_PLUGINS.equals(plug.getGroupId()) && Constants.PLUGIN_CHECKSTYLE.equals(plug.getArtifactId())) { //NOI18N return true; } } return false; }
private void writeReportPlugin(ReportPlugin reportPlugin, String tagName, XmlSerializer serializer) throws java.io.IOException { serializer.startTag(NAMESPACE, tagName); flush(serializer); StringBuffer b = b(serializer); int start = b.length(); if ((reportPlugin.getGroupId() != null) && !reportPlugin.getGroupId().equals("org.apache.maven.plugins")) { writeValue(serializer, "groupId", reportPlugin.getGroupId(), reportPlugin); } if (reportPlugin.getArtifactId() != null) { writeValue(serializer, "artifactId", reportPlugin.getArtifactId(), reportPlugin); } if (reportPlugin.getVersion() != null) { writeValue(serializer, "version", reportPlugin.getVersion(), reportPlugin); } if ((reportPlugin.getReportSets() != null) && (reportPlugin.getReportSets().size() > 0)) { serializer.startTag(NAMESPACE, "reportSets"); for (Iterator iter = reportPlugin.getReportSets().iterator(); iter.hasNext();) { ReportSet o = (ReportSet) iter.next(); writeReportSet(o, "reportSet", serializer); } serializer.endTag(NAMESPACE, "reportSets"); } if (reportPlugin.getInherited() != null) { writeValue(serializer, "inherited", reportPlugin.getInherited(), reportPlugin); } if (reportPlugin.getConfiguration() != null) { writeXpp3DOM(serializer, (Xpp3Dom)reportPlugin.getConfiguration(), reportPlugin); } serializer.endTag(NAMESPACE, tagName).flush(); logLocation(reportPlugin, "", start, b.length()); }
/** * Method updateReportPlugin * * @param value * @param element * @param counter * @param xmlTag */ protected void updateReportPlugin( ReportPlugin value, String xmlTag, Counter counter, Element element ) { Element root = element; Counter innerCount = new Counter( counter.getDepth() + 1 ); findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins" ); findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null ); findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null ); findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null ); findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() ); iterateReportSet( innerCount, root, value.getReportSets(), "reportSets", "reportSet" ); }
@CheckForNull private static ReportPlugin getReportPlugin(Collection<ReportPlugin> plugins, String groupId, String artifactId) { for (ReportPlugin plugin : plugins) { if (isEqual(plugin, groupId, artifactId)) { return plugin; } } return null; }
/** * Compares to {@link Plugin} or {@link ReportPlugin} instances. * * @param o1 the first object * @param o2 the second object. * @return the comparison result * @see java.util.Comparator#compare(Object, Object) * @since 1.0-beta-1 */ public int compare( Object o1, Object o2 ) { if ( !( o1 instanceof Plugin || o1 instanceof ReportPlugin ) ) { throw new IllegalArgumentException( "This comparator can only be used to compare Plugin and ReportPlugin instances" ); } if ( !( o2 instanceof Plugin || o2 instanceof ReportPlugin ) ) { throw new IllegalArgumentException( "This comparator can only be used to compare Plugin and ReportPlugin instances" ); } String g1 = o1 instanceof Plugin ? ( (Plugin) o1 ).getGroupId() : ( (ReportPlugin) o1 ).getGroupId(); String g2 = o2 instanceof Plugin ? ( (Plugin) o2 ).getGroupId() : ( (ReportPlugin) o2 ).getGroupId(); int r = g1.compareTo( g2 ); if ( r == 0 ) { String a1 = o1 instanceof Plugin ? ( (Plugin) o1 ).getArtifactId() : ( (ReportPlugin) o1 ).getArtifactId(); String a2 = o2 instanceof Plugin ? ( (Plugin) o2 ).getArtifactId() : ( (ReportPlugin) o2 ).getArtifactId(); r = a1.compareTo( a2 ); } if ( r == 0 ) { String v1 = o1 instanceof Plugin ? ( (Plugin) o1 ).getVersion() : ( (ReportPlugin) o1 ).getVersion(); String v2 = o2 instanceof Plugin ? ( (Plugin) o2 ).getVersion() : ( (ReportPlugin) o2 ).getVersion(); if ( v1 == null ) { // hope I got the +1/-1 the right way around return v2 == null ? 0 : -1; } if ( v2 == null ) { return 1; } r = v1.compareTo( v2 ); } return r; }
private static Plugin toPlugin( ReportPlugin reportPlugin ) { Plugin plugin = new Plugin(); plugin.setGroupId( reportPlugin.getGroupId() ); plugin.setArtifactId( reportPlugin.getArtifactId() ); plugin.setVersion( reportPlugin.getVersion() ); return plugin; }
private static ReportPlugin toReportPlugin( Plugin plugin ) { ReportPlugin reportPlugin = new ReportPlugin(); reportPlugin.setGroupId( plugin.getGroupId() ); reportPlugin.setArtifactId( plugin.getArtifactId() ); reportPlugin.setVersion( plugin.getVersion() ); return reportPlugin; }
private static Set<Plugin> toPlugins( Set<ReportPlugin> reportPlugins ) { Set<Plugin> result; if ( reportPlugins instanceof LinkedHashSet ) { result = new LinkedHashSet<>( reportPlugins.size() ); } else if ( reportPlugins instanceof SortedSet ) { final Comparator<? super ReportPlugin> comparator = ( (SortedSet<ReportPlugin>) reportPlugins ).comparator(); result = new TreeSet<>( new Comparator<Plugin>() { public int compare( Plugin o1, Plugin o2 ) { return comparator.compare( toReportPlugin( o1 ), toReportPlugin( o2 ) ); } } ); } else { result = new HashSet<>( reportPlugins.size() ); } for ( ReportPlugin reportPlugin : reportPlugins ) { result.add( toPlugin( reportPlugin ) ); } return result; }
private static List<Plugin> toPlugins( List<ReportPlugin> reportPlugins ) { List<Plugin> result = new ArrayList<>( reportPlugins.size() ); for ( ReportPlugin reportPlugin : reportPlugins ) { result.add( toPlugin( reportPlugin ) ); } return result; }
private static Collection<Plugin> toPlugins( Collection<ReportPlugin> reportPlugins ) { if ( reportPlugins instanceof Set ) { return toPlugins( (Set<ReportPlugin>) reportPlugins ); } if ( reportPlugins instanceof List ) { return toPlugins( (List<ReportPlugin>) reportPlugins ); } return toPlugins( new ArrayList<>( reportPlugins ) ); }
private static Set<Plugin> toPlugins( Set<ReportPlugin> reportPlugins ) { Set<Plugin> result; if ( reportPlugins instanceof LinkedHashSet ) { result = new LinkedHashSet<Plugin>( reportPlugins.size() ); } else if ( reportPlugins instanceof SortedSet ) { final Comparator<? super ReportPlugin> comparator = ( (SortedSet<ReportPlugin>) reportPlugins ).comparator(); result = new TreeSet<Plugin>( new Comparator<Plugin>() { public int compare( Plugin o1, Plugin o2 ) { return comparator.compare( toReportPlugin( o1 ), toReportPlugin( o2 ) ); } } ); } else { result = new HashSet<Plugin>( reportPlugins.size() ); } for ( ReportPlugin reportPlugin : reportPlugins ) { result.add( toPlugin( reportPlugin ) ); } return result; }
private static List<Plugin> toPlugins( List<ReportPlugin> reportPlugins ) { List<Plugin> result = new ArrayList<Plugin>( reportPlugins.size() ); for ( ReportPlugin reportPlugin : reportPlugins ) { result.add( toPlugin( reportPlugin ) ); } return result; }
private static Collection<Plugin> toPlugins( Collection<ReportPlugin> reportPlugins ) { if ( reportPlugins instanceof Set ) { return toPlugins( (Set<ReportPlugin>) reportPlugins ); } if ( reportPlugins instanceof List ) { return toPlugins( (List<ReportPlugin>) reportPlugins ); } return toPlugins( new ArrayList<ReportPlugin>( reportPlugins ) ); }
@Deprecated public Set<Artifact> getReportArtifacts() { if ( reportArtifacts != null ) { return reportArtifacts; } reportArtifacts = new HashSet<Artifact>(); if ( repositorySystem != null ) { for ( ReportPlugin p : getReportPlugins() ) { Plugin pp = new Plugin(); pp.setGroupId( p.getGroupId() ); pp.setArtifactId( p.getArtifactId() ); pp.setVersion( p.getVersion() ); Artifact artifact = repositorySystem.createPluginArtifact( pp ); if ( artifact != null ) { reportArtifacts.add( artifact ); } } } reportArtifactMap = null; return reportArtifacts; }
@Deprecated public List<ReportPlugin> getReportPlugins() { if ( getModel().getReporting() == null ) { return Collections.emptyList(); } return getModel().getReporting().getPlugins(); }
protected void mergeReportPlugin( ReportPlugin target, ReportPlugin source, boolean sourceDominant, Map<Object, Object> context ) { mergeConfigurationContainer( target, source, sourceDominant, context ); mergeReportPlugin_GroupId( target, source, sourceDominant, context ); mergeReportPlugin_ArtifactId( target, source, sourceDominant, context ); mergeReportPlugin_Version( target, source, sourceDominant, context ); mergeReportPlugin_ReportSets( target, source, sourceDominant, context ); }
protected void mergeReportPlugin_GroupId( ReportPlugin target, ReportPlugin source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getGroupId(); if ( src != null ) { if ( sourceDominant || target.getGroupId() == null ) { target.setGroupId( src ); target.setLocation( "groupId", source.getLocation( "groupId" ) ); } } }
protected void mergeReportPlugin_ArtifactId( ReportPlugin target, ReportPlugin source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getArtifactId(); if ( src != null ) { if ( sourceDominant || target.getArtifactId() == null ) { target.setArtifactId( src ); target.setLocation( "artifactId", source.getLocation( "artifactId" ) ); } } }
protected void mergeReportPlugin_Version( ReportPlugin target, ReportPlugin source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getVersion(); if ( src != null ) { if ( sourceDominant || target.getVersion() == null ) { target.setVersion( src ); target.setLocation( "version", source.getLocation( "version" ) ); } } }
/** * Returns a plugin from a pom based on its group id and artifact id * <p> * It searches in the build section, then the reporting section and finally the pluginManagement section * </p> * * @param pom the project pom * @param groupId the plugin group id * @param artifactId the plugin artifact id * @return the plugin if it exists, null otherwise */ @CheckForNull public static MavenPlugin getPlugin(MavenProject pom, String groupId, String artifactId) { Object pluginConfiguration = null; // look for plugin in <build> section Plugin plugin = getPlugin(pom.getBuildPlugins(), groupId, artifactId); if (plugin != null) { pluginConfiguration = plugin.getConfiguration(); } else { // look for plugin in reporting Reporting reporting = pom.getModel().getReporting(); if (reporting != null) { ReportPlugin reportPlugin = getReportPlugin(reporting.getPlugins(), groupId, artifactId); if (reportPlugin != null) { pluginConfiguration = reportPlugin.getConfiguration(); } } } // look for plugin in <pluginManagement> section PluginManagement pluginManagement = pom.getPluginManagement(); if (pluginManagement != null) { Plugin pluginFromManagement = getPlugin(pluginManagement.getPlugins(), groupId, artifactId); if (pluginFromManagement != null) { Object pluginConfigFromManagement = pluginFromManagement.getConfiguration(); if (pluginConfiguration == null) { pluginConfiguration = pluginConfigFromManagement; } else if (pluginConfigFromManagement != null) { Xpp3Dom.mergeXpp3Dom((Xpp3Dom) pluginConfiguration, (Xpp3Dom) pluginConfigFromManagement); } } } if (pluginConfiguration != null) { return new MavenPlugin(pluginConfiguration); } return null; }
private static boolean isEqual(ReportPlugin plugin, String groupId, String artifactId) { return plugin.getArtifactId().equals(artifactId) && plugin.getGroupId().equals(groupId); }
@Override public ReportPlugin replaceProfileReportingPlugin( ReportPlugin plugin ) { return plugin; }
@Override public ReportPlugin replaceReportingPlugin( ReportPlugin plugin ) { return plugin; }
@Override public void visitProfileReportingPlugin( ReportPlugin plugin ) { }
@Override public void visitReportingPlugin( ReportPlugin plugin ) { }
private static void addReportPluginAssociations( VersionsHelper helper, ExpressionEvaluator expressionEvaluator, Map<String, PropertyVersionsBuilder> result, List<ReportPlugin> reportPlugins ) throws ExpressionEvaluationException { if ( reportPlugins == null ) { return; } for ( ReportPlugin plugin : reportPlugins ) { String version = plugin.getVersion(); if ( version != null && version.contains( "${" ) && version.indexOf( '}' ) != -1 ) { version = StringUtils.deleteWhitespace( version ); for ( PropertyVersionsBuilder property : result.values() ) { final String propertyRef = "${" + property.getName() + "}"; if ( version.contains( propertyRef ) ) { // any of these could be defined by a property String groupId = plugin.getGroupId(); if ( groupId == null || groupId.trim().length() == 0 ) { // group Id has a special default groupId = APACHE_MAVEN_PLUGINS_GROUPID; } else { groupId = (String) expressionEvaluator.evaluate( groupId ); } String artifactId = plugin.getArtifactId(); if ( artifactId == null || artifactId.trim().length() == 0 ) { // malformed pom continue; } else { artifactId = (String) expressionEvaluator.evaluate( artifactId ); } // might as well capture the current value VersionRange versionRange = VersionRange.createFromVersion( (String) expressionEvaluator.evaluate( plugin.getVersion() ) ); property.addAssociation( helper.createPluginArtifact( groupId, artifactId, versionRange ), true ); if ( !propertyRef.equals( version ) ) { addBounds( property, version, propertyRef, versionRange.toString() ); } } } } } }
/** * Method iterateReportPlugin * * @param counter * @param childTag * @param parentTag * @param list * @param parent */ protected void iterateReportPlugin( Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag ) { boolean shouldExist = list != null && list.size() > 0; Element element = updateElement( counter, parent, parentTag, shouldExist ); if ( shouldExist ) { Iterator it = list.iterator(); Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator(); if ( !elIt.hasNext() ) { elIt = null; } Counter innerCount = new Counter( counter.getDepth() + 1 ); while ( it.hasNext() ) { ReportPlugin value = (ReportPlugin) it.next(); Element el; if ( elIt != null && elIt.hasNext() ) { el = (Element) elIt.next(); if ( !elIt.hasNext() ) { elIt = null; } } else { el = factory.element( childTag, element.getNamespace() ); insertAtPreferredLocation( element, el, innerCount ); } updateReportPlugin( value, childTag, innerCount, el ); innerCount.increaseCount(); } if ( elIt != null ) { while ( elIt.hasNext() ) { elIt.next(); elIt.remove(); } } } }