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

radu pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new 646b413  SLING-9047 - The CIStatusValidator cannot verify multi-module 
releases
646b413 is described below

commit 646b413438943354b12d56001df449e24398b2eb
Author: Radu Cotescu <[email protected]>
AuthorDate: Wed Feb 5 13:38:55 2020 +0100

    SLING-9047 - The CIStatusValidator cannot verify multi-module releases
---
 .../sling/cli/impl/ci/CIStatusValidator.java       | 33 +++++++++++++---------
 .../cli/impl/release/VerifyReleasesCommand.java    | 16 +++++++----
 .../sling/cli/impl/ci/CIStatusValidatorTest.java   | 15 +++++-----
 src/test/resources/ci/{repo.pom => repo-1.0.pom}   |  2 +-
 src/test/resources/ci/{repo.pom => repo-1.1.pom}   |  4 +--
 5 files changed, 42 insertions(+), 28 deletions(-)

diff --git a/src/main/java/org/apache/sling/cli/impl/ci/CIStatusValidator.java 
b/src/main/java/org/apache/sling/cli/impl/ci/CIStatusValidator.java
index b2462ea..f363df9 100644
--- a/src/main/java/org/apache/sling/cli/impl/ci/CIStatusValidator.java
+++ b/src/main/java/org/apache/sling/cli/impl/ci/CIStatusValidator.java
@@ -94,35 +94,42 @@ public class CIStatusValidator {
         }
     }
 
