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

Gradle custom java zippublish plugin #2988

Merged
merged 65 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
d60eafe
Added custom plugin
prudhvigodithi Apr 18, 2022
4a61852
fixed failure checks
prudhvigodithi Apr 20, 2022
1e8c5f1
fixed failure checks
prudhvigodithi Apr 20, 2022
5e87cde
ref String to null
prudhvigodithi Apr 20, 2022
770c886
Added gradlePlugin config
prudhvigodithi Apr 20, 2022
342bc64
Added gradlePlugin config
prudhvigodithi Apr 20, 2022
a8647ec
Added gradlePlugin config
prudhvigodithi Apr 20, 2022
0865be2
Added zipFilePath injection
prudhvigodithi Apr 21, 2022
be37b91
Added custom plugin eval logic
prudhvigodithi Apr 21, 2022
8a7c18e
Added system property for version check
prudhvigodithi Apr 21, 2022
a43e651
spotlessApply check
prudhvigodithi Apr 21, 2022
a523ab1
Added custom plugin eval logic
prudhvigodithi Apr 21, 2022
e8a11b7
spotlessJavaCheck fix
prudhvigodithi Apr 21, 2022
cf9e291
Reverted back existing publish plugin
prudhvigodithi Apr 22, 2022
88d21d4
Added feedback code fix
prudhvigodithi Apr 22, 2022
056d06e
modified BUILD_DISTRIBUTIONS_LOCATION to zipDistributionLocation
prudhvigodithi Apr 22, 2022
edf9028
fix lint issues
prudhvigodithi Apr 22, 2022
6baf646
fix lint issues
prudhvigodithi Apr 22, 2022
f8a528c
changed the zip artifcat identify logic
prudhvigodithi Apr 22, 2022
ebd85a3
Changed the zip file identify logic
prudhvigodithi Apr 22, 2022
26d83ee
Changed the zip file identify logic
prudhvigodithi Apr 22, 2022
cf9ee09
Changed the zip file identify logic
prudhvigodithi Apr 22, 2022
1aeb73a
Changed the zip file identify logic
prudhvigodithi Apr 22, 2022
b98ab64
Changed the zip file identify logic
prudhvigodithi Apr 22, 2022
bdf32dd
Merge branch 'gradleplugin-2.2' of github.com:prudhvigodithi/OpenSear…
prudhvigodithi Apr 22, 2022
321ec96
Changed the zip file identify logic
prudhvigodithi Apr 22, 2022
5e97819
ran spotlessApply
prudhvigodithi Apr 22, 2022
9ccbf81
ran spotlessApply
prudhvigodithi Apr 22, 2022
8b85320
fix lint issues
prudhvigodithi Apr 23, 2022
4d83dd1
fix lint issues
prudhvigodithi Apr 23, 2022
ac2f151
fix lint issues
prudhvigodithi Apr 23, 2022
daa06c3
fix lint issues
prudhvigodithi Apr 23, 2022
88d4562
fix lint issues
prudhvigodithi Apr 23, 2022
dba1cac
fix lint issues
prudhvigodithi Apr 23, 2022
36a98f9
fix lint issues
prudhvigodithi Apr 23, 2022
5e3ca97
fix lint issues
prudhvigodithi Apr 23, 2022
f1da84e
fix lint issues
prudhvigodithi Apr 23, 2022
71b1337
fix lint issues
prudhvigodithi Apr 23, 2022
15cd29f
fix lint issues
prudhvigodithi Apr 23, 2022
122d48f
fix lint issues
prudhvigodithi Apr 23, 2022
30ca4c6
fix lint issues
prudhvigodithi Apr 23, 2022
c733586
fix lint issues
prudhvigodithi Apr 23, 2022
89bf24a
fix lint issues
prudhvigodithi Apr 23, 2022
416e74e
fix lint issues
prudhvigodithi Apr 23, 2022
02a8234
fix lint issues
prudhvigodithi Apr 23, 2022
ad1e589
fix lint issues
prudhvigodithi Apr 23, 2022
2f9bca8
fix lint issues
prudhvigodithi Apr 23, 2022
ed0d1b0
fix lint issues
prudhvigodithi Apr 23, 2022
4445608
fix lint issues
prudhvigodithi Apr 23, 2022
b48cf2e
fix lint issues
prudhvigodithi Apr 23, 2022
710611c
fix lint issues
prudhvigodithi Apr 23, 2022
b61104d
fix lint issues
prudhvigodithi Apr 23, 2022
eb17f5a
fix lint issues
prudhvigodithi Apr 23, 2022
bfb812d
fix lint issues
prudhvigodithi Apr 23, 2022
740516e
fix lint issues
prudhvigodithi Apr 23, 2022
3071a55
fix lint issues
prudhvigodithi Apr 23, 2022
c2b5121
Code cleanup
prudhvigodithi Apr 23, 2022
f44aa2a
Code cleanup
prudhvigodithi Apr 23, 2022
303465f
Code cleanup
prudhvigodithi Apr 23, 2022
8f4a8d3
Code cleanup typos
prudhvigodithi Apr 23, 2022
7f87df9
Merge branch 'gradleplugin-2.2' of github.com:prudhvigodithi/OpenSear…
prudhvigodithi Apr 24, 2022
9b1cb92
code cleanup and extended unit tests
prudhvigodithi Apr 26, 2022
c866641
code cleanup and extended unit tests
prudhvigodithi Apr 26, 2022
9f32f4d
Naming convention fix
prudhvigodithi Apr 26, 2022
cdac61d
Naming convention fix
prudhvigodithi Apr 26, 2022
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 @@ -49,6 +49,7 @@
public class TestWithSslPlugin implements Plugin<Project> {

@Override
@SuppressWarnings({ "unchecked" })
prudhvigodithi marked this conversation as resolved.
Show resolved Hide resolved
public void apply(Project project) {
File keyStoreDir = new File(project.getBuildDir(), "keystore");
TaskProvider<ExportOpenSearchBuildResourcesTask> exportKeyStore = project.getTasks()
Expand Down
32 changes: 17 additions & 15 deletions buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,25 @@ public String call() throws Exception {
});
});
});

