org.apache.maven.model.ReportPlugin Java Examples

The following examples show how to use org.apache.maven.model.ReportPlugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PluginPropertyUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: LocationAwareMavenXpp3Writer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #3
Source File: PluginPropertyUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: PluginPropertyUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: AuxPropsImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: LocationAwareMavenXpp3Writer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #7
Source File: PluginComparator.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: DisplayPluginUpdatesMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static Plugin toPlugin( ReportPlugin reportPlugin )
{
    Plugin plugin = new Plugin();
    plugin.setGroupId( reportPlugin.getGroupId() );
    plugin.setArtifactId( reportPlugin.getArtifactId() );
    plugin.setVersion( reportPlugin.getVersion() );
    return plugin;
}
 
Example #9
Source File: DisplayPluginUpdatesMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: PomHelper.java    From versions-maven-plugin with Apache License 2.0 4 votes vote down vote up
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() );
                    }
                }
            }
        }
    }
}
 
Example #11
Source File: DisplayPluginUpdatesMojo.java    From versions-maven-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the Inherited of a {@link Plugin} or {@link ReportPlugin}
 *
 * @param plugin the {@link Plugin} or {@link ReportPlugin}
 * @return the Inherited of the {@link Plugin} or {@link ReportPlugin}
 * @since 1.0-alpha-1
 */
private static boolean getPluginInherited( Object plugin )
{
    return "true".equalsIgnoreCase( plugin instanceof ReportPlugin ? ( (ReportPlugin) plugin ).getInherited()
                    : ( (Plugin) plugin ).getInherited() );
}