Skip to content
Permalink
Browse files
COMMONSSITE-108: need some assert stattements, but mostly done
  • Loading branch information
chtompki committed May 21, 2018
1 parent 34bf87e commit 0c14b25f200a6854a5912a64ff3db000b3a66158
Showing 8 changed files with 190 additions and 51 deletions.
@@ -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>
@@ -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.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,26 +254,106 @@ private List<File> copyDistributionsIntoScmDirectoryStructure(File copiedRelease
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.
*
@@ -65,16 +65,16 @@ public void testSuccess() throws Exception {
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");
@@ -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
@@ -38,43 +39,95 @@ 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;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 0c14b25

Please sign in to comment.