publishing.getPublications().withType(MavenPublication.class, publication -> {
// Add git origin info to generated POM files
publication.getPom().withXml(PublishPlugin::addScmInfo);

// have to defer this until archivesBaseName is set
project.afterEvaluate(p -> publication.setArtifactId(getArchivesBaseName(project)));

// publish sources and javadoc for Java projects.
if (project.getPluginManager().hasPlugin("opensearch.java")) {
publication.artifact(project.getTasks().getByName("sourcesJar"));
publication.artifact(project.getTasks().getByName("javadocJar"));
// To exclude java artifcats for maven zip type publications
String zipPublicationSearch = "zip";
if (!publication.getName().toLowerCase().contains(zipPublicationSearch.toLowerCase())) {
prudhvigodithi marked this conversation as resolved.
Show resolved Hide resolved
// Add git origin info to generated POM files
publication.getPom().withXml(PublishPlugin::addScmInfo);

// have to defer this until archivesBaseName is set
project.afterEvaluate(p -> publication.setArtifactId(getArchivesBaseName(project)));

// publish sources and javadoc for Java projects.
if (project.getPluginManager().hasPlugin("opensearch.java")) {
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())))
);
prudhvigodithi marked this conversation as resolved.
Show resolved Hide resolved
});

}
Expand Down
146 changes: 146 additions & 0 deletions buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublish.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
prudhvigodithi marked this conversation as resolved.
Show resolved Hide resolved

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.gradle.zipplugin;

