From 4a66e9d40a9843c3b0dfec36234860737072af0b Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Tue, 7 Nov 2023 23:37:43 +0100 Subject: [PATCH] Strip .git suffix from code repo https URLs --- .../java/io/quarkus/bom/decomposer/Util.java | 14 ++-- .../domino/ProjectDependencyResolver.java | 79 ++++++++++--------- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/bom-decomposer/src/main/java/io/quarkus/bom/decomposer/Util.java b/bom-decomposer/src/main/java/io/quarkus/bom/decomposer/Util.java index d7500b4c..b3a4fadb 100644 --- a/bom-decomposer/src/main/java/io/quarkus/bom/decomposer/Util.java +++ b/bom-decomposer/src/main/java/io/quarkus/bom/decomposer/Util.java @@ -47,12 +47,11 @@ public static String getScmOrigin(Model model) { if (scm == null) { return null; } - if (scm.getConnection() != null) { - String s = resolveModelValue(model, scm.getConnection()); - s = scmToHttps(s); - return s; + String url = resolveModelValue(model, scm.getConnection()); + if (url != null && !url.isEmpty()) { + return scmToHttps(url); } - String url = resolveModelValue(model, model.getUrl()); + url = resolveModelValue(model, model.getUrl()); if (url != null && url.startsWith("https://github.com/")) { return scmToHttps(url); } @@ -74,11 +73,10 @@ private static String scmToHttps(String s) { s = s.replace("http://", "https://"); } else if (!s.startsWith("https://")) { s = s.replace(':', '/'); - if (s.startsWith("github.com:")) { - s = s.replace(':', '/'); - } if (s.startsWith("//")) { s = "https:" + s; + } else if (s.charAt(0) == '/') { + s = "https:/" + s; } else { s = "https://" + s; } diff --git a/domino/api/src/main/java/io/quarkus/domino/ProjectDependencyResolver.java b/domino/api/src/main/java/io/quarkus/domino/ProjectDependencyResolver.java index 9ef00947..146f6017 100644 --- a/domino/api/src/main/java/io/quarkus/domino/ProjectDependencyResolver.java +++ b/domino/api/src/main/java/io/quarkus/domino/ProjectDependencyResolver.java @@ -812,48 +812,48 @@ public void run() { .setGitCloneBaseDir(cloneBaseDir) .setCacheRepoTags(true) .setCloneLocalRecipeRepos(false) - .setFallback(new ScmLocator() { - @Override - public TagInfo resolveTagInfo(GAV gav) { - - var pomArtifact = new DefaultArtifact(gav.getGroupId(), gav.getArtifactId(), ArtifactCoords.TYPE_POM, - gav.getVersion()); - - ScmRevision releaseId = null; - for (ReleaseIdDetector rd : releaseDetectors) { - try { - var rid = rd.detectReleaseId(ref.get(), pomArtifact); - if (rid != null && rid.getRepository().hasUrl() - && rid.getRepository().getUrl().contains("git")) { - releaseId = rid; - break; - } - } catch (BomDecomposerException e) { - log.warn("Failed to determine SCM for " + gav.getGroupId() + ":" + gav.getArtifactId() + ":" - + gav.getVersion() + ": " + e.getLocalizedMessage()); + .setFallback(gav -> { + + var pomArtifact = new DefaultArtifact(gav.getGroupId(), gav.getArtifactId(), ArtifactCoords.TYPE_POM, + gav.getVersion()); + + ScmRevision releaseId = null; + for (ReleaseIdDetector rd : releaseDetectors) { + try { + var rid = rd.detectReleaseId(ref.get(), pomArtifact); + if (rid != null && rid.getRepository().hasUrl() + && rid.getRepository().getUrl().contains("git")) { + releaseId = rid; + break; } + } catch (BomDecomposerException e) { + log.warn("Failed to determine SCM for " + gav.getGroupId() + ":" + gav.getArtifactId() + ":" + + gav.getVersion() + ": " + e.getLocalizedMessage()); } + } - if (releaseId == null) { - try { - releaseId = ref.get().readRevisionFromPom(pomArtifact); - } catch (BomDecomposerException e) { - log.warn("Failed to determine SCM for " + gav.getGroupId() + ":" + gav.getArtifactId() + ":" - + gav.getVersion() + " from POM metadata: " - + e.getLocalizedMessage()); - } + if (releaseId == null) { + try { + releaseId = ref.get().readRevisionFromPom(pomArtifact); + } catch (BomDecomposerException e) { + log.warn("Failed to determine SCM for " + gav.getGroupId() + ":" + gav.getArtifactId() + ":" + + gav.getVersion() + " from POM metadata: " + + e.getLocalizedMessage()); } + } - if (releaseId != null && releaseId.getRepository().hasUrl() - && releaseId.getRepository().getUrl().contains("git")) { - log.warn("The SCM recipe database is missing an entry for " + gav.getGroupId() + ":" - + gav.getArtifactId() + ":" + gav.getVersion() + ", " + releaseId - + " will be used as a fallback"); - return new TagInfo(new RepositoryInfo("git", releaseId.getRepository().getUrl()), - releaseId.getValue(), null); - } - return null; + if (releaseId != null && releaseId.getRepository().toString().contains(".git")) { + throw new IllegalStateException(releaseId.toString()); } + if (releaseId != null && releaseId.getRepository().hasUrl() + && releaseId.getRepository().getUrl().contains("git")) { + log.warn("The SCM recipe database is missing an entry for " + gav.getGroupId() + ":" + + gav.getArtifactId() + ":" + gav.getVersion() + ", " + releaseId + + " will be used as a fallback"); + return new TagInfo(new RepositoryInfo("git", releaseId.getRepository().getUrl()), + releaseId.getValue(), null); + } + return null; }) .build(); @@ -875,7 +875,12 @@ public ScmRevision detectReleaseId(ScmRevisionResolver releaseResolver, Artifact final TagInfo tag = scmLocator.resolveTagInfo(gav); if (tag != null) { ++succeeded; - return ScmRevision.tag(ScmRepository.ofUrl(tag.getRepoInfo().getUri()), tag.getTag()); + var uri = tag.getRepoInfo().getUri(); + if (uri.endsWith(".git")) { + // strip .git at the end + uri = uri.substring(0, uri.length() - 4); + } + return ScmRevision.tag(ScmRepository.ofUrl(uri), tag.getTag()); } } catch (Exception e) { error = e;