Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less temperamental bwc artifacts check when between versions #7398

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

import static java.util.Arrays.asList;
Expand Down Expand Up @@ -106,6 +108,7 @@ private void configureBwcProject(Project project, BwcVersions.UnreleasedVersionI
distributionProject.name,
distributionProject.getProjectPath(),
distributionProject.getDistFile(),
distributionProject.getAlternativeDistFiles(),
buildBwcTaskProvider
);

Expand Down Expand Up @@ -200,6 +203,7 @@ static void createBuildBwcTask(
String projectName,
String projectPath,
File projectArtifact,
List<File> alternativeProjectArtifacts,
TaskProvider<Task> bwcTaskProvider
) {
String bwcTaskName = buildBwcTaskName(projectName);
Expand All @@ -220,8 +224,27 @@ public void execute(LoggedExec c) {
@Override
public void execute(Task task) {
if (projectArtifact.exists() == false) {
Optional<String> foundAlternative = alternativeProjectArtifacts.stream()
.filter(File::exists)
.map(File::getName)
.findFirst();
if (foundAlternative.isPresent()) {
project.getLogger()
.warn(
"Building " + bwcVersion.get() + " found acceptable alternative artifact " + foundAlternative.get()
);
return;
}
String foundArtifacts = stream(projectArtifact.getParentFile().listFiles()).map(f -> f.getName())
.map(s -> " - " + s)
.collect(Collectors.joining("\r\n"));
throw new InvalidUserDataException(
"Building " + bwcVersion.get() + " didn't generate expected file " + projectArtifact
"Building "
+ bwcVersion.get()
+ " didn't generate expected file "
+ projectArtifact
+ "\r\nFound the following artifacts:\r\n"
+ foundArtifacts
);
}
}
Expand All @@ -239,22 +262,35 @@ private static class DistributionProject {
private final String name;
private String projectPath;
private File distFile;
private List<File> alternativeDistFiles;
private File expandedDistDir;

DistributionProject(String name, String baseDir, Version version, String classifier, String extension, File checkoutDir) {
this.name = name;
this.projectPath = baseDir + "/" + name;
if (version.onOrAfter("1.1.0")) {
this.distFile = new File(
checkoutDir,
baseDir + "/" + name + "/build/distributions/opensearch-min-" + version + "-SNAPSHOT" + classifier + "." + extension
);
} else {
this.distFile = new File(
checkoutDir,
baseDir + "/" + name + "/build/distributions/opensearch-" + version + "-SNAPSHOT" + classifier + "." + extension
);
}
final String minDesignation = version.onOrAfter("1.1.0") ? "min-" : "";
final Function<Version, String> generateName = (Version ver) -> {
return baseDir
+ "/"
+ name
+ "/build/distributions/opensearch-"
+ minDesignation
+ ver
+ "-SNAPSHOT"
+ classifier
+ "."
+ extension;
};
this.distFile = new File(checkoutDir, generateName.apply(version));

final Version nextPatchVersion = new Version(version.getMajor(), version.getMinor(), version.getRevision() + 1);
final Version nextMinorVersion = new Version(version.getMajor(), version.getMinor() + 1, 0);
this.alternativeDistFiles = List.of(nextPatchVersion, nextMinorVersion)
.stream()
.map(generateName)
.map(n -> new File(checkoutDir, n))
.collect(Collectors.toList());

// we only ported this down to the 7.x branch.
if (version.onOrAfter("7.10.0") && (name.endsWith("zip") || name.endsWith("tar"))) {
this.expandedDistDir = new File(checkoutDir, baseDir + "/" + name + "/build/install");
Expand All @@ -269,6 +305,10 @@ public File getDistFile() {
return distFile;
}

public List<File> getAlternativeDistFiles() {
return alternativeDistFiles;
}

public File getExpandedDistDirectory() {
return expandedDistDir;
}
Expand Down