import java.util.*;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.publish.PublishingExtension;
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 ZipPublish implements Plugin<Project> {
private Project project;

public final static String EXTENSION_NAME = "zipmavensettings";
public final static String PUBLICATION_NAME = "mavenzip";
public final static String STAGING_REPO = "zipstaging";
public final static String MAVEN_ZIP_PUBLISH_TASK = "publish"
+ ZipPublishUtil.capitalize(PUBLICATION_NAME)
+ "PublicationTo"
+ ZipPublishUtil.capitalize(STAGING_REPO)
+ "Repository";
public final static String MAVEN_ZIP_PUBLISH_POM_TASK = "generatePomFileFor"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcode generatePomFileForMavenZipPublication, get rid of ZipPublishUtil

+ ZipPublishUtil.capitalize(PUBLICATION_NAME)
+ "Publication";
public final static String LOCALMAVEN = "publishToMavenLocal";
public final static String LOCAL_STAGING_REPO_PATH = "/build/local-staging-repo";
public static String BUILD_DISTRIBUTIONS_LOCATION = "/build/distributions/";

private void configMaven() {
final Path buildDirectory = this.project.getRootDir().toPath();
this.project.getPluginManager().apply(MavenPublishPlugin.class);
this.project.getExtensions().configure(PublishingExtension.class, publishing -> {
publishing.repositories(repositories -> {
repositories.maven(maven -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need LOCAL_STAGING_REPO_PATH? I assume we should use appropriate Maven repository (local or not)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reta LOCAL_STAGING_REPO_PATH = "/build/local-staging-repo";, this is a file system path, that we consider as a local staging repo, for maven (in terms on maven terminology) its just a publication repo, so considering this local-staging-repo which is added across build scripts I have added LOCAL_STAGING_REPO_PATH, which denotes that its a filesystem path for locally staging the artifacts.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly what is unclear: there is a clear notion of Maven repository (for publishing), why we need staging one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So right now with the code flow and process, we dont directly publish to end maven repo, we create a local staging repo on filesystem, publish the artifacts to this local staging repo and using CI, having secure creds republish the artifacts from local maven repo to actual nexus maven repo.
Example: https://github.com/opensearch-project/job-scheduler/blob/main/scripts/build.sh#L71-L73

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks @prudhvigodithi , not much we can do about it ...

maven.setName(STAGING_REPO);
maven.setUrl(buildDirectory.toString() + LOCAL_STAGING_REPO_PATH);
});
});
System.out.println("Starting " + MAVEN_ZIP_PUBLISH_TASK + " task");
prudhvigodithi marked this conversation as resolved.
Show resolved Hide resolved
publishing.publications(publications -> {
publications.create(PUBLICATION_NAME, MavenPublication.class, mavenZip -> {
ZipPublishExtension extset = this.project.getExtensions().findByType(ZipPublishExtension.class);
// Getting the Zip group from created extension
String zipGroup = extset.getZipgroup();
String zipArtifact = getProperty("zipArtifact");
// Getting the Zip version from gradle property with/without added snapshot and qualifier
String zipVersion = System.getProperty("opensearch.version");
String version = null;
String extraSuffix = null;
if (zipVersion != null) {
StringTokenizer st = new StringTokenizer(zipVersion);
version = st.nextToken("-") + ".0";
try {
extraSuffix = zipVersion.substring(zipVersion.indexOf("-"));
} catch (Exception e) {
System.out.println("");
}
}
String finalZipVersion = version + extraSuffix;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is backwards. You have access to version and qualifier properties, so the last thing you should be doing is parsing the ZIP filename. Build the correct version from those.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dblock, the $VERSION currently already has the qualifier and snapshot info ex 2.0.0-rc1-SNAPSHOT, it will save some flags for running the task and would reduce the human errors
Now a user just need to pass ./gradlew publishMavenzipPublicationToZipstagingRepository -Dopensearch.version=$VERSION , dont need to pass any additional flags.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have it backwards. When I do ./gradlew publishMavenzipPublicationToZipstagingRepository -Dopensearch.version=2.0.0 the output is -2.0.0.zip, but when I do ./gradlew publishMavenzipPublicationToZipstagingRepository -Dopensearch.version=2.0.0 -Dbuild.version_qualifier=rc1 the output is -2.0.0-rc1.zip. All this version parsing you're trying to do is not necessary.

I believe what you want here is VersionProperties.getOpenSearch() - see how it's used all over the place in .gradle scripts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version that is getting passed has the value as VERSION=2.0.0-alpha1-SNAPSHOT, not just 2.0.0, hence I went with that parsing logic as in $VERSION itself I can get the qualifier and snapshot info.
so now a user need not pass all other flags version_qualifier and build.snapshot. I can try with VersionProperties.getOpenSearch(), but again it this only gives just the version number, then we expect a user to add the other flags to execute the task.

Copy link
Member Author

@prudhvigodithi prudhvigodithi Apr 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the existing task bundlePlugin coming from PluginBuildPlugin, the output is an generated as a zip file, I have added the publish artifact to look for this output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zipArtifact name will be the project root name and version is the gradle property of the project.

String zipFilePath = null;
// -PzipFilePath=/build/distributions/opensearch-job-scheduler-2.0.0.0-alpha1-SNAPSHOT.zip
if (getProperty("zipFilePath") != null) {
BUILD_DISTRIBUTIONS_LOCATION = getProperty("zipFilePath");
zipFilePath = BUILD_DISTRIBUTIONS_LOCATION + zipArtifact + "-" + finalZipVersion + ".zip";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is the same, just BUILD_DISTRIBUTIONS_LOCATION changes.

All these CAPITALIZED variables are weird. Only CONSTANTS should be capitalized and I suspect half of them aren't needed anyway. Cleanup.

Copy link
Member Author

@prudhvigodithi prudhvigodithi Apr 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have considered them as constants (using variable modifiers static and final ) :)
As these vars are constants, and have added final to them, these are referenced throughout the code once or multiple times, also these should not be changed moving forward with any logic, hence considering these I have CAPITALIZED them. Please correct me if my though process is wrong, tomorrow if we have to change some name setting, staging repo settings and distributions path, all we need is to just update the constants, no need to touch the actual methods.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this example BUILD_DISTRIBUTIONS_LOCATION is not a constant. You declared it in the class as public static String BUILD_DISTRIBUTIONS_LOCATION = "/build/distributions/"; and you are reassigning it here as BUILD_DISTRIBUTIONS_LOCATION = getProperty("zipFilePath");.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with BUILD_DISTRIBUTIONS_LOCATION, also when I read back again, better it would be as zipDistributionLocation, fixed this in my latest commit.

} else {
zipFilePath = BUILD_DISTRIBUTIONS_LOCATION + zipArtifact + "-" + finalZipVersion + ".zip";
}
mavenZip.artifact(buildDirectory.toString() + zipFilePath);
mavenZip.setGroupId(zipGroup);
mavenZip.setArtifactId(zipArtifact);
mavenZip.setVersion(finalZipVersion);
});
});
});
}