-    String getCIEndpoint(Artifact artifact, Path artifactFilePath) {
+    String getCIEndpoint(Path artifactFilePath) {
         log.trace("getCIEndpoint");
         String ciEndpoint = null;
         try {
             DocumentBuilder builder = builderFactory.newDocumentBuilder();
             Document xmlDocument = builder.parse(artifactFilePath.toFile());
             XPath xPath = xPathFactory.newXPath();
-            String url = (String) 
xPath.compile("/project/scm/url/text()").evaluate(xmlDocument, 
XPathConstants.STRING);
-            if (url != null && url.trim().length() > 0) {
-
-                url = url.substring(url.indexOf("?p=") + 3);
-                url = url.substring(0, url.indexOf(".git"));
-                log.debug("Extracted REPO: {}", url);
+            String repositoryName = (String) 
xPath.compile("/project/scm/url/text()").evaluate(xmlDocument, 
XPathConstants.STRING);
+            String tagName = (String) 
xPath.compile("/project/scm/tag/text()").evaluate(xmlDocument, 
XPathConstants.STRING);
+            if (!tagName.isEmpty()) {
+                tagName = tagName.trim();
+                log.debug("Extracted TAG: {}", tagName);
+            }
+            if (repositoryName != null && repositoryName.trim().length() > 0) {
 
-                ciEndpoint = 
String.format("https://api.github.com/repos/apache/%s/commits/%s-%s/status";, 
url,
-                        artifact.getArtifactId(), artifact.getVersion());
+                repositoryName = 
repositoryName.substring(repositoryName.indexOf("?p=") + 3);
+                repositoryName = repositoryName.substring(0, 
repositoryName.indexOf(".git"));
+                log.debug("Extracted REPO: {}", repositoryName);
+            }
+            if (repositoryName != null && !repositoryName.isEmpty() && 
!tagName.isEmpty() && !tagName.equalsIgnoreCase("HEAD")) {
+                ciEndpoint = 
String.format("https://api.github.com/repos/apache/%s/commits/%s/status";, 
repositoryName, tagName);
                 log.debug("Loaded CI Endpoint: {}", ciEndpoint);
             }
-            log.debug("Retrieved SCM URL: {}", url);
         } catch (XPathExpressionException | SAXException | IOException | 
ParserConfigurationException e) {
             log.debug("Failed to extract SCM URL", e);
         }
         return ciEndpoint;
     }
 
-    public ValidationResult isValid(Artifact artifact, Path artifactFilePath) {
+    public ValidationResult isValid(Path artifactFilePath) {
         log.trace("isValid");
 
-        String ciEndpoint = getCIEndpoint(artifact, artifactFilePath);
+        String ciEndpoint = getCIEndpoint(artifactFilePath);
+        if (ciEndpoint == null) {
+            return new ValidationResult(false, "Cannot extract a CI endpoint 
from " + artifactFilePath.getFileName());
+        }
         try {
             JsonObject status = fetchCIStatus(ciEndpoint);
             List<String> messageEntries = new ArrayList<>();
@@ -149,6 +156,6 @@ public class CIStatusValidator {
 
     public boolean shouldCheck(Artifact artifact, Path artifactFilePath) {
         log.trace("shouldCheck");
-        return "pom".equals(artifact.getType()) && getCIEndpoint(artifact, 
artifactFilePath) != null;
+        return "pom".equals(artifact.getType()) && 
getCIEndpoint(artifactFilePath) != null;
     }
 }
diff --git 
a/src/main/java/org/apache/sling/cli/impl/release/VerifyReleasesCommand.java 
b/src/main/java/org/apache/sling/cli/impl/release/VerifyReleasesCommand.java
index e3e4477..d9614f2 100644
--- a/src/main/java/org/apache/sling/cli/impl/release/VerifyReleasesCommand.java
+++ b/src/main/java/org/apache/sling/cli/impl/release/VerifyReleasesCommand.java
@@ -75,7 +75,13 @@ public class VerifyReleasesCommand implements Command {
         try {
             LocalRepository repository = 
repositoryService.download(repositoryService.find(repositoryId));
             Path repositoryRootPath = repository.getRootFolder();
+            Artifact pom = null;
+            Path pomPath = null;
             for (Artifact artifact : repository.getArtifacts()) {
+                if ("pom".equals(artifact.getType())) {
+                    pom = artifact;
+                    pomPath = 
repositoryRootPath.resolve(artifact.getRepositoryRelativePath());
+                }
                 Path artifactFilePath = 
repositoryRootPath.resolve(artifact.getRepositoryRelativePath());
                 Path artifactSignaturePath = 
repositoryRootPath.resolve(artifact.getRepositoryRelativeSignaturePath());
                 PGPSignatureValidator.ValidationResult validationResult = 
pgpSignatureValidator.verify(artifactFilePath,
@@ -111,11 +117,11 @@ public class VerifyReleasesCommand implements Command {
                         md5validationResult.isValid() ? String.format("VALID 
(%s)", md5validationResult.getActualHash())
                                 : String.format("INVALID (expected %s, got 
%s)", md5validationResult.getExpectedHash(),
                                         md5validationResult.getActualHash()));
-
-                if (ciStatusValidator.shouldCheck(artifact, artifactFilePath)) 
{
-                    CIStatusValidator.ValidationResult ciValidationResult = 
ciStatusValidator.isValid(artifact,
-                            artifactFilePath);
-                    LOGGER.info("CI Status: {}",
+            }
+            if (pom != null && pomPath != null) {
+                if (ciStatusValidator.shouldCheck(pom, pomPath)) {
+                    CIStatusValidator.ValidationResult ciValidationResult = 
ciStatusValidator.isValid(pomPath);
+                    LOGGER.info("\nCI Status: {}",
                             ciValidationResult.isValid() ? 
String.format("VALID: %n%s", ciValidationResult.getMessage())
                                     : String.format("INVALID: %n%s", 
ciValidationResult.getMessage()));
                     checksRun++;
diff --git 
a/src/test/java/org/apache/sling/cli/impl/ci/CIStatusValidatorTest.java 
b/src/test/java/org/apache/sling/cli/impl/ci/CIStatusValidatorTest.java
index d891ef2..183c0dd 100644
--- a/src/test/java/org/apache/sling/cli/impl/ci/CIStatusValidatorTest.java
+++ b/src/test/java/org/apache/sling/cli/impl/ci/CIStatusValidatorTest.java
@@ -43,7 +43,7 @@ public class CIStatusValidatorTest {
             InputStreamReader reader = null;
             if 
("https://api.github.com/repos/apache/sling-repo-pom/commits/repo-pom-1.0/status".equals(ciEndpoint))
 {
                 reader = new 
InputStreamReader(CIStatusValidatorTest.class.getResourceAsStream("/ci/failure.json"));
-            } else if 
("https://api.github.com/repos/apache/sling-repo-pom/commits/successful-pom-1.0/status";
+            } else if 
("https://api.github.com/repos/apache/sling-repo-pom/commits/repo-pom-1.1/status";
                     .equals(ciEndpoint)) {
                 reader = new 
InputStreamReader(CIStatusValidatorTest.class.getResourceAsStream("/ci/success.json"));
             }
@@ -60,16 +60,17 @@ public class CIStatusValidatorTest {
     private static Artifact NON_REPO_POM_ARTIFACT = new Artifact(REPOSITORY, 
"org.apache.sling", "no-repo-pom", "1.0", "", "pom");
     private static Path NON_REPO_POM_FILE;
     private static Artifact POM_ARTIFACT = new Artifact(REPOSITORY, 
"org.apache.sling", "repo-pom", "1.0", "", "pom");
-    private static Artifact SUCCESSFUL_POM_ARTIFACT = new Artifact(REPOSITORY, 
"org.apache.sling", "successful-pom", "1.0", "",
-            "pom");
     private static Path POM_FILE;
+    private static Path SUCCESSFUL_POM_FILE;
 
     static {
         try {
             URI nonrepo = 
CIStatusValidatorTest.class.getResource("/ci/no-repo.pom").toURI();
             NON_REPO_POM_FILE = Path.of(nonrepo);
-            URI repo = 
CIStatusValidatorTest.class.getResource("/ci/repo.pom").toURI();
+            URI repo = 
CIStatusValidatorTest.class.getResource("/ci/repo-1.0.pom").toURI();
+            URI successfulRepo = 
CIStatusValidatorTest.class.getResource("/ci/repo-1.1.pom").toURI();
             POM_FILE = Path.of(repo);
+            SUCCESSFUL_POM_FILE = Path.of(successfulRepo);
         } catch (URISyntaxException e) {
             throw new RuntimeException(e);
         }
@@ -85,16 +86,16 @@ public class CIStatusValidatorTest {
     @Test
     public void getCIEndpoint() {
         
assertEquals("https://api.github.com/repos/apache/sling-repo-pom/commits/repo-pom-1.0/status";,
-                validator.getCIEndpoint(POM_ARTIFACT, POM_FILE));
+                validator.getCIEndpoint(POM_FILE));
     }
 
     @Test
     public void isValid() {
-        ValidationResult invalid = validator.isValid(POM_ARTIFACT, POM_FILE);
+        ValidationResult invalid = validator.isValid(POM_FILE);
         assertFalse(invalid.isValid());
         assertNotNull(invalid.getMessage());
 
-        ValidationResult valid = validator.isValid(SUCCESSFUL_POM_ARTIFACT, 
POM_FILE);
+        ValidationResult valid = validator.isValid(SUCCESSFUL_POM_FILE);
         assertTrue(valid.isValid());
         assertNotNull(valid.getMessage());
     }
diff --git a/src/test/resources/ci/repo.pom b/src/test/resources/ci/repo-1.0.pom
similarity index 98%
copy from src/test/resources/ci/repo.pom
copy to src/test/resources/ci/repo-1.0.pom
index 8e29c6e..42d53cd 100644
--- a/src/test/resources/ci/repo.pom
+++ b/src/test/resources/ci/repo-1.0.pom
@@ -26,7 +26,7 @@
         
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-repo-pom.git</connection>
         
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-repo-pom.git</developerConnection>
         <url>https://gitbox.apache.org/repos/asf?p=sling-repo-pom.git</url>
-        <tag>HEAD</tag>
+        <tag>repo-pom-1.0</tag>
     </scm>
 
 </project>
diff --git a/src/test/resources/ci/repo.pom b/src/test/resources/ci/repo-1.1.pom
similarity index 96%
rename from src/test/resources/ci/repo.pom
rename to src/test/resources/ci/repo-1.1.pom
index 8e29c6e..0d03044 100644
--- a/src/test/resources/ci/repo.pom
+++ b/src/test/resources/ci/repo-1.1.pom
@@ -17,7 +17,7 @@
     </parent>
 
     <artifactId>repo-pom</artifactId>
-    <version>1.0</version>
+    <version>1.1</version>
 
     <name>Repo POM</name>
     <description>A Sample POM File with a repo</description>
@@ -26,7 +26,7 @@
         
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-repo-pom.git</connection>
         
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-repo-pom.git</developerConnection>
         <url>https://gitbox.apache.org/repos/asf?p=sling-repo-pom.git</url>
-        <tag>HEAD</tag>
+        <tag>repo-pom-1.1</tag>
     </scm>
 
 </project>

Reply via email to