bmarwell commented on code in PR #95:
URL: https://github.com/apache/maven-gpg-plugin/pull/95#discussion_r1561581736


##########
src/it/sign-release-best-practices-fail/verify.groovy:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+
+import org.codehaus.plexus.util.FileUtils
+
+var buildLog = new File(basedir, "build.log")
+var logContent = FileUtils.fileRead(buildLog)

Review Comment:
   Groovy can do that without plexus utils:
   
   ```
   String logContent = new File( basedir, "build.log").text
   ```



##########
src/main/java/org/apache/maven/plugins/gpg/AbstractGpgMojo.java:
##########
@@ -299,11 +300,18 @@ public final void execute() throws 
MojoExecutionException, MojoFailureException
             // We're skipping the signing stuff
             return;
         }
-        if (bestPractices && (isNotBlank(passphrase) || 
isNotBlank(passphraseServerId))) {
-            // Stop propagating worst practices: passphrase MUST NOT be in any 
file on disk
-            throw new MojoFailureException(
-                    "Do not store passphrase in any file (disk or SCM 
repository), rely on GnuPG agent or provide passphrase in "
-                            + passphraseEnvName + " environment variable.");
+        if (bestPractices) {
+            if (isNotBlank(passphrase) || isNotBlank(passphraseServerId)) {
+                // Stop propagating worst practices: passphrase MUST NOT be in 
any file on disk
+                throw new MojoFailureException(
+                        "Do not store passphrase in any file (disk or SCM 
repository), rely on GnuPG agent or provide passphrase in "
+                                + passphraseEnvName + " environment 
variable.");
+            }
+        } else {

Review Comment:
   As best practices will probably be extended in the future, why not just 
refactor out a method here?
   
   ```suggestion
           if (bestPractices) {
               checkForBestPractices();
           } else {
   ```



##########
src/main/java/org/apache/maven/plugins/gpg/AbstractGpgMojo.java:
##########
@@ -299,11 +300,18 @@ public final void execute() throws 
MojoExecutionException, MojoFailureException
             // We're skipping the signing stuff
             return;
         }
-        if (bestPractices && (isNotBlank(passphrase) || 
isNotBlank(passphraseServerId))) {
-            // Stop propagating worst practices: passphrase MUST NOT be in any 
file on disk
-            throw new MojoFailureException(
-                    "Do not store passphrase in any file (disk or SCM 
repository), rely on GnuPG agent or provide passphrase in "
-                            + passphraseEnvName + " environment variable.");
+        if (bestPractices) {
+            if (isNotBlank(passphrase) || isNotBlank(passphraseServerId)) {
+                // Stop propagating worst practices: passphrase MUST NOT be in 
any file on disk
+                throw new MojoFailureException(
+                        "Do not store passphrase in any file (disk or SCM 
repository), rely on GnuPG agent or provide passphrase in "
+                                + passphraseEnvName + " environment 
variable.");
+            }
+        } else {
+            if (!isNotBlank(passphraseServerId)) {
+                // default it programmatically: this is needed to handle 
different cases re bestPractices
+                passphraseServerId = GPG_PASSPHRASE;
+            }

Review Comment:
   I feel this is a default case inside an else-if nesting. However, as the 
isolated if(bestPractices) improves readability, I'd say: keep it for now.
   
   One solution would be to refactor out a method like `setDefaults()`, but 
probably not worth it.



##########
src/it/sign-release-best-practices-fail/verify.groovy:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+
+import org.codehaus.plexus.util.FileUtils
+
+var buildLog = new File(basedir, "build.log")
+var logContent = FileUtils.fileRead(buildLog)
+
+// assert that bestPractice+worstPractice => MojoFailure
+if (!logContent.contains("MojoFailureException: Do not store passphrase in any 
file")) {
+    throw new Exception("Maven build did not fail in consequence of 
bestPractices+worstPractices")
+}

Review Comment:
   Groovy's native assert is quite suitable here:
   
   ```
   assert logContent.contains( "..." )
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to