Skip to content

Commit

Permalink
Add explicit dependency to PomValidation
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <[email protected]>
  • Loading branch information
zelinh committed Mar 20, 2024
1 parent d4e1ab1 commit feea594
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public void apply(Project project) {
addLocalMavenRepo(project);
addZipArtifact(project);
Task validatePluginZipPom = project.getTasks().findByName("validatePluginZipPom");
if (validatePluginZipPom != null) {
validatePluginZipPom.dependsOn("generatePomFileForNebulaPublication");
}

// There are number of tasks prefixed by 'publishPluginZipPublication', f.e.:
// publishPluginZipPublicationToZipStagingRepository, publishPluginZipPublicationToMavenLocal
Expand All @@ -76,7 +73,11 @@ public void apply(Project project) {
.filter(t -> t.getName().startsWith("publishPluginZipPublicationTo"))
.collect(Collectors.toSet());
if (!publishPluginZipPublicationToTasks.isEmpty()) {
publishPluginZipPublicationToTasks.forEach(t -> t.dependsOn("generatePomFileForNebulaPublication"));
if (validatePluginZipPom != null) {
publishPluginZipPublicationToTasks.forEach(t -> t.dependsOn(validatePluginZipPom));

Check warning on line 77 in buildSrc/src/main/java/org/opensearch/gradle/pluginzip/Publish.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/pluginzip/Publish.java#L77

Added line #L77 was not covered by tests
} else {
publishPluginZipPublicationToTasks.forEach(t -> t.dependsOn("generatePomFileForNebulaPublication"));

Check warning on line 79 in buildSrc/src/main/java/org/opensearch/gradle/pluginzip/Publish.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/pluginzip/Publish.java#L79

Added line #L79 was not covered by tests
}
}
} else {
project.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,24 @@ public class PomValidationPrecommitPlugin extends PrecommitPlugin {
public TaskProvider<? extends Task> createTask(Project project) {
TaskProvider<Task> validatePom = project.getTasks().register("validatePom");
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
publishing.getPublications().all(publication -> {
publishing.getPublications().configureEach(publication -> {
String publicationName = Util.capitalize(publication.getName());
TaskProvider<PomValidationTask> validateTask = project.getTasks()
.register("validate" + publicationName + "Pom", PomValidationTask.class);
validatePom.configure(t -> t.dependsOn(validateTask));
TaskProvider<GenerateMavenPom> generateMavenPom = project.getTasks()
.withType(GenerateMavenPom.class)
.named("generatePomFileFor" + publicationName + "Publication");
validateTask.configure(task -> {
GenerateMavenPom generateMavenPom = project.getTasks()
.withType(GenerateMavenPom.class)
.getByName("generatePomFileFor" + publicationName + "Publication");
task.dependsOn(generateMavenPom);
task.getPomFile().fileValue(generateMavenPom.getDestination());
task.getPomFile().fileProvider(generateMavenPom.map(GenerateMavenPom::getDestination));
publishing.getPublications().configureEach(publicationForPomGen -> {
task.mustRunAfter(
project.getTasks()
.withType(GenerateMavenPom.class)
.getByName("generatePomFileFor" + Util.capitalize(publicationForPomGen.getName()) + "Publication")

Check warning on line 66 in buildSrc/src/main/java/org/opensearch/gradle/precommit/PomValidationPrecommitPlugin.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/PomValidationPrecommitPlugin.java#L61-L66

Added lines #L61 - L66 were not covered by tests
);
});

Check warning on line 68 in buildSrc/src/main/java/org/opensearch/gradle/precommit/PomValidationPrecommitPlugin.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/PomValidationPrecommitPlugin.java#L68

Added line #L68 was not covered by tests
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private <T> void validateNonNull(String element, T value, Runnable validator) {

private void validateString(String element, String value) {
validateNonNull(element, value, () -> validateNonEmpty(element, value, s -> s.trim().isEmpty()));
getLogger().info(element + " with value " + value + " is validated.");

Check warning on line 109 in buildSrc/src/main/java/org/opensearch/gradle/precommit/PomValidationTask.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/PomValidationTask.java#L109

Added line #L109 was not covered by tests
}

private <T> void validateCollection(String element, Collection<T> value, Consumer<T> validator) {
Expand Down

0 comments on commit feea594

Please sign in to comment.