001    package org.apache.maven.plugin.plugin;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.artifact.Artifact;
023    import org.apache.maven.artifact.repository.ArtifactRepository;
024    import org.apache.maven.doxia.sink.Sink;
025    import org.apache.maven.doxia.siterenderer.Renderer;
026    import org.apache.maven.model.Plugin;
027    import org.apache.maven.model.ReportPlugin;
028    import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
029    import org.apache.maven.plugin.descriptor.MojoDescriptor;
030    import org.apache.maven.plugin.descriptor.PluginDescriptor;
031    import org.apache.maven.project.MavenProject;
032    import org.apache.maven.reporting.AbstractMavenReport;
033    import org.apache.maven.reporting.AbstractMavenReportRenderer;
034    import org.apache.maven.reporting.MavenReportException;
035    import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
036    import org.apache.maven.tools.plugin.PluginToolsRequest;
037    import org.apache.maven.tools.plugin.extractor.ExtractionException;
038    import org.apache.maven.tools.plugin.generator.GeneratorException;
039    import org.apache.maven.tools.plugin.generator.GeneratorUtils;
040    import org.apache.maven.tools.plugin.generator.PluginXdocGenerator;
041    import org.apache.maven.tools.plugin.scanner.MojoScanner;
042    import org.apache.maven.tools.plugin.util.PluginUtils;
043    import org.codehaus.plexus.util.StringUtils;
044    import org.codehaus.plexus.util.xml.Xpp3Dom;
045    
046    import java.io.File;
047    import java.util.ArrayList;
048    import java.util.Iterator;
049    import java.util.List;
050    import java.util.Locale;
051    import java.util.Map;
052    import java.util.ResourceBundle;
053    import java.util.Set;
054    
055    /**
056     * Generates the Plugin's documentation report.
057     *
058     * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
059     * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
060     * @version $Id: PluginReport.java 1338439 2012-05-14 21:33:29Z olamy $
061     * @goal report
062     * @execute phase="process-classes"
063     * @since 2.0
064     */
065    public class PluginReport
066        extends AbstractMavenReport
067    {
068        /**
069         * Report output directory.
070         *
071         * @parameter default-value="${project.build.directory}/generated-site/xdoc"
072         */
073        private File outputDirectory;
074    
075        /**
076         * Doxia Site Renderer.
077         *
078         * @component
079         */
080        private Renderer siteRenderer;
081    
082        /**
083         * The Maven Project.
084         *
085         * @parameter expression="${project}"
086         * @required
087         * @readonly
088         */
089        private MavenProject project;
090    
091        /**
092         * Mojo scanner tools.
093         *
094         * @component
095         */
096        protected MojoScanner mojoScanner;
097    
098        /**
099         * The file encoding of the source files.
100         *
101         * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
102         * @since 2.7
103         */
104        private String encoding;
105    
106    
107        /**
108         * Specify some requirements to execute this plugin.
109         * Example:
110         * <pre>
111         * &lt;requirements&gt;
112         *   &lt;maven&gt;2.0&lt;/maven&gt;
113         *   &lt;jdk&gt;1.4&lt;/jdk&gt;
114         *   &lt;memory&gt;256m&lt;/memory&gt;
115         *   &lt;diskSpace&gt;1m&lt;/diskSpace&gt;
116         *   &lt;others&gt;
117         *     &lt;property&gt;
118         *       &lt;name&gt;SVN&lt;/name&gt;
119         *       &lt;value&gt;1.4.6&lt;/value&gt;
120         *     &lt;/property&gt;
121         *   &lt;/others&gt;
122         * &lt;/requirements&gt;
123         * </pre>
124         *
125         * @parameter
126         */
127        private Requirements requirements;
128    
129        /**
130         * The goal prefix that will appear before the ":".
131         * By default, this plugin applies a heuristic to derive a heuristic from
132         * the plugin's artifactId.
133         * <p/>
134         * It removes any occurrences of the regular expression <strong>-?maven-?</strong>,
135         * and then removes any occurrences of <strong>-?plugin-?</strong>.
136         * <p>
137         * For example, horsefeature-maven-plugin becomes horsefeature.
138         * </p>
139         * <p>
140         * (There is a special for maven-plugin-plugin; it is mapped to 'plugin'.
141         * </p>
142         *
143         * @parameter expression="${goalPrefix}"
144         * @since 2.4
145         */
146        protected String goalPrefix;
147    
148        /**
149         * Set this to "true" to skip invoking any goals or reports of the plugin.
150         *
151         * @parameter default-value="false" expression="${maven.plugin.skip}"
152         * @since 2.8
153         */
154        private boolean skip;
155    
156        /**
157         * Set this to "true" to skip generating the report.
158         *
159         * @parameter default-value="false" expression="${maven.plugin.report.skip}"
160         * @since 2.8
161         */
162        private boolean skipReport;
163    
164        /**
165         * The set of dependencies for the current project
166         *
167         * @parameter default-value = "${project.artifacts}"
168         * @required
169         * @readonly
170         * @since 3.0
171         */
172        protected Set<Artifact> dependencies;
173    
174        /**
175         * List of Remote Repositories used by the resolver
176         *
177         * @parameter expression="${project.remoteArtifactRepositories}"
178         * @readonly
179         * @required
180         * @since 3.0
181         */
182        protected List<ArtifactRepository> remoteRepos;
183    
184        /**
185         * Location of the local repository.
186         *
187         * @parameter expression="${localRepository}"
188         * @readonly
189         * @required
190         * @since 3.0
191         */
192        protected ArtifactRepository local;
193    
194        /**
195         * {@inheritDoc}
196         */
197        protected Renderer getSiteRenderer()
198        {
199            return siteRenderer;
200        }
201    
202        /**
203         * {@inheritDoc}
204         */
205        protected String getOutputDirectory()
206        {
207            return outputDirectory.getPath();
208        }
209    
210        /**
211         * {@inheritDoc}
212         */
213        protected MavenProject getProject()
214        {
215            return project;
216        }
217    
218        /**
219         * {@inheritDoc}
220         */
221        public boolean canGenerateReport()
222        {
223            return "maven-plugin".equals( project.getPackaging() );
224        }
225    
226        /**
227         * {@inheritDoc}
228         */
229        @SuppressWarnings( "unchecked" )
230        protected void executeReport( Locale locale )
231            throws MavenReportException
232        {
233            if ( !canGenerateReport() )
234            {
235                return;
236            }
237            if ( skip || skipReport )
238            {
239                getLog().info( "Maven Plugin Plugin Report generation skipped." );
240                return;
241            }
242    
243            // Copy from AbstractGeneratorMojo#execute()
244            String defaultGoalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() );
245            if ( goalPrefix == null )
246            {
247                goalPrefix = defaultGoalPrefix;
248            }
249            else
250            {
251                getLog().warn( "\n\nGoal prefix is specified as: '" + goalPrefix + "'. Maven currently expects it to be '"
252                                   + defaultGoalPrefix + "'.\n" );
253            }
254    
255            // TODO: could use this more, eg in the writing of the plugin descriptor!
256            PluginDescriptor pluginDescriptor = new PluginDescriptor();
257    
258            pluginDescriptor.setGroupId( project.getGroupId() );
259    
260            pluginDescriptor.setArtifactId( project.getArtifactId() );
261    
262            pluginDescriptor.setVersion( project.getVersion() );
263    
264            pluginDescriptor.setGoalPrefix( goalPrefix );
265    
266            try
267            {
268                pluginDescriptor.setDependencies( GeneratorUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
269    
270                PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
271                request.setEncoding( encoding );
272                request.setSkipErrorNoDescriptorsFound( true );
273                request.setDependencies( dependencies );
274                request.setLocal( this.local );
275                request.setRemoteRepos( this.remoteRepos );
276    
277    
278                try
279                {
280                    mojoScanner.populatePluginDescriptor( request );
281                }
282                catch ( InvalidPluginDescriptorException e )
283                {
284                    // this is OK, it happens to lifecycle plugins. Allow generation to proceed.
285                    getLog().debug( "Plugin without mojos.", e );
286    
287                }
288    
289                // Generate the plugin's documentation
290                generatePluginDocumentation( pluginDescriptor, locale );
291    
292                // Write the overview
293                PluginOverviewRenderer r =
294                    new PluginOverviewRenderer( project, requirements, getSink(), pluginDescriptor, locale );
295                r.render();
296            }
297    
298            catch ( ExtractionException e )
299            {
300                throw new MavenReportException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'",
301                                                e );
302            }
303        }
304    
305        /**
306         * {@inheritDoc}
307         */
308        public String getDescription( Locale locale )
309        {
310            return getBundle( locale ).getString( "report.plugin.description" );
311        }
312    
313        /**
314         * {@inheritDoc}
315         */
316        public String getName( Locale locale )
317        {
318            return getBundle( locale ).getString( "report.plugin.name" );
319        }
320    
321        /**
322         * {@inheritDoc}
323         */
324        public String getOutputName()
325        {
326            return "plugin-info";
327        }
328    
329        /**
330         * @param pluginDescriptor not null
331         * @param locale           not null
332         * @throws MavenReportException if any
333         */
334        private void generatePluginDocumentation( PluginDescriptor pluginDescriptor, Locale locale )
335            throws MavenReportException
336        {
337            try
338            {
339                File outputDir = new File( getOutputDirectory() );
340                outputDir.mkdirs();
341    
342                PluginXdocGenerator generator = new PluginXdocGenerator( project, locale );
343                PluginToolsRequest pluginToolsRequest = new DefaultPluginToolsRequest( project, pluginDescriptor );
344                generator.execute( outputDir, pluginToolsRequest );
345            }
346            catch ( GeneratorException e )
347            {
348                throw new MavenReportException( "Error writing plugin documentation", e );
349            }
350    
351        }
352    
353        /**
354         * @param locale not null
355         * @return the bundle for this report
356         */
357        protected static ResourceBundle getBundle( Locale locale )
358        {
359            return ResourceBundle.getBundle( "plugin-report", locale, PluginReport.class.getClassLoader() );
360        }
361    
362        /**
363         * Generates an overview page with the list of goals
364         * and a link to the goal's page.
365         */
366        static class PluginOverviewRenderer
367            extends AbstractMavenReportRenderer
368        {
369            private final MavenProject project;
370    
371            private final Requirements requirements;
372    
373            private final PluginDescriptor pluginDescriptor;
374    
375            private final Locale locale;
376    
377            /**
378             * @param project          not null
379             * @param requirements     not null
380             * @param sink             not null
381             * @param pluginDescriptor not null
382             * @param locale           not null
383             */
384            public PluginOverviewRenderer( MavenProject project, Requirements requirements, Sink sink,
385                                           PluginDescriptor pluginDescriptor, Locale locale )
386            {
387                super( sink );
388    
389                this.project = project;
390    
391                this.requirements = ( requirements == null ? new Requirements() : requirements );
392    
393                this.pluginDescriptor = pluginDescriptor;
394    
395                this.locale = locale;
396            }
397    
398            /**
399             * {@inheritDoc}
400             */
401            public String getTitle()
402            {
403                return getBundle( locale ).getString( "report.plugin.title" );
404            }
405    
406            /**
407             * {@inheritDoc}
408             */
409            @SuppressWarnings( { "unchecked", "rawtypes" } )
410            public void renderBody()
411            {
412                startSection( getTitle() );
413    
414                if ( !( pluginDescriptor.getMojos() != null && pluginDescriptor.getMojos().size() > 0 ) )
415                {
416                    paragraph( getBundle( locale ).getString( "report.plugin.goals.nogoal" ) );
417                    endSection();
418                    return;
419                }
420    
421                paragraph( getBundle( locale ).getString( "report.plugin.goals.intro" ) );
422    
423                boolean hasMavenReport = false;
424                for ( Iterator<MojoDescriptor> i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
425                {
426                    MojoDescriptor mojo = i.next();
427    
428                    if ( GeneratorUtils.isMavenReport( mojo.getImplementation(), project ) )
429                    {
430                        hasMavenReport = true;
431                    }
432                }
433    
434                startTable();
435    
436                String goalColumnName = getBundle( locale ).getString( "report.plugin.goals.column.goal" );
437                String isMavenReport = getBundle( locale ).getString( "report.plugin.goals.column.isMavenReport" );
438                String descriptionColumnName = getBundle( locale ).getString( "report.plugin.goals.column.description" );
439                if ( hasMavenReport )
440                {
441                    tableHeader( new String[]{ goalColumnName, isMavenReport, descriptionColumnName } );
442                }
443                else
444                {
445                    tableHeader( new String[]{ goalColumnName, descriptionColumnName } );
446                }
447    
448                List<MojoDescriptor> mojos = new ArrayList<MojoDescriptor>();
449                mojos.addAll( pluginDescriptor.getMojos() );
450                PluginUtils.sortMojos( mojos );
451                for ( MojoDescriptor mojo : mojos )
452                {
453                    String goalName = mojo.getFullGoalName();
454    
455                    /*
456                     * Added ./ to define a relative path
457                     * @see AbstractMavenReportRenderer#getValidHref(java.lang.String)
458                     */
459                    String goalDocumentationLink = "./" + mojo.getGoal() + "-mojo.html";
460    
461                    String description;
462                    if ( StringUtils.isNotEmpty( mojo.getDeprecated() ) )
463                    {
464                        description =
465                            "<strong>" + getBundle( locale ).getString( "report.plugin.goal.deprecated" ) + "</strong> "
466                                + GeneratorUtils.makeHtmlValid( mojo.getDeprecated() );
467                    }
468                    else if ( StringUtils.isNotEmpty( mojo.getDescription() ) )
469                    {
470                        description = GeneratorUtils.makeHtmlValid( mojo.getDescription() );
471                    }
472                    else
473                    {
474                        description = getBundle( locale ).getString( "report.plugin.goal.nodescription" );
475                    }
476    
477                    sink.tableRow();
478                    tableCell( createLinkPatternedText( goalName, goalDocumentationLink ) );
479                    if ( hasMavenReport )
480                    {
481                        if ( GeneratorUtils.isMavenReport( mojo.getImplementation(), project ) )
482                        {
483                            sink.tableCell();
484                            sink.text( getBundle( locale ).getString( "report.plugin.isReport" ) );
485                            sink.tableCell_();
486                        }
487                        else
488                        {
489                            sink.tableCell();
490                            sink.text( getBundle( locale ).getString( "report.plugin.isNotReport" ) );
491                            sink.tableCell_();
492                        }
493                    }
494                    tableCell( description, true );
495                    sink.tableRow_();
496                }
497    
498                endTable();
499    
500                startSection( getBundle( locale ).getString( "report.plugin.systemrequirements" ) );
501    
502                paragraph( getBundle( locale ).getString( "report.plugin.systemrequirements.intro" ) );
503    
504                startTable();
505    
506                String maven = discoverMavenRequirement( project, requirements );
507                sink.tableRow();
508                tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.maven" ) );
509                tableCell( ( maven != null
510                    ? maven
511                    : getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) );
512                sink.tableRow_();
513    
514                String jdk = discoverJdkRequirement( project, requirements );
515                sink.tableRow();
516                tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.jdk" ) );
517                tableCell(
518                    ( jdk != null ? jdk : getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) );
519                sink.tableRow_();
520    
521                sink.tableRow();
522                tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.memory" ) );
523                tableCell( ( StringUtils.isNotEmpty( requirements.getMemory() )
524                    ? requirements.getMemory()
525                    : getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) );
526                sink.tableRow_();
527    
528                sink.tableRow();
529                tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.diskspace" ) );
530                tableCell( ( StringUtils.isNotEmpty( requirements.getDiskSpace() )
531                    ? requirements.getDiskSpace()
532                    : getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) );
533                sink.tableRow_();
534    
535                if ( requirements.getOthers() != null && requirements.getOthers().size() > 0 )
536                {
537                    for ( Iterator it = requirements.getOthers().keySet().iterator(); it.hasNext(); )
538                    {
539                        String key = it.next().toString();
540    
541                        sink.tableRow();
542                        tableCell( key );
543                        tableCell( ( StringUtils.isNotEmpty( requirements.getOthers().getProperty( key ) )
544                            ? requirements.getOthers().getProperty( key )
545                            : getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) );
546                        sink.tableRow_();
547                    }
548                }
549                endTable();
550    
551                endSection();
552    
553                renderUsageSection( hasMavenReport );
554    
555                endSection();
556            }
557    
558            /**
559             * Render the section about the usage of the plugin.
560             *
561             * @param hasMavenReport If the plugin has a report or not
562             */
563            private void renderUsageSection( boolean hasMavenReport )
564            {
565                startSection( getBundle( locale ).getString( "report.plugin.usage" ) );
566    
567                // Configuration
568                sink.paragraph();
569                text( getBundle( locale ).getString( "report.plugin.usage.intro" ) );
570                sink.paragraph_();
571    
572                StringBuilder sb = new StringBuilder();
573                sb.append( "<project>" ).append( '\n' );
574                sb.append( "  ..." ).append( '\n' );
575                sb.append( "  <build>" ).append( '\n' );
576                sb.append(
577                    "    <!-- " + getBundle( locale ).getString( "report.plugin.usage.pluginManagement" ) + " -->" ).append(
578                    '\n' );
579                sb.append( "    <pluginManagement>" ).append( '\n' );
580                sb.append( "      <plugins>" ).append( '\n' );
581                sb.append( "        <plugin>" ).append( '\n' );
582                sb.append( "          <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" ).append(
583                    '\n' );
584                sb.append( "          <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append(
585                    "</artifactId>" ).append( '\n' );
586                sb.append( "          <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" ).append(
587                    '\n' );
588                sb.append( "        </plugin>" ).append( '\n' );
589                sb.append( "        ..." ).append( '\n' );
590                sb.append( "      </plugins>" ).append( '\n' );
591                sb.append( "    </pluginManagement>" ).append( '\n' );
592                sb.append( "    <!-- " + getBundle( locale ).getString( "report.plugin.usage.plugins" ) + " -->" ).append(
593                    '\n' );
594                sb.append( "    <plugins>" ).append( '\n' );
595                sb.append( "      <plugin>" ).append( '\n' );
596                sb.append( "        <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" ).append(
597                    '\n' );
598                sb.append( "        <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append(
599                    "</artifactId>" ).append( '\n' );
600                sb.append( "        <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" ).append(
601                    '\n' );
602                sb.append( "      </plugin>" ).append( '\n' );
603                sb.append( "      ..." ).append( '\n' );
604                sb.append( "    </plugins>" ).append( '\n' );
605                sb.append( "  </build>" ).append( '\n' );
606    
607                if ( hasMavenReport )
608                {
609                    sb.append( "  ..." ).append( '\n' );
610                    sb.append(
611                        "  <!-- " + getBundle( locale ).getString( "report.plugin.usage.reporting" ) + " -->" ).append(
612                        '\n' );
613                    sb.append( "  <reporting>" ).append( '\n' );
614                    sb.append( "    <plugins>" ).append( '\n' );
615                    sb.append( "      <plugin>" ).append( '\n' );
616                    sb.append( "        <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" ).append(
617                        '\n' );
618                    sb.append( "        <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append(
619                        "</artifactId>" ).append( '\n' );
620                    sb.append( "        <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" ).append(
621                        '\n' );
622                    sb.append( "      </plugin>" ).append( '\n' );
623                    sb.append( "      ..." ).append( '\n' );
624                    sb.append( "    </plugins>" ).append( '\n' );
625                    sb.append( "  </reporting>" ).append( '\n' );
626                }
627    
628                sb.append( "  ..." ).append( '\n' );
629                sb.append( "</project>" ).append( '\n' );
630    
631                verbatimText( sb.toString() );
632    
633                sink.paragraph();
634                linkPatternedText( getBundle( locale ).getString( "report.plugin.configuration.end" ) );
635                sink.paragraph_();
636    
637                endSection();
638            }
639    
640            /**
641             * Try to lookup on the Maven prerequisites property.
642             * If not specified, uses the value defined by the user.
643             *
644             * @param project      not null
645             * @param requirements not null
646             * @return the Maven version
647             */
648            private static String discoverMavenRequirement( MavenProject project, Requirements requirements )
649            {
650                String maven = requirements.getMaven();
651                if ( maven == null )
652                {
653                    maven = ( project.getPrerequisites() != null ? project.getPrerequisites().getMaven() : null );
654                }
655                if ( maven == null )
656                {
657                    maven = "2.0";
658                }
659    
660                return maven;
661            }
662    
663            /**
664             * Try to lookup on the <code>org.apache.maven.plugins:maven-compiler-plugin</code> plugin to
665             * find the value of the <code>target</code> option.
666             * If not specified, uses the value defined by the user.
667             * If not specified, uses the value of the system property <code>java.specification.version</code>.
668             *
669             * @param project      not null
670             * @param requirements not null
671             * @return the JDK version
672             */
673            private static String discoverJdkRequirement( MavenProject project, Requirements requirements )
674            {
675                String jdk = requirements.getJdk();
676                if ( jdk == null )
677                {
678                    jdk = discoverJdkRequirementFromPlugins( project.getBuild().getPluginsAsMap() );
679                }
680                if ( jdk == null )
681                {
682                    if ( project.getPluginManagement() != null )
683                    {
684                        jdk = discoverJdkRequirementFromPlugins( project.getPluginManagement().getPluginsAsMap() );
685                    }
686                }
687                if ( jdk == null )
688                {
689                    jdk = "Unknown";
690                }
691    
692                return jdk;
693            }
694    
695            /**
696             * @param pluginsAsMap could be null
697             * @return the value of the <code>target</code> in the configuration of <code>maven-compiler-plugin</code>.
698             */
699            @SuppressWarnings( "rawtypes" )
700            private static String discoverJdkRequirementFromPlugins( Map pluginsAsMap )
701            {
702                if ( pluginsAsMap == null )
703                {
704                    return null;
705                }
706    
707                String jdk = null;
708                String backupJdk = null;
709                for ( Iterator it = pluginsAsMap.keySet().iterator(); it.hasNext(); )
710                {
711                    String key = it.next().toString();
712    
713                    if ( !key.equals( "org.apache.maven.plugins:maven-compiler-plugin" ) )
714                    {
715                        continue;
716                    }
717    
718                    Object value = pluginsAsMap.get( key );
719                    Xpp3Dom pluginConf = null;
720    
721                    backupJdk = "Default version for maven-compiler-plugin";
722                    if ( value instanceof Plugin )
723                    {
724                        Plugin plugin = (Plugin) value;
725                        backupJdk = "Default target for maven-compiler-plugin version " + plugin.getVersion();
726                        pluginConf = (Xpp3Dom) plugin.getConfiguration();
727                    }
728    
729                    if ( value instanceof ReportPlugin )
730                    {
731                        ReportPlugin reportPlugin = (ReportPlugin) value;
732                        backupJdk = "Default target for maven-compiler-plugin version " + reportPlugin.getVersion();
733                        pluginConf = (Xpp3Dom) reportPlugin.getConfiguration();
734                    }
735    
736                    if ( pluginConf == null )
737                    {
738                        continue;
739                    }
740    
741                    if ( pluginConf.getChild( "target" ) == null )
742                    {
743                        continue;
744                    }
745    
746                    jdk = pluginConf.getChild( "target" ).getValue();
747                }
748    
749                if ( jdk == null )
750                {
751                    return backupJdk;
752                }
753                else
754                {
755                    return jdk;
756                }
757            }
758        }
759    }