This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch check-as-unit
in repository https://gitbox.apache.org/repos/asf/maven-dist-tool.git

commit ef9ec67a2c9ce302942217e5b4cb4d3803047a66
Author: Slawomir Jaranowski <s.jaranow...@gmail.com>
AuthorDate: Thu Oct 31 17:14:40 2024 +0100

    Report a check errors as unit integration test
---
 Jenkinsfile                                        |  34 +++++--
 pom.xml                                            |  38 ++------
 .../maven/dist/tools/DistCheckErrorsReport.java    | 104 ++++++++++-----------
 .../maven/dist/tools/DummyFailureReport.java       |  68 --------------
 .../maven/dist/tools/CheckReportResultIT.java      |  53 +++++++++++
 5 files changed, 132 insertions(+), 165 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 445ce19..7fa28d8 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -33,26 +33,42 @@ pipeline {
                 checkout scm
             }
         }
-        stage('Check') {
+
+        stage('Build') {
             steps {
                 withMaven(jdk:'jdk_17_latest', maven:'maven_3_latest', 
mavenLocalRepo:'.repository', options: [
                   artifactsPublisher(disabled: true),
                   findbugsPublisher(disabled: true),
                 ]) {
-                    catchError {
-                        sh "mvn -ntp -V -e -Preporting -Dscreenshot=clean 
install site"
-                    }
+                    sh "mvn -ntp -V -e -Preporting -Dscreenshot=false clean 
install site"
                 }
                 archiveArtifacts artifacts: 
"**/target/site/**/*",allowEmptyArchive: true
-                script {
-                    if (env.BRANCH_NAME == 'master') {
-                        publishHTML([allowMissing: false, 
alwaysLinkToLastBuild: true, keepAll: true, reportDir: 
"${env.WORKSPACE}/target/site", reportFiles: 'index.html', reportName: 'site', 
reportTitles: ''])
-                    }
+            }
+        }
+
+        stage('Publish') {
+            when {
+                branch 'master'
+            }
+            steps {
+                publishHTML([allowMissing: false, alwaysLinkToLastBuild: true, 
keepAll: true, reportDir: "${env.WORKSPACE}/target/site", reportFiles: 
'index.html', reportName: 'site', reportTitles: ''])
+            }
+        }
+
+        stage('Check errors') {
+            when {
+                branch 'master'
+            }
+            steps {
+                withMaven(jdk:'jdk_17_latest', maven:'maven_3_latest', 
mavenLocalRepo:'.repository', options: [
+                  artifactsPublisher(disabled: true),
+                  findbugsPublisher(disabled: true),
+                ]) {
+                    sh "mvn -ntp -V -e failsafe:integration-test"
                 }
             }
         }
     }
-
     options {
         buildDiscarder(logRotator(numToKeepStr:'15'))
         timeout(time: 10, unit: 'MINUTES')
diff --git a/pom.xml b/pom.xml
index e635640..24f942e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,6 +60,8 @@
     <project.build.outputTimestamp>x</project.build.outputTimestamp>
     <netbeans.checkstyle.format>true</netbeans.checkstyle.format>
     <mvnversion>3.2.5</mvnversion>
+    <!-- TODO check with next parent -->
+    <versions.junit5>5.11.3</versions.junit5>
     <maven.compiler.source>8</maven.compiler.source>
     <maven.compiler.target>8</maven.compiler.target>
   </properties>
@@ -165,6 +167,11 @@
       <artifactId>junit-jupiter-api</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-params</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
@@ -203,31 +210,6 @@
           </execution>
         </executions>
       </plugin>
-      <!-- copy data from fluido skin to make generated site usable even if 
failure -->
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-dependency-plugin</artifactId>
-        <executions>
-          <execution>
-            <id>unpack</id>
-            <goals>
-              <goal>unpack</goal>
-            </goals>
-            <phase>pre-site</phase>
-            <configuration>
-              <artifactItems>
-                <artifactItem>
-                  <groupId>org.apache.maven.skins</groupId>
-                  <artifactId>maven-fluido-skin</artifactId>
-                  <version>2.0.0-M11</version>
-                  
<outputDirectory>${project.build.directory}/site</outputDirectory>
-                  <includes>**\/*.css, **\/*.png, **\/*.gif</includes>
-                </artifactItem>
-              </artifactItems>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
       <plugin>
         <groupId>org.apache.rat</groupId>
         <artifactId>apache-rat-plugin</artifactId>
@@ -296,12 +278,6 @@
               <report>memory-check</report>
             </reports>
           </reportSet>
-          <reportSet>
-            <id>fail</id>
-            <reports>
-              <report>failure-report</report>
-            </reports>
-          </reportSet>
         </reportSets>
         <!-- <configuration> <configurationLines> 
<configurationLine>org.apache.maven.wagon;wagon;https://dist.apache.org/repos/dist/release/maven/wagon/</configurationLine>
           </configurationLines> </configuration> -->
diff --git 
a/src/main/java/org/apache/maven/dist/tools/DistCheckErrorsReport.java 
b/src/main/java/org/apache/maven/dist/tools/DistCheckErrorsReport.java
index 4a2c76d..cbc6be1 100644
--- a/src/main/java/org/apache/maven/dist/tools/DistCheckErrorsReport.java
+++ b/src/main/java/org/apache/maven/dist/tools/DistCheckErrorsReport.java
@@ -42,30 +42,22 @@ import org.codehaus.plexus.util.FileUtils;
  */
 @Mojo(name = "check-errors", requiresProject = false)
 public class DistCheckErrorsReport extends AbstractDistCheckReport {
-    private static final String[] FAILURES_FILENAMES = {
+
+    public static final String[] FAILURES_FILENAMES = {
         DistCheckSourceReleaseReport.FAILURES_FILENAME,
         DistCheckSiteReport.FAILURES_FILENAME,
         DistCheckIndexPageReport.FAILURES_FILENAME,
         CheckPgpKeysReport.FAILURES_FILENAME
     };
 
-    private static final String EOL = System.getProperty("line.separator");
-
     /**
-     * Dist Check Errors Report.
+     * {@inheritDoc}
      */
-    public DistCheckErrorsReport() {}
-
-    /** {@inheritDoc} */
     @Override
     protected boolean isIndexPageCheck() {
         return false;
     }
 
-    boolean isDummyFailure() {
-        return false;
-    }
-
     private boolean checkError(String failuresFilename) throws 
MavenReportException {
         File failureFile = new File(failuresDirectory, failuresFilename);
 
@@ -73,39 +65,35 @@ public class DistCheckErrorsReport extends 
AbstractDistCheckReport {
             if (failureFile.exists()) {
                 String content = FileUtils.fileRead(failureFile);
 
-                if (isDummyFailure()) {
-                    getLog().error(failuresFilename + " error log not empty:" 
+ EOL + content);
-                } else {
-                    String failure = failuresFilename.substring(0, 
failuresFilename.length() - 4);
-                    Sink s = getSink();
-                    s.section2();
-                    s.sectionTitle2();
-                    s.link("dist-tool-" + failure + ".html");
-                    s.text(failure);
-                    s.link_();
-                    s.sectionTitle2_();
-                    s.verbatim();
-                    s.rawText(content);
-                    s.verbatim_();
-                    s.section2_();
-
-                    Set<String> urls = new HashSet<>();
-                    Pattern p = Pattern.compile("https://[\\S]+";);
-                    Matcher m = p.matcher(content);
-                    while (m.find()) {
-                        urls.add(m.group());
-                    }
-                    if (!urls.isEmpty()) {
-                        s.list();
-                        for (String url : urls) {
-                            s.listItem();
-                            s.link(url);
-                            s.text(url);
-                            s.link_();
-                            s.listItem_();
-                        }
-                        s.list_();
+                String failure = failuresFilename.substring(0, 
failuresFilename.length() - 4);
+                Sink s = getSink();
+                s.section2();
+                s.sectionTitle2();
+                s.link("dist-tool-" + failure + ".html");
+                s.text(failure);
+                s.link_();
+                s.sectionTitle2_();
+                s.verbatim();
+                s.rawText(content);
+                s.verbatim_();
+                s.section2_();
+
+                Set<String> urls = new HashSet<>();
+                Pattern p = Pattern.compile("https://[\\S]+";);
+                Matcher m = p.matcher(content);
+                while (m.find()) {
+                    urls.add(m.group());
+                }
+                if (!urls.isEmpty()) {
+                    s.list();
+                    for (String url : urls) {
+                        s.listItem();
+                        s.link(url);
+                        s.text(url);
+                        s.link_();
+                        s.listItem_();
                     }
+                    s.list_();
                 }
             }
 
@@ -115,23 +103,17 @@ public class DistCheckErrorsReport extends 
AbstractDistCheckReport {
         }
     }
 
-    /** {@inheritDoc} */
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected void executeReport(Locale locale) throws MavenReportException {
         boolean failure = false;
-        // if failures log file is present, throw exception to fail build
         for (String failuresFilename : FAILURES_FILENAMES) {
             failure |= checkError(failuresFilename);
         }
 
-        if (failure) {
-            if (isDummyFailure()) {
-                throw new MavenReportException(
-                        "Dist Tool> Checks found inconsistencies in some 
released artifacts, see "
-                                + 
"https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-dist-tool/job/master/site/";
-                                + "dist-tool-check-errors.html for more 
information");
-            }
-        } else {
+        if (!failure) {
             getSink().paragraph();
             getSink().text("No issue found.");
             getSink().paragraph_();
@@ -147,25 +129,33 @@ public class DistCheckErrorsReport extends 
AbstractDistCheckReport {
         return "dummy";
     }
 
-    /** {@inheritDoc} */
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public String getOutputName() {
         return "dist-tool-check-errors";
     }
 
-    /** {@inheritDoc} */
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public String getName(Locale locale) {
         return "Dist Tool> Check Errors";
     }
 
-    /** {@inheritDoc} */
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public String getDescription(Locale locale) {
         return "Dist Tool report to display inconsistencies found by any check 
report";
     }
 
-    /** {@inheritDoc} */
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected void checkArtifact(ConfigurationLineInfo request, String 
repoBase) {}
 }
diff --git a/src/main/java/org/apache/maven/dist/tools/DummyFailureReport.java 
b/src/main/java/org/apache/maven/dist/tools/DummyFailureReport.java
deleted file mode 100644
index 022418b..0000000
--- a/src/main/java/org/apache/maven/dist/tools/DummyFailureReport.java
+++ /dev/null
@@ -1,68 +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.maven.dist.tools;
-
-import java.util.Locale;
-
-import org.apache.maven.plugins.annotations.Mojo;
-
-/**
- * <p>DummyFailureReport class.</p>
- *
- * @author skygo
- */
-@Mojo(name = "failure-report", requiresProject = false)
-public class DummyFailureReport extends DistCheckErrorsReport {
-    /**
-     * Dummy
-     */
-    public DummyFailureReport() {}
-
-    @Override
-    boolean isDummyFailure() {
-        return true;
-    }
-
-    /**
-     * <p>getFailuresFilename.</p>
-     *
-     * @return a {@link java.lang.String} object
-     */
-    protected String getFailuresFilename() {
-        return "dummy";
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public String getOutputName() {
-        return "dist-tool-failure";
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public String getName(Locale locale) {
-        return "Dist Tool> Failure Hack";
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public String getDescription(Locale locale) {
-        return "Dist Tool report to fail the build in case of inconsistency 
found by any check reports";
-    }
-}
diff --git a/src/test/java/org/apache/maven/dist/tools/CheckReportResultIT.java 
b/src/test/java/org/apache/maven/dist/tools/CheckReportResultIT.java
new file mode 100644
index 0000000..752fb7b
--- /dev/null
+++ b/src/test/java/org/apache/maven/dist/tools/CheckReportResultIT.java
@@ -0,0 +1,53 @@
+/*
+ * 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.maven.dist.tools;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.FieldSource;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+class CheckReportResultIT {
+
+    private static final Path ERROR_LOGS_PATH = Paths.get(
+                    System.getProperty("basedir", new 
File(".").getAbsolutePath()))
+            .resolve("target")
+            .resolve("dist-tool")
+            .normalize();
+
+    @ParameterizedTest
+    
@FieldSource("org.apache.maven.dist.tools.DistCheckErrorsReport#FAILURES_FILENAMES")
+    void shouldBeNoErrors(Path logFile) throws IOException {
+        Path logPath = ERROR_LOGS_PATH.resolve(logFile);
+        if (Files.isRegularFile(logPath)) {
+            List<String> lines = Files.readAllLines(logPath);
+            if (!lines.isEmpty()) {
+                System.err.println(String.join(System.lineSeparator(), lines));
+                fail();
+            }
+        }
+    }
+}

Reply via email to