CommonsDistributionStagingMojo.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.release.plugin.mojos;

  18. import java.io.File;
  19. import java.io.IOException;
  20. import java.io.OutputStreamWriter;
  21. import java.io.Writer;
  22. import java.nio.charset.StandardCharsets;
  23. import java.nio.file.Files;
  24. import java.nio.file.Path;
  25. import java.nio.file.Paths;
  26. import java.util.ArrayList;
  27. import java.util.Arrays;
  28. import java.util.List;

  29. import org.apache.commons.io.FileUtils;
  30. import org.apache.commons.io.file.PathUtils;
  31. import org.apache.commons.lang3.StringUtils;
  32. import org.apache.commons.release.plugin.SharedFunctions;
  33. import org.apache.commons.release.plugin.velocity.HeaderHtmlVelocityDelegate;
  34. import org.apache.commons.release.plugin.velocity.ReadmeHtmlVelocityDelegate;
  35. import org.apache.maven.plugin.AbstractMojo;
  36. import org.apache.maven.plugin.MojoExecutionException;
  37. import org.apache.maven.plugin.MojoFailureException;
  38. import org.apache.maven.plugin.logging.Log;
  39. import org.apache.maven.plugins.annotations.Component;
  40. import org.apache.maven.plugins.annotations.LifecyclePhase;
  41. import org.apache.maven.plugins.annotations.Mojo;
  42. import org.apache.maven.plugins.annotations.Parameter;
  43. import org.apache.maven.project.MavenProject;
  44. import org.apache.maven.scm.ScmException;
  45. import org.apache.maven.scm.ScmFileSet;
  46. import org.apache.maven.scm.command.add.AddScmResult;
  47. import org.apache.maven.scm.command.checkin.CheckInScmResult;
  48. import org.apache.maven.scm.command.checkout.CheckOutScmResult;
  49. import org.apache.maven.scm.manager.BasicScmManager;
  50. import org.apache.maven.scm.manager.ScmManager;
  51. import org.apache.maven.scm.provider.ScmProvider;
  52. import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
  53. import org.apache.maven.scm.provider.svn.svnexe.SvnExeScmProvider;
  54. import org.apache.maven.scm.repository.ScmRepository;
  55. import org.apache.maven.settings.Settings;
  56. import org.apache.maven.settings.crypto.SettingsDecrypter;

  57. /**
  58.  * This class checks out the dev distribution location, copies the distributions into that directory
  59.  * structure under the <code>target/commons-release-plugin/scm</code> directory. Then commits the
  60.  * distributions back up to SVN. Also, we include the built and zipped site as well as the RELEASE-NOTES.txt.
  61.  *
  62.  * @since 1.0
  63.  */
  64. @Mojo(name = "stage-distributions",
  65.         defaultPhase = LifecyclePhase.DEPLOY,
  66.         threadSafe = true,
  67.         aggregator = true)
  68. public class CommonsDistributionStagingMojo extends AbstractMojo {

  69.     /** The name of file generated from the README.vm velocity template to be checked into the dist svn repo. */
  70.     private static final String README_FILE_NAME = "README.html";

  71.     /** The name of file generated from the HEADER.vm velocity template to be checked into the dist svn repo. */
  72.     private static final String HEADER_FILE_NAME = "HEADER.html";

  73.     /** The name of the signature validation shell script to be checked into the dist svn repo. */
  74.     private static final String SIGNATURE_VALIDATOR_NAME = "signature-validator.sh";

  75.     /**
  76.      * The {@link MavenProject} object is essentially the context of the maven build at
  77.      * a given time.
  78.      */
  79.     @Parameter(defaultValue = "${project}", required = true)
  80.     private MavenProject project;
  81.     /**
  82.      * The {@link File} that contains a file to the root directory of the working project. Typically
  83.      * this directory is where the <code>pom.xml</code> resides.
  84.      */
  85.     @Parameter(defaultValue = "${basedir}")
  86.     private File baseDir;

  87.     /** The location to which the site gets built during running <code>mvn site</code>. */
  88.     @Parameter(defaultValue = "${project.build.directory}/site", property = "commons.siteOutputDirectory")
  89.     private File siteDirectory;

  90.     /**
  91.      * The main working directory for the plugin, namely <code>target/commons-release-plugin</code>, but
  92.      * that assumes that we're using the default maven <code>${project.build.directory}</code>.
  93.      */
  94.     @Parameter(defaultValue = "${project.build.directory}/commons-release-plugin", property = "commons.outputDirectory")
  95.     private File workingDirectory;

  96.     /**
  97.      * The location to which to check out the dist subversion repository under our working directory, which
  98.      * was given above.
  99.      */
  100.     @Parameter(defaultValue = "${project.build.directory}/commons-release-plugin/scm",
  101.             property = "commons.distCheckoutDirectory")
  102.     private File distCheckoutDirectory;

  103.     /**
  104.      * The location of the RELEASE-NOTES.txt file such that multi-module builds can configure it.
  105.      */
  106.     @Parameter(defaultValue = "${basedir}/RELEASE-NOTES.txt", property = "commons.releaseNotesLocation")
  107.     private File releaseNotesFile;

  108.     /**
  109.      * A boolean that determines whether or not we actually commit the files up to the subversion repository.
  110.      * If this is set to {@code true}, we do all but make the commits. We do checkout the repository in question
  111.      * though.
  112.      */
  113.     @Parameter(property = "commons.release.dryRun", defaultValue = "false")
  114.     private Boolean dryRun;

  115.     /**
  116.      * The url of the subversion repository to which we wish the artifacts to be staged. Typically this would need to
  117.      * be of the form: <code>scm:svn:https://dist.apache.org/repos/dist/dev/commons/foo/version-RC#</code>. Note. that
  118.      * the prefix to the substring <code>https</code> is a requirement.
  119.      */
  120.     @Parameter(defaultValue = "", property = "commons.distSvnStagingUrl")
  121.     private String distSvnStagingUrl;

  122.     /**
  123.      * A parameter to generally avoid running unless it is specifically turned on by the consuming module.
  124.      */
  125.     @Parameter(defaultValue = "false", property = "commons.release.isDistModule")
  126.     private Boolean isDistModule;

  127.     /**
  128.      * The release version of the artifact to be built.
  129.      */
  130.     @Parameter(property = "commons.release.version")
  131.     private String commonsReleaseVersion;

  132.     /**
  133.      * The RC version of the release. For example the first voted on candidate would be "RC1".
  134.      */
  135.     @Parameter(property = "commons.rc.version")
  136.     private String commonsRcVersion;

  137.     /**
  138.      * The ID of the server (specified in settings.xml) which should be used for dist authentication.
  139.      * This will be used in preference to {@link #username}/{@link #password}.
  140.      */
  141.     @Parameter(property = "commons.distServer")
  142.     private String distServer;

  143.     /**
  144.      * The username for the distribution subversion repository. This is typically your Apache id.
  145.      */
  146.     @Parameter(property = "user.name")
  147.     private String username;

  148.     /**
  149.      * The password associated with {@link CommonsDistributionStagingMojo#username}.
  150.      */
  151.     @Parameter(property = "user.password")
  152.     private String password;

  153.     /**
  154.      * Maven {@link Settings}.
  155.      */
  156.     @Parameter(defaultValue = "${settings}", readonly = true, required = true)
  157.     private Settings settings;

  158.     /**
  159.      * Maven {@link SettingsDecrypter} component.
  160.      */
  161.     @Component
  162.     private SettingsDecrypter settingsDecrypter;

  163.     /**
  164.      * A subdirectory of the dist directory into which we are going to stage the release candidate. We
  165.      * build this up in the {@link CommonsDistributionStagingMojo#execute()} method. And, for example,
  166.      * the directory should look like <code>https://dist.apache.org/repos/dist/dev/commons/text/1.4-RC1</code>.
  167.      */
  168.     private File distRcVersionDirectory;

  169.     /**
  170.      * Constructs a new instance.
  171.      */
  172.     public CommonsDistributionStagingMojo() {
  173.         // empty
  174.     }

  175.     /**
  176.      * Builds up <code>README.html</code> and <code>HEADER.html</code> that reside in following.
  177.      * <ul>
  178.      *     <li>distRoot
  179.      *     <ul>
  180.      *         <li>binaries/HEADER.html (symlink)</li>
  181.      *         <li>binaries/README.html (symlink)</li>
  182.      *         <li>source/HEADER.html (symlink)</li>
  183.      *         <li>source/README.html (symlink)</li>
  184.      *         <li>HEADER.html</li>
  185.      *         <li>README.html</li>
  186.      *     </ul>
  187.      *     </li>
  188.      * </ul>
  189.      * @return the {@link List} of created files above
  190.      * @throws MojoExecutionException if an {@link IOException} occurs in the creation of these
  191.      *                                files fails.
  192.      */
  193.     private List<File> buildReadmeAndHeaderHtmlFiles() throws MojoExecutionException {
  194.         final List<File> headerAndReadmeFiles = new ArrayList<>();
  195.         final File headerFile = new File(distRcVersionDirectory, HEADER_FILE_NAME);
  196.         //
  197.         // HEADER file
  198.         //
  199.         try (Writer headerWriter = new OutputStreamWriter(Files.newOutputStream(headerFile.toPath()),
  200.                 StandardCharsets.UTF_8)) {
  201.             HeaderHtmlVelocityDelegate.builder().build().render(headerWriter);
  202.         } catch (final IOException e) {
  203.             final String message = "Could not build HEADER html file " + headerFile;
  204.             getLog().error(message, e);
  205.             throw new MojoExecutionException(message, e);
  206.         }
  207.         headerAndReadmeFiles.add(headerFile);
  208.         //
  209.         // README file
  210.         //
  211.         final File readmeFile = new File(distRcVersionDirectory, README_FILE_NAME);
  212.         try (Writer readmeWriter = new OutputStreamWriter(Files.newOutputStream(readmeFile.toPath()),
  213.                 StandardCharsets.UTF_8)) {
  214.             // @formatter:off
  215.             final ReadmeHtmlVelocityDelegate readmeHtmlVelocityDelegate = ReadmeHtmlVelocityDelegate.builder()
  216.                     .withArtifactId(project.getArtifactId())
  217.                     .withVersion(project.getVersion())
  218.                     .withSiteUrl(project.getUrl())
  219.                     .build();
  220.             // @formatter:on
  221.             readmeHtmlVelocityDelegate.render(readmeWriter);
  222.         } catch (final IOException e) {
  223.             final String message = "Could not build README html file " + readmeFile;
  224.             getLog().error(message, e);
  225.             throw new MojoExecutionException(message, e);
  226.         }
  227.         headerAndReadmeFiles.add(readmeFile);
  228.         //
  229.         // signature-validator.sh file copy
  230.         //
  231.         headerAndReadmeFiles.addAll(copyHeaderAndReadmeToSubdirectories(headerFile, readmeFile));
  232.         return headerAndReadmeFiles;
  233.     }

  234.     /**
  235.      * Copies the list of files at the root of the {@link CommonsDistributionStagingMojo#workingDirectory} into
  236.      * the directory structure of the distribution staging repository. Specifically:
  237.      * <ul>
  238.      *   <li>root:
  239.      *     <ul>
  240.      *         <li>site</li>
  241.      *         <li>site.zip</li>
  242.      *         <li>RELEASE-NOTES.txt</li>
  243.      *         <li>source:
  244.      *           <ul>
  245.      *             <li>-src artifacts....</li>
  246.      *           </ul>
  247.      *         </li>
  248.      *         <li>binaries:
  249.      *           <ul>
  250.      *             <li>-bin artifacts....</li>
  251.      *           </ul>
  252.      *         </li>
  253.      *     </ul>
  254.      *   </li>
  255.      * </ul>
  256.      *
  257.      * @param copiedReleaseNotes is the RELEASE-NOTES.txt file that exists in the
  258.      *                           <code>target/commons-release-plugin/scm</code> directory.
  259.      * @param provider is the {@link ScmProvider} that we will use for adding the files we wish to commit.
  260.      * @param repository is the {@link ScmRepository} that we will use for adding the files that we wish to commit.
  261.      * @return a {@link List} of {@link File}'s in the directory for the purpose of adding them to the maven
  262.      *         {@link ScmFileSet}.
  263.      * @throws MojoExecutionException if an {@link IOException} occurs so that Maven can handle it properly.
  264.      */
  265.     private List<File> copyDistributionsIntoScmDirectoryStructureAndAddToSvn(final File copiedReleaseNotes,
  266.                                                                              final ScmProvider provider,
  267.                                                                              final ScmRepository repository)
  268.             throws MojoExecutionException {
  269.         final List<File> workingDirectoryFiles = Arrays.asList(workingDirectory.listFiles());
  270.         final List<File> filesForMavenScmFileSet = new ArrayList<>();
  271.         final File scmBinariesRoot = new File(distRcVersionDirectory, "binaries");
  272.         final File scmSourceRoot = new File(distRcVersionDirectory, "source");
  273.         SharedFunctions.initDirectory(getLog(), scmBinariesRoot);
  274.         SharedFunctions.initDirectory(getLog(), scmSourceRoot);
  275.         File copy;
  276.         for (final File file : workingDirectoryFiles) {
  277.             if (file.getName().contains("src")) {
  278.                 copy = new File(scmSourceRoot,  file.getName());
  279.                 SharedFunctions.copyFile(getLog(), file, copy);
  280.                 filesForMavenScmFileSet.add(file);
  281.             } else if (file.getName().contains("bin")) {
  282.                 copy = new File(scmBinariesRoot,  file.getName());
  283.                 SharedFunctions.copyFile(getLog(), file, copy);
  284.                 filesForMavenScmFileSet.add(file);
  285.             } else if (StringUtils.containsAny(file.getName(), "scm", "sha256.properties", "sha512.properties")) {
  286.                 getLog().debug("Not copying scm directory over to the scm directory because it is the scm directory.");
  287.                 //do nothing because we are copying into scm
  288.             } else {
  289.                 copy = new File(distCheckoutDirectory.getAbsolutePath(),  file.getName());
  290.                 SharedFunctions.copyFile(getLog(), file, copy);
  291.                 filesForMavenScmFileSet.add(file);
  292.             }
  293.         }
  294.         filesForMavenScmFileSet.addAll(buildReadmeAndHeaderHtmlFiles());
  295.         filesForMavenScmFileSet.add(copySignatureValidatorScriptToScmDirectory());
  296.         filesForMavenScmFileSet.addAll(copySiteToScmDirectory());
  297.         return filesForMavenScmFileSet;
  298.     }

  299.     /**
  300.      * Copies <code>README.html</code> and <code>HEADER.html</code> to the source and binaries
  301.      * directories.
  302.      *
  303.      * @param headerFile The originally created <code>HEADER.html</code> file.
  304.      * @param readmeFile The originally created <code>README.html</code> file.
  305.      * @return a {@link List} of created files.
  306.      * @throws MojoExecutionException if the {@link SharedFunctions#copyFile(Log, File, File)}
  307.      *                                fails.
  308.      */
  309.     private List<File> copyHeaderAndReadmeToSubdirectories(final File headerFile, final File readmeFile)
  310.             throws MojoExecutionException {
  311.         final List<File> symbolicLinkFiles = new ArrayList<>();
  312.         final File sourceRoot = new File(distRcVersionDirectory, "source");
  313.         final File binariesRoot = new File(distRcVersionDirectory, "binaries");
  314.         final File sourceHeaderFile = new File(sourceRoot, HEADER_FILE_NAME);
  315.         final File sourceReadmeFile = new File(sourceRoot, README_FILE_NAME);
  316.         final File binariesHeaderFile = new File(binariesRoot, HEADER_FILE_NAME);
  317.         final File binariesReadmeFile = new File(binariesRoot, README_FILE_NAME);
  318.         SharedFunctions.copyFile(getLog(), headerFile, sourceHeaderFile);
  319.         symbolicLinkFiles.add(sourceHeaderFile);
  320.         SharedFunctions.copyFile(getLog(), readmeFile, sourceReadmeFile);
  321.         symbolicLinkFiles.add(sourceReadmeFile);
  322.         SharedFunctions.copyFile(getLog(), headerFile, binariesHeaderFile);
  323.         symbolicLinkFiles.add(binariesHeaderFile);
  324.         SharedFunctions.copyFile(getLog(), readmeFile, binariesReadmeFile);
  325.         symbolicLinkFiles.add(binariesReadmeFile);
  326.         return symbolicLinkFiles;
  327.     }

  328.     /**
  329.      * A utility method that takes the <code>RELEASE-NOTES.txt</code> file from the base directory of the
  330.      * project and copies it into {@link CommonsDistributionStagingMojo#workingDirectory}.
  331.      *
  332.      * @return the RELEASE-NOTES.txt file that exists in the <code>target/commons-release-notes/scm</code>
  333.      *         directory for the purpose of adding it to the scm change set in the method
  334.      *         {@link CommonsDistributionStagingMojo#copyDistributionsIntoScmDirectoryStructureAndAddToSvn(File,
  335.      *         ScmProvider, ScmRepository)}.
  336.      * @throws MojoExecutionException if an {@link IOException} occurs as a wrapper so that maven
  337.      *                                can properly handle the exception.
  338.      */
  339.     private File copyReleaseNotesToWorkingDirectory() throws MojoExecutionException {
  340.         SharedFunctions.initDirectory(getLog(), distRcVersionDirectory);
  341.         getLog().info("Copying RELEASE-NOTES.txt to working directory.");
  342.         final File copiedReleaseNotes = new File(distRcVersionDirectory, releaseNotesFile.getName());
  343.         SharedFunctions.copyFile(getLog(), releaseNotesFile, copiedReleaseNotes);
  344.         return copiedReleaseNotes;
  345.     }

  346.     /**
  347.      * Copies our <code>signature-validator.sh</code> script into
  348.      * <code>${basedir}/target/commons-release-plugin/scm/signature-validator.sh</code>.
  349.      *
  350.      * @return the {@link File} for the signature-validator.sh
  351.      * @throws MojoExecutionException if an error occurs while the resource is being copied
  352.      */
  353.     private File copySignatureValidatorScriptToScmDirectory() throws MojoExecutionException {
  354.         final Path scmTargetPath = Paths.get(distRcVersionDirectory.toString(), SIGNATURE_VALIDATOR_NAME);
  355.         final String name = "/resources/" + SIGNATURE_VALIDATOR_NAME;
  356.         // The source can be in a local file or inside a jar file.
  357.         try {
  358.             PathUtils.copyFile(getClass().getResource(name), scmTargetPath);
  359.         } catch (final Exception e) {
  360.             throw new MojoExecutionException(String.format("Failed to copy '%s' to '%s'", name, scmTargetPath), e);
  361.         }
  362.         return scmTargetPath.toFile();
  363.     }

  364.     /**
  365.      * Copies <code>${basedir}/target/site</code> to <code>${basedir}/target/commons-release-plugin/scm/site</code>.
  366.      *
  367.      * @return the {@link List} of {@link File}'s contained in
  368.      *         <code>${basedir}/target/commons-release-plugin/scm/site</code>, after the copy is complete.
  369.      * @throws MojoExecutionException if the site copying fails for some reason.
  370.      */
  371.     private List<File> copySiteToScmDirectory() throws MojoExecutionException {
  372.         if (!siteDirectory.exists()) {
  373.             getLog().error("\"mvn site\" was not run before this goal, or a siteDirectory did not exist.");
  374.             throw new MojoExecutionException(
  375.                     "\"mvn site\" was not run before this goal, or a siteDirectory did not exist."
  376.             );
  377.         }
  378.         final File siteInScm = new File(distRcVersionDirectory, "site");
  379.         try {
  380.             FileUtils.copyDirectory(siteDirectory, siteInScm);
  381.         } catch (final IOException e) {
  382.             throw new MojoExecutionException("Site copying failed", e);
  383.         }
  384.         return new ArrayList<>(FileUtils.listFiles(siteInScm, null, true));
  385.     }

  386.     @Override
  387.     public void execute() throws MojoExecutionException, MojoFailureException {
  388.         if (!isDistModule) {
  389.             getLog().info("This module is marked as a non distribution "
  390.                     + "or assembly module, and the plugin will not run.");
  391.             return;
  392.         }
  393.         if (StringUtils.isEmpty(distSvnStagingUrl)) {
  394.             getLog().warn("commons.distSvnStagingUrl is not set, the commons-release-plugin will not run.");
  395.             return;
  396.         }
  397.         if (!workingDirectory.exists()) {
  398.             getLog().info("Current project contains no distributions. Not executing.");
  399.             return;
  400.         }
  401.         getLog().info("Preparing to stage distributions");
  402.         try {
  403.             final ScmManager scmManager = new BasicScmManager();
  404.             scmManager.setScmProvider("svn", new SvnExeScmProvider());
  405.             final ScmRepository repository = scmManager.makeScmRepository(distSvnStagingUrl);
  406.             final ScmProvider provider = scmManager.getProviderByRepository(repository);
  407.             final SvnScmProviderRepository providerRepository = (SvnScmProviderRepository) repository
  408.                     .getProviderRepository();
  409.             SharedFunctions.setAuthentication(
  410.                     providerRepository,
  411.                     distServer,
  412.                     settings,
  413.                     settingsDecrypter,
  414.                     username,
  415.                     password
  416.             );
  417.             distRcVersionDirectory =
  418.                     new File(distCheckoutDirectory, commonsReleaseVersion + "-" + commonsRcVersion);
  419.             if (!distCheckoutDirectory.exists()) {
  420.                 SharedFunctions.initDirectory(getLog(), distCheckoutDirectory);
  421.             }
  422.             final ScmFileSet scmFileSet = new ScmFileSet(distCheckoutDirectory);
  423.             getLog().info("Checking out dist from: " + distSvnStagingUrl);
  424.             final CheckOutScmResult checkOutResult = provider.checkOut(repository, scmFileSet);
  425.             if (!checkOutResult.isSuccess()) {
  426.                 throw new MojoExecutionException("Failed to checkout files from SCM: "
  427.                         + checkOutResult.getProviderMessage() + " [" + checkOutResult.getCommandOutput() + "]");
  428.             }
  429.             final File copiedReleaseNotes = copyReleaseNotesToWorkingDirectory();
  430.             copyDistributionsIntoScmDirectoryStructureAndAddToSvn(copiedReleaseNotes,
  431.                     provider, repository);
  432.             final List<File> filesToAdd = new ArrayList<>();
  433.             listNotHiddenFilesAndDirectories(distCheckoutDirectory, filesToAdd);
  434.             if (!dryRun) {
  435.                 final ScmFileSet fileSet = new ScmFileSet(distCheckoutDirectory, filesToAdd);
  436.                 final AddScmResult addResult = provider.add(
  437.                         repository,
  438.                         fileSet
  439.                 );
  440.                 if (!addResult.isSuccess()) {
  441.                     throw new MojoExecutionException("Failed to add files to SCM: " + addResult.getProviderMessage()
  442.                             + " [" + addResult.getCommandOutput() + "]");
  443.                 }
  444.                 getLog().info("Staging release: " + project.getArtifactId() + ", version: " + project.getVersion());
  445.                 final CheckInScmResult checkInResult = provider.checkIn(
  446.                         repository,
  447.                         fileSet,
  448.                         "Staging release: " + project.getArtifactId() + ", version: " + project.getVersion()
  449.                 );
  450.                 if (!checkInResult.isSuccess()) {
  451.                     getLog().error("Committing dist files failed: " + checkInResult.getCommandOutput());
  452.                     throw new MojoExecutionException(
  453.                             "Committing dist files failed: " + checkInResult.getCommandOutput()
  454.                     );
  455.                 }
  456.                 getLog().info("Committed revision " + checkInResult.getScmRevision());
  457.             } else {
  458.                 getLog().info("[Dry run] Would have committed to: " + distSvnStagingUrl);
  459.                 getLog().info(
  460.                         "[Dry run] Staging release: " + project.getArtifactId() + ", version: " + project.getVersion());
  461.             }
  462.         } catch (final ScmException e) {
  463.             getLog().error("Could not commit files to dist: " + distSvnStagingUrl, e);
  464.             throw new MojoExecutionException("Could not commit files to dist: " + distSvnStagingUrl, e);
  465.         }
  466.     }

  467.     /**
  468.      * Lists all directories and files to a flat list.
  469.      * @param directory {@link File} containing directory to list
  470.      * @param files a {@link List} of {@link File} to which to append the files.
  471.      */
  472.     private void listNotHiddenFilesAndDirectories(final File directory, final List<File> files) {
  473.         // Get all the files and directories from a directory.
  474.         final File[] fList = directory.listFiles();
  475.         for (final File file : fList) {
  476.             if (file.isFile() && !file.isHidden()) {
  477.                 files.add(file);
  478.             } else if (file.isDirectory() && !file.isHidden()) {
  479.                 files.add(file);
  480.                 listNotHiddenFilesAndDirectories(file, files);
  481.             }
  482.         }
  483.     }

  484.     /**
  485.      * This method is the setter for the {@link CommonsDistributionStagingMojo#baseDir} field, specifically
  486.      * for the usage in the unit tests.
  487.      *
  488.      * @param baseDir is the {@link File} to be used as the project's root directory when this mojo
  489.      *                is invoked.
  490.      */
  491.     protected void setBaseDir(final File baseDir) {
  492.         this.baseDir = baseDir;
  493.     }
  494. }