Repository: commons-release-plugin Updated Branches: refs/heads/master 7e3c6cd29 -> d8b0e0e74
COMMONSSITE-99: improving jacoco metrics 72% 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/d8b0e0e7 Tree: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/tree/d8b0e0e7 Diff: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/diff/d8b0e0e7 Branch: refs/heads/master Commit: d8b0e0e74ba2fb174e26b33f8358f70c00a55138 Parents: 7e3c6cd Author: Rob Tompkins <chtom...@gmail.com> Authored: Sun Jan 7 16:50:00 2018 -0500 Committer: Rob Tompkins <chtom...@gmail.com> Committed: Sun Jan 7 16:50:00 2018 -0500 ---------------------------------------------------------------------- .../CommonsDistributionDetatchmentMojo.java | 154 ------------------- .../mojos/CommonsDistributionStagingMojo.java | 4 + .../CommonsDistributionDetatchmentMojoTest.java | 75 --------- .../DistributionDetatchmentProjectStub.java | 93 ----------- .../detatch-distributions.xml | 52 ------- .../target/mockAttachedFile.html | 24 --- .../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 10 files changed, 4 insertions(+), 398 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d8b0e0e7/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java deleted file mode 100644 index 746a51c..0000000 --- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.release.plugin.mojos; - -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.release.plugin.SharedFunctions; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.apache.maven.artifact.Artifact; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.*; - -/** - * The purpose of this maven mojo is to detach the artifacts generated by the maven-assembly-plugin, - * which for the Apache Commons Project do not get uploaded to Nexus, and putting those artifacts - * in the dev distribution location for apache projects. - * - * @author chtompki - * @since 1.0 - */ -@Mojo( name = "detatch-distributions", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true) -public class CommonsDistributionDetatchmentMojo extends AbstractMojo { - - /** - * A list of "artifact types" in the maven vernacular, to - * be detatched from the deployment. For the time being we want - * all artifacts generated by the maven-assembly-plugin to be detatched - * from the deployment, namely *-src.zip, *-src.tar.gz, *-bin.zip, - * *-bin.tar.gz, and the corresponding .asc pgp signatures. - */ - private static final Set<String> ARTIFACT_TYPES_TO_DETATCH; - static { - Set<String> hashSet = new HashSet<>(); - hashSet.add("zip"); - hashSet.add("tar.gz"); - hashSet.add("zip.asc"); - hashSet.add("tar.gz.asc"); - ARTIFACT_TYPES_TO_DETATCH = Collections.unmodifiableSet(hashSet); - } - - /** - * This list is supposed to hold the maven references to the aformentioned artifacts so that we - * can upload them to svn after they've been detatched from the maven deployment. - */ - private List<Artifact> detatchedArtifacts = new ArrayList<>(); - - /** - * The maven project context injection so that we can get a hold of the variables at hand. - */ - @Parameter( defaultValue = "${project}", required = true ) - private MavenProject project; - - /** - */ - @Parameter( defaultValue = "${project.build.directory}/commons-release-plugin", alias = "outputDirectory" ) - private File workingDirectory; - - /** - */ - @Parameter(required = true) - private String distSvnStagingUrl; - - public void execute() throws MojoExecutionException { - getLog().info("Detatching Assemblies"); - for (Object attachedArtifact : project.getAttachedArtifacts()) { - if (ARTIFACT_TYPES_TO_DETATCH.contains(((Artifact) attachedArtifact).getType())) { - detatchedArtifacts.add((Artifact) attachedArtifact); - } - } - for(Artifact artifactToRemove : detatchedArtifacts) { - project.getAttachedArtifacts().remove(artifactToRemove); - } - if (!workingDirectory.exists()) { - SharedFunctions.initDirectory(getLog(), workingDirectory); - } - copyRemovedArtifactsToWorkingDirectory(); - getLog().info(""); - sha1AndMd5SignArtifacts(); - } - - private void copyRemovedArtifactsToWorkingDirectory() throws MojoExecutionException { - StringBuffer copiedArtifactAbsolutePath; - getLog().info("Copying detatched artifacts to working directory."); - for (Artifact artifact: detatchedArtifacts) { - File artifactFile = artifact.getFile(); - copiedArtifactAbsolutePath = new StringBuffer(workingDirectory.getAbsolutePath()); - copiedArtifactAbsolutePath.append("/"); - copiedArtifactAbsolutePath.append(artifactFile.getName()); - File copiedArtifact = new File(copiedArtifactAbsolutePath.toString()); - getLog().info("Copying: " + artifactFile.getName()); - SharedFunctions.copyFile(getLog(), artifactFile, copiedArtifact); - } - } - - private void sha1AndMd5SignArtifacts() throws MojoExecutionException { - for (Artifact artifact : detatchedArtifacts) { - if (!artifact.getFile().getName().contains("asc")) { - try { - FileInputStream artifactFileInputStream = new FileInputStream(artifact.getFile()); - String md5 = DigestUtils.md5Hex(artifactFileInputStream); - getLog().info(artifact.getFile().getName() + " md5: " + md5); - PrintWriter md5Writer = new PrintWriter(getMd5FilePath(workingDirectory, artifact.getFile())); - md5Writer.println(md5); - String sha1 = DigestUtils.sha1Hex(artifactFileInputStream); - getLog().info(artifact.getFile().getName() + " sha1: " + sha1); - PrintWriter sha1Writer = new PrintWriter(getSha1FilePath(workingDirectory, artifact.getFile())); - sha1Writer.println(sha1); - md5Writer.close(); - sha1Writer.close(); - } catch (IOException e) { - throw new MojoExecutionException("Could not sign file: " + artifact.getFile().getName(), e); - } - } - } - } - - private String getMd5FilePath(File workingDirectory, File file) { - StringBuffer buffer = new StringBuffer(workingDirectory.getAbsolutePath()); - buffer.append("/"); - buffer.append(file.getName()); - buffer.append(".md5"); - return buffer.toString(); - } - - private String getSha1FilePath(File workingDirectory, File file) { - StringBuffer buffer = new StringBuffer(workingDirectory.getAbsolutePath()); - buffer.append("/"); - buffer.append(file.getName()); - buffer.append(".sha1"); - return buffer.toString(); - } -} http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d8b0e0e7/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 7920f52..0b44b77 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 @@ -194,4 +194,8 @@ public class CommonsDistributionStagingMojo extends AbstractMojo { buffer.append("/source"); return buffer.toString(); } + + protected void setBasedir(File basedir) { + this.basedir = basedir; + } } http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d8b0e0e7/src/test/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojoTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojoTest.java b/src/test/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojoTest.java deleted file mode 100644 index 78809b6..0000000 --- a/src/test/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojoTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.release.plugin.mojos; - -import org.apache.maven.plugin.testing.MojoRule; -import org.junit.Rule; -import org.junit.Test; - -import java.io.File; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -/** - * Unit tests for {@link CommonsDistributionDetatchmentMojo}. - * - * @author chtompki - */ -public class CommonsDistributionDetatchmentMojoTest { - - @Rule - public MojoRule rule = new MojoRule() { - @Override - protected void before() throws Throwable { - } - - @Override - protected void after() { - } - }; - - private CommonsDistributionDetatchmentMojo mojo; - - @Test - public void testSuccess() throws Exception { - File testPom = new File("src/test/resources/mojos/detatch-distributions/detatch-distributions.xml"); - assertNotNull(testPom); - assertTrue(testPom.exists()); - mojo = (CommonsDistributionDetatchmentMojo) rule.lookupMojo("detatch-distributions", testPom); - mojo.execute(); - File detachedTarGz = new File("target/commons-release-plugin/mockAttachedTar.tar.gz"); - File detachedTarGzAsc = new File("target/commons-release-plugin/mockAttachedTar.tar.gz.asc"); - File detachedTarMd5 = new File("target/commons-release-plugin/mockAttachedTar.tar.gz.md5"); - File detachedTarGzSha1 = new File("target/commons-release-plugin/mockAttachedTar.tar.gz.sha1"); - File detachedZip = new File("target/commons-release-plugin/mockAttachedZip.zip"); - File detachedZipAsc = new File("target/commons-release-plugin/mockAttachedZip.zip.asc"); - File detachedZipMd5 = new File("target/commons-release-plugin/mockAttachedZip.zip.md5"); - File detachedZipSha1 = new File("target/commons-release-plugin/mockAttachedZip.zip.sha1"); - File notDetatchedMockAttachedFile = new File("target/commons-release-plugin/mockAttachedFile.html"); - assertTrue(detachedTarGz.exists()); - assertTrue(detachedTarGzAsc.exists()); - assertTrue(detachedTarMd5.exists()); - assertTrue(detachedTarGzSha1.exists()); - assertTrue(detachedZip.exists()); - assertTrue(detachedZipAsc.exists()); - assertTrue(detachedZipMd5.exists()); - assertTrue(detachedZipSha1.exists()); - assertFalse(notDetatchedMockAttachedFile.exists()); - } -} http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d8b0e0e7/src/test/java/org/apache/commons/release/plugin/stubs/DistributionDetatchmentProjectStub.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/release/plugin/stubs/DistributionDetatchmentProjectStub.java b/src/test/java/org/apache/commons/release/plugin/stubs/DistributionDetatchmentProjectStub.java deleted file mode 100644 index 003d398..0000000 --- a/src/test/java/org/apache/commons/release/plugin/stubs/DistributionDetatchmentProjectStub.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.release.plugin.stubs; - -import org.apache.commons.release.plugin.mojos.CommonsDistributionDetatchmentMojoTest; -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 CommonsDistributionDetatchmentMojoTest}. - * - * @author chtompki - */ -public class DistributionDetatchmentProjectStub extends MavenProjectStub { - - private List<Artifact> attachedArtifacts; - - @Override - public List<Artifact> getAttachedArtifacts() { - attachedArtifacts = new ArrayList<>(); - attachedArtifacts.add( - new DistributionDetatchmentArtifactStub( - new File("src/test/resources/mojos/detatch-distributions/target/mockAttachedFile.html"), - "html" - ) - ); - attachedArtifacts.add( - new DistributionDetatchmentArtifactStub( - new File("src/test/resources/mojos/detatch-distributions/target/mockAttachedTar.tar.gz"), - "tar.gz" - ) - ); - attachedArtifacts.add( - new DistributionDetatchmentArtifactStub( - new File("src/test/resources/mojos/detatch-distributions/target/mockAttachedTar.tar.gz.asc"), - "tar.gz.asc" - ) - ); - attachedArtifacts.add( - new DistributionDetatchmentArtifactStub( - new File("src/test/resources/mojos/detatch-distributions/target/mockAttachedZip.zip"), - "zip" - ) - ); - attachedArtifacts.add( - new DistributionDetatchmentArtifactStub( - new File("src/test/resources/mojos/detatch-distributions/target/mockAttachedZip.zip.asc"), - "zip.asc" - ) - ); - return attachedArtifacts; - } - - public class DistributionDetatchmentArtifactStub extends ArtifactStub { - - private File artifact; - - private String type; - - public DistributionDetatchmentArtifactStub(File file, String type) { - this.artifact = file; - this.type = type; - } - - public File getFile() { - return this.artifact; - } - - public String getType() { - return this.type; - } - } -} http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d8b0e0e7/src/test/resources/mojos/detatch-distributions/detatch-distributions.xml ---------------------------------------------------------------------- diff --git a/src/test/resources/mojos/detatch-distributions/detatch-distributions.xml b/src/test/resources/mojos/detatch-distributions/detatch-distributions.xml deleted file mode 100644 index 36c9207..0000000 --- a/src/test/resources/mojos/detatch-distributions/detatch-distributions.xml +++ /dev/null @@ -1,52 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.commons.release.plugin.unit</groupId> - <artifactId>detatch-distributions-test</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>jar</packaging> - <name>Mock Pom For Testing CommonsDistributionDetatchmentMojo</name> - - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.commons</groupId> - <artifactId>commons-release-plugin</artifactId> - <configuration> - <project implementation="org.apache.commons.release.plugin.stubs.DistributionDetatchmentProjectStub" /> - <workingDirectory>target/commons-release-plugin</workingDirectory> - <distSvnStagingUrl>mockDistSvnStagingUrl</distSvnStagingUrl> - </configuration> - </plugin> - </plugins> - </build> -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d8b0e0e7/src/test/resources/mojos/detatch-distributions/target/mockAttachedFile.html ---------------------------------------------------------------------- diff --git a/src/test/resources/mojos/detatch-distributions/target/mockAttachedFile.html b/src/test/resources/mojos/detatch-distributions/target/mockAttachedFile.html deleted file mode 100644 index c9a72dd..0000000 --- a/src/test/resources/mojos/detatch-distributions/target/mockAttachedFile.html +++ /dev/null @@ -1,24 +0,0 @@ -<html> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<header><title>Mock maven site</title></header> -<body> -mock body -</body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d8b0e0e7/src/test/resources/mojos/detatch-distributions/target/mockAttachedTar.tar.gz ---------------------------------------------------------------------- diff --git a/src/test/resources/mojos/detatch-distributions/target/mockAttachedTar.tar.gz b/src/test/resources/mojos/detatch-distributions/target/mockAttachedTar.tar.gz deleted file mode 100644 index dda7e6c..0000000 Binary files a/src/test/resources/mojos/detatch-distributions/target/mockAttachedTar.tar.gz and /dev/null differ http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d8b0e0e7/src/test/resources/mojos/detatch-distributions/target/mockAttachedTar.tar.gz.asc ---------------------------------------------------------------------- diff --git a/src/test/resources/mojos/detatch-distributions/target/mockAttachedTar.tar.gz.asc b/src/test/resources/mojos/detatch-distributions/target/mockAttachedTar.tar.gz.asc deleted file mode 100644 index f45982f..0000000 Binary files a/src/test/resources/mojos/detatch-distributions/target/mockAttachedTar.tar.gz.asc and /dev/null differ http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d8b0e0e7/src/test/resources/mojos/detatch-distributions/target/mockAttachedZip.zip ---------------------------------------------------------------------- diff --git a/src/test/resources/mojos/detatch-distributions/target/mockAttachedZip.zip b/src/test/resources/mojos/detatch-distributions/target/mockAttachedZip.zip deleted file mode 100644 index 1f34188..0000000 Binary files a/src/test/resources/mojos/detatch-distributions/target/mockAttachedZip.zip and /dev/null differ http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d8b0e0e7/src/test/resources/mojos/detatch-distributions/target/mockAttachedZip.zip.asc ---------------------------------------------------------------------- diff --git a/src/test/resources/mojos/detatch-distributions/target/mockAttachedZip.zip.asc b/src/test/resources/mojos/detatch-distributions/target/mockAttachedZip.zip.asc deleted file mode 100644 index 804d188..0000000 Binary files a/src/test/resources/mojos/detatch-distributions/target/mockAttachedZip.zip.asc and /dev/null differ