Skip to content

Commit 5f63b49

Browse files
committed
Support downloading pre-built SNAPSHOT artifacts for BWC tests
Add a -Dbwc.buildUnreleasedFromSource=false flag that downloads pre-built SNAPSHOT artifacts from artifacts.opensearch.org for unreleased versions instead of checking out git branches and compiling from source. The default behavior (building from source) is unchanged. Signed-off-by: Andrew Ross <andrross@amazon.com>
1 parent 14faf38 commit 5f63b49

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

buildSrc/src/main/java/org/opensearch/gradle/info/BuildParams.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class BuildParams {
6161
private static Boolean isInternal;
6262
private static Integer defaultParallel;
6363
private static Boolean isSnapshotBuild;
64+
private static Boolean buildUnreleasedFromSource;
6465
private static BwcVersions bwcVersions;
6566

6667
/**
@@ -147,6 +148,10 @@ public static boolean isSnapshotBuild() {
147148
return value(BuildParams.isSnapshotBuild);
148149
}
149150

151+
public static boolean buildUnreleasedFromSource() {
152+
return buildUnreleasedFromSource == null || buildUnreleasedFromSource;
153+
}
154+
150155
private static <T> T value(T object) {
151156
if (object == null) {
152157
String callingMethod = Thread.currentThread().getStackTrace()[2].getMethodName();
@@ -256,6 +261,10 @@ public void setIsSnapshotBuild(final boolean isSnapshotBuild) {
256261
BuildParams.isSnapshotBuild = isSnapshotBuild;
257262
}
258263

264+
public void setBuildUnreleasedFromSource(final boolean buildUnreleasedFromSource) {
265+
BuildParams.buildUnreleasedFromSource = buildUnreleasedFromSource;
266+
}
267+
259268
public void setBwcVersions(BwcVersions bwcVersions) {
260269
BuildParams.bwcVersions = requireNonNull(bwcVersions);
261270
}

buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public void apply(Project project) {
133133
params.setDefaultParallel(findDefaultParallel(project));
134134
params.setInFipsJvm(FipsBuildParams.isInFipsMode());
135135
params.setIsSnapshotBuild(Util.getBooleanProperty("build.snapshot", true));
136+
params.setBuildUnreleasedFromSource(Util.getBooleanProperty("bwc.buildUnreleasedFromSource", true));
136137
if (isInternal) {
137138
params.setBwcVersions(resolveBwcVersions(rootDir));
138139
}

buildSrc/src/main/java/org/opensearch/gradle/internal/InternalDistributionDownloadPlugin.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ private void registerInternalDistributionResolutions(NamedDomainObjectContainer<
100100
resolutions.register("bwc", distributionResolution -> distributionResolution.setResolver((project, distribution) -> {
101101
BwcVersions.UnreleasedVersionInfo unreleasedInfo = bwcVersions.unreleasedInfo(Version.fromString(distribution.getVersion()));
102102
if (unreleasedInfo != null) {
103+
if (BuildParams.buildUnreleasedFromSource() == false) {
104+
// Download pre-built SNAPSHOT artifacts instead of building from source
105+
return DistributionDependency.of(snapshotDependencyNotation(distribution));
106+
}
103107
if (distribution.getBundledJdk() == JavaPackageType.NONE) {
104108
throw new GradleException(
105109
"Configuring a snapshot bwc distribution ('"
@@ -195,6 +199,40 @@ private static String distributionProjectName(OpenSearchDistribution distributio
195199
return projectName;
196200
}
197201

202+
/**
203+
* Constructs a dependency notation that resolves an unreleased version from the snapshot artifact repository.
204+
*/
205+
private static String snapshotDependencyNotation(OpenSearchDistribution distribution) {
206+
String snapshotVersion = distribution.getVersion() + "-SNAPSHOT";
207+
String extension = distribution.getType().toString();
208+
String classifier = ":x64";
209+
if (distribution.getType() == OpenSearchDistribution.Type.ARCHIVE) {
210+
extension = distribution.getPlatform() == OpenSearchDistribution.Platform.WINDOWS ? "zip" : "tar.gz";
211+
switch (distribution.getArchitecture()) {
212+
case ARM64:
213+
classifier = ":" + distribution.getPlatform() + "-arm64";
214+
break;
215+
case X64:
216+
classifier = ":" + distribution.getPlatform() + "-x64";
217+
break;
218+
case S390X:
219+
classifier = ":" + distribution.getPlatform() + "-s390x";
220+
break;
221+
case PPC64LE:
222+
classifier = ":" + distribution.getPlatform() + "-ppc64le";
223+
break;
224+
case RISCV64:
225+
classifier = ":" + distribution.getPlatform() + "-riscv64";
226+
break;
227+
default:
228+
throw new IllegalArgumentException("Unsupported architecture: " + distribution.getArchitecture());
229+
}
230+
} else if (distribution.getType() == OpenSearchDistribution.Type.DEB) {
231+
classifier = ":amd64";
232+
}
233+
return "opensearch-distribution-snapshot:opensearch:" + snapshotVersion + classifier + "@" + extension;
234+
}
235+
198236
private static class ProjectBasedDistributionDependency implements DistributionDependency {
199237

200238
private Function<String, Dependency> function;

0 commit comments

Comments
 (0)