// function to get Project properties
private String getProperty(String name) {
if (this.project.hasProperty(name)) {
Object property = this.project.property(name);
if (property != null) {
return property.toString();
}
}
return null;
}

@Override
public void apply(Project project) {
final Path buildDirectory = project.getRootDir().toPath();
this.project = project;
project.getExtensions().create(EXTENSION_NAME, ZipPublishExtension.class);
// Applies the new publication once the plugin is applied
configMaven();
Task compileJava = project.getTasks().findByName("compileJava");
if (compileJava != null) {
compileJava.setEnabled(false);
}
Task sourceJarTask = project.getTasks().findByName("sourcesJar");
if (sourceJarTask != null) {
sourceJarTask.setEnabled(false);
}
Task javaDocJarTask = project.getTasks().findByName("javadocJar");
if (javaDocJarTask != null) {
javaDocJarTask.setEnabled(false);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will conflict when multiple publication tasks are run. Care to explain what breaks if, for example, sourceJarTask.setEnabled(false); is not here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, anyhow I see we are not publishing the generated sourcesJar and javadocJar to actual nexus maven repo, this publish code will ignore these jars before uploading them to nexus, so ideally these just exists on the local staging repo (filesystem) and not in maven repo.
We can also proceed to remove the task suspension from plugin code which will cause no harm but along with zips, javadocJar and sourcesJar are also included to local staging repo, and off course we stop them from publishing to nexus with the existing publish code .
The other way is remove the task suspension and allow users to declare the suspension at their own will in their gradle project globally in settings .gradle as startParameter.excludedTaskNames=["sourcesJar", "javadocJar"] or from task using ./gradlew publishMavenzipPublicationToZipstagingRepository -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER -x sourcesJar -x javadocJar
So there are multiple options go with.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prudhvigodithi

I mean, anyhow I see we are not publishing the generated sourcesJar and javadocJar to actual nexus maven repo ...

For plugins we do [1] (and for everything else as well), probably we only skip that for snapshots:

mapper-size-1.3.1-javadoc.jar 2022-03-30 20:38 414035
mapper-size-1.3.1-javadoc.jar.asc 2022-03-30 20:38 287
mapper-size-1.3.1-javadoc.jar.md5 2022-03-30 20:38 32
mapper-size-1.3.1-javadoc.jar.sha1 2022-03-30 20:38 40
mapper-size-1.3.1-javadoc.jar.sha256 2022-03-30 20:38 64
mapper-size-1.3.1-javadoc.jar.sha512 2022-03-30 20:38 128
mapper-size-1.3.1-sources.jar 2022-03-30 20:38 8245
mapper-size-1.3.1-sources.jar.asc 2022-03-30 20:38 287
mapper-size-1.3.1-sources.jar.md5 2022-03-30 20:38 32
mapper-size-1.3.1-sources.jar.sha1 2022-03-30 20:38 40
mapper-size-1.3.1-sources.jar.sha256 2022-03-30 20:38 64
mapper-size-1.3.1-sources.jar.sha512 2022-03-30 20:38 128
mapper-size-1.3.1.jar 2022-03-30 20:38 10416
mapper-size-1.3.1.jar.asc 2022-03-30 20:38 287
mapper-size-1.3.1.jar.md5 2022-03-30 20:38 32
mapper-size-1.3.1.jar.sha1 2022-03-30 20:38 40
mapper-size-1.3.1.jar.sha256 2022-03-30 20:38 64
mapper-size-1.3.1.jar.sha512 2022-03-30 20:38 128

We should not disable that.

[1] https://repo1.maven.org/maven2/org/opensearch/plugin/mapper-size/1.3.1/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks @reta, this info really helps, I can see them on releases repo as well example: https://aws.oss.sonatype.org/content/repositories/releases/org/opensearch/opensearch-job-scheduler/1.3.0.0/.

Copy link
Member Author

@prudhvigodithi prudhvigodithi Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So based on this @reta and @dblock we should be going back to my previous changes to actually modify the existing PublishPlugin to avoid publication artifact's of sourcesJar and javadocJar if the publication is for zip.
We should be removing the setEnabled(false) from the plugin code.

To refer here are the changes we need to add to existing PublishPlugin, to make the sourcesJar and javadocJar are still enabled for other publications but not zip, changes are

https://github.com/prudhvigodithi/OpenSearch/blob/gradleplugin-2.3/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java#L124-L145

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the above change for PublishPlugin and tested job-scheduler, anomaly-detection and alerting, looks good just published the zip and not the sourcesJar and javadocJar along with zips, but they are added for jar maven publication, so no interruption for existing jar publications.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this change here, am I missing something?

project.getGradle().getTaskGraph().whenReady(graph -> {
if (graph.hasTask(LOCALMAVEN)) {
project.getTasks().getByName(MAVEN_ZIP_PUBLISH_POM_TASK).setEnabled(false);
}

});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.gradle.zipplugin;

public class ZipPublishExtension {
Copy link
Collaborator

@reta reta Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace zip terminology with PluginDistribution since this is reflects what exactly we intend to publish and where is it applicable, fe PublishPluginDistributionExtension, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since i have organized as folder under zippublish/ I guess it should be good, the entire effort of this plugin is to publish the zips, hence added with start Zip :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the notion of zip is implementation detail, what we are developing is publication mechanism for plugin distribution

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have add the java classes based on plugin name zippublish (with camel case), how about this ZipPublishPluginDistributionExtension @reta ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am with @reta and would call this PluginDistributionExtension


private String zipGroup = "org.opensearch.plugin";

public void setZipgroup(String zipGroup) {
this.zipGroup = zipGroup;
}

public String getZipgroup() {
prudhvigodithi marked this conversation as resolved.
Show resolved Hide resolved
return zipGroup;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.gradle.zipplugin;

class ZipPublishUtil {

static String capitalize(String str) {
return str.substring(0, 1).toUpperCase() + str.substring(1);
}

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you call this with well known values, so just hard-code those values and remove this method.

Copy link
Member Author

@prudhvigodithi prudhvigodithi Apr 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Util's I have added in consideration for future as well, we might need to merge the existing publish task and this zippublish plugin to one common plugin, so then these handy Util's will come into picture. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Publication name is a constant, public final static String PUBLICATION_NAME = "mavenzip";.
  2. MAVEN_ZIP_PUBLISH_POM_TASK is a constant that uses that, public final static String MAVEN_ZIP_PUBLISH_POM_TASK = "generatePomFileFor" + ZipPublishUtil.capitalize(PUBLICATION_NAME) + "Publication";
  3. So nothing is dynamic that needs to call capitalize, just do
public final static String PUBLICATION_NAME = "mavenzip";
public final static String MAVEN_ZIP_PUBLISH_POM_TASK = "generatePomFileForMavenZipPublication";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

off course I can hardcode them, but if we change the PUBLICATION_NAME, then its expected from user to also modify MAVEN_ZIP_PUBLISH_POM_TASK to fix the publication, hence I added the Util.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we ever want to change these constants? I think you're over-optimizing for a complicated future problem by adding a new method (and no tests for it).

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implementation-class=org.opensearch.gradle.zipplugin.ZipPublish
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.gradle.zipplugin;

import org.gradle.testfixtures.ProjectBuilder
import org.gradle.api.Project


class ZipPublishTest {
public void zippublish_plugin_should_add_task_to_project() {
prudhvigodithi marked this conversation as resolved.
Show resolved Hide resolved
Project project = ProjectBuilder.builder().build()
project.getPlugins().apply 'opensearch.zippublish'

assertTrue(project.tasks.publishMavenzipPublicationToZipstagingRepository instanceof ZipPublish)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to write tests that ensure that this new plugin actually works.

Copy link
Member Author

@prudhvigodithi prudhvigodithi Apr 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}