Skip to content

Commit 72fa709

Browse files
committed
fix(ci): check local cache before Maven Central in reachability test
Modify BomContentTest to check if an artifact exists in the local Maven repository (.m2) before checking its reachability on Maven Central. During release PRs, new versions of libraries are built and installed locally (via pre-install.sh) but are not yet published to Maven Central. This change allows the reachability check to pass for these new versions if they are found in the local cache, while still verifying that other dependencies (which should be on Central) are reachable. This removes the need for conditional flags in GHA workflows.
1 parent affdc9c commit 72fa709

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

java-cloud-bom/tests/src/test/java/com/google/cloud/BomContentTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.IOException;
3131
import java.net.HttpURLConnection;
3232
import java.net.URL;
33+
import java.nio.file.Files;
3334
import java.nio.file.Path;
3435
import java.nio.file.Paths;
3536
import java.util.ArrayList;
@@ -76,6 +77,9 @@ private void checkBom(Path bomPath) throws Exception {
7677
if (artifact.getVersion().contains("SNAPSHOT")) {
7778
continue;
7879
}
80+
if (existsLocally(artifact)) {
81+
continue;
82+
}
7983
assertReachable(buildMavenCentralUrl(artifact));
8084
}
8185

@@ -104,6 +108,9 @@ static void checkBomReachable(Path bomPath) throws Exception {
104108
if (artifact.getVersion().contains("SNAPSHOT")) {
105109
continue;
106110
}
111+
if (existsLocally(artifact)) {
112+
continue;
113+
}
107114
try {
108115
assertReachable(buildMavenCentralUrl(artifact));
109116
} catch (IOException ex) {
@@ -134,6 +141,19 @@ private static String buildMavenCentralUrl(Artifact artifact) {
134141
+ ".pom";
135142
}
136143

144+
private static boolean existsLocally(Artifact artifact) {
145+
String localRepository = System.getProperty("maven.repo.local");
146+
if (localRepository == null) {
147+
localRepository = System.getProperty("user.home") + "/.m2/repository";
148+
}
149+
Path localPath = Paths.get(localRepository,
150+
artifact.getGroupId().replace('.', '/'),
151+
artifact.getArtifactId(),
152+
artifact.getVersion(),
153+
artifact.getArtifactId() + "-" + artifact.getVersion() + ".pom");
154+
return Files.exists(localPath);
155+
}
156+
137157
/** Asserts that the BOM only provides JARs which contains unique class names to the classpath. */
138158
private static void assertUniqueClasses(List<Artifact> allArtifacts)
139159
throws InvalidVersionSpecificationException, IOException {

0 commit comments

Comments
 (0)