You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "QualiteSys QualiteSys (JIRA)" <ji...@apache.org> on 2017/05/07 20:02:04 UTC

[jira] [Commented] (MSITE-793) MavenMultiPage example

    [ https://issues.apache.org/jira/browse/MSITE-793?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16000030#comment-16000030 ] 

QualiteSys QualiteSys commented on MSITE-793:
---------------------------------------------

I have been able to do it.

The main thing is to create a new sink for each additional page. The siterenderer process will then create the html files, with the same left menu as the orginal page. 

Didier

Here is an example (using maven-site-plugin version 3.5)

package com.qualitesys.qcrmavenplugin;

/*
 * Copyright 2001-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.project.MavenProject;

/**
 * Generation of part 96 of qualitychecker report in the site phase, essai rapport multi page
 *
 * @goal qcrgoalreporting96
 * 
 * @phase site
 */
public class QcrReporting96Mojo
    extends AbstractMavenReport
{
    /**
     * Language of the project.
     * @parameter expression="${sonar.language}"
     * @required
     */
    private String language;
    /**
     * Location of the sourcedirectory
     * @parameter expression="${project.build.sourceDirectory}"
     * @required
     */
    private String sourceDirectory;
    /**
     * Location of the file.
     * @parameter expression="${project.build.directory}"
     * @required
     */
    private File outputDirectory;
    /**
     * Modele objet du projet Maven
     * @parameter expression="${project}"
     * @required
     * @readonly
     */
    private MavenProject project;

    /**
     * List of reportings to produce 0102030405 etc 
     * @parameter expression="${sonar.reporting}"
     */
    private String reporting;
    
    
  /*
   * (non-Javadoc)
   *
   * @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory()
   */
    @Override
    protected String getOutputDirectory() {
      return outputDirectory.getAbsolutePath();
    }

    @Override
    protected MavenProject getProject() {
        return project;
    }
    @Override
    public boolean canGenerateReport() {
        boolean res =  null==reporting
                    || reporting.isEmpty()
                    || reporting.contains("96")
                ;
        return res;
    }

    @Override
  public String getOutputName() {
    return "QcrReportFile96";
  }

    @Override
  public String getName(Locale arg0) {
    return "QC96 Essai multipage";
  }

    @Override
  public String getDescription(Locale arg0) {
    return "Report for QualityChecker version "+QcrCommunDec.VERSION+" according to CWE MITRE's repository see http://www.mitre.org/";
  }
  // Constructeur pour forcer le outputDirectory voir code source de AbstractMavenReport
  public QcrReporting96Mojo() {
      super();
      if (null==outputDirectory) {
          outputDirectory = new File("");
      }
      this.setReportOutputDirectory(outputDirectory);
  }
  private static final String MOI = "QcrReporting96Mojo::";

  
    @Override
    public void executeReport(Locale defaultLocale)
            throws MavenReportException {
        final String ROUTINE = "executeReport";
        if (null == project) {
           return;
        }

        if (null == project)
            throw new MavenReportException( MOI+ROUTINE+"02 project non initialized " );
        if (null == outputDirectory) {
            throw new MavenReportException( MOI+ROUTINE+"03 outputDirectory non initialized " );
        }
        if (null == this.getOutputName()) {
            throw new MavenReportException( MOI+ROUTINE+"06 outputName is null " );
        }
        String lsFic = this.getReportOutputDirectory() + "/" + this.getOutputName();
        try {
            List<Sink> lesSinks = new Vector<Sink>();
            for (int liInt=0; liInt<4; liInt++) {
                File   lsDir = this.getReportOutputDirectory();
                String lsOut = this.getOutputName()+liInt+".html";
                lesSinks.add(this.getSinkFactory().createSink(
                        lsDir, 
                        lsOut)
                );
            }
            doProcess(lesSinks,lsFic);
        } catch (Exception ex) {
        }
        
        // Ici le sink principal
        Sink sink = this.getSink();
        sink.head();
        sink.title();
        sink.text("QualityChecker Rules violations, security rules");
        sink.title_();

        sink.head_();
        sink.body();
        sink.section1();

        sink.lineBreak();
        sink.text("Some stuff main");
        sink.lineBreak();
        sink.section1_();
        sink.section1();

        sink.lineBreak();
        sink.text("Links to Multipages ");
        sink.lineBreak();
        sink.lineBreak();
        sink.link(lsFic+"0.html");
        sink.text("Fichier0");
        sink.link_();
        sink.lineBreak();
        sink.link(lsFic+"1.html");
        sink.text("Fichier1");
        sink.link_();
        sink.lineBreak();
        sink.link(lsFic+"2.html");
        sink.text("Fichier2");
        sink.link_();
        sink.lineBreak();
        sink.link(lsFic+"3.html");
        sink.text("Fichier3");
        sink.link_();
        sink.lineBreak();
        sink.section1_();
        sink.body_();
        sink.flush();
        sink.close();
    }
    private void doProcess(List<Sink> alsSink, String asFic) {
        final String ROUTINE = "doProcess";
        int indice = 0;
        for (Sink sink : alsSink) {
            sink.head();
            sink.title();
            sink.text("Inner sink details");
            sink.title_();

            sink.head_();
            sink.body();
            sink.section1();

            sink.lineBreak();
            sink.text("Some stuff for the inner sink "+indice);
            sink.lineBreak();
            sink.link(asFic+".html");
            sink.text("Links to main page ");
            sink.link_();
            sink.section1_();
            sink.body_();
            sink.flush();
            sink.close();
            indice++;
        }
    }
}


> MavenMultiPage example
> ----------------------
>
>                 Key: MSITE-793
>                 URL: https://issues.apache.org/jira/browse/MSITE-793
>             Project: Maven Site Plugin
>          Issue Type: Wish
>          Components: doxia integration
>            Reporter: QualiteSys QualiteSys
>
> I am used to produce Maven Site static Html reports. I wish to produce multi pages reports (one report page per source code for example). In version 2.1.1 of org.apache.maven.reporting is defined the MavenMultiPageReport interface. How to use it with the maven-site-plugin ?
> Thanks for your help.
> Didier



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)