COMMONSSITE-108: need some assert stattements, but mostly done
Project: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/commit/0c14b25f Tree: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/tree/0c14b25f Diff: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/diff/0c14b25f Branch: refs/heads/master Commit: 0c14b25f200a6854a5912a64ff3db000b3a66158 Parents: 34bf87e Author: Rob Tompkins <[email protected]> Authored: Mon May 21 15:10:30 2018 -0400 Committer: Rob Tompkins <[email protected]> Committed: Mon May 21 15:10:30 2018 -0400 ---------------------------------------------------------------------- checkstyle-suppressions.xml | 2 + .../mojos/CommonsDistributionStagingMojo.java | 104 +++++++++++++++-- .../CommonsDistributionDetachmentMojoTest.java | 20 ++-- .../DistributionDetachmentProjectStub.java | 115 ++++++++++++++----- .../target/mockAttachedTar.tar.gz | Bin 327 -> 0 bytes .../target/mockAttachedTar.tar.gz.asc | Bin 566 -> 0 bytes .../target/mockAttachedZip.zip | Bin 1323 -> 0 bytes .../target/mockAttachedZip.zip.asc | Bin 566 -> 0 bytes 8 files changed, 190 insertions(+), 51 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/0c14b25f/checkstyle-suppressions.xml ---------------------------------------------------------------------- diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml index dcf3176..d5c3419 100644 --- a/checkstyle-suppressions.xml +++ b/checkstyle-suppressions.xml @@ -28,5 +28,7 @@ <suppress checks="MethodName" files=".*[/\\]test[/\\].*" /> <suppress checks="Javadoc" files=".*[/\\]test[/\\].*" /> + + <suppress checks="LineLength" files=".*CommonsDistributionDetachmentMojoTest.java" /> <suppress checks="FinalClassCheck" files=".*Delegate.java" /> </suppressions> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/0c14b25f/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java index 44a39ba..6a4839c 100644 --- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java +++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java @@ -16,8 +16,18 @@ */ package org.apache.commons.release.plugin.mojos; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.commons.release.plugin.SharedFunctions; +import org.apache.commons.release.plugin.velocity.HeaderHtmlVelocityDelegate; +import org.apache.commons.release.plugin.velocity.ReadmeHtmlVelocityDelegate; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -36,12 +46,6 @@ import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository; import org.apache.maven.scm.provider.svn.svnexe.SvnExeScmProvider; import org.apache.maven.scm.repository.ScmRepository; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - /** * This class checks out the dev distribution location, copies the distributions into that directory * structure under the <code>target/commons-release-plugin/scm</code> directory. Then commits the @@ -250,27 +254,107 @@ public class CommonsDistributionStagingMojo extends AbstractMojo { File copy; for (File file : workingDirectoryFiles) { if (file.getName().contains("src")) { - copy = new File(scmSourceRoot + "/" + file.getName()); + copy = new File(scmSourceRoot, file.getName()); SharedFunctions.copyFile(getLog(), file, copy); filesForMavenScmFileSet.add(copy); } else if (file.getName().contains("bin")) { - copy = new File(scmBinariesRoot + "/" + file.getName()); + copy = new File(scmBinariesRoot, file.getName()); SharedFunctions.copyFile(getLog(), file, copy); filesForMavenScmFileSet.add(copy); } else if (StringUtils.containsAny(file.getName(), "scm", "sha1.properties")) { - getLog().debug("Not copying scm directory over to the scm directory because it is the scm directory."); + getLog().debug("Not copying scm directory over " + + "to the scm directory because it is the scm directory."); //do nothing because we are copying into scm } else { - copy = new File(distCheckoutDirectory.getAbsolutePath() + "/" + file.getName()); + copy = new File(distCheckoutDirectory.getAbsolutePath(), file.getName()); SharedFunctions.copyFile(getLog(), file, copy); filesForMavenScmFileSet.add(copy); } } + filesForMavenScmFileSet.addAll(buildReadmeAndHeaderHtmlFiles()); filesForMavenScmFileSet.add(copiedReleaseNotes); return filesForMavenScmFileSet; } /** + * Builds up <code>README.html</code> and <code>HEADER.html</code> that reside in following. + * <ul> + * <li>distRoot + * <ul> + * <li>binaries/HEADER.html (symlink)</li> + * <li>binaries/README.html (symlink)</li> + * <li>source/HEADER.html (symlink)</li> + * <li>source/README.html (symlink)</li> + * <li>HEADER.html</li> + * <li>README.html</li> + * </ul> + * </li> + * </ul> + * @return the {@link List} of created files above + * @throws MojoExecutionException if an {@link IOException} occurs in the creation of these + * files fails. + */ + private List<File> buildReadmeAndHeaderHtmlFiles() throws MojoExecutionException { + List<File> headerAndReadmeFiles = new ArrayList<>(); + File headerFile = new File(distCheckoutDirectory, "HEADER.html"); + File readmeFile = new File(distCheckoutDirectory, "README.html"); + try { + Writer headerWriter = new FileWriter(headerFile); + Writer readmeWriter = new FileWriter(readmeFile); + HeaderHtmlVelocityDelegate headerHtmlVelocityDelegate = HeaderHtmlVelocityDelegate + .builder() + .build(); + headerWriter = headerHtmlVelocityDelegate.render(headerWriter); + headerWriter.close(); + headerAndReadmeFiles.add(headerFile); + ReadmeHtmlVelocityDelegate readmeHtmlVelocityDelegate = ReadmeHtmlVelocityDelegate + .builder() + .withArtifactId(project.getArtifactId()) + .withVersion(project.getVersion()) + .withSiteUrl(project.getUrl()) + .build(); + readmeWriter = readmeHtmlVelocityDelegate.render(readmeWriter); + readmeWriter.close(); + headerAndReadmeFiles.add(readmeFile); + headerAndReadmeFiles.addAll(buildSymbolicLinks(headerFile, readmeFile)); + } catch (IOException e) { + getLog().error("Could not build HEADER and README html files", e); + throw new MojoExecutionException("Could not build HEADER and README html files", e); + } + return headerAndReadmeFiles; + } + + /** + * SOmething. + * @param headerFile something. + * @param readmeFile something. + * @return something. + * @throws IOException Someting. + */ + private List<File> buildSymbolicLinks(File headerFile, File readmeFile) throws IOException { + List<File> symbolicLinkFiles = new ArrayList<>(); + File sourceRoot = new File(buildDistSourceRoot()); + File binariesRoot = new File(buildDistBinariesRoot()); + File sourceHeaderFile = new File(sourceRoot, "HEADER.html"); + File sourceReadmeFile = new File(sourceRoot, "README.html"); + File binariesHeaderFile = new File(binariesRoot, "HEADER.html"); + File binariesReadmeFile = new File(binariesRoot, "README.html"); + Files.createSymbolicLink(sourceHeaderFile.toPath().toAbsolutePath(), + sourceRoot.toPath().toAbsolutePath().relativize(headerFile.toPath().toAbsolutePath())); + symbolicLinkFiles.add(sourceHeaderFile); + Files.createSymbolicLink(sourceReadmeFile.toPath().toAbsolutePath(), + sourceRoot.toPath().toAbsolutePath().relativize(readmeFile.toPath().toAbsolutePath())); + symbolicLinkFiles.add(sourceReadmeFile); + Files.createSymbolicLink(binariesHeaderFile.toPath().toAbsolutePath(), + binariesRoot.toPath().toAbsolutePath().relativize(headerFile.toPath().toAbsolutePath())); + symbolicLinkFiles.add(binariesHeaderFile); + Files.createSymbolicLink(binariesReadmeFile.toPath().toAbsolutePath(), + binariesRoot.toPath().toAbsolutePath().relativize(readmeFile.toPath().toAbsolutePath())); + symbolicLinkFiles.add(binariesReadmeFile); + return symbolicLinkFiles; + } + + /** * Build the path for the distribution binaries directory. * * @return the local absolute path into the checkedout subversion repository that is where http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/0c14b25f/src/test/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojoTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojoTest.java b/src/test/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojoTest.java index 36b80b1..d5dbcf9 100644 --- a/src/test/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojoTest.java +++ b/src/test/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojoTest.java @@ -65,16 +65,16 @@ public class CommonsDistributionDetachmentMojoTest { assertTrue(testPom.exists()); mojo = (CommonsDistributionDetachmentMojo) rule.lookupMojo("detach-distributions", testPom); mojo.execute(); - File detachedTarGz = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedTar.tar.gz"); - File detachedTarGzAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedTar.tar.gz.asc"); - File detachedTarMd5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedTar.tar.gz.md5"); - File detachedTarGzSha1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedTar.tar.gz.sha1"); - File detachedTarGzSha256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedTar.tar.gz.sha256"); - File detachedZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedZip.zip"); - File detachedZipAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedZip.zip.asc"); - File detachedZipMd5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedZip.zip.md5"); - File detachedZipSha1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedZip.zip.sha1"); - File detachedZipSha256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedZip.zip.sha256"); + File detachedTarGz = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedTar-src.tar.gz"); + File detachedTarGzAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedTar-src.tar.gz.asc"); + File detachedTarMd5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedTar-src.tar.gz.md5"); + File detachedTarGzSha1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedTar-src.tar.gz.sha1"); + File detachedTarGzSha256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedTar-src.tar.gz.sha256"); + File detachedZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedZip-src.zip"); + File detachedZipAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedZip-src.zip.asc"); + File detachedZipMd5 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedZip-src.zip.md5"); + File detachedZipSha1 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedZip-src.zip.sha1"); + File detachedZipSha256 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedZip-src.zip.sha256"); File notDetachedMockAttachedFile = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/mockAttachedFile.html"); File sha1Properties = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/sha1.properties"); File sha256Properties = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/sha256.properties"); http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/0c14b25f/src/test/java/org/apache/commons/release/plugin/stubs/DistributionDetachmentProjectStub.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/release/plugin/stubs/DistributionDetachmentProjectStub.java b/src/test/java/org/apache/commons/release/plugin/stubs/DistributionDetachmentProjectStub.java index 5eb68ae..7f4fb12 100644 --- a/src/test/java/org/apache/commons/release/plugin/stubs/DistributionDetachmentProjectStub.java +++ b/src/test/java/org/apache/commons/release/plugin/stubs/DistributionDetachmentProjectStub.java @@ -16,19 +16,20 @@ */ package org.apache.commons.release.plugin.stubs; +import java.io.File; +import java.util.ArrayList; +import java.util.List; import org.apache.commons.release.plugin.mojos.CommonsDistributionDetachmentMojoTest; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.apache.maven.project.MavenProject; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - /** - * Stub for {@link MavenProject} for the {@link CommonsDistributionDetachmentMojoTest}. See the testing pom, - * <code>src/test/resources/detach-distributions/detach-distributions.xml</code> for the declared usage of + * Stub for {@link MavenProject} for the {@link CommonsDistributionDetachmentMojoTest}. See the + * testing pom, + * <code>src/test/resources/detach-distributions/detach-distributions.xml</code> for the declared + * usage of * this class. * * @author chtompki @@ -39,42 +40,94 @@ public class DistributionDetachmentProjectStub extends MavenProjectStub { private List<Artifact> attachedArtifacts; @Override + public String getArtifactId() { + return "commons-text"; + } + + @Override + public String getVersion() { + return "1.4"; + } + + @Override + public String getUrl() { + return "http://commons.apache.org/proper/commons-text/"; + } + + @Override public List<Artifact> getAttachedArtifacts() { attachedArtifacts = new ArrayList<>(); attachedArtifacts.add( - new DistributionDetachmentArtifactStub( - new File("src/test/resources/mojos/detach-distributions/target/mockAttachedFile.html"), - "html", - "mockAttachedFile" - ) + new DistributionDetachmentArtifactStub( + new File( + "src/test/resources/mojos/detach-distributions/target/mockAttachedFile.html"), + "html", + "mockAttachedFile" + ) + ); + attachedArtifacts.add( + new DistributionDetachmentArtifactStub( + new File( + "src/test/resources/mojos/detach-distributions/target/mockAttachedTar-src.tar.gz"), + "tar.gz", + "mockAttachedTar" + ) + ); + attachedArtifacts.add( + new DistributionDetachmentArtifactStub( + new File( + "src/test/resources/mojos/detach-distributions/target/mockAttachedTar-src.tar.gz.asc"), + "tar.gz.asc", + "mockAttachedTar" + ) + ); + attachedArtifacts.add( + new DistributionDetachmentArtifactStub( + new File( + "src/test/resources/mojos/detach-distributions/target/mockAttachedTar-bin.tar.gz"), + "tar.gz", + "mockAttachedTar" + ) + ); + attachedArtifacts.add( + new DistributionDetachmentArtifactStub( + new File( + "src/test/resources/mojos/detach-distributions/target/mockAttachedTar-bin.tar.gz.asc"), + "tar.gz.asc", + "mockAttachedTar" + ) ); attachedArtifacts.add( - new DistributionDetachmentArtifactStub( - new File("src/test/resources/mojos/detach-distributions/target/mockAttachedTar.tar.gz"), - "tar.gz", - "mockAttachedTar" - ) + new DistributionDetachmentArtifactStub( + new File( + "src/test/resources/mojos/detach-distributions/target/mockAttachedZip-src.zip"), + "zip", + "mockAttachedZip" + ) ); attachedArtifacts.add( - new DistributionDetachmentArtifactStub( - new File("src/test/resources/mojos/detach-distributions/target/mockAttachedTar.tar.gz.asc"), - "tar.gz.asc", - "mockAttachedTar" - ) + new DistributionDetachmentArtifactStub( + new File( + "src/test/resources/mojos/detach-distributions/target/mockAttachedZip-src.zip.asc"), + "zip.asc", + "mockAttachedZip" + ) ); attachedArtifacts.add( - new DistributionDetachmentArtifactStub( - new File("src/test/resources/mojos/detach-distributions/target/mockAttachedZip.zip"), - "zip", - "mockAttachedZip" - ) + new DistributionDetachmentArtifactStub( + new File( + "src/test/resources/mojos/detach-distributions/target/mockAttachedZip-bin.zip"), + "zip", + "mockAttachedZip" + ) ); attachedArtifacts.add( - new DistributionDetachmentArtifactStub( - new File("src/test/resources/mojos/detach-distributions/target/mockAttachedZip.zip.asc"), - "zip.asc", - "mockAttachedZip" - ) + new DistributionDetachmentArtifactStub( + new File( + "src/test/resources/mojos/detach-distributions/target/mockAttachedZip-bin.zip.asc"), + "zip.asc", + "mockAttachedZip" + ) ); return attachedArtifacts; } http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/0c14b25f/src/test/resources/mojos/detach-distributions/target/mockAttachedTar.tar.gz ---------------------------------------------------------------------- diff --git a/src/test/resources/mojos/detach-distributions/target/mockAttachedTar.tar.gz b/src/test/resources/mojos/detach-distributions/target/mockAttachedTar.tar.gz deleted file mode 100644 index dda7e6c..0000000 Binary files a/src/test/resources/mojos/detach-distributions/target/mockAttachedTar.tar.gz and /dev/null differ http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/0c14b25f/src/test/resources/mojos/detach-distributions/target/mockAttachedTar.tar.gz.asc ---------------------------------------------------------------------- diff --git a/src/test/resources/mojos/detach-distributions/target/mockAttachedTar.tar.gz.asc b/src/test/resources/mojos/detach-distributions/target/mockAttachedTar.tar.gz.asc deleted file mode 100644 index f45982f..0000000 Binary files a/src/test/resources/mojos/detach-distributions/target/mockAttachedTar.tar.gz.asc and /dev/null differ http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/0c14b25f/src/test/resources/mojos/detach-distributions/target/mockAttachedZip.zip ---------------------------------------------------------------------- diff --git a/src/test/resources/mojos/detach-distributions/target/mockAttachedZip.zip b/src/test/resources/mojos/detach-distributions/target/mockAttachedZip.zip deleted file mode 100644 index 1f34188..0000000 Binary files a/src/test/resources/mojos/detach-distributions/target/mockAttachedZip.zip and /dev/null differ http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/0c14b25f/src/test/resources/mojos/detach-distributions/target/mockAttachedZip.zip.asc ---------------------------------------------------------------------- diff --git a/src/test/resources/mojos/detach-distributions/target/mockAttachedZip.zip.asc b/src/test/resources/mojos/detach-distributions/target/mockAttachedZip.zip.asc deleted file mode 100644 index 804d188..0000000 Binary files a/src/test/resources/mojos/detach-distributions/target/mockAttachedZip.zip.asc and /dev/null differ
