Skip to content
Permalink
Browse files
COMMONSSITE-113: moving the logic from parent to release-plugin
  • Loading branch information
chtompki committed Jun 11, 2018
1 parent 92eb2ab commit 3b775f6f6a8d4a27aabafea7476084dd5b171a3d
Showing 4 changed files with 83 additions and 80 deletions.
@@ -129,6 +129,18 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
@Parameter(defaultValue = "false", property = "commons.release.isDistModule")
private Boolean isDistModule;

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

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

/**
* The username for the distribution subversion repository. This is typically your Apache id.
*/
@@ -141,6 +153,13 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
@Parameter(property = "user.password")
private String password;

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

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (!isDistModule) {
@@ -165,6 +184,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
SvnScmProviderRepository providerRepository = (SvnScmProviderRepository) repository.getProviderRepository();
providerRepository.setUser(username);
providerRepository.setPassword(password);
distVersionRcVersionDirectory =
new File(distCheckoutDirectory, commonsReleaseVersion + "-" + commonsRcVersion);
if (!distCheckoutDirectory.exists()) {
SharedFunctions.initDirectory(getLog(), distCheckoutDirectory);
}
@@ -221,11 +242,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
*/
private File copyReleaseNotesToWorkingDirectory() throws MojoExecutionException {
StringBuffer copiedReleaseNotesAbsolutePath;
SharedFunctions.initDirectory(getLog(), distVersionRcVersionDirectory);
getLog().info("Copying RELEASE-NOTES.txt to working directory.");
copiedReleaseNotesAbsolutePath = new StringBuffer(workingDirectory.getAbsolutePath());
copiedReleaseNotesAbsolutePath.append("/scm/");
copiedReleaseNotesAbsolutePath.append(releaseNotesFile.getName());
File copiedReleaseNotes = new File(copiedReleaseNotesAbsolutePath.toString());
File copiedReleaseNotes = new File(distVersionRcVersionDirectory, releaseNotesFile.getName());
SharedFunctions.copyFile(getLog(), releaseNotesFile, copiedReleaseNotes);
return copiedReleaseNotes;
}
@@ -258,10 +277,10 @@ private File copyReleaseNotesToWorkingDirectory() throws MojoExecutionException
private List<File> copyDistributionsIntoScmDirectoryStructure(File copiedReleaseNotes)
throws MojoExecutionException {
List<File> workingDirectoryFiles = Arrays.asList(workingDirectory.listFiles());
String scmBinariesRoot = buildDistBinariesRoot();
String scmSourceRoot = buildDistSourceRoot();
SharedFunctions.initDirectory(getLog(), new File(scmBinariesRoot));
SharedFunctions.initDirectory(getLog(), new File(scmSourceRoot));
File scmBinariesRoot = new File(distVersionRcVersionDirectory, "binaries");
File scmSourceRoot = new File(distVersionRcVersionDirectory, "source");
SharedFunctions.initDirectory(getLog(), scmBinariesRoot);
SharedFunctions.initDirectory(getLog(), scmSourceRoot);
List<File> filesForMavenScmFileSet = new ArrayList<>();
File copy;
for (File file : workingDirectoryFiles) {
@@ -303,7 +322,7 @@ private List<File> copySiteToScmDirectory() throws MojoExecutionException {
);
}
try {
FileUtils.copyDirectoryToDirectory(siteDirectory, distCheckoutDirectory);
FileUtils.copyDirectoryToDirectory(siteDirectory, distVersionRcVersionDirectory);
} catch (IOException e) {
throw new MojoExecutionException("Site copying failed", e);
}
@@ -330,7 +349,7 @@ private List<File> copySiteToScmDirectory() throws MojoExecutionException {
*/
private List<File> buildReadmeAndHeaderHtmlFiles() throws MojoExecutionException {
List<File> headerAndReadmeFiles = new ArrayList<>();
File headerFile = new File(distCheckoutDirectory, HEADER_FILE_NAME);
File headerFile = new File(distVersionRcVersionDirectory, HEADER_FILE_NAME);
//
// HEADER file
//
@@ -345,7 +364,7 @@ private List<File> buildReadmeAndHeaderHtmlFiles() throws MojoExecutionException
//
// README file
//
File readmeFile = new File(distCheckoutDirectory, README_FILE_NAME);
File readmeFile = new File(distVersionRcVersionDirectory, README_FILE_NAME);
try (Writer readmeWriter = new OutputStreamWriter(new FileOutputStream(readmeFile), "UTF-8")) {
// @formatter:off
ReadmeHtmlVelocityDelegate readmeHtmlVelocityDelegate = ReadmeHtmlVelocityDelegate.builder()
@@ -378,8 +397,8 @@ private List<File> buildReadmeAndHeaderHtmlFiles() throws MojoExecutionException
private List<File> copyHeaderAndReadmeToSubdirectories(File headerFile, File readmeFile)
throws MojoExecutionException {
List<File> symbolicLinkFiles = new ArrayList<>();
File sourceRoot = new File(buildDistSourceRoot());
File binariesRoot = new File(buildDistBinariesRoot());
File sourceRoot = new File(distVersionRcVersionDirectory, "source");
File binariesRoot = new File(distVersionRcVersionDirectory, "binaries");
File sourceHeaderFile = new File(sourceRoot, HEADER_FILE_NAME);
File sourceReadmeFile = new File(sourceRoot, README_FILE_NAME);
File binariesHeaderFile = new File(binariesRoot, HEADER_FILE_NAME);
@@ -395,30 +414,6 @@ private List<File> copyHeaderAndReadmeToSubdirectories(File headerFile, File rea
return symbolicLinkFiles;
}

/**
* Build the path for the distribution binaries directory.
*
* @return the local absolute path into the checked out subversion repository that is where
* the binaries distributions are to be copied.
*/
private String buildDistBinariesRoot() {
StringBuffer buffer = new StringBuffer(distCheckoutDirectory.getAbsolutePath());
buffer.append("/binaries");
return buffer.toString();
}

/**
* Build the path for the distribution source directory.
*
* @return the local absolute path into the checked out subversion repository that is where
* the source distributions are to be copied.
*/
private String buildDistSourceRoot() {
StringBuffer buffer = new StringBuffer(distCheckoutDirectory.getAbsolutePath());
buffer.append("/source");
return buffer.toString();
}

/**
* This method is the setter for the {@link CommonsDistributionStagingMojo#baseDir} field, specifically
* for the usage in the unit tests.
@@ -75,38 +75,53 @@ public void testSuccess() throws Exception {
File releaseNotesBasedir = new File("src/test/resources/mojos/stage-distributions/");
mojoForTest.setBaseDir(releaseNotesBasedir);
mojoForTest.execute();
File targetScmDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm");
File releaseNotes = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/RELEASE-NOTES.txt");
File readmeHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/README.html");
File headerHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/HEADER.html");
File binariesReadmeHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/README.html");
File binariesHeaderHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/HEADER.html");
File binTar = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/mockAttachedTar-bin.tar.gz");
File binTarASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/mockAttachedTar-bin.tar.gz.asc");
File binTarMD5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/mockAttachedTar-bin.tar.gz.md5");
File binTarSHA1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/mockAttachedTar-bin.tar.gz.sha1");
File binTarSHA256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/mockAttachedTar-bin.tar.gz.sha256");
File binZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/mockAttachedZip-bin.zip");
File binZipASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/mockAttachedZip-bin.zip.asc");
File binZipMD5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/mockAttachedZip-bin.zip.md5");
File binZipSHA1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/mockAttachedZip-bin.zip.sha1");
File binZipSHA256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/mockAttachedZip-bin.zip.sha256");
File sourcesReadmeHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/README.html");
File sourceHeaderHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/binaries/HEADER.html");
File srcTar = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/source/mockAttachedTar-src.tar.gz");
File srcTarASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/source/mockAttachedTar-src.tar.gz.asc");
File srcTarMD5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/source/mockAttachedTar-src.tar.gz.md5");
File srcTarSHA1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/source/mockAttachedTar-src.tar.gz.sha1");
File srcTarSHA256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/source/mockAttachedTar-src.tar.gz.sha256");
File srcZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/source/mockAttachedZip-src.zip");
File srcZipASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/source/mockAttachedZip-src.zip.asc");
File srcZipMD5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/source/mockAttachedZip-src.zip.md5");
File srcZipSHA1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/source/mockAttachedZip-src.zip.sha1");
File srcZipSHA256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/source/mockAttachedZip-src.zip.sha256");
File site = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/site");
File siteIndexHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/site/index.html");
File siteSubdirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/site/subdirectory");
File siteSubdirectoryIndexHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/site/subdirectory/index.html");
assertRequisiteFilesExist();
}

@Test
public void testDisabled() throws Exception {
File testPom = new File("src/test/resources/mojos/stage-distributions/stage-distributions-disabled.xml");
assertNotNull(testPom);
assertTrue(testPom.exists());
mojoForTest = (CommonsDistributionStagingMojo) rule.lookupMojo("stage-distributions", testPom);
mojoForTest.execute();
File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
assertFalse(testingDirectory.exists());
}

private void assertRequisiteFilesExist() {
File targetScmDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1");
File releaseNotes = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/RELEASE-NOTES.txt");
File readmeHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/README.html");
File headerHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/HEADER.html");
File binariesReadmeHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/README.html");
File binariesHeaderHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/HEADER.html");
File binTar = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/mockAttachedTar-bin.tar.gz");
File binTarASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/mockAttachedTar-bin.tar.gz.asc");
File binTarMD5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/mockAttachedTar-bin.tar.gz.md5");
File binTarSHA1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/mockAttachedTar-bin.tar.gz.sha1");
File binTarSHA256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/mockAttachedTar-bin.tar.gz.sha256");
File binZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/mockAttachedZip-bin.zip");
File binZipASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/mockAttachedZip-bin.zip.asc");
File binZipMD5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/mockAttachedZip-bin.zip.md5");
File binZipSHA1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/mockAttachedZip-bin.zip.sha1");
File binZipSHA256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/mockAttachedZip-bin.zip.sha256");
File sourcesReadmeHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/README.html");
File sourceHeaderHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/HEADER.html");
File srcTar = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/mockAttachedTar-src.tar.gz");
File srcTarASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/mockAttachedTar-src.tar.gz.asc");
File srcTarMD5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/mockAttachedTar-src.tar.gz.md5");
File srcTarSHA1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/mockAttachedTar-src.tar.gz.sha1");
File srcTarSHA256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/mockAttachedTar-src.tar.gz.sha256");
File srcZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/mockAttachedZip-src.zip");
File srcZipASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/mockAttachedZip-src.zip.asc");
File srcZipMD5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/mockAttachedZip-src.zip.md5");
File srcZipSHA1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/mockAttachedZip-src.zip.sha1");
File srcZipSHA256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/mockAttachedZip-src.zip.sha256");
File site = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/site");
File siteIndexHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/site/index.html");
File siteSubdirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/site/subdirectory");
File siteSubdirectoryIndexHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/site/subdirectory/index.html");
assertTrue(targetScmDirectory.exists());
assertTrue(releaseNotes.exists());
assertTrue(readmeHtml.exists());
@@ -140,15 +155,4 @@ public void testSuccess() throws Exception {
assertTrue(siteSubdirectory.exists());
assertTrue(siteSubdirectoryIndexHtml.exists());
}

@Test
public void testDisabled() throws Exception {
File testPom = new File("src/test/resources/mojos/stage-distributions/stage-distributions-disabled.xml");
assertNotNull(testPom);
assertTrue(testPom.exists());
mojoForTest = (CommonsDistributionStagingMojo) rule.lookupMojo("stage-distributions", testPom);
mojoForTest.execute();
File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
assertFalse(testingDirectory.exists());
}
}
@@ -50,6 +50,8 @@
<distSvnStagingUrl>scm:svn:https://dist.apache.org/repos/dist/dev/commons/release-plugin</distSvnStagingUrl>
<isDistModule>false</isDistModule>
<dryRun>true</dryRun>
<commonsReleaseVersion>1.0-SNAPSHOT</commonsReleaseVersion>
<commonsRcVersion>RC1</commonsRcVersion>
</configuration>
</plugin>
</plugins>
@@ -50,6 +50,8 @@
<distSvnStagingUrl>scm:svn:https://dist.apache.org/repos/dist/dev/commons/release-plugin</distSvnStagingUrl>
<isDistModule>true</isDistModule>
<dryRun>true</dryRun>
<commonsReleaseVersion>1.0-SNAPSHOT</commonsReleaseVersion>
<commonsRcVersion>RC1</commonsRcVersion>
</configuration>
</plugin>
</plugins>

0 comments on commit 3b775f6

Please sign in to comment.