protected void aggregate(MavenProject parent) throws Exception {
   List<MavenProject> modules = parent.getCollectedProjects();
   File dest = new File(parent.getReporting().getOutputDirectory() + "/" + outputDirectory);
   getLog().info("start aggregation into " + dest);
   StringBuilder mpath = new StringBuilder();
   for (MavenProject module : modules) {
     if ("pom".equals(module.getPackaging().toLowerCase())) {
       continue;
     }
     if (aggregateDirectOnly && module.getParent() != parent) {
       continue;
     }
     File subScaladocPath =
         new File(module.getReporting().getOutputDirectory() + "/" + outputDirectory)
             .getAbsoluteFile();
     // System.out.println(" -> " + project.getModulePathAdjustment(module)  +" // " +
     // subScaladocPath + " // " + module.getBasedir() );
     if (subScaladocPath.exists()) {
       mpath.append(subScaladocPath).append(File.pathSeparatorChar);
     }
   }
   if (mpath.length() != 0) {
     getLog().info("aggregate vscaladoc from : " + mpath);
     JavaMainCaller jcmd = getScalaCommand();
     jcmd.addOption("-d", dest.getAbsolutePath());
     jcmd.addOption("-aggregate", mpath.toString());
     jcmd.run(displayCmd);
   } else {
     getLog().warn("no vscaladoc to aggregate");
   }
   tryAggregateUpper(parent);
 }
  public void generate(Sink sink, Locale locale) throws MavenReportException {
    try {
      if (!canGenerateReport()) {
        getLog().warn("No source files found");
        return;
      }

      File reportOutputDir = getReportOutputDirectory();
      if (!reportOutputDir.exists()) {
        reportOutputDir.mkdirs();
      }
      if (StringUtils.isNotEmpty(vscaladocVersion)) {
        scaladocClassName = "org.scala_tools.vscaladoc.Main";
        BasicArtifact artifact = new BasicArtifact();
        artifact.artifactId = "vscaladoc";
        artifact.groupId = "org.scala-tools";
        artifact.version = vscaladocVersion;
        dependencies = new BasicArtifact[] {artifact};
      }

      List<File> sources = findSourceFiles();
      if (sources.size() > 0) {
        JavaMainCaller jcmd = getScalaCommand();
        jcmd.addOption("-d", reportOutputDir.getAbsolutePath());
        for (File x : sources) {
          jcmd.addArgs(FileUtils.pathOf(x, useCanonicalPath));
        }
        jcmd.run(displayCmd);
      }
      if (forceAggregate) {
        aggregate(project);
      } else {
        // Mojo could not be run from parent after all its children
        // So the aggregation will be run after the last child
        tryAggregateUpper(project);
      }

    } catch (MavenReportException exc) {
      throw exc;
    } catch (RuntimeException exc) {
      throw exc;
    } catch (Exception exc) {
      throw new MavenReportException("wrap: " + exc.getMessage(), exc);
    }
  }
  @Override
  protected JavaMainCaller getScalaCommand() throws Exception {
    // This ensures we have a valid scala version...
    checkScalaVersion();
    boolean isPreviousScala271 = (new VersionNumber("2.7.1").compareTo(findScalaVersion()) > 0);
    if (StringUtils.isEmpty(scaladocClassName)) {
      if (!isPreviousScala271) {
        scaladocClassName = "scala.tools.nsc.ScalaDoc";
      } else {
        scaladocClassName = scalaClassName;
      }
    }

    JavaMainCaller jcmd = getEmptyScalaCommand(scaladocClassName);
    jcmd.addArgs(args);
    jcmd.addJvmArgs(jvmArgs);

    if (isPreviousScala271) {
      jcmd.addArgs("-Ydoc");
    }
    // copy the classpathElements to not modify the global project definition see
    // https://github.com/davidB/maven-scala-plugin/issues/60
    List<String> paths = new ArrayList<String>(project.getCompileClasspathElements());
    paths.remove(
        project
            .getBuild()
            .getOutputDirectory()); // remove output to avoid "error for" : error:  XXX is already
                                    // defined as package XXX ... object XXX {
    jcmd.addOption("-classpath", MainHelper.toMultiPath(paths));
    // jcmd.addOption("-sourcepath", sourceDir.getAbsolutePath());

    boolean isScaladoc2 =
        (new VersionNumber("2.8.0").compareTo(findScalaVersion()) <= 0)
            && ("scala.tools.nsc.ScalaDoc".equals(scaladocClassName));
    if (isScaladoc2) {
      jcmd.addArgs("-doc-format:html");
      jcmd.addOption("-doc-title", doctitle);
    } else {
      jcmd.addOption("-bottom", getBottomText());
      jcmd.addOption("-charset", charset);
      jcmd.addOption("-doctitle", doctitle);
      jcmd.addOption("-footer", footer);
      jcmd.addOption("-header", header);
      jcmd.addOption("-linksource", linksource);
      jcmd.addOption("-nocomment", nocomment);
      jcmd.addOption("-stylesheetfile", stylesheetfile);
      jcmd.addOption("-top", top);
      jcmd.addOption("-windowtitle", windowtitle);
    }
    return jcmd;
  }