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

[Backport 2.0] Gradle plugin opensearch.pluginzip Add implicit dependency. #3212

Merged
merged 1 commit into from
May 7, 2022
Merged
Show file tree
Hide file tree
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 @@ -135,11 +135,11 @@ public String call() throws Exception {
publication.artifact(project.getTasks().getByName("sourcesJar"));
publication.artifact(project.getTasks().getByName("javadocJar"));
}

generatePomTask.configure(
t -> t.dependsOn(String.format("generatePomFileFor%sPublication", Util.capitalize(publication.getName())))
);
}

generatePomTask.configure(
t -> t.dependsOn(String.format("generatePomFileFor%sPublication", Util.capitalize(publication.getName())))
);
});

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
import java.nio.file.Path;
import org.gradle.api.Task;

public class Publish implements Plugin<Project> {
private Project project;
Expand Down Expand Up @@ -63,12 +64,19 @@ static String getProperty(String name, Project project) {
@Override
public void apply(Project project) {
this.project = project;
project.afterEvaluate(evaluatedProject -> { configMaven(project); });
project.getGradle().getTaskGraph().whenReady(graph -> {
if (graph.hasTask(LOCALMAVEN)) {
project.getTasks().getByName(PLUGIN_ZIP_PUBLISH_POM_TASK).setEnabled(false);
project.afterEvaluate(evaluatedProject -> {
configMaven(project);
Task validatePluginZipPom = project.getTasks().findByName("validatePluginZipPom");
if (validatePluginZipPom != null) {
project.getTasks().getByName("validatePluginZipPom").dependsOn("generatePomFileForNebulaPublication");
}
Task publishPluginZipPublicationToZipStagingRepository = project.getTasks()
.findByName("publishPluginZipPublicationToZipStagingRepository");
if (validatePluginZipPom != null) {
project.getTasks()
.getByName("publishPluginZipPublicationToZipStagingRepository")
.dependsOn("generatePomFileForNebulaPublication");
}

});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.FileReader;
import org.gradle.api.tasks.bundling.Zip;
import java.util.List;
import java.util.ArrayList;

public class PublishTests extends GradleUnitTestCase {

Expand Down Expand Up @@ -56,6 +58,7 @@ public void testZipPublish() throws IOException, XmlPullParserException {
writeString(new File(projectDir, "settings.gradle"), "");
// Generate the build.gradle file
String buildFileContent = "apply plugin: 'maven-publish' \n"
+ "apply plugin: 'java' \n"
+ "publishing {\n"
+ " repositories {\n"
+ " maven {\n"
Expand All @@ -74,10 +77,13 @@ public void testZipPublish() throws IOException, XmlPullParserException {
+ "}";
writeString(new File(projectDir, "build.gradle"), buildFileContent);
// Execute the task publishPluginZipPublicationToZipStagingRepository
List<String> allArguments = new ArrayList<String>();
allArguments.add("build");
allArguments.add(zipPublishTask);
GradleRunner runner = GradleRunner.create();
runner.forwardOutput();
runner.withPluginClasspath();
runner.withArguments(zipPublishTask);
runner.withArguments(allArguments);
runner.withProjectDir(projectDir);
BuildResult result = runner.build();
// Check if task publishMavenzipPublicationToZipstagingRepository has ran well
Expand All @@ -87,6 +93,7 @@ public void testZipPublish() throws IOException, XmlPullParserException {
new File("build/functionalTest/local-staging-repo/org/opensearch/plugin/sample-plugin/2.0.0.0/sample-plugin-2.0.0.0.zip")
.exists()
);
assertEquals(SUCCESS, result.task(":" + "build").getOutcome());
// Parse the maven file and validate the groupID to org.opensearch.plugin
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(
Expand Down