Skip to content

Commit

Permalink
Gradle plugin opensearch.pluginzip Add implicit dependency. (#3189) (
Browse files Browse the repository at this point in the history
…#3211)

* Add implicit dependency

Signed-off-by: pgodithi <pgodithi@amazon.com>

* Add implicit dependency

Signed-off-by: pgodithi <pgodithi@amazon.com>

* Add implicit dependency

Signed-off-by: pgodithi <pgodithi@amazon.com>

* Add implicit dependency

Signed-off-by: pgodithi <pgodithi@amazon.com>

* Add implicit dependency

Signed-off-by: pgodithi <pgodithi@amazon.com>

* Add implicit dependency

Signed-off-by: pgodithi <pgodithi@amazon.com>

* Add dependsOn

Signed-off-by: pgodithi <pgodithi@amazon.com>
(cherry picked from commit 2fe2e37)

Co-authored-by: Prudhvi Godithi <pgodithi@amazon.com>
  • Loading branch information
1 parent 95b29ad commit 2e339df
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
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

0 comments on commit 2e339df

Please sign in to